From b1a5e7bd7fafb79ab3559fd40c5ff1dd14fa99ef Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Tue, 12 Mar 2024 16:16:45 +0100
Subject: [PATCH] externalise isis_high_metric as configurable parameter in
 config.json

---
 gso/oss-params-example.json                      |  3 ++-
 gso/settings.py                                  |  1 +
 gso/utils/workflow_steps.py                      | 10 ++++++----
 gso/workflows/iptrunk/create_iptrunk.py          |  4 +++-
 gso/workflows/iptrunk/migrate_iptrunk.py         |  4 ++--
 gso/workflows/iptrunk/terminate_iptrunk.py       |  4 ++--
 test/conftest.py                                 |  2 +-
 test/workflows/iptrunk/test_terminate_iptrunk.py |  4 +++-
 8 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/gso/oss-params-example.json b/gso/oss-params-example.json
index 2ef1cd14..74d81cc9 100644
--- a/gso/oss-params-example.json
+++ b/gso/oss-params-example.json
@@ -1,6 +1,7 @@
 {
   "GENERAL": {
-    "public_hostname": "https://gap.geant.org"
+    "public_hostname": "https://gap.geant.org",
+    "isis_high_metric": 999999
   },
   "NETBOX": {
     "api": "https://127.0.0.1:8000",
diff --git a/gso/settings.py b/gso/settings.py
index 2055e96c..2c86b723 100644
--- a/gso/settings.py
+++ b/gso/settings.py
@@ -21,6 +21,7 @@ class GeneralParams(BaseSettings):
     public_hostname: str
     """The hostname that :term:`GSO` is publicly served at, used for building the callback URL that the provisioning
     proxy uses."""
+    isis_high_metric: int
 
 
 class CeleryParams(BaseSettings):
diff --git a/gso/utils/workflow_steps.py b/gso/utils/workflow_steps.py
index 5890d62b..f4fcdf2d 100644
--- a/gso/utils/workflow_steps.py
+++ b/gso/utils/workflow_steps.py
@@ -9,6 +9,7 @@ from orchestrator.utils.json import json_dumps
 
 from gso.products.product_types.iptrunk import Iptrunk
 from gso.services.provisioning_proxy import execute_playbook
+from gso.settings import load_oss_params
 
 
 def _deploy_base_config(
@@ -62,11 +63,12 @@ def deploy_base_config_real(
     return {"subscription": subscription}
 
 
-@step("[COMMIT] Set ISIS metric to 90.000")
-def set_isis_to_90000(subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str) -> State:
-    """Workflow step for setting the :term:`ISIS` metric to 90k as an arbitrarily high value to drain a link."""
+@step("[COMMIT] Set ISIS metric to very high value")
+def set_isis_to_max(subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str) -> State:
+    """Workflow step for setting the :term:`ISIS` metric to an arbitrarily high value to drain a link."""
     old_isis_metric = subscription.iptrunk.iptrunk_isis_metric
-    subscription.iptrunk.iptrunk_isis_metric = 90000
+    params = load_oss_params()
+    subscription.iptrunk.iptrunk_isis_metric = params.GENERAL.isis_high_metric
     extra_vars = {
         "wfo_trunk_json": json.loads(json_dumps(subscription)),
         "dry_run": False,
diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py
index e9e304d2..ac482121 100644
--- a/gso/workflows/iptrunk/create_iptrunk.py
+++ b/gso/workflows/iptrunk/create_iptrunk.py
@@ -27,6 +27,7 @@ from gso.services import infoblox, subscriptions
 from gso.services.crm import get_customer_by_name
 from gso.services.netbox_client import NetboxClient
 from gso.services.provisioning_proxy import execute_playbook, pp_interaction
+from gso.settings import load_oss_params
 from gso.utils.helpers import (
     LAGMember,
     available_interfaces_choices,
@@ -220,13 +221,14 @@ def initialize_subscription(
     side_b_ae_members: list[dict],
 ) -> State:
     """Take all input from the user, and store it in the database."""
+    oss_params = load_oss_params()
     side_a = Router.from_subscription(side_a_node_id).router
     side_b = Router.from_subscription(side_b_node_id).router
     subscription.iptrunk.geant_s_sid = geant_s_sid
     subscription.iptrunk.iptrunk_description = iptrunk_description
     subscription.iptrunk.iptrunk_type = iptrunk_type
     subscription.iptrunk.iptrunk_speed = iptrunk_speed
-    subscription.iptrunk.iptrunk_isis_metric = 90000
+    subscription.iptrunk.iptrunk_isis_metric = oss_params.GENERAL.isis_high_metric
     subscription.iptrunk.iptrunk_minimum_links = iptrunk_minimum_links
 
     subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node = side_a
diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py
index 5f1240c5..04ae9af5 100644
--- a/gso/workflows/iptrunk/migrate_iptrunk.py
+++ b/gso/workflows/iptrunk/migrate_iptrunk.py
@@ -41,7 +41,7 @@ from gso.utils.helpers import (
     validate_tt_number,
 )
 from gso.utils.shared_enums import Vendor
-from gso.utils.workflow_steps import set_isis_to_90000
+from gso.utils.workflow_steps import set_isis_to_max
 
 
 def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator:
@@ -656,7 +656,7 @@ def migrate_iptrunk() -> StepList:
         >> unsync
         >> new_side_is_nokia(netbox_reserve_interfaces)
         >> calculate_old_side_data
-        >> pp_interaction(set_isis_to_90000)
+        >> pp_interaction(set_isis_to_max)
         >> pp_interaction(disable_old_config_dry)
         >> pp_interaction(disable_old_config_real)
         >> pp_interaction(deploy_new_config_dry)
diff --git a/gso/workflows/iptrunk/terminate_iptrunk.py b/gso/workflows/iptrunk/terminate_iptrunk.py
index 330c90c3..93f8bd96 100644
--- a/gso/workflows/iptrunk/terminate_iptrunk.py
+++ b/gso/workflows/iptrunk/terminate_iptrunk.py
@@ -25,7 +25,7 @@ from gso.services.netbox_client import NetboxClient
 from gso.services.provisioning_proxy import execute_playbook, pp_interaction
 from gso.utils.helpers import get_router_vendor, validate_tt_number
 from gso.utils.shared_enums import Vendor
-from gso.utils.workflow_steps import set_isis_to_90000
+from gso.utils.workflow_steps import set_isis_to_max
 
 
 def initial_input_form_generator() -> FormGenerator:
@@ -171,7 +171,7 @@ def terminate_iptrunk() -> StepList:
 
     config_steps = (
         init
-        >> pp_interaction(set_isis_to_90000)
+        >> pp_interaction(set_isis_to_max)
         >> pp_interaction(deprovision_ip_trunk_dry)
         >> pp_interaction(deprovision_ip_trunk_real)
     )
diff --git a/test/conftest.py b/test/conftest.py
index b0e8ddbd..bc5dd61b 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -97,7 +97,7 @@ def configuration_data() -> dict:
         s.bind(("", 0))
         s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         yield {
-            "GENERAL": {"public_hostname": "https://orchestrator.dev.gap.geant.org"},
+            "GENERAL": {"public_hostname": "https://orchestrator.dev.gap.geant.org", "isis_high_metric": 999999},
             "NETBOX": {"api": "https://127.0.0.1:8000", "token": "TOKEN"},
             "IPAM": {
                 "INFOBLOX": {
diff --git a/test/workflows/iptrunk/test_terminate_iptrunk.py b/test/workflows/iptrunk/test_terminate_iptrunk.py
index 68b5f4ed..bc890afa 100644
--- a/test/workflows/iptrunk/test_terminate_iptrunk.py
+++ b/test/workflows/iptrunk/test_terminate_iptrunk.py
@@ -3,6 +3,7 @@ from unittest.mock import patch
 import pytest
 
 from gso.products import Iptrunk
+from gso.settings import load_oss_params
 from test.services.conftest import MockedNetboxClient
 from test.workflows import (
     assert_complete,
@@ -35,6 +36,7 @@ def test_successful_iptrunk_termination(
     mocked_free_interface.return_value = mocked_netbox.free_interface()
 
     #  Run workflow
+    oss_params = load_oss_params()
     initial_iptrunk_data = [
         {"subscription_id": product_id},
         {
@@ -62,4 +64,4 @@ def test_successful_iptrunk_termination(
     assert mock_execute_playbook.call_count == 2
     assert mock_set_isis_to_90k.call_count == 1
     assert mock_infoblox_delete_network.call_count == 2
-    assert subscription.iptrunk.iptrunk_isis_metric == 90000
+    assert subscription.iptrunk.iptrunk_isis_metric == oss_params.GENERAL.isis_high_metric
-- 
GitLab