Skip to content
Snippets Groups Projects
Verified Commit ec61421c authored by Aleksandr Kurbatov's avatar Aleksandr Kurbatov Committed by Karel van Klink
Browse files

Include GSO process ID in every LSO call

Also added a fixture that auto-applies to all LSO interactions in unit tests
parent 69a3114e
Branches
Tags
1 merge request!413Include GSO process ID in every LSO call
Pipeline #93725 passed
Showing
with 37 additions and 92 deletions
...@@ -14,7 +14,7 @@ from orchestrator.forms import SubmitFormPage ...@@ -14,7 +14,7 @@ from orchestrator.forms import SubmitFormPage
from orchestrator.utils.errors import ProcessFailureError from orchestrator.utils.errors import ProcessFailureError
from orchestrator.workflow import Step, StepList, begin, callback_step, conditional, inputstep from orchestrator.workflow import Step, StepList, begin, callback_step, conditional, inputstep
from pydantic import ConfigDict from pydantic import ConfigDict
from pydantic_forms.types import FormGenerator, State from pydantic_forms.types import FormGenerator, State, UUIDstr
from pydantic_forms.validators import Label, LongText, ReadOnlyField from pydantic_forms.validators import Label, LongText, ReadOnlyField
from unidecode import unidecode from unidecode import unidecode
...@@ -64,7 +64,7 @@ def _send_request(parameters: dict, callback_route: str) -> None: ...@@ -64,7 +64,7 @@ def _send_request(parameters: dict, callback_route: str) -> None:
@step("Execute Ansible playbook") @step("Execute Ansible playbook")
def _execute_playbook( def _execute_playbook(
playbook_name: str, callback_route: str, inventory: dict[str, Any], extra_vars: dict[str, Any] playbook_name: str, callback_route: str, inventory: dict[str, Any], extra_vars: dict[str, Any], process_id: UUIDstr
) -> None: ) -> None:
"""Execute a playbook remotely through the provisioning proxy. """Execute a playbook remotely through the provisioning proxy.
...@@ -112,7 +112,10 @@ def _execute_playbook( ...@@ -112,7 +112,10 @@ def _execute_playbook(
extra_vars: Any extra variables that the playbook relies on. This can include a subscription object, a boolean extra_vars: Any extra variables that the playbook relies on. This can include a subscription object, a boolean
value indicating a dry run, a commit comment, etc. All unicode character values are decoded to prevent value indicating a dry run, a commit comment, etc. All unicode character values are decoded to prevent
sending special characters to remote machines that don't support this. sending special characters to remote machines that don't support this.
process_id: The process ID of the workflow that is running the playbook. This is used in Ansible playbooks to
fetch custom configuration.
""" """
extra_vars["gso_process_id"] = process_id
parameters = { parameters = {
"playbook_name": playbook_name, "playbook_name": playbook_name,
"inventory": inventory, "inventory": inventory,
......
...@@ -12,7 +12,7 @@ from alembic.config import Config ...@@ -12,7 +12,7 @@ from alembic.config import Config
from faker import Faker from faker import Faker
from faker.providers import BaseProvider from faker.providers import BaseProvider
from oauth2_lib.settings import oauth2lib_settings from oauth2_lib.settings import oauth2lib_settings
from orchestrator import app_settings from orchestrator import app_settings, step
from orchestrator.db import ( from orchestrator.db import (
Database, Database,
ProductBlockTable, ProductBlockTable,
...@@ -26,7 +26,7 @@ from orchestrator.db.database import ENGINE_ARGUMENTS, SESSION_ARGUMENTS, BaseMo ...@@ -26,7 +26,7 @@ from orchestrator.db.database import ENGINE_ARGUMENTS, SESSION_ARGUMENTS, BaseMo
from orchestrator.domain import SUBSCRIPTION_MODEL_REGISTRY, SubscriptionModel from orchestrator.domain import SUBSCRIPTION_MODEL_REGISTRY, SubscriptionModel
from orchestrator.domain.base import ProductBlockModel from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
from pydantic_forms.types import strEnum from pydantic_forms.types import UUIDstr, strEnum
from sqlalchemy import create_engine, select, text from sqlalchemy import create_engine, select, text
from sqlalchemy.engine import make_url from sqlalchemy.engine import make_url
from sqlalchemy.orm import scoped_session, sessionmaker from sqlalchemy.orm import scoped_session, sessionmaker
...@@ -606,3 +606,20 @@ def _no_mail(monkeypatch): ...@@ -606,3 +606,20 @@ def _no_mail(monkeypatch):
logger.info(email) logger.info(email)
monkeypatch.setattr(gso.services.mailer, "send_mail", send_mail) monkeypatch.setattr(gso.services.mailer, "send_mail", send_mail)
@pytest.fixture(autouse=True)
def _no_lso_interactions(monkeypatch):
"""Remove all external LSO calls."""
@step("Mocked playbook execution")
def _execute_playbook(
playbook_name: str, callback_route: str, inventory: dict, extra_vars: dict, process_id: UUIDstr
) -> None:
assert playbook_name
assert callback_route
assert inventory
assert extra_vars
assert process_id
monkeypatch.setattr(gso.services.lso_client, "_execute_playbook", _execute_playbook)
...@@ -4,7 +4,8 @@ from gso.services.lso_client import _execute_playbook ...@@ -4,7 +4,8 @@ from gso.services.lso_client import _execute_playbook
@patch("gso.services.lso_client.requests.post") @patch("gso.services.lso_client.requests.post")
def test_replace_unicode_in_lso_call_success(mock_post): def test_replace_unicode_in_lso_call_success(mock_post, faker):
mocked_uuid = faker.uuid4()
extra_vars = { extra_vars = {
"deployment_description": "I am going to deploy the best GÉANT service EVER!!", "deployment_description": "I am going to deploy the best GÉANT service EVER!!",
"email": "goat@géant.org", "email": "goat@géant.org",
...@@ -19,10 +20,11 @@ def test_replace_unicode_in_lso_call_success(mock_post): ...@@ -19,10 +20,11 @@ def test_replace_unicode_in_lso_call_success(mock_post):
"deployment_description": "I am going to deploy the best GEANT service EVER!!", "deployment_description": "I am going to deploy the best GEANT service EVER!!",
"email": "goat@geant.org", "email": "goat@geant.org",
"translations": {"ja": "zieantonosugoinasa-bisuwodepuroisuru"}, "translations": {"ja": "zieantonosugoinasa-bisuwodepuroisuru"},
"gso_process_id": mocked_uuid,
}, },
} }
execute_playbook = _execute_playbook.__wrapped__ execute_playbook = _execute_playbook.__wrapped__
execute_playbook("playbook.yaml", "/api/callback_route", {}, extra_vars) execute_playbook("playbook.yaml", "/api/callback_route", {}, extra_vars, mocked_uuid)
mock_post.assert_called_once_with("https://localhost:44444/api/playbook", json=expected_parameters, timeout=10) mock_post.assert_called_once_with("https://localhost:44444/api/playbook", json=expected_parameters, timeout=10)
...@@ -87,9 +87,7 @@ def input_form_wizard_data(request, router_subscription_factory, partner_factory ...@@ -87,9 +87,7 @@ def input_form_wizard_data(request, router_subscription_factory, partner_factory
@pytest.mark.workflow() @pytest.mark.workflow()
@pytest.mark.parametrize("router_vendor", [*Vendor.values()]) @pytest.mark.parametrize("router_vendor", [*Vendor.values()])
@patch("gso.services.lso_client._send_request")
def test_successful_edge_port_creation( def test_successful_edge_port_creation(
mock_execute_playbook,
router_vendor, router_vendor,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
...@@ -119,13 +117,10 @@ def test_successful_edge_port_creation( ...@@ -119,13 +117,10 @@ def test_successful_edge_port_creation(
== f"Edge Port {initial_data[2]["name"]} on {router_fqdn}, GAAR, {subscription.edge_port.ga_id}" == f"Edge Port {initial_data[2]["name"]} on {router_fqdn}, GAAR, {subscription.edge_port.ga_id}"
) )
assert len(subscription.edge_port.edge_port_ae_members) == 2 assert len(subscription.edge_port.edge_port_ae_members) == 2
assert mock_execute_playbook.call_count == 4
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_successful_edge_port_creation_with_auto_ga_id_creation( def test_successful_edge_port_creation_with_auto_ga_id_creation(
mock_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
_netbox_client_mock, # noqa: PT019 _netbox_client_mock, # noqa: PT019
...@@ -150,7 +145,6 @@ def test_successful_edge_port_creation_with_auto_ga_id_creation( ...@@ -150,7 +145,6 @@ def test_successful_edge_port_creation_with_auto_ga_id_creation(
assert subscription.status == "active" assert subscription.status == "active"
assert subscription.edge_port.ga_id.startswith("GA-5000") assert subscription.edge_port.ga_id.startswith("GA-5000")
assert mock_execute_playbook.call_count == 4
def test_edge_port_creation_with_invalid_input( def test_edge_port_creation_with_invalid_input(
...@@ -173,9 +167,7 @@ def test_edge_port_creation_with_invalid_input( ...@@ -173,9 +167,7 @@ def test_edge_port_creation_with_invalid_input(
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_edge_port_creation_with_existing_ga_id( def test_edge_port_creation_with_existing_ga_id(
mock_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
_netbox_client_mock, # noqa: PT019 _netbox_client_mock, # noqa: PT019
......
...@@ -75,9 +75,7 @@ def input_form_wizard_data(request, router_subscription_factory, partner, faker) ...@@ -75,9 +75,7 @@ def input_form_wizard_data(request, router_subscription_factory, partner, faker)
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.tasks.start_process.start_process_task.apply_async") @patch("gso.tasks.start_process.start_process_task.apply_async")
@patch("gso.services.lso_client._send_request")
def test_successful_edge_port_migration( def test_successful_edge_port_migration(
mock_execute_playbook,
start_process_task_apply_async, start_process_task_apply_async,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
...@@ -128,4 +126,3 @@ def test_successful_edge_port_migration( ...@@ -128,4 +126,3 @@ def test_successful_edge_port_migration(
assert subscription.edge_port.ga_id is not None assert subscription.edge_port.ga_id is not None
assert subscription.description == f"Edge Port lag-21 on {router_fqdn}, GAAR, {subscription.edge_port.ga_id}" assert subscription.description == f"Edge Port lag-21 on {router_fqdn}, GAAR, {subscription.edge_port.ga_id}"
assert len(subscription.edge_port.edge_port_ae_members) == 2 assert len(subscription.edge_port.edge_port_ae_members) == 2
assert mock_execute_playbook.call_count == 4
...@@ -56,7 +56,6 @@ def test_modify_edge_port_with_invalid_ga_id( ...@@ -56,7 +56,6 @@ def test_modify_edge_port_with_invalid_ga_id(
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces")
@patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag") @patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag")
@patch("gso.services.netbox_client.NetboxClient.reserve_interface") @patch("gso.services.netbox_client.NetboxClient.reserve_interface")
...@@ -72,7 +71,6 @@ def test_modify_edge_port_with_changing_capacity( ...@@ -72,7 +71,6 @@ def test_modify_edge_port_with_changing_capacity(
mocked_reserve_interface, mocked_reserve_interface,
mocked_attach_interface_to_lag, mocked_attach_interface_to_lag,
mocked_get_available_interfaces, mocked_get_available_interfaces,
mocked_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
): ):
...@@ -99,7 +97,6 @@ def test_modify_edge_port_with_changing_capacity( ...@@ -99,7 +97,6 @@ def test_modify_edge_port_with_changing_capacity(
subscription = EdgePort.from_subscription(subscription_id) subscription = EdgePort.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mocked_execute_playbook.call_count == 2
# The number of members have been changed from 2 to 1 # The number of members have been changed from 2 to 1
assert mocked_reserve_interface.call_count == 1 assert mocked_reserve_interface.call_count == 1
...@@ -132,7 +129,6 @@ def input_form_wizard_without_changing_capacity(request, faker, edge_port_subscr ...@@ -132,7 +129,6 @@ def input_form_wizard_without_changing_capacity(request, faker, edge_port_subscr
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces")
@patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag") @patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag")
@patch("gso.services.netbox_client.NetboxClient.reserve_interface") @patch("gso.services.netbox_client.NetboxClient.reserve_interface")
...@@ -148,7 +144,6 @@ def test_modify_edge_port_without_changing_capacity( ...@@ -148,7 +144,6 @@ def test_modify_edge_port_without_changing_capacity(
mocked_reserve_interface, mocked_reserve_interface,
mocked_attach_interface_to_lag, mocked_attach_interface_to_lag,
mocked_get_available_interfaces, mocked_get_available_interfaces,
mocked_execute_playbook,
input_form_wizard_without_changing_capacity, input_form_wizard_without_changing_capacity,
faker, faker,
): ):
...@@ -173,7 +168,6 @@ def test_modify_edge_port_without_changing_capacity( ...@@ -173,7 +168,6 @@ def test_modify_edge_port_without_changing_capacity(
assert subscription.status == "active" assert subscription.status == "active"
# The capacity has not been changed so the following methods should not be called # The capacity has not been changed so the following methods should not be called
assert mocked_execute_playbook.call_count == 0
assert mocked_reserve_interface.call_count == 0 assert mocked_reserve_interface.call_count == 0
assert mocked_attach_interface_to_lag.call_count == 0 assert mocked_attach_interface_to_lag.call_count == 0
assert mocked_free_interface.call_count == 0 assert mocked_free_interface.call_count == 0
......
...@@ -13,13 +13,11 @@ from test.workflows import ( ...@@ -13,13 +13,11 @@ from test.workflows import (
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.delete_interface") @patch("gso.services.netbox_client.NetboxClient.delete_interface")
@patch("gso.services.netbox_client.NetboxClient.free_interface") @patch("gso.services.netbox_client.NetboxClient.free_interface")
def test_successful_edge_port_termination( def test_successful_edge_port_termination(
mocked_free_interface, mocked_free_interface,
mocked_delete_interface, mocked_delete_interface,
mock_execute_playbook,
edge_port_subscription_factory, edge_port_subscription_factory,
faker, faker,
): ):
...@@ -52,4 +50,3 @@ def test_successful_edge_port_termination( ...@@ -52,4 +50,3 @@ def test_successful_edge_port_termination(
subscription = EdgePort.from_subscription(subscription_id) subscription = EdgePort.from_subscription(subscription_id)
assert subscription.status == "terminated" assert subscription.status == "terminated"
assert mock_execute_playbook.call_count == 2
...@@ -13,11 +13,9 @@ from test.workflows import ( ...@@ -13,11 +13,9 @@ from test.workflows import (
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device") @patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device")
def test_validate_edge_port_success( def test_validate_edge_port_success(
mock_get_interface_by_name_and_device, mock_get_interface_by_name_and_device,
mock_execute_playbook,
edge_port_subscription_factory, edge_port_subscription_factory,
faker, faker,
): ):
...@@ -56,6 +54,6 @@ def test_validate_edge_port_success( ...@@ -56,6 +54,6 @@ def test_validate_edge_port_success(
assert_complete(result) assert_complete(result)
subscription = EdgePort.from_subscription(subscription_id) subscription = EdgePort.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_execute_playbook.call_count == 1
# One time for getting the LAG and two times for getting the interfaces # One time for getting the LAG and two times for getting the interfaces
assert mock_get_interface_by_name_and_device.call_count == 3 assert mock_get_interface_by_name_and_device.call_count == 3
...@@ -100,7 +100,6 @@ def input_form_wizard_data(request, router_subscription_factory, faker): ...@@ -100,7 +100,6 @@ def input_form_wizard_data(request, router_subscription_factory, faker):
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip")
...@@ -114,7 +113,6 @@ def test_successful_iptrunk_creation_with_standard_lso_result( ...@@ -114,7 +113,6 @@ def test_successful_iptrunk_creation_with_standard_lso_result(
mock_create_host, mock_create_host,
mock_allocate_v4_network, mock_allocate_v4_network,
mock_allocate_v6_network, mock_allocate_v6_network,
mock_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
_netbox_client_mock, # noqa: PT019 _netbox_client_mock, # noqa: PT019
...@@ -154,14 +152,12 @@ def test_successful_iptrunk_creation_with_standard_lso_result( ...@@ -154,14 +152,12 @@ def test_successful_iptrunk_creation_with_standard_lso_result(
f"{subscription.iptrunk.gs_id}" f"{subscription.iptrunk.gs_id}"
) )
assert mock_execute_playbook.call_count == 6
# We search for 6 hosts in total, 2 in a /31 and 4 in a /126 # We search for 6 hosts in total, 2 in a /31 and 4 in a /126
assert mock_find_host_by_ip.call_count == 6 assert mock_find_host_by_ip.call_count == 6
assert mock_ping.call_count == 6 assert mock_ping.call_count == 6
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.find_host_by_ip") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.find_host_by_ip")
...@@ -171,7 +167,6 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one( ...@@ -171,7 +167,6 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one(
mock_find_host_by_ip, mock_find_host_by_ip,
mock_allocate_v4_network, mock_allocate_v4_network,
mock_allocate_v6_network, mock_allocate_v6_network,
mock_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
_netbox_client_mock, # noqa: PT019 _netbox_client_mock, # noqa: PT019
...@@ -189,14 +184,12 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one( ...@@ -189,14 +184,12 @@ def test_iptrunk_creation_fails_when_lso_return_code_is_one(
assert_lso_interaction_failure(result, process_stat, step_log) assert_lso_interaction_failure(result, process_stat, step_log)
assert mock_execute_playbook.call_count == 2
assert mock_find_host_by_ip.call_count == 6 assert mock_find_host_by_ip.call_count == 6
assert mock_ping.call_count == 6 assert mock_ping.call_count == 6
@pytest.mark.parametrize("input_form_wizard_data", [Vendor.JUNIPER], indirect=True) @pytest.mark.parametrize("input_form_wizard_data", [Vendor.JUNIPER], indirect=True)
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v4_network")
@patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.create_host_by_ip")
...@@ -210,7 +203,6 @@ def test_successful_iptrunk_creation_with_juniper_interface_names( ...@@ -210,7 +203,6 @@ def test_successful_iptrunk_creation_with_juniper_interface_names(
mock_create_host, mock_create_host,
mock_allocate_v4_network, mock_allocate_v4_network,
mock_allocate_v6_network, mock_allocate_v6_network,
mock_execute_playbook,
input_form_wizard_data, input_form_wizard_data,
faker, faker,
_netbox_client_mock, # noqa: PT019 _netbox_client_mock, # noqa: PT019
...@@ -233,7 +225,7 @@ def test_successful_iptrunk_creation_with_juniper_interface_names( ...@@ -233,7 +225,7 @@ def test_successful_iptrunk_creation_with_juniper_interface_names(
result, step_log = resume_suspended_workflow(result, process_stat, step_log, input_data=USER_CONFIRM_EMPTY_FORM) result, step_log = resume_suspended_workflow(result, process_stat, step_log, input_data=USER_CONFIRM_EMPTY_FORM)
assert_complete(result) assert_complete(result)
assert mock_execute_playbook.call_count == 6
assert mock_find_host_by_ip.call_count == 6 assert mock_find_host_by_ip.call_count == 6
assert mock_ping.call_count == 6 assert mock_ping.call_count == 6
......
from unittest.mock import patch
import pytest import pytest
from gso.products.product_types.iptrunk import Iptrunk from gso.products.product_types.iptrunk import Iptrunk
...@@ -12,9 +10,7 @@ from test.workflows import ( ...@@ -12,9 +10,7 @@ from test.workflows import (
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_iptrunk_deploy_twamp_success( def test_iptrunk_deploy_twamp_success(
mock_execute_playbook,
iptrunk_subscription_factory, iptrunk_subscription_factory,
faker, faker,
): ):
...@@ -35,4 +31,3 @@ def test_iptrunk_deploy_twamp_success( ...@@ -35,4 +31,3 @@ def test_iptrunk_deploy_twamp_success(
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_execute_playbook.call_count == 3
...@@ -111,7 +111,6 @@ def interface_lists_are_equal(list1, list2): ...@@ -111,7 +111,6 @@ def interface_lists_are_equal(list1, list2):
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.infoblox.create_host_by_ip") @patch("gso.services.infoblox.create_host_by_ip")
@patch("gso.services.infoblox.delete_host_by_ip") @patch("gso.services.infoblox.delete_host_by_ip")
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces")
@patch("gso.services.netbox_client.NetboxClient.get_available_lags") @patch("gso.services.netbox_client.NetboxClient.get_available_lags")
@patch("gso.services.netbox_client.NetboxClient.create_interface") @patch("gso.services.netbox_client.NetboxClient.create_interface")
...@@ -131,7 +130,6 @@ def test_migrate_iptrunk_success( # noqa: PLR0915 ...@@ -131,7 +130,6 @@ def test_migrate_iptrunk_success( # noqa: PLR0915
mocked_create_interface, mocked_create_interface,
mocked_get_available_lags, mocked_get_available_lags,
mocked_get_available_interfaces, mocked_get_available_interfaces,
mock_execute_playbook,
mock_delete_host_by_ip, mock_delete_host_by_ip,
mock_create_host_by_ip, mock_create_host_by_ip,
migrate_form_input, migrate_form_input,
...@@ -180,7 +178,7 @@ def test_migrate_iptrunk_success( # noqa: PLR0915 ...@@ -180,7 +178,7 @@ def test_migrate_iptrunk_success( # noqa: PLR0915
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_execute_playbook.call_count == (17 if restore_isis_metric else 16)
assert mock_create_host_by_ip.call_count == 1 assert mock_create_host_by_ip.call_count == 1
assert mock_delete_host_by_ip.call_count == 1 assert mock_delete_host_by_ip.call_count == 1
......
from unittest.mock import patch
import pytest import pytest
from gso.products.product_types.iptrunk import Iptrunk from gso.products.product_types.iptrunk import Iptrunk
...@@ -12,9 +10,7 @@ from test.workflows import ( ...@@ -12,9 +10,7 @@ from test.workflows import (
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_iptrunk_modify_isis_metric_success( def test_iptrunk_modify_isis_metric_success(
mock_provision_ip_trunk,
iptrunk_subscription_factory, iptrunk_subscription_factory,
faker, faker,
): ):
...@@ -40,5 +36,4 @@ def test_iptrunk_modify_isis_metric_success( ...@@ -40,5 +36,4 @@ def test_iptrunk_modify_isis_metric_success(
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_provision_ip_trunk.call_count == 2
assert subscription.iptrunk.iptrunk_isis_metric == new_isis_metric assert subscription.iptrunk.iptrunk_isis_metric == new_isis_metric
...@@ -92,7 +92,6 @@ def input_form_iptrunk_data( ...@@ -92,7 +92,6 @@ def input_form_iptrunk_data(
indirect=True, indirect=True,
) )
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces")
@patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag") @patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag")
@patch("gso.services.netbox_client.NetboxClient.reserve_interface") @patch("gso.services.netbox_client.NetboxClient.reserve_interface")
...@@ -106,7 +105,6 @@ def test_iptrunk_modify_trunk_interface_success( ...@@ -106,7 +105,6 @@ def test_iptrunk_modify_trunk_interface_success(
mocked_reserve_interface, mocked_reserve_interface,
mocked_attach_interface_to_lag, mocked_attach_interface_to_lag,
mocked_get_available_interfaces, mocked_get_available_interfaces,
mock_provision_ip_trunk,
input_form_iptrunk_data, input_form_iptrunk_data,
faker, faker,
): ):
...@@ -134,7 +132,6 @@ def test_iptrunk_modify_trunk_interface_success( ...@@ -134,7 +132,6 @@ def test_iptrunk_modify_trunk_interface_success(
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_provision_ip_trunk.call_count == lso_interaction_count
# Assert all Netbox calls have been made # Assert all Netbox calls have been made
new_sid = input_form_iptrunk_data[1]["gs_id"] new_sid = input_form_iptrunk_data[1]["gs_id"]
new_side_a_gid = input_form_iptrunk_data[3]["side_a_ga_id"] new_side_a_gid = input_form_iptrunk_data[3]["side_a_ga_id"]
......
...@@ -15,7 +15,6 @@ from test.workflows import ( ...@@ -15,7 +15,6 @@ from test.workflows import (
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.iptrunk.terminate_iptrunk.infoblox.delete_network") @patch("gso.workflows.iptrunk.terminate_iptrunk.infoblox.delete_network")
@patch("gso.services.netbox_client.NetboxClient.delete_interface") @patch("gso.services.netbox_client.NetboxClient.delete_interface")
@patch("gso.services.netbox_client.NetboxClient.free_interface") @patch("gso.services.netbox_client.NetboxClient.free_interface")
...@@ -23,7 +22,6 @@ def test_successful_iptrunk_termination( ...@@ -23,7 +22,6 @@ def test_successful_iptrunk_termination(
mocked_free_interface, mocked_free_interface,
mocked_delete_interface, mocked_delete_interface,
mock_infoblox_delete_network, mock_infoblox_delete_network,
mock_execute_playbook,
iptrunk_subscription_factory, iptrunk_subscription_factory,
faker, faker,
router_subscription_factory, router_subscription_factory,
...@@ -62,6 +60,6 @@ def test_successful_iptrunk_termination( ...@@ -62,6 +60,6 @@ def test_successful_iptrunk_termination(
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == "terminated" assert subscription.status == "terminated"
assert mock_execute_playbook.call_count == 3
assert mock_infoblox_delete_network.call_count == 2 assert mock_infoblox_delete_network.call_count == 2
assert subscription.iptrunk.iptrunk_isis_metric == oss_params.GENERAL.isis_high_metric assert subscription.iptrunk.iptrunk_isis_metric == oss_params.GENERAL.isis_high_metric
...@@ -45,11 +45,9 @@ def _mocked_netbox_client(): ...@@ -45,11 +45,9 @@ def _mocked_netbox_client():
@patch("gso.services.infoblox.find_network_by_cidr") @patch("gso.services.infoblox.find_network_by_cidr")
@patch("gso.services.infoblox.find_v6_host_by_fqdn") @patch("gso.services.infoblox.find_v6_host_by_fqdn")
@patch("gso.services.infoblox.find_host_by_fqdn") @patch("gso.services.infoblox.find_host_by_fqdn")
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device") @patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device")
def test_validate_iptrunk_success( def test_validate_iptrunk_success(
mock_get_interface_by_name, mock_get_interface_by_name,
mock_validate_iptrunk,
mock_find_host_by_fqdn, mock_find_host_by_fqdn,
mock_find_v6_host_by_fqdn, mock_find_v6_host_by_fqdn,
mock_find_network_by_cidr, mock_find_network_by_cidr,
...@@ -191,7 +189,6 @@ def test_validate_iptrunk_success( ...@@ -191,7 +189,6 @@ def test_validate_iptrunk_success(
subscription = Iptrunk.from_subscription(subscription_id) subscription = Iptrunk.from_subscription(subscription_id)
assert subscription.status == subscription_status assert subscription.status == subscription_status
assert mock_validate_iptrunk.call_count == 3
assert mock_find_host_by_fqdn.call_count == 2 assert mock_find_host_by_fqdn.call_count == 2
assert mock_find_v6_host_by_fqdn.call_count == 2 assert mock_find_v6_host_by_fqdn.call_count == 2
assert mock_find_network_by_cidr.call_count == 2 assert mock_find_network_by_cidr.call_count == 2
...@@ -203,11 +200,9 @@ def test_validate_iptrunk_success( ...@@ -203,11 +200,9 @@ def test_validate_iptrunk_success(
@patch("gso.services.infoblox.find_network_by_cidr") @patch("gso.services.infoblox.find_network_by_cidr")
@patch("gso.services.infoblox.find_v6_host_by_fqdn") @patch("gso.services.infoblox.find_v6_host_by_fqdn")
@patch("gso.services.infoblox.find_host_by_fqdn") @patch("gso.services.infoblox.find_host_by_fqdn")
@patch("gso.services.lso_client._send_request")
@patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device") @patch("gso.services.netbox_client.NetboxClient.get_interface_by_name_and_device")
def test_validate_iptrunk_skip_legacy_trunks( def test_validate_iptrunk_skip_legacy_trunks(
mock_get_interface_by_name, mock_get_interface_by_name,
mock_validate_iptrunk,
mock_find_host_by_fqdn, mock_find_host_by_fqdn,
mock_find_v6_host_by_fqdn, mock_find_v6_host_by_fqdn,
mock_find_network_by_cidr, mock_find_network_by_cidr,
...@@ -235,7 +230,6 @@ def test_validate_iptrunk_skip_legacy_trunks( ...@@ -235,7 +230,6 @@ def test_validate_iptrunk_skip_legacy_trunks(
assert subscription.status == subscription_status assert subscription.status == subscription_status
assert mock_get_interface_by_name.call_count == 0 assert mock_get_interface_by_name.call_count == 0
assert mock_validate_iptrunk.call_count == 0
assert mock_find_host_by_fqdn.call_count == 0 assert mock_find_host_by_fqdn.call_count == 0
assert mock_find_v6_host_by_fqdn.call_count == 0 assert mock_find_v6_host_by_fqdn.call_count == 0
assert mock_find_network_by_cidr.call_count == 0 assert mock_find_network_by_cidr.call_count == 0
from unittest.mock import patch
import pytest import pytest
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
...@@ -60,9 +58,7 @@ def layer_2_circuit_ethernet_input( ...@@ -60,9 +58,7 @@ def layer_2_circuit_ethernet_input(
@pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES) @pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES)
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_create_layer_2_circuit_success( def test_create_layer_2_circuit_success(
mock_lso_interaction,
layer_2_circuit_service_type, layer_2_circuit_service_type,
layer_2_circuit_input, layer_2_circuit_input,
faker, faker,
...@@ -76,7 +72,7 @@ def test_create_layer_2_circuit_success( ...@@ -76,7 +72,7 @@ def test_create_layer_2_circuit_success(
assert_complete(result) assert_complete(result)
state = extract_state(result) state = extract_state(result)
subscription = Layer2Circuit.from_subscription(state["subscription_id"]) subscription = Layer2Circuit.from_subscription(state["subscription_id"])
assert mock_lso_interaction.call_count == 2
assert subscription.status == SubscriptionLifecycle.ACTIVE assert subscription.status == SubscriptionLifecycle.ACTIVE
assert subscription.layer_2_circuit.virtual_circuit_id is not None assert subscription.layer_2_circuit.virtual_circuit_id is not None
assert len(subscription.layer_2_circuit.layer_2_circuit_sides) == 2 assert len(subscription.layer_2_circuit.layer_2_circuit_sides) == 2
...@@ -113,9 +109,7 @@ def test_create_layer_2_circuit_success( ...@@ -113,9 +109,7 @@ def test_create_layer_2_circuit_success(
@pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES) @pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES)
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_create_layer_2_circuit_with_ethernet_type( def test_create_layer_2_circuit_with_ethernet_type(
mock_lso_interaction,
layer_2_circuit_service_type, layer_2_circuit_service_type,
layer_2_circuit_ethernet_input, layer_2_circuit_ethernet_input,
faker, faker,
...@@ -129,7 +123,7 @@ def test_create_layer_2_circuit_with_ethernet_type( ...@@ -129,7 +123,7 @@ def test_create_layer_2_circuit_with_ethernet_type(
assert_complete(result) assert_complete(result)
state = extract_state(result) state = extract_state(result)
subscription = Layer2Circuit.from_subscription(state["subscription_id"]) subscription = Layer2Circuit.from_subscription(state["subscription_id"])
assert mock_lso_interaction.call_count == 2
assert subscription.status == SubscriptionLifecycle.ACTIVE assert subscription.status == SubscriptionLifecycle.ACTIVE
assert subscription.layer_2_circuit.virtual_circuit_id is not None assert subscription.layer_2_circuit.virtual_circuit_id is not None
assert len(subscription.layer_2_circuit.layer_2_circuit_sides) == 2 assert len(subscription.layer_2_circuit.layer_2_circuit_sides) == 2
......
from unittest.mock import patch
import pytest import pytest
from gso.products.product_types.edge_port import EdgePort from gso.products.product_types.edge_port import EdgePort
...@@ -13,9 +11,7 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr ...@@ -13,9 +11,7 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr
@pytest.mark.parametrize("run_old_side_ansible", [False, True]) @pytest.mark.parametrize("run_old_side_ansible", [False, True])
@pytest.mark.parametrize("run_new_side_ansible", [False, True]) @pytest.mark.parametrize("run_new_side_ansible", [False, True])
@pytest.mark.parametrize("generate_new_vc_id", [False, True]) @pytest.mark.parametrize("generate_new_vc_id", [False, True])
@patch("gso.services.lso_client._send_request")
def test_migrate_layer_2_circuit( def test_migrate_layer_2_circuit(
mock_lso_interaction,
generate_new_vc_id, generate_new_vc_id,
run_new_side_ansible, run_new_side_ansible,
run_old_side_ansible, run_old_side_ansible,
...@@ -64,7 +60,6 @@ def test_migrate_layer_2_circuit( ...@@ -64,7 +60,6 @@ def test_migrate_layer_2_circuit(
subscription_id = state["subscription_id"] subscription_id = state["subscription_id"]
subscription = Layer2Circuit.from_subscription(subscription_id) subscription = Layer2Circuit.from_subscription(subscription_id)
assert subscription.status == "active" assert subscription.status == "active"
assert mock_lso_interaction.call_count == lso_step_count
replaced_edge_port = subscription.layer_2_circuit.layer_2_circuit_sides[1].sbp.edge_port replaced_edge_port = subscription.layer_2_circuit.layer_2_circuit_sides[1].sbp.edge_port
assert replaced_edge_port.model_dump(exclude="edge_port_ae_members") == new_edge_port.edge_port.model_dump( assert replaced_edge_port.model_dump(exclude="edge_port_ae_members") == new_edge_port.edge_port.model_dump(
......
from unittest.mock import patch
import pytest import pytest
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
...@@ -11,9 +9,7 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr ...@@ -11,9 +9,7 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr
@pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES) @pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES)
@pytest.mark.parametrize("run_ansible_steps", [False, True]) @pytest.mark.parametrize("run_ansible_steps", [False, True])
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_modify_layer_2_circuit_change_policer_bandwidth( def test_modify_layer_2_circuit_change_policer_bandwidth(
mock_lso_interaction,
layer_2_circuit_service_type, layer_2_circuit_service_type,
run_ansible_steps, run_ansible_steps,
layer_2_circuit_subscription_factory, layer_2_circuit_subscription_factory,
...@@ -48,7 +44,7 @@ def test_modify_layer_2_circuit_change_policer_bandwidth( ...@@ -48,7 +44,7 @@ def test_modify_layer_2_circuit_change_policer_bandwidth(
subscription = Layer2Circuit.from_subscription(str(subscription.subscription_id)) subscription = Layer2Circuit.from_subscription(str(subscription.subscription_id))
assert_complete(result) assert_complete(result)
assert mock_lso_interaction.call_count == lso_step_count
assert subscription.status == SubscriptionLifecycle.ACTIVE assert subscription.status == SubscriptionLifecycle.ACTIVE
assert subscription.layer_2_circuit.policer_enabled is False assert subscription.layer_2_circuit.policer_enabled is False
assert subscription.layer_2_circuit.bandwidth is None assert subscription.layer_2_circuit.bandwidth is None
...@@ -70,9 +66,7 @@ def test_modify_layer_2_circuit_change_policer_bandwidth( ...@@ -70,9 +66,7 @@ def test_modify_layer_2_circuit_change_policer_bandwidth(
@pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES) @pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES)
@pytest.mark.parametrize("run_ansible_steps", [False, True]) @pytest.mark.parametrize("run_ansible_steps", [False, True])
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
def test_modify_layer_2_circuit_change_circuit_type( def test_modify_layer_2_circuit_change_circuit_type(
mock_lso_interaction,
layer_2_circuit_service_type, layer_2_circuit_service_type,
run_ansible_steps, run_ansible_steps,
layer_2_circuit_subscription_factory, layer_2_circuit_subscription_factory,
...@@ -105,7 +99,7 @@ def test_modify_layer_2_circuit_change_circuit_type( ...@@ -105,7 +99,7 @@ def test_modify_layer_2_circuit_change_circuit_type(
assert_complete(result) assert_complete(result)
state = extract_state(result) state = extract_state(result)
subscription = Layer2Circuit.from_subscription(state["subscription_id"]) subscription = Layer2Circuit.from_subscription(state["subscription_id"])
assert mock_lso_interaction.call_count == lso_step_count
assert subscription.status == SubscriptionLifecycle.ACTIVE assert subscription.status == SubscriptionLifecycle.ACTIVE
assert subscription.layer_2_circuit.vlan_range_lower_bound is None assert subscription.layer_2_circuit.vlan_range_lower_bound is None
assert subscription.layer_2_circuit.vlan_range_upper_bound is None assert subscription.layer_2_circuit.vlan_range_upper_bound is None
......
from unittest.mock import patch
import pytest import pytest
from gso.products.product_types.layer_2_circuit import LAYER_2_CIRCUIT_SERVICE_TYPES, Layer2Circuit from gso.products.product_types.layer_2_circuit import LAYER_2_CIRCUIT_SERVICE_TYPES, Layer2Circuit
...@@ -9,9 +7,8 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr ...@@ -9,9 +7,8 @@ from test.workflows import assert_complete, assert_lso_interaction_success, extr
@pytest.mark.workflow() @pytest.mark.workflow()
@pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES) @pytest.mark.parametrize("layer_2_circuit_service_type", LAYER_2_CIRCUIT_SERVICE_TYPES)
@pytest.mark.parametrize("run_ansible_steps", [True, False]) @pytest.mark.parametrize("run_ansible_steps", [True, False])
@patch("gso.services.lso_client._send_request")
def test_terminate_layer_2_circuit( def test_terminate_layer_2_circuit(
mock_lso_interaction, layer_2_circuit_service_type, run_ansible_steps, layer_2_circuit_subscription_factory, faker layer_2_circuit_service_type, run_ansible_steps, layer_2_circuit_subscription_factory, faker
): ):
subscription_id = str( subscription_id = str(
layer_2_circuit_subscription_factory(layer_2_circuit_service_type=layer_2_circuit_service_type).subscription_id layer_2_circuit_subscription_factory(layer_2_circuit_service_type=layer_2_circuit_service_type).subscription_id
...@@ -33,4 +30,3 @@ def test_terminate_layer_2_circuit( ...@@ -33,4 +30,3 @@ def test_terminate_layer_2_circuit(
subscription_id = state["subscription_id"] subscription_id = state["subscription_id"]
subscription = Layer2Circuit.from_subscription(subscription_id) subscription = Layer2Circuit.from_subscription(subscription_id)
assert subscription.status == "terminated" assert subscription.status == "terminated"
assert mock_lso_interaction.call_count == lso_step_count
...@@ -39,11 +39,9 @@ def base_bgp_peer_input(faker): ...@@ -39,11 +39,9 @@ def base_bgp_peer_input(faker):
@pytest.mark.parametrize("product_name", L3_PRODUCT_NAMES) @pytest.mark.parametrize("product_name", L3_PRODUCT_NAMES)
@pytest.mark.workflow() @pytest.mark.workflow()
@patch("gso.services.lso_client._send_request")
@patch("gso.workflows.l3_core_service.base_create_l3_core_service.SharePointClient") @patch("gso.workflows.l3_core_service.base_create_l3_core_service.SharePointClient")
def test_create_l3_core_service_success( def test_create_l3_core_service_success(
mock_sharepoint_client, mock_sharepoint_client,
mock_lso_client,
product_name, product_name,
faker, faker,
partner_factory, partner_factory,
...@@ -108,7 +106,6 @@ def test_create_l3_core_service_success( ...@@ -108,7 +106,6 @@ def test_create_l3_core_service_success(
subscription = SubscriptionModel.from_subscription(state["subscription_id"]) subscription = SubscriptionModel.from_subscription(state["subscription_id"])
assert subscription.product.name == product_name assert subscription.product.name == product_name
assert mock_lso_client.call_count == lso_interaction_count + 1
assert subscription.status == SubscriptionLifecycle.ACTIVE assert subscription.status == SubscriptionLifecycle.ACTIVE
assert len(subscription.l3_core.ap_list) == 1 assert len(subscription.l3_core.ap_list) == 1
assert ( assert (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment