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

NAT-329 mostly all issues fixed only count for free netbox interfaces need to solved

parent b43444fe
No related branches found
No related tags found
1 merge request!125Feature/nat 329 validate interface names for migrate
......@@ -4,7 +4,8 @@ from unittest.mock import patch
import pytest
from gso.products import Iptrunk
from gso.utils.helpers import LAGMember
from gso.products.product_types.router import Router
from gso.products.product_blocks.router import RouterVendor
from test import USER_CONFIRM_EMPTY_FORM
from test.conftest import UseJuniperSide
from test.workflows import (
......@@ -16,7 +17,6 @@ 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()
......@@ -43,7 +43,7 @@ def migrate_form_input(
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)
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_BOTH:
......@@ -82,6 +82,7 @@ def migrate_form_input(
},
]
@pytest.mark.parametrize(
"migrate_form_input",
[UseJuniperSide.NONE, UseJuniperSide.SIDE_A, UseJuniperSide.SIDE_B, UseJuniperSide.SIDE_BOTH],
......@@ -154,24 +155,27 @@ def test_migrate_iptrunk_success(
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
# Get vendor for the migrated node
vendor_new = Router.from_subscription(new_router).router.vendor
# Only Nokia will be checked on netbox
num_nokia_lags = 1 if vendor_new == RouterVendor.NOKIA else 0
num_nokia_reserved = 2 * (vendor_new == RouterVendor.NOKIA)
num_nokia_attached = 2 * (vendor_new == RouterVendor.NOKIA)
# 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.
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
# This test case is for migrating Nokia to Nokia, juniper to nokia and juniper to juniper.
# Therefore, the netbox counts need to set correctly
assert mocked_create_interface.call_count == num_nokia_lags # once for creating the LAG on the newly replaced side:
assert mocked_reserve_interface.call_count == num_nokia_reserved # Twice for the new interfaces
assert mocked_attach_interface_to_lag.call_count == num_nokia_attached # Twice for the new interfaces
assert mocked_allocate_interface.call_count == num_nokia_attached # Twice for the new interfaces
assert mocked_free_interface.call_count == num_nokia_attached # Twice for the old interfaces
assert mocked_delete_interface.call_count == num_nokia_lags # 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 == new_lag_interface
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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment