Skip to content
Snippets Groups Projects
Commit 0080f770 authored by Hakan Calim's avatar Hakan Calim Committed by Neda Moeini
Browse files

NAT-329 test adjusted to new input form

parent ac944609
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !125. Comments created here will be created in the context of that merge request.
...@@ -6,6 +6,7 @@ import pytest ...@@ -6,6 +6,7 @@ import pytest
from gso.products import Iptrunk from gso.products import Iptrunk
from gso.utils.helpers import LAGMember from gso.utils.helpers import LAGMember
from test import USER_CONFIRM_EMPTY_FORM from test import USER_CONFIRM_EMPTY_FORM
from test.conftest import UseJuniperSide
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
assert_pp_interaction_success, assert_pp_interaction_success,
...@@ -15,8 +16,77 @@ from test.workflows import ( ...@@ -15,8 +16,77 @@ from test.workflows import (
run_workflow, run_workflow,
) )
from test.workflows.iptrunk.test_create_iptrunk import MockedNetboxClient 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() @pytest.mark.workflow()
@patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.migrate_ip_trunk") @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.migrate_ip_trunk")
@patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.provision_ip_trunk") @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.provision_ip_trunk")
...@@ -39,9 +109,7 @@ def test_migrate_iptrunk_success( ...@@ -39,9 +109,7 @@ def test_migrate_iptrunk_success(
mocked_get_available_interfaces, mocked_get_available_interfaces,
mock_provision_ip_trunk, mock_provision_ip_trunk,
mock_migrate_ip_trunk, mock_migrate_ip_trunk,
iptrunk_subscription_factory, migrate_form_input,
nokia_router_subscription_factory,
faker,
data_config_filename: PathLike, data_config_filename: PathLike,
): ):
# Set up mock return values # Set up mock return values
...@@ -55,34 +123,6 @@ def test_migrate_iptrunk_success( ...@@ -55,34 +123,6 @@ def test_migrate_iptrunk_success(
mocked_get_available_lags.return_value = mocked_netbox.get_available_lags() mocked_get_available_lags.return_value = mocked_netbox.get_available_lags()
mocked_delete_interface.return_value = mocked_netbox.delete_interface() 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) result, process_stat, step_log = run_workflow("migrate_iptrunk", migrate_form_input)
for _ in range(5): for _ in range(5):
...@@ -108,19 +148,30 @@ def test_migrate_iptrunk_success( ...@@ -108,19 +148,30 @@ def test_migrate_iptrunk_success(
assert subscription.status == "active" assert subscription.status == "active"
assert mock_provision_ip_trunk.call_count == 2 assert mock_provision_ip_trunk.call_count == 2
assert mock_migrate_ip_trunk.call_count == 7 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 # Assert all Netbox calls have been made
# This test case is only for migrating Nokia to Nokia. # This test case is only for migrating Nokia to Nokia.
# For Juniper to Nokia and Nokia to Juniper, the workflow is different. # 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 if (vendor_side_a == RouterVendor.NOKIA and vendor_side_b == RouterVendor.NOKIA):
assert mocked_reserve_interface.call_count == 2 # Twice for the new interfaces assert mocked_create_interface.call_count == 1 # once for creating the LAG on the newly replaced side:
assert mocked_attach_interface_to_lag.call_count == 2 # Twice for the new interfaces assert mocked_reserve_interface.call_count == 2 # Twice for the new interfaces
assert mocked_allocate_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_free_interface.call_count == 2 # Twice for the old interfaces assert mocked_allocate_interface.call_count == 2 # Twice for the new interfaces
assert mocked_delete_interface.call_count == 1 # once for deleting the LAG on the old replaced side 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 the new side is replaced
assert str(subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id) == new_router 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 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[0].interface_name == "Interface0"
assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members[1].interface_name == "Interface1" assert subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members[1].interface_name == "Interface1"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment