diff --git a/gso/services/kentik_client.py b/gso/services/kentik_client.py index f1a1f15862e94583de90175711e341cdbe51e472..be289e5c6f8562e0b2dc0fad9c34258a04b70d76 100644 --- a/gso/services/kentik_client.py +++ b/gso/services/kentik_client.py @@ -144,7 +144,7 @@ class KentikClient: """Update an existing device in Kentik.""" return self._send_request("PUT", f"v5/device/{device_id}", updated_device).json() - def remove_device(self, device_id: str, *, archive: bool = True) -> None: + def remove_device(self, device_id: str, *, archive: bool) -> None: """Remove a device from Kentik. :param str device_id: The Kentik internal ID of the device that is to be removed. diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py index b9e521da831dbcc091286c21cb2d67862b963074..fb6a425a92445a9ca6f7b22d70e2c0e40672894f 100644 --- a/gso/workflows/router/terminate_router.py +++ b/gso/workflows/router/terminate_router.py @@ -20,6 +20,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form from gso.products.product_types.router import Router from gso.services import infoblox +from gso.services.kentik_client import KentikClient from gso.services.lso_client import execute_playbook, lso_interaction from gso.services.netbox_client import NetboxClient from gso.utils.shared_enums import Vendor @@ -104,6 +105,12 @@ def remove_device_from_netbox(subscription: Router) -> dict[str, Router]: return {"subscription": subscription} +@step("Archive device in Kentik") +def remove_device_from_kentik(subscription: Router) -> None: + """Archive the device in Kentik.""" + KentikClient().remove_device(subscription.router.router_fqdn, archive=True) + + @workflow( "Terminate router", initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator), @@ -128,6 +135,7 @@ def terminate_router() -> StepList: >> run_config_steps(lso_interaction(remove_config_from_router_dry)) >> run_config_steps(lso_interaction(remove_config_from_router_real)) >> router_is_nokia(remove_device_from_netbox) + >> remove_device_from_kentik >> set_status(SubscriptionLifecycle.TERMINATED) >> resync >> done diff --git a/test/workflows/router/test_terminate_router.py b/test/workflows/router/test_terminate_router.py index e52826820084981798541f1189a134eda5d1d9c0..ccdf99224ba787da3f822083254132d56627e111 100644 --- a/test/workflows/router/test_terminate_router.py +++ b/test/workflows/router/test_terminate_router.py @@ -11,7 +11,9 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr @patch("gso.services.lso_client._send_request") @patch("gso.workflows.router.terminate_router.NetboxClient.delete_device") @patch("gso.workflows.router.terminate_router.infoblox.delete_host_by_ip") +@patch("gso.workflows.router.terminate_router.KentikClient") def test_terminate_router_full_success( + mock_kentik_client, mock_delete_host_by_ip, mock_delete_device, mock_execute_playbook, @@ -44,4 +46,5 @@ def test_terminate_router_full_success( assert subscription.status == "terminated" assert mock_delete_device.call_count == 1 assert mock_delete_host_by_ip.call_count == 1 + assert mock_kentik_client.call_count == 1 assert mock_execute_playbook.call_count == lso_interaction_count