From ef6276e8b9cbe0163321954ae56d3b931b827b84 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Wed, 25 Oct 2023 13:55:21 +0200
Subject: [PATCH] rework the last workflows, and start updating the unit test
 suite

---
 gso/services/provisioning_proxy.py                    | 11 +++++++----
 gso/utils/helpers.py                                  |  4 ++--
 gso/workflows/router/create_router.py                 |  3 +--
 test/workflows/__init__.py                            |  6 ++++++
 test/workflows/iptrunk/test_create_iptrunk.py         |  5 +++--
 .../iptrunks/iptrunks/test_create_iptrunks.py         |  9 +++------
 tox.ini                                               |  2 ++
 7 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py
index a3e9f2f6..c36c5a7d 100644
--- a/gso/services/provisioning_proxy.py
+++ b/gso/services/provisioning_proxy.py
@@ -4,15 +4,15 @@
 """
 import json
 import logging
+from functools import partial
 
 import requests
-from functools import partial
 from orchestrator import step
 from orchestrator.config.assignee import Assignee
 from orchestrator.types import State, UUIDstr, strEnum
 from orchestrator.utils.errors import ProcessFailureError
 from orchestrator.utils.json import json_dumps
-from orchestrator.workflow import Step, callback_step, begin, StepList, inputstep
+from orchestrator.workflow import Step, StepList, begin, callback_step, inputstep
 from pydantic_forms.core import FormPage, ReadOnlyField
 from pydantic_forms.types import FormGenerator
 from pydantic_forms.validators import LongText
@@ -285,8 +285,11 @@ def _show_pp_results(state: State) -> FormGenerator:
 
 
 def pp_interaction(provisioning_step: Step) -> StepList:
-    """
-    An interaction with the provisioning proxy :term:`LSO` as a callback step.
+    """Interact with the provisioning proxy :term:`LSO` using a callback step.
+
+    An asynchronous interaction with the provisioning proxy. This is an external system that executes Ansible playbooks
+    in order to provision service subscriptions. If the playbook fails, this step will also fail, allowing for the user
+    to retry provisioning from the UI.
 
     :param provisioning_step: A workflow step that performs an operation remotely using the provisioning proxy.
     :type provisioning_step: :class:`Step`
diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py
index aa09bc82..faea0544 100644
--- a/gso/utils/helpers.py
+++ b/gso/utils/helpers.py
@@ -26,10 +26,10 @@ class LAGMember(BaseModel):
 
 
 @step("[COMMIT] Set ISIS metric to 90.000")
-def set_isis_to_90000(subscription: Iptrunk, process_id: UUIDstr, tt_number: str) -> State:
+def set_isis_to_90000(subscription: Iptrunk, process_id: UUIDstr, callback_route: str, 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)
+    provisioning_proxy.provision_ip_trunk(subscription, process_id, callback_route, tt_number, "isis_interface", False)
 
     return {
         "subscription": subscription,
diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py
index 1f452e05..3f681a02 100644
--- a/gso/workflows/router/create_router.py
+++ b/gso/workflows/router/create_router.py
@@ -1,4 +1,3 @@
-import secrets
 from ipaddress import IPv4Network, IPv6Network
 from typing import Any
 
@@ -7,7 +6,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, conditional, done, init, step, workflow, Step, callback_step
+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/test/workflows/__init__.py b/test/workflows/__init__.py
index 876b0e3e..4fcc1990 100644
--- a/test/workflows/__init__.py
+++ b/test/workflows/__init__.py
@@ -42,6 +42,12 @@ def assert_suspended(result):
     ).issuspend(), f"Unexpected process status. Expected Suspend, but was: {result}"
 
 
+def assert_awaiting_callback(result):
+    assert result.on_failed(
+        _raise_exception
+    ).isawaitingcallback(), f"Unexpected process status. Expected Awaiting Callback, but was: {result}"
+
+
 def assert_aborted(result):
     assert result.on_failed(_raise_exception).isabort(), f"Unexpected process status. Expected Abort, but was: {result}"
 
diff --git a/test/workflows/iptrunk/test_create_iptrunk.py b/test/workflows/iptrunk/test_create_iptrunk.py
index 77ca88fd..d5c23c2a 100644
--- a/test/workflows/iptrunk/test_create_iptrunk.py
+++ b/test/workflows/iptrunk/test_create_iptrunk.py
@@ -11,6 +11,7 @@ from gso.utils.helpers import LAGMember
 from test.services.conftest import MockedNetboxClient
 from test.workflows import (
     assert_aborted,
+    assert_awaiting_callback,
     assert_complete,
     assert_suspended,
     extract_state,
@@ -106,7 +107,7 @@ def test_successful_iptrunk_creation_with_standard_lso_result(
     product_id = get_product_id_by_name(ProductType.IP_TRUNK)
     initial_site_data = [{"product": product_id}, *input_form_wizard_data]
     result, process_stat, step_log = run_workflow("create_iptrunk", initial_site_data)
-    assert_suspended(result)
+    assert_awaiting_callback(result)
 
     standard_lso_result = {
         "pp_run_results": {
@@ -158,7 +159,7 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one(
 
     initial_site_data = [{"product": product_id}, *input_form_wizard_data]
     result, process_stat, step_log = run_workflow("create_iptrunk", initial_site_data)
-    assert_suspended(result)
+    assert_awaiting_callback(result)
 
     standard_lso_result = {
         "pp_run_results": {
diff --git a/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py b/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py
index c0d09fb7..3ec39fd8 100644
--- a/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py
+++ b/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py
@@ -2,13 +2,10 @@ from unittest.mock import patch
 
 import pytest
 
-from gso.products import Iptrunk
-from gso.products.product_blocks import PhyPortCapacity
-from gso.products.product_blocks.iptrunk import IptrunkType
-from gso.schemas.enums import ProductType
-from gso.services.crm import get_customer_by_name
+from gso.products import Iptrunk, ProductType
+from gso.products.product_blocks.iptrunk import IptrunkType, PhyPortCapacity
+from gso.services.crm import customer_selector, get_customer_by_name
 from gso.services.subscriptions import get_product_id_by_name
-from gso.workflows.utils import customer_selector
 from test.workflows import (
     assert_aborted,
     assert_complete,
diff --git a/tox.ini b/tox.ini
index c259455b..50b62202 100644
--- a/tox.ini
+++ b/tox.ini
@@ -12,6 +12,8 @@ markers = workflow
 
 [testenv]
 passenv = DATABASE_URI_TEST,SKIP_ALL_TESTS
+setenv =
+    OAUTH2_ACTIVE = False
 deps =
     coverage
     flake8
-- 
GitLab