Skip to content
Snippets Groups Projects
Commit 6f5da249 authored by Neda Moeini's avatar Neda Moeini
Browse files

Added unit tests for generate inventory function.

parent ea2c0492
No related branches found
No related tags found
1 merge request!231Added more steps in router termination including:
from unittest.mock import patch
import pytest
from orchestrator.types import SubscriptionLifecycle
from gso.products import Router
from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock
from gso.utils.helpers import available_interfaces_choices_including_current_members, validate_tt_number
from gso.products.product_blocks.router import RouterRole
from gso.utils.helpers import (
available_interfaces_choices_including_current_members,
generate_inventory_for_active_routers,
validate_tt_number,
)
from gso.utils.shared_enums import Vendor
......@@ -90,3 +97,45 @@ def test_tt_number(generate_tt_numbers):
with pytest.raises(ValueError, match=err_msg):
validate_tt_number(tt_number)
def test_generate_inventory_for_active_routers_with_single_active_router(nokia_router_subscription_factory):
"""Test the generation of inventory for a single active P router."""
router = Router.from_subscription(nokia_router_subscription_factory(router_role=RouterRole.P))
expected_result = {
"all": {
"hosts": {
router.router.router_fqdn: {
"lo4": str(router.router.router_lo_ipv4_address),
"lo6": str(router.router.router_lo_ipv6_address),
"vendor": str(router.router.vendor),
}
}
}
}
assert generate_inventory_for_active_routers(RouterRole.P) == expected_result
def test_generate_inventory_for_active_routers_with_multiple_routers(nokia_router_subscription_factory):
"""Test the generation of inventory for multiple active P and PE routers"""
for _ in range(5):
nokia_router_subscription_factory(router_role=RouterRole.P)
for _ in range(3):
nokia_router_subscription_factory(router_role=RouterRole.PE)
nokia_router_subscription_factory(status=SubscriptionLifecycle.TERMINATED)
nokia_router_subscription_factory(status=SubscriptionLifecycle.INITIAL)
# Test the generation of inventory for multiple active P routers.
inventory = generate_inventory_for_active_routers(RouterRole.P)
assert len(inventory["all"]["hosts"]) == 5
inventory = generate_inventory_for_active_routers(RouterRole.PE)
assert len(inventory["all"]["hosts"]) == 3
def test_generate_inventory_for_active_routers_with_excluded_router(nokia_router_subscription_factory):
"""Test the generation of inventory for active P routers with an excluded router."""
for _ in range(5):
nokia_router_subscription_factory(router_role=RouterRole.P)
router = nokia_router_subscription_factory(router_role=RouterRole.P)
excluded_routers = [Router.from_subscription(router).router.router_fqdn]
inventory = generate_inventory_for_active_routers(RouterRole.P, exclude_routers=excluded_routers)
assert len(inventory["all"]["hosts"]) == 5 # 6 P routers, the last one is excluded, so 5 P routers are left.
......@@ -3,6 +3,7 @@ from unittest.mock import patch
import pytest
from gso.products import Router
from gso.products.product_blocks.router import RouterRole
from test.workflows import assert_complete, assert_lso_interaction_success, extract_state, run_workflow
......@@ -75,7 +76,7 @@ def test_terminate_p_router_full_success(
data_config_filename,
):
# Prepare mock values and expected results
product_id = nokia_router_subscription_factory(router_role="p")
product_id = nokia_router_subscription_factory(router_role=RouterRole.P)
router_termination_input_form_data = {
"tt_number": faker.tt_number(),
"remove_configuration": remove_configuration,
......
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