From 3cf22e8effb252f9718504de45db77212d908eb5 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Mon, 28 Aug 2023 11:21:47 +0200
Subject: [PATCH] add boolean that prevents a workflow from getting aborted to
 pp interaction steps

---
 gso/services/provisioning_proxy.py       | 11 +++++++----
 gso/workflows/iptrunk/create_iptrunk.py  |  4 ++--
 gso/workflows/iptrunk/migrate_iptrunk.py |  4 ++--
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py
index 4c90ea7b..af0902a1 100644
--- a/gso/services/provisioning_proxy.py
+++ b/gso/services/provisioning_proxy.py
@@ -295,7 +295,7 @@ def _confirm_pp_results(state: State) -> FormGenerator:
     return {"pp_did_succeed": successful_run}
 
 
-def pp_interaction(provisioning_step: Step, attempts: int) -> StepList:
+def pp_interaction(provisioning_step: Step, attempts: int, abort_on_failure: bool = True) -> StepList:
     """Interaction with the provisioning proxy.
 
     This method returns the three steps that make up an interaction with the provisioning proxy:
@@ -308,12 +308,14 @@ def pp_interaction(provisioning_step: Step, attempts: int) -> StepList:
     in a later release.
 
     The parameter `attempts` indicates how many times a provisioning may be attempted. When this amount is exceeded, and
-    it's still not successful, the workflow will be aborted.
+    it's still not successful, the workflow will be aborted if so indicated with the `abort_on_failure` boolean.
 
     :param provisioning_step: The step that executes an interaction with the provisioning proxy.
     :type provisioning_step: {class}`orchestrator.workflow.Step`
     :param attempts: The maximum amount of times that a provisioning can be retried.
     :type attempts: int
+    :param abort_on_failure: A boolean value that indicates whether a workflow should abort if the provisioning has
+                             failed the maximum amount of tries. Defaults to `True`.
     :return: A list of three steps that form one interaction with the provisioning proxy.
     :rtype: {class}`orchestrator.workflow.StepList`
     """
@@ -328,7 +330,8 @@ def pp_interaction(provisioning_step: Step, attempts: int) -> StepList:
             >> should_retry_pp_steps(_confirm_pp_results)
         )
 
-    # Abort a workflow if provisioning has failed too many times
-    pp_steps >>= should_retry_pp_steps(abort)
+    if abort_on_failure:
+        # Abort a workflow if provisioning has failed too many times
+        pp_steps >>= should_retry_pp_steps(abort)
 
     return pp_steps
diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py
index 0bc9d4ae..16b4a291 100644
--- a/gso/workflows/iptrunk/create_iptrunk.py
+++ b/gso/workflows/iptrunk/create_iptrunk.py
@@ -241,10 +241,10 @@ def create_iptrunk() -> StepList:
         >> get_info_from_ipam
         >> pp_interaction(provision_ip_trunk_iface_dry, 3)
         >> pp_interaction(provision_ip_trunk_iface_real, 3)
-        >> pp_interaction(check_ip_trunk_connectivity, 2)
+        >> pp_interaction(check_ip_trunk_connectivity, 2, False)
         >> pp_interaction(provision_ip_trunk_isis_iface_dry, 3)
         >> pp_interaction(provision_ip_trunk_isis_iface_real, 3)
-        >> pp_interaction(check_ip_trunk_isis, 2)
+        >> pp_interaction(check_ip_trunk_isis, 2, False)
         >> set_status(SubscriptionLifecycle.ACTIVE)
         >> resync
         >> done
diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py
index 7161f083..e6acfb36 100644
--- a/gso/workflows/iptrunk/migrate_iptrunk.py
+++ b/gso/workflows/iptrunk/migrate_iptrunk.py
@@ -397,9 +397,9 @@ def migrate_iptrunk() -> StepList:
         >> pp_interaction(deploy_new_config_dry, 3)
         >> pp_interaction(deploy_new_config_real, 3)
         >> confirm_continue
-        >> pp_interaction(run_interface_checks, 3)
+        >> pp_interaction(run_interface_checks, 3, False)
         >> pp_interaction(deploy_new_isis, 3)
-        >> pp_interaction(check_isis, 3)
+        >> pp_interaction(check_isis, 3, False)
         >> confirm_continue
         >> restore_isis_metric
         >> pp_interaction(delete_old_config_dry, 3)
-- 
GitLab