From b43444fed811a59b186f1c36a8a195c6dd980dc8 Mon Sep 17 00:00:00 2001 From: Hakan Calim <hakan.calim@fau.de> Date: Fri, 15 Dec 2023 15:12:30 +0100 Subject: [PATCH] NAT-329 test adjusted to new input form --- .../workflows/iptrunk/test_migrate_iptrunk.py | 127 ++++++++++++------ 1 file changed, 89 insertions(+), 38 deletions(-) diff --git a/test/workflows/iptrunk/test_migrate_iptrunk.py b/test/workflows/iptrunk/test_migrate_iptrunk.py index ef096214..958addef 100644 --- a/test/workflows/iptrunk/test_migrate_iptrunk.py +++ b/test/workflows/iptrunk/test_migrate_iptrunk.py @@ -6,6 +6,7 @@ import pytest from gso.products import Iptrunk from gso.utils.helpers import LAGMember from test import USER_CONFIRM_EMPTY_FORM +from test.conftest import UseJuniperSide from test.workflows import ( assert_complete, assert_pp_interaction_success, @@ -15,8 +16,77 @@ from test.workflows import ( run_workflow, ) from test.workflows.iptrunk.test_create_iptrunk import MockedNetboxClient +from gso.products.product_blocks.router import RouterVendor +@pytest.fixture() +def migrate_form_input( + request, + faker, + iptrunk_subscription_factory, + juniper_router_subscription_factory, + nokia_router_subscription_factory, + iptrunk_side_subscription_factory, +): + use_juniper = getattr(request, "param", UseJuniperSide.NONE) + + if use_juniper == UseJuniperSide.SIDE_A: + # Both side Nokia -> side A will be Juniper + product_id = iptrunk_subscription_factory() + old_subscription = Iptrunk.from_subscription(product_id) + new_router = juniper_router_subscription_factory() + replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id) + new_side_ae_members = faker.generate_juniper_members_list()[0:2] + lag_name = "ae1" + elif use_juniper == UseJuniperSide.SIDE_B: + # Both side are Nokia -> side b will be Juniper + product_id = iptrunk_subscription_factory() + old_subscription = Iptrunk.from_subscription(product_id) + new_router = juniper_router_subscription_factory() + replace_side = str(old_subscription.iptrunk.iptrunk_sides[1].iptrunk_side_node.subscription.subscription_id) + new_side_ae_members = faker.generate_juniper_members_list()[0:2] + lag_name = "ae1" + elif use_juniper == UseJuniperSide.SIDE_BOTH: + # Both side are Juniper -> side A will be new Juniper + old_side_a_node = juniper_router_subscription_factory() + old_side_a_node = iptrunk_side_subscription_factory(iptrunk_side_node=old_side_a_node) + old_side_b_node = juniper_router_subscription_factory() + old_side_b_node = iptrunk_side_subscription_factory(iptrunk_side_node=old_side_b_node) + product_id = iptrunk_subscription_factory(iptrunk_sides=[old_side_a_node, old_side_b_node]) + old_subscription = Iptrunk.from_subscription(product_id) + new_router = juniper_router_subscription_factory() + replace_side = str(old_subscription.iptrunk.iptrunk_sides[1].iptrunk_side_node.subscription.subscription_id) + new_side_ae_members = faker.generate_juniper_members_list()[0:2] + lag_name = "ae1" + else: + # Both side are Nokia -> side a will be Nokia + product_id = iptrunk_subscription_factory() + old_subscription = Iptrunk.from_subscription(product_id) + new_router = nokia_router_subscription_factory() + replace_side = str(old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id) + new_side_ae_members = faker.generate_nokia_members_list()[0:2] + lag_name = "LAG1" + + return [ + {"subscription_id": product_id}, + { + "tt_number": faker.tt_number(), + "replace_side": replace_side, + }, + { + "new_node": new_router, + }, + { + "new_lag_interface": lag_name, + "new_lag_member_interfaces": new_side_ae_members, + }, + ] + +@pytest.mark.parametrize( + "migrate_form_input", + [UseJuniperSide.NONE, UseJuniperSide.SIDE_A, UseJuniperSide.SIDE_B, UseJuniperSide.SIDE_BOTH], + indirect=True, +) @pytest.mark.workflow() @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.migrate_ip_trunk") @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.provision_ip_trunk") @@ -39,9 +109,7 @@ def test_migrate_iptrunk_success( mocked_get_available_interfaces, mock_provision_ip_trunk, mock_migrate_ip_trunk, - iptrunk_subscription_factory, - nokia_router_subscription_factory, - faker, + migrate_form_input, data_config_filename: PathLike, ): # Set up mock return values @@ -55,34 +123,6 @@ def test_migrate_iptrunk_success( mocked_get_available_lags.return_value = mocked_netbox.get_available_lags() mocked_delete_interface.return_value = mocked_netbox.delete_interface() - product_id = iptrunk_subscription_factory() - old_subscription = Iptrunk.from_subscription(product_id) - new_router = nokia_router_subscription_factory() - - # Run workflow - migrate_form_input = [ - {"subscription_id": product_id}, - { - "tt_number": faker.tt_number(), - "replace_side": str( - old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id, - ), - }, - { - "new_node": new_router, - }, - { - "new_lag_interface": "LAG1", - "new_lag_member_interfaces": [ - LAGMember( - interface_name=f"Interface{interface}", - interface_description=faker.sentence(), - ) - for interface in range(2) - ], - }, - ] - result, process_stat, step_log = run_workflow("migrate_iptrunk", migrate_form_input) for _ in range(5): @@ -108,19 +148,30 @@ def test_migrate_iptrunk_success( assert subscription.status == "active" assert mock_provision_ip_trunk.call_count == 2 assert mock_migrate_ip_trunk.call_count == 7 + + # get some values from form + new_router = migrate_form_input[2]["new_node"] + new_lag_interface = migrate_form_input[3]["new_lag_interface"] + replace_side = migrate_form_input[1]["replace_side"] + + # Only Nokia interfaces will checked + vendor_side_a = subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.vendor + vendor_side_b = subscription.iptrunk.iptrunk_sides[1].iptrunk_side_node.vendor + # Assert all Netbox calls have been made # This test case is only for migrating Nokia to Nokia. # For Juniper to Nokia and Nokia to Juniper, the workflow is different. - assert mocked_create_interface.call_count == 1 # once for creating the LAG on the newly replaced side - assert mocked_reserve_interface.call_count == 2 # Twice for the new interfaces - assert mocked_attach_interface_to_lag.call_count == 2 # Twice for the new interfaces - assert mocked_allocate_interface.call_count == 2 # Twice for the new interfaces - assert mocked_free_interface.call_count == 2 # Twice for the old interfaces - assert mocked_delete_interface.call_count == 1 # once for deleting the LAG on the old replaced side + if (vendor_side_a == RouterVendor.NOKIA and vendor_side_b == RouterVendor.NOKIA): + assert mocked_create_interface.call_count == 1 # once for creating the LAG on the newly replaced side: + assert mocked_reserve_interface.call_count == 2 # Twice for the new interfaces + assert mocked_attach_interface_to_lag.call_count == 2 # Twice for the new interfaces + assert mocked_allocate_interface.call_count == 2 # Twice for the new interfaces + assert mocked_free_interface.call_count == 2 # Twice for the old interfaces + assert mocked_delete_interface.call_count == 1 # once for deleting the LAG on the old replaced side # Assert the new side is replaced assert str(subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id) == new_router - assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_iface == "LAG1" + assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_iface == new_lag_interface assert len(subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members) == 2 assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members[0].interface_name == "Interface0" assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members[1].interface_name == "Interface1" -- GitLab