From 643926ad043e9f965c6662ad92df9c575c6ad6c4 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Wed, 20 Sep 2023 10:33:54 +0200
Subject: [PATCH] split off duplicate ISIS 90000 method

---
 Dockerfile                                 |  3 +--
 gso/services/provisioning_proxy.py         |  4 ++--
 gso/workflows/iptrunk/migrate_iptrunk.py   | 18 ++----------------
 gso/workflows/iptrunk/terminate_iptrunk.py | 21 ++++-----------------
 gso/workflows/iptrunk/utils.py             | 18 ++++++++++++++++++
 gso/workflows/router/terminate_router.py   |  4 +---
 6 files changed, 28 insertions(+), 40 deletions(-)
 create mode 100644 gso/workflows/iptrunk/utils.py

diff --git a/Dockerfile b/Dockerfile
index ae2cef11..e1ddb155 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -8,8 +8,7 @@ RUN pip install \
     geant-service-orchestrator==${ARTIFACT_VERSION}
 
 # Create the directory for the configuration and copy the example config into it
-# NOTE: a real config must be mounted at
-# /etc/gso/config.json when running the container
+# NOTE: a real config must be mounted at /etc/gso/config.json when running the container
 RUN mkdir -p /etc/gso
 COPY gso/oss-params-example.json /etc/gso/config.json
 
diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py
index 6bd5bd10..7ce76ac9 100644
--- a/gso/services/provisioning_proxy.py
+++ b/gso/services/provisioning_proxy.py
@@ -14,7 +14,7 @@ from orchestrator.forms import FormPage, ReadOnlyField
 from orchestrator.forms.validators import Accept, Label, LongText
 from orchestrator.types import FormGenerator, State, UUIDstr, strEnum
 from orchestrator.utils.json import json_dumps
-from orchestrator.workflow import Step, StepList, abort
+from orchestrator.workflow import Step, StepList, abort, init
 from pydantic import validator
 
 from gso import settings
@@ -340,7 +340,7 @@ def pp_interaction(provisioning_step: Step, attempts: int, abort_on_failure: boo
     """
     should_retry_pp_steps = conditional(lambda state: not state.get("pp_did_succeed"))
 
-    pp_steps = StepList([_reset_pp_success_state])
+    pp_steps = init >> _reset_pp_success_state
 
     for _ in range(attempts):
         pp_steps >>= (
diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py
index 948e9070..8b9fc6b4 100644
--- a/gso/workflows/iptrunk/migrate_iptrunk.py
+++ b/gso/workflows/iptrunk/migrate_iptrunk.py
@@ -18,6 +18,7 @@ from gso.products.product_types.iptrunk import Iptrunk
 from gso.products.product_types.router import Router
 from gso.services import provisioning_proxy
 from gso.services.provisioning_proxy import pp_interaction
+from gso.workflows.iptrunk.utils import set_isis_to_90000
 
 logger = getLogger(__name__)
 
@@ -115,19 +116,6 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
     return old_side_input.dict() | new_side_input.dict() | {"replace_index": replace_index}
 
 
-@step("[COMMIT] Set ISIS metric to 90000")
-def set_isis_to_9000(subscription: Iptrunk, process_id: UUIDstr, tt_number: str) -> State:
-    old_isis_metric = subscription.iptrunk.iptrunk_isis_metric
-    subscription.iptrunk.iptrunk_isis_metric = 90000
-    provisioning_proxy.provision_ip_trunk(subscription, process_id, tt_number, "isis_interface", False)
-
-    return {
-        "subscription": subscription,
-        "old_isis_metric": old_isis_metric,
-        "label_text": "ISIS is being set to 90K by the provisioning proxy, please wait for the results",
-    }
-
-
 @step("[DRY RUN] Disable configuration on old router")
 def disable_old_config_dry(
     subscription: Iptrunk,
@@ -425,15 +413,13 @@ def migrate_iptrunk() -> StepList:
         init
         >> store_process_subscription(Target.MODIFY)
         >> unsync
-        >> pp_interaction(set_isis_to_9000, 3)
+        >> pp_interaction(set_isis_to_90000, 3)
         >> pp_interaction(disable_old_config_dry, 3)
         >> pp_interaction(disable_old_config_real, 3)
         >> pp_interaction(deploy_new_config_dry, 3)
         >> pp_interaction(deploy_new_config_real, 3)
         >> confirm_continue_move_fiber
-        # >> pp_interaction(run_interface_checks, 3, False)
         >> pp_interaction(deploy_new_isis, 3)
-        # >> pp_interaction(check_isis, 3, False)
         >> confirm_continue_restore_isis
         >> pp_interaction(restore_isis_metric, 3)
         >> pp_interaction(delete_old_config_dry, 3)
diff --git a/gso/workflows/iptrunk/terminate_iptrunk.py b/gso/workflows/iptrunk/terminate_iptrunk.py
index 88e72e41..8ee23423 100644
--- a/gso/workflows/iptrunk/terminate_iptrunk.py
+++ b/gso/workflows/iptrunk/terminate_iptrunk.py
@@ -11,6 +11,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form
 from gso.products.product_types.iptrunk import Iptrunk
 from gso.services import infoblox, provisioning_proxy
 from gso.services.provisioning_proxy import pp_interaction
+from gso.workflows.iptrunk.utils import set_isis_to_90000
 
 
 def initial_input_form_generator() -> FormGenerator:
@@ -27,19 +28,6 @@ def initial_input_form_generator() -> FormGenerator:
     return user_input.dict()
 
 
-@step("[COMMIT] Set ISIS metric to 90000")
-def set_isis_to_9000(subscription: Iptrunk, process_id: UUIDstr, tt_number: str) -> State:
-    old_isis_metric = subscription.iptrunk.iptrunk_isis_metric
-    subscription.iptrunk.iptrunk_isis_metric = 90000
-    provisioning_proxy.provision_ip_trunk(subscription, process_id, tt_number, "isis_interface", False)
-
-    return {
-        "subscription": subscription,
-        "old_isis_metric": old_isis_metric,
-        "label_text": "ISIS is being set to 90K by the provisioning proxy, please wait for the results",
-    }
-
-
 @step("Drain traffic from trunk")
 def drain_traffic_from_ip_trunk(subscription: Iptrunk, process_id: UUIDstr, tt_number: str) -> State:
     provisioning_proxy.provision_ip_trunk(subscription, process_id, tt_number, "isis_interface", False)
@@ -94,13 +82,12 @@ def terminate_iptrunk() -> StepList:
     run_ipam_steps = conditional(lambda state: state["clean_up_ipam"])
 
     config_steps = (
-        # StepList([set_isis_to_9000])
-        StepList()
-        >> pp_interaction(set_isis_to_9000, 3)
+        init
+        >> pp_interaction(set_isis_to_90000, 3)
         >> pp_interaction(deprovision_ip_trunk_dry, 3)
         >> pp_interaction(deprovision_ip_trunk_real, 3)
     )
-    ipam_steps = StepList([deprovision_ip_trunk_ipv4, deprovision_ip_trunk_ipv6])
+    ipam_steps = init >> deprovision_ip_trunk_ipv4 >> deprovision_ip_trunk_ipv6
 
     return (
         init
diff --git a/gso/workflows/iptrunk/utils.py b/gso/workflows/iptrunk/utils.py
new file mode 100644
index 00000000..690cfc58
--- /dev/null
+++ b/gso/workflows/iptrunk/utils.py
@@ -0,0 +1,18 @@
+from orchestrator import step
+from orchestrator.types import State, UUIDstr
+
+from gso.products.product_types.iptrunk import Iptrunk
+from gso.services import provisioning_proxy
+
+
+@step("[COMMIT] Set ISIS metric to 90000")
+def set_isis_to_90000(subscription: Iptrunk, process_id: UUIDstr, tt_number: str) -> State:
+    old_isis_metric = subscription.iptrunk.iptrunk_isis_metric
+    subscription.iptrunk.iptrunk_isis_metric = 90000
+    provisioning_proxy.provision_ip_trunk(subscription, process_id, tt_number, "isis_interface", False)
+
+    return {
+        "subscription": subscription,
+        "old_isis_metric": old_isis_metric,
+        "label_text": "ISIS is being set to 90K by the provisioning proxy, please wait for the results",
+    }
diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py
index 8723ef5e..5d4c405e 100644
--- a/gso/workflows/router/terminate_router.py
+++ b/gso/workflows/router/terminate_router.py
@@ -69,9 +69,7 @@ def terminate_router() -> StepList:
     run_ias_removal = conditional(lambda state: state["subscription"]["router"]["router_is_ias_connected"])
 
     ipam_steps = (
-        StepList([deprovision_loopback_ips])
-        >> run_ias_removal(deprovision_si_ips)
-        >> run_ias_removal(deprovision_lt_ips)
+        init >> deprovision_loopback_ips >> run_ias_removal(deprovision_si_ips) >> run_ias_removal(deprovision_lt_ips)
     )
 
     return (
-- 
GitLab