Skip to content
Snippets Groups Projects
Commit 6560462e authored by Karel van Klink's avatar Karel van Klink :smiley_cat: Committed by Neda Moeini
Browse files

Add Kentik device removal to router termination workflow

parent 9ee9b344
No related branches found
No related tags found
1 merge request!235Add a Kentik service to GSO
......@@ -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.
......
......@@ -21,6 +21,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form
from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router
from gso.services import infoblox, lso_client
from gso.services.kentik_client import KentikClient
from gso.services.librenms_client import LibreNMSClient
from gso.services.lso_client import execute_playbook, lso_interaction
from gso.services.netbox_client import NetboxClient
......@@ -237,6 +238,12 @@ def remove_device_from_librenms(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),
......@@ -271,6 +278,7 @@ def terminate_router() -> StepList:
>> run_config_steps(lso_interaction(remove_config_from_router_real))
>> router_is_nokia(remove_device_from_netbox)
>> remove_device_from_librenms
>> remove_device_from_kentik
>> set_status(SubscriptionLifecycle.TERMINATED)
>> resync
>> done
......
......@@ -14,7 +14,9 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr
@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.LibreNMSClient.remove_device")
@patch("gso.workflows.router.terminate_router.KentikClient")
def test_terminate_pe_router_full_success(
mock_kentik_client,
mock_librenms_remove_device,
mock_delete_host_by_ip,
mock_delete_device,
......@@ -54,6 +56,7 @@ def test_terminate_pe_router_full_success(
assert mock_delete_device.call_count == 1
assert mock_delete_host_by_ip.call_count == 1
assert mock_librenms_remove_device.call_count == 1
assert mock_kentik_client.call_count == 1
assert mock_execute_playbook.call_count == lso_interaction_count
......@@ -61,6 +64,7 @@ def test_terminate_pe_router_full_success(
@pytest.mark.parametrize("remove_configuration", [True, False])
@pytest.mark.parametrize("update_ibgp_mesh", [True, False])
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.router.terminate_router.KentikClient")
@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.LibreNMSClient.remove_device")
......@@ -68,6 +72,7 @@ def test_terminate_p_router_full_success(
mock_librenms_remove_device,
mock_delete_host_by_ip,
mock_delete_device,
mock_kentik_client,
mock_execute_playbook,
remove_configuration,
update_ibgp_mesh,
......@@ -104,4 +109,5 @@ def test_terminate_p_router_full_success(
assert mock_delete_device.call_count == 1
assert mock_delete_host_by_ip.call_count == 1
assert mock_librenms_remove_device.call_count == 1
assert mock_kentik_client.call_count == 1
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.
Finish editing this message first!
Please register or to comment