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

fill in workflow steps for removing configuration from a terminated router,...

fill in workflow steps for removing configuration from a terminated router, and update the unit test
parent 861faf77
Branches
Tags
1 merge request!136Run playbook when terminating router
"""A workflow that terminates a router."""
import ipaddress
import json
import logging
from orchestrator.forms import FormPage
from orchestrator.forms.validators import Label
from orchestrator.targets import Target
from orchestrator.types import FormGenerator, SubscriptionLifecycle, UUIDstr
from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, conditional, done, init, step, workflow
from orchestrator.workflows.steps import (
resync,
......@@ -20,6 +22,7 @@ from gso.products.product_blocks.router import RouterVendor
from gso.products.product_types.router import Router
from gso.services import infoblox
from gso.services.netbox_client import NetboxClient
from gso.services.provisioning_proxy import execute_playbook, pp_interaction
logger = logging.getLogger(__name__)
......@@ -49,13 +52,46 @@ def deprovision_loopback_ips(subscription: Router) -> dict:
return {"subscription": subscription}
@step("Remove configuration from router")
def remove_config_from_router() -> None:
"""Remove configuration from the router, first as a dry run.
@step("[DRY RUN] Remove configuration from router")
def remove_config_from_router_dry(
subscription: Router, callback_route: str, process_id: UUIDstr, tt_number: str
) -> None:
"""Remove configuration from the router, first as a dry run."""
extra_vars = {
"wfo_router_json": json.loads(json_dumps(subscription)),
"dry_run": True,
"verb": "terminate",
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Terminating "
f"{subscription.router.router_fqdn}",
}
execute_playbook(
playbook_name="base_config.yaml",
callback_route=callback_route,
inventory=subscription.router.router_fqdn,
extra_vars=extra_vars,
)
FIXME: Add actual content
TODO: update unit test accordingly
"""
@step("[FOR REAL] Remove configuration from router")
def remove_config_from_router_real(
subscription: Router, callback_route: str, process_id: UUIDstr, tt_number: str
) -> None:
"""Remove configuration from the router."""
extra_vars = {
"wfo_router_json": json.loads(json_dumps(subscription)),
"dry_run": False,
"verb": "terminate",
"commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Terminating "
f"{subscription.router.router_fqdn}",
}
execute_playbook(
playbook_name="base_config.yaml",
callback_route=callback_route,
inventory=subscription.router.router_fqdn,
extra_vars=extra_vars,
)
@step("Remove Device from Netbox")
......@@ -87,7 +123,8 @@ def terminate_router() -> StepList:
>> store_process_subscription(Target.TERMINATE)
>> unsync
>> run_ipam_steps(deprovision_loopback_ips)
>> run_config_steps(remove_config_from_router)
>> run_config_steps(pp_interaction(remove_config_from_router_dry))
>> run_config_steps(pp_interaction(remove_config_from_router_real))
>> router_is_nokia(remove_device_from_netbox)
>> set_status(SubscriptionLifecycle.TERMINATED)
>> resync
......
......@@ -3,38 +3,36 @@ from unittest.mock import patch
import pytest
from gso.products import Router
from test.workflows import assert_complete, extract_state, run_workflow
@pytest.fixture()
def router_termination_input_form_data(site_subscription_factory, faker):
return {
"tt_number": faker.tt_number(),
"remove_configuration": True,
"clean_up_ipam": True,
}
from test.workflows import assert_complete, extract_state, run_workflow, assert_pp_interaction_success
@pytest.mark.workflow()
@patch("gso.services.provisioning_proxy._send_request")
@patch("gso.workflows.router.terminate_router.NetboxClient.delete_device")
@patch("gso.workflows.router.terminate_router.infoblox.delete_host_by_ip")
def test_terminate_router_success(
def test_terminate_router_full_success(
mock_delete_host_by_ip,
mock_delete_device,
router_termination_input_form_data,
mock_execute_playbook,
nokia_router_subscription_factory,
faker,
data_config_filename,
):
# Set up active subscription in database
product_id = nokia_router_subscription_factory()
router_termination_input_form_data = {
"tt_number": faker.tt_number(),
"remove_configuration": True,
"clean_up_ipam": True,
}
# Run workflow
initial_router_data = [
{"subscription_id": product_id},
router_termination_input_form_data,
]
result, _, _ = run_workflow("terminate_router", initial_router_data)
initial_router_data = [{"subscription_id": product_id}, router_termination_input_form_data]
result, process_stat, step_log = run_workflow("terminate_router", initial_router_data)
for _ in range(2):
result, step_log = assert_pp_interaction_success(result, process_stat, step_log)
assert_complete(result)
state = extract_state(result)
......@@ -44,3 +42,4 @@ def test_terminate_router_success(
assert subscription.status == "terminated"
assert mock_delete_device.call_count == 1
assert mock_delete_host_by_ip.call_count == 1
assert mock_execute_playbook.call_count == 2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment