Skip to content
Snippets Groups Projects
Commit f80c3d17 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

fix redeploy base config if there is a vprn

parent fada3935
Branches
No related tags found
1 merge request!356Fix/nat 1009/fix redeploy base config if there is a vprn
Pipeline #91813 failed
......@@ -222,6 +222,28 @@ def get_active_l2_circuit_services_linked_to_edge_port(edge_port_id: UUIDstr) ->
)
def get_active_vrfs_linked_to_router(router_id: UUIDstr) -> list[SubscriptionTable]:
"""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.
"""
return (
query_in_use_by_subscriptions(UUID(router_id))
.join(ProductTable)
.filter(
and_(
ProductTable.product_type == ProductType.VRF.value,
SubscriptionTable.status == SubscriptionLifecycle.ACTIVE,
)
)
.all()
)
def get_product_id_by_name(product_name: ProductName) -> UUID:
"""Retrieve the UUID of a product by its name.
......
......@@ -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["router"]["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",
......
......@@ -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
......
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 = router_subscription_factory()
router_list = [router_subscription_factory() for _ in range(3)]
excluded_vrf = vrf_subscription_factory(vrf_router_list=router_list)
router_list.append(router)
vrf_ids = []
for _ in range(3):
vrf = vrf_subscription_factory(vrf_router_list=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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment