Skip to content

Commit f2b463a

Browse files
committed
custom exception example
1 parent 489c0ab commit f2b463a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

generic-orchestration-samples/setup/setup_call_health_check/dut_health_check.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
DUT_MODEL = "Putshell"
44

55

6+
class HealtCheckException(Exception):
7+
pass
8+
9+
610
# ========== Primary Function ==========
711
def run_dut_health_check(sandbox, components=None):
812
"""
@@ -18,12 +22,17 @@ def run_dut_health_check(sandbox, components=None):
1822
dut_resources = [resource for resource in resources
1923
if resource.ResourceModelName == DUT_MODEL]
2024
if not dut_resources:
21-
raise Exception("No Juniper")
25+
raise Exception("No DUT resource found")
2226

2327
dut1 = dut_resources[0]
2428

25-
api.ExecuteCommand(reservationId=res_id,
26-
targetName=dut1.Name,
27-
targetType="Resource",
28-
commandName="health_check",
29-
printOutput=True)
29+
try:
30+
api.ExecuteCommand(reservationId=res_id,
31+
targetName=dut1.Name,
32+
targetType="Resource",
33+
commandName="health_check",
34+
printOutput=True)
35+
except Exception as e:
36+
err_msg = f"Issue caught during health check. {str(e)}"
37+
api.WriteMessageToReservationOutput(err_msg)
38+
raise HealtCheckException(err_msg)

0 commit comments

Comments
 (0)