From 3d1d07b9b6b4a58958bbb5d0fe54671a3b7745de Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Wed, 27 Dec 2023 11:25:12 +0100
Subject: [PATCH] use conditional to skip step in create_router workflow

---
 gso/workflows/router/create_router.py | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py
index 72f9dd9b..8b37cd07 100644
--- a/gso/workflows/router/create_router.py
+++ b/gso/workflows/router/create_router.py
@@ -7,7 +7,7 @@ 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
+from orchestrator.workflow import StepList, done, init, step, workflow, conditional
 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
@@ -126,16 +126,11 @@ def ipam_allocate_loopback(subscription: RouterProvisioning) -> State:
 
 @step("Create NetBox Device")
 def create_netbox_device(subscription: RouterProvisioning) -> State:
-    """Create a new device in Netbox.
-
-    HACK: use a conditional instead for execution of this step
-    """
-    if subscription.router.vendor == RouterVendor.NOKIA:
-        NetboxClient().create_device(
-            subscription.router.router_fqdn,
-            str(subscription.router.router_site.site_tier),  # type: ignore[union-attr]
-        )
-        return {"subscription": subscription}
+    """Create a new NOKIA device in Netbox."""
+    NetboxClient().create_device(
+        subscription.router.router_fqdn,
+        str(subscription.router.router_site.site_tier),  # type: ignore[union-attr]
+    )
     return {"subscription": subscription}
 
 
@@ -163,6 +158,8 @@ def create_router() -> StepList:
     * Validate :term:`IPAM` resources
     * Create a new device in Netbox
     """
+    router_is_nokia = conditional(lambda state: state["vendor"] == RouterVendor.NOKIA)
+
     return (
         init
         >> create_subscription
@@ -172,7 +169,7 @@ def create_router() -> StepList:
         >> pp_interaction(deploy_base_config_dry)
         >> pp_interaction(deploy_base_config_real)
         >> verify_ipam_loopback
-        >> create_netbox_device
+        >> router_is_nokia(create_netbox_device)
         >> set_status(SubscriptionLifecycle.ACTIVE)
         >> resync
         >> done
-- 
GitLab