From 51ffc223341f9012f8a2113917fbc5b3328009db Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Wed, 27 Dec 2023 11:38:24 +0100
Subject: [PATCH] use a conditional to skip a step in terminate_router

---
 gso/workflows/router/create_router.py    |  3 +--
 gso/workflows/router/terminate_router.py | 13 ++++++-------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py
index 8b37cd07..e1f5efb7 100644
--- a/gso/workflows/router/create_router.py
+++ b/gso/workflows/router/create_router.py
@@ -2,12 +2,11 @@
 
 from typing import Any
 
-# noinspection PyProtectedMember
 from orchestrator.forms import FormPage
 from orchestrator.forms.validators import Choice
 from orchestrator.targets import Target
 from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
-from orchestrator.workflow import StepList, done, init, step, workflow, conditional
+from orchestrator.workflow import StepList, conditional, done, init, step, workflow
 from orchestrator.workflows.steps import resync, set_status, store_process_subscription
 from orchestrator.workflows.utils import wrap_create_initial_input_form
 from pydantic import validator
diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py
index b258cf76..b7d70d1e 100644
--- a/gso/workflows/router/terminate_router.py
+++ b/gso/workflows/router/terminate_router.py
@@ -26,7 +26,7 @@ logger = logging.getLogger(__name__)
 
 def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
     """Let the operator decide whether to delete configuration on the router, and clear up :term:`IPAM` resources."""
-    Router.from_subscription(subscription_id)
+    router = Router.from_subscription(subscription_id)
 
     class TerminateForm(FormPage):
         termination_label: Label = (
@@ -38,7 +38,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
         clean_up_ipam: bool = True
 
     user_input = yield TerminateForm
-    return user_input.dict()
+    return user_input.dict() | {"router_is_nokia": router.router.vendor == RouterVendor.NOKIA}
 
 
 @step("Deprovision loopback IPs from IPAM")
@@ -58,12 +58,10 @@ def remove_config_from_router() -> None:
     """
 
 
-@step("Remove Device from NetBox")
+@step("Remove Device from Netbox")
 def remove_device_from_netbox(subscription: Router) -> dict[str, Router]:
     """Remove the device from Netbox."""
-    if subscription.router.vendor == RouterVendor.NOKIA:
-        #  TODO: This should be solved with a conditional
-        NetboxClient().delete_device(subscription.router.router_fqdn)
+    NetboxClient().delete_device(subscription.router.router_fqdn)
     return {"subscription": subscription}
 
 
@@ -82,6 +80,7 @@ def terminate_router() -> StepList:
     """
     run_ipam_steps = conditional(lambda state: state["clean_up_ipam"])
     run_config_steps = conditional(lambda state: state["remove_configuration"])
+    router_is_nokia = conditional(lambda state: state["router_is_nokia"])
 
     return (
         init
@@ -89,7 +88,7 @@ def terminate_router() -> StepList:
         >> unsync
         >> run_ipam_steps(deprovision_loopback_ips)
         >> run_config_steps(remove_config_from_router)
-        >> remove_device_from_netbox
+        >> router_is_nokia(remove_device_from_netbox)
         >> set_status(SubscriptionLifecycle.TERMINATED)
         >> resync
         >> done
-- 
GitLab