Skip to content
Snippets Groups Projects
Verified Commit c66483df authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Add Kentik device removal to router termination workflow

parent a6da314a
No related branches found
No related tags found
No related merge requests found
Pipeline #88075 failed
...@@ -144,7 +144,7 @@ class KentikClient: ...@@ -144,7 +144,7 @@ class KentikClient:
"""Update an existing device in Kentik.""" """Update an existing device in Kentik."""
return self._send_request("PUT", f"v5/device/{device_id}", updated_device).json() 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. """Remove a device from Kentik.
:param str device_id: The Kentik internal ID of the device that is to be removed. :param str device_id: The Kentik internal ID of the device that is to be removed.
......
...@@ -20,6 +20,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form ...@@ -20,6 +20,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form
from gso.products.product_types.router import Router from gso.products.product_types.router import Router
from gso.services import infoblox 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.lso_client import execute_playbook, lso_interaction
from gso.services.netbox_client import NetboxClient from gso.services.netbox_client import NetboxClient
from gso.utils.shared_enums import Vendor from gso.utils.shared_enums import Vendor
...@@ -104,6 +105,12 @@ def remove_device_from_netbox(subscription: Router) -> dict[str, Router]: ...@@ -104,6 +105,12 @@ def remove_device_from_netbox(subscription: Router) -> dict[str, Router]:
return {"subscription": subscription} 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( @workflow(
"Terminate router", "Terminate router",
initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator), initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator),
...@@ -128,6 +135,7 @@ def terminate_router() -> StepList: ...@@ -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_dry))
>> run_config_steps(lso_interaction(remove_config_from_router_real)) >> run_config_steps(lso_interaction(remove_config_from_router_real))
>> router_is_nokia(remove_device_from_netbox) >> router_is_nokia(remove_device_from_netbox)
>> remove_device_from_kentik
>> set_status(SubscriptionLifecycle.TERMINATED) >> set_status(SubscriptionLifecycle.TERMINATED)
>> resync >> resync
>> done >> done
......
...@@ -11,7 +11,9 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr ...@@ -11,7 +11,9 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr
@patch("gso.services.lso_client._send_request") @patch("gso.services.lso_client._send_request")
@patch("gso.workflows.router.terminate_router.NetboxClient.delete_device") @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.infoblox.delete_host_by_ip")
@patch("gso.workflows.router.terminate_router.KentikClient")
def test_terminate_router_full_success( def test_terminate_router_full_success(
mock_kentik_client,
mock_delete_host_by_ip, mock_delete_host_by_ip,
mock_delete_device, mock_delete_device,
mock_execute_playbook, mock_execute_playbook,
...@@ -44,4 +46,5 @@ def test_terminate_router_full_success( ...@@ -44,4 +46,5 @@ def test_terminate_router_full_success(
assert subscription.status == "terminated" assert subscription.status == "terminated"
assert mock_delete_device.call_count == 1 assert mock_delete_device.call_count == 1
assert mock_delete_host_by_ip.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 assert mock_execute_playbook.call_count == lso_interaction_count
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment