diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py index ad374f23f11623074131c414f10c1ee208798272..56f927d8fafd06f54400b1ff34e34bade725a901 100644 --- a/gso/workflows/router/terminate_router.py +++ b/gso/workflows/router/terminate_router.py @@ -8,6 +8,7 @@ from orchestrator.forms import FormPage from orchestrator.forms.validators import Label from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr +from orchestrator.utils.errors import ProcessFailureError from orchestrator.utils.json import json_dumps from orchestrator.workflow import StepList, begin, conditional, done, step, workflow from orchestrator.workflows.steps import ( @@ -223,13 +224,19 @@ def remove_pe_from_all_p_real(subscription: Router, tt_number: str, process_id: @step("Remove Device from Librenms") -def remove_device_from_librenms(subscription: Router) -> State | None: +def remove_device_from_librenms(subscription: Router) -> State: """Remove the device from LibreNMS.""" try: LibreNMSClient().remove_device(subscription.router.router_fqdn) except HTTPError as e: - return {"librenms_error": str(e)} - return None + response = e.response.json() + if response["message"] == f"Device {subscription.router.router_fqdn} not found": + return { + "librenms_error": str(e.response.json()), + "librenms_device": "Device not found, please confirm nothing needs to be removed from LibreNMS", + } + raise ProcessFailureError(message="LibreNMS error", details=response) from None + return {"librenms_device": "Device removed from LibreNMS"} @step("Apply the archiving license in Kentik")