diff --git a/Changelog.md b/Changelog.md index 23070ceba819813e5c8505db656b8c6c2b36e112..19b63b7d1e636579620c0f0611ba1a4ef970a372 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ # Changelog +## [2.37] - 2025-02-14 +- fix redeploy base config if there is a vprn + ## [2.36] - 2025-02-11 - Make use of already available app_settings instead of calling os environment - Hotfix sharepoint interaction (2 attempts) diff --git a/gso/services/subscriptions.py b/gso/services/subscriptions.py index 8c378697e64d863beb30854c5d18ce5184bcd7bf..102b2ddb29ea0954cd57c6a8b55dbbde8788e76a 100644 --- a/gso/services/subscriptions.py +++ b/gso/services/subscriptions.py @@ -185,7 +185,7 @@ def get_trunks_that_terminate_on_router( ) -def get_active_l3_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[SubscriptionTable]: +def get_active_l3_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[SubscriptionModel]: """Retrieve all active l3 core services that are on top of the given edge port. Args: @@ -194,7 +194,7 @@ def get_active_l3_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[Su Returns: A list of active services that are on top of the edge port. """ - return ( + results = ( query_in_use_by_subscriptions(UUID(edge_port_id)) .join(ProductTable) .filter( @@ -206,10 +206,12 @@ def get_active_l3_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[Su .all() ) + return [SubscriptionModel.from_subscription(result.subscription_id) for result in results] + -def get_active_l2_circuit_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[SubscriptionTable]: +def get_active_l2_circuit_services_linked_to_edge_port(edge_port_id: UUIDstr) -> list[SubscriptionModel]: """Retrieve all active l2 circuit services that are on top of the given edge port.""" - return ( + results = ( query_in_use_by_subscriptions(UUID(edge_port_id)) .join(ProductTable) .filter( @@ -221,6 +223,32 @@ def get_active_l2_circuit_services_linked_to_edge_port(edge_port_id: UUIDstr) -> .all() ) + return [SubscriptionModel.from_subscription(result.subscription_id) for result in results] + + +def get_active_vrfs_linked_to_router(router_id: UUIDstr) -> list[SubscriptionModel]: + """Retrieve all active VRFs that are linked to the router. + + Args: + router_id: The ID of the router. + + Returns: + A list of active VRFs that are linked to the router. + """ + results = ( + query_in_use_by_subscriptions(UUID(router_id)) + .join(ProductTable) + .filter( + and_( + ProductTable.product_type == ProductType.VRF.value, + SubscriptionTable.status == SubscriptionLifecycle.ACTIVE, + ) + ) + .all() + ) + + return [SubscriptionModel.from_subscription(result.subscription_id) for result in results] + def get_product_id_by_name(product_name: ProductName) -> UUID: """Retrieve the UUID of a product by its name. diff --git a/gso/utils/workflow_steps.py b/gso/utils/workflow_steps.py index fd5eac9a335ec46a25fa6f44bacf9e2694b6862e..5d6e54fb384b5f89546dc67020933fbb8a61e6c0 100644 --- a/gso/utils/workflow_steps.py +++ b/gso/utils/workflow_steps.py @@ -18,6 +18,7 @@ from gso.products.product_blocks.router import RouterRole from gso.products.product_types.iptrunk import Iptrunk from gso.services.kentik_client import KentikClient, NewKentikDevice from gso.services.lso_client import LSOState, anonymous_indifferent_lso_interaction, indifferent_lso_interaction +from gso.services.subscriptions import get_active_vrfs_linked_to_router from gso.settings import load_oss_params from gso.utils.helpers import generate_inventory_for_routers from gso.utils.shared_enums import Vendor @@ -33,8 +34,10 @@ def _deploy_base_config( *, dry_run: bool, ) -> LSOState: + vrf_list = get_active_vrfs_linked_to_router(str(subscription["subscription_id"])) extra_vars = { "wfo_router_json": subscription, + "vrf_list": vrf_list, "dry_run": dry_run, "verb": "deploy", "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Deploy base config", diff --git a/setup.py b/setup.py index 742fe44ffba1d95b3319c42ff8cd314af7ffe1bf..34e18cd6f9e462edfac6d9c7c580536662a9c247 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import find_packages, setup setup( name="geant-service-orchestrator", - version="2.36", + version="2.37", author="GÉANT Orchestration and Automation Team", author_email="goat@geant.org", description="GÉANT Service Orchestrator", diff --git a/test/fixtures/vrf_fixtures.py b/test/fixtures/vrf_fixtures.py index 09b02ed2683d7aa805654711bcaba9d56503e706..32f53447c63045b5e2a25845f4200894efb48821 100644 --- a/test/fixtures/vrf_fixtures.py +++ b/test/fixtures/vrf_fixtures.py @@ -3,7 +3,7 @@ from orchestrator.db import db from orchestrator.domain import SubscriptionModel from orchestrator.types import SubscriptionLifecycle -from gso.products import ProductName +from gso.products import ProductName, Router from gso.products.product_types.vrf import VRFInactive from gso.services.subscriptions import get_product_id_by_name @@ -19,9 +19,13 @@ def vrf_subscription_factory(faker, geant_partner): route_target: str | None = None, vrf_as_number: int | None = None, status: SubscriptionLifecycle | None = None, + vrf_router_list: list[Router] | None = None, ) -> SubscriptionModel: if partner is None: partner = geant_partner + + vrf_router_list = vrf_router_list or [] + product_id = get_product_id_by_name(ProductName.VRF) vrf_subscription = VRFInactive.from_product_id(product_id, customer_id=partner["partner_id"], insync=True) vrf_subscription.vrf.vrf_name = vrf_name or faker.pystr() @@ -32,6 +36,7 @@ def vrf_subscription_factory(faker, geant_partner): vrf_subscription = SubscriptionModel.from_other_lifecycle(vrf_subscription, SubscriptionLifecycle.ACTIVE) vrf_subscription.description = description or f"VRF {vrf_subscription.vrf.vrf_name}" vrf_subscription.start_date = start_date + vrf_subscription.vrf.vrf_router_list = [router.router for router in vrf_router_list] if status: vrf_subscription.status = status diff --git a/test/services/subscriptions.py b/test/services/subscriptions.py new file mode 100644 index 0000000000000000000000000000000000000000..599dacd5819278d21b1eaa5b5ace7352ef903ed8 --- /dev/null +++ b/test/services/subscriptions.py @@ -0,0 +1,18 @@ +from gso.services.subscriptions import get_active_vrfs_linked_to_router + + +def test_get_active_vrfs_linked_to_router(vrf_subscription_factory, router_subscription_factory): + router_list = [router_subscription_factory() for _ in range(3)] + excluded_vrf = vrf_subscription_factory(vrf_router_list=router_list) + + router = router_subscription_factory() + new_router_list = [*router_list, router] + vrf_ids = [] + for _ in range(3): + vrf = vrf_subscription_factory(vrf_router_list=new_router_list) + vrf_ids.append(vrf.subscription_id) + + vrfs = get_active_vrfs_linked_to_router(str(router.subscription_id)) + assert len(vrfs) == 3 + assert all(vrf.subscription_id in vrf_ids for vrf in vrfs) + assert excluded_vrf.subscription_id not in vrf_ids