Skip to content
Snippets Groups Projects
Verified Commit 2c0193b3 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Fix unit tests for L3 Core Services

parent 7474c033
No related branches found
No related tags found
No related merge requests found
Pipeline #89781 passed
This commit is part of merge request !286. Comments created here will be created in the context of that merge request.
Showing
with 138 additions and 87 deletions
...@@ -23,6 +23,7 @@ from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationTyp ...@@ -23,6 +23,7 @@ from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationTyp
from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.iptrunk import IptrunkType
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_blocks.service_binding_port import VLAN_ID from gso.products.product_blocks.service_binding_port import VLAN_ID
from gso.products.product_types.nren_l3_core_service import NRENL3CoreServiceType
from gso.services.partners import ( from gso.services.partners import (
PartnerEmail, PartnerEmail,
PartnerName, PartnerName,
...@@ -214,11 +215,11 @@ class EdgePortImportModel(BaseModel): ...@@ -214,11 +215,11 @@ class EdgePortImportModel(BaseModel):
return self return self
class GeantIPImportModel(BaseModel): class NRENL3CoreServiceImportModel(BaseModel):
"""Import GEANT IP model.""" """Import :term:`NREN` L3 Core Service model."""
partner: str partner: str
service_binding_ports: list["GeantIPImportModel.ServiceBindingPort"] service_binding_ports: list["NRENL3CoreServiceImportModel.ServiceBindingPort"]
class BaseBGPPeer(BaseModel): class BaseBGPPeer(BaseModel):
"""Base BGP Peer model.""" """Base BGP Peer model."""
...@@ -250,7 +251,7 @@ class GeantIPImportModel(BaseModel): ...@@ -250,7 +251,7 @@ class GeantIPImportModel(BaseModel):
ipv6_address: IPv6AddressType ipv6_address: IPv6AddressType
rtbh_enabled: bool = True rtbh_enabled: bool = True
is_multi_hop: bool = True is_multi_hop: bool = True
bgp_peers: list["GeantIPImportModel.BaseBGPPeer"] bgp_peers: list["NRENL3CoreServiceImportModel.BaseBGPPeer"]
T = TypeVar( T = TypeVar(
...@@ -262,7 +263,7 @@ T = TypeVar( ...@@ -262,7 +263,7 @@ T = TypeVar(
OfficeRouterImportModel, OfficeRouterImportModel,
OpenGearImportModel, OpenGearImportModel,
EdgePortImportModel, EdgePortImportModel,
GeantIPImportModel, NRENL3CoreServiceImportModel,
) )
common_filepath_option = typer.Option( common_filepath_option = typer.Option(
...@@ -519,21 +520,22 @@ def import_partners(file_path: str = typer.Argument(..., help="Path to the CSV f ...@@ -519,21 +520,22 @@ def import_partners(file_path: str = typer.Argument(..., help="Path to the CSV f
@app.command() @app.command()
def import_geant_ip(filepath: str = common_filepath_option) -> None: def import_nren_l3_core_service(filepath: str = common_filepath_option) -> None:
"""Import GEANT IP into GSO.""" """Import :term:`NREN` L3 Core Services into :term:`GSO`."""
successfully_imported_data = [] successfully_imported_data = []
geant_ip_list = _read_data(Path(filepath)) nren_l3_core_service_list = _read_data(Path(filepath))
for geant_ip in geant_ip_list: for nren_l3_core_service in nren_l3_core_service_list:
partner = geant_ip["partner"] partner = nren_l3_core_service["partner"]
typer.echo(f"Creating imported GEANT IP for {partner}") service_type = NRENL3CoreServiceType(nren_l3_core_service["service_type"])
typer.echo(f"Creating imported {service_type} for {partner}")
try: try:
initial_data = GeantIPImportModel(**geant_ip) initial_data = NRENL3CoreServiceImportModel(**nren_l3_core_service)
start_process("create_imported_geant_ip", [initial_data.model_dump()]) start_process("create_imported_nren_l3_core_service", [initial_data.model_dump()])
edge_ports = [sbp["edge_port"] for sbp in geant_ip["service_binding_ports"]] edge_ports = [sbp["edge_port"] for sbp in nren_l3_core_service["service_binding_ports"]]
successfully_imported_data.append(edge_ports) successfully_imported_data.append(edge_ports)
typer.echo(f"Successfully created imported GEANT IP for {partner}") typer.echo(f"Successfully created imported {service_type} for {partner}")
except ValidationError as e: except ValidationError as e:
typer.echo(f"Validation error: {e}") typer.echo(f"Validation error: {e}")
...@@ -542,14 +544,16 @@ def import_geant_ip(filepath: str = common_filepath_option) -> None: ...@@ -542,14 +544,16 @@ def import_geant_ip(filepath: str = common_filepath_option) -> None:
# Migrate new products from imported to "full" counterpart. # Migrate new products from imported to "full" counterpart.
imported_products = get_subscriptions( imported_products = get_subscriptions(
[ProductType.IMPORTED_GEANT_IP], lifecycles=[SubscriptionLifecycle.ACTIVE], includes=["subscription_id"] product_types=[ProductType.IMPORTED_GEANT_IP, ProductType.IMPORTED_IAS],
lifecycles=[SubscriptionLifecycle.ACTIVE],
includes=["subscription_id"],
) )
for subscription_id in imported_products: for subscription_id in imported_products:
typer.echo(f"Importing {subscription_id}") typer.echo(f"Importing {subscription_id}")
start_process("import_geant_ip", [subscription_id]) start_process("import_nren_l3_core_service", [subscription_id])
if successfully_imported_data: if successfully_imported_data:
typer.echo("Successfully created imported GEANT IPs:") typer.echo("Successfully created imported NREN L3 Core Services:")
for item in successfully_imported_data: for item in successfully_imported_data:
typer.echo(f"- {item}") typer.echo(f"- {item}")
...@@ -57,31 +57,31 @@ new_workflows = [ ...@@ -57,31 +57,31 @@ new_workflows = [
{ {
"name": "create_nren_l3_core_service", "name": "create_nren_l3_core_service",
"target": "CREATE", "target": "CREATE",
"description": "Create G\u00c9ANT IP", "description": "Create NREN L3 Core Service",
"product_type": "NRENL3CoreService" "product_type": "NRENL3CoreService"
}, },
{ {
"name": "modify_nren_l3_core_service", "name": "modify_nren_l3_core_service",
"target": "MODIFY", "target": "MODIFY",
"description": "Modify G\u00c9ANT IP", "description": "Modify NREN L3 Core Service",
"product_type": "NRENL3CoreService" "product_type": "NRENL3CoreService"
}, },
{ {
"name": "create_imported_nren_l3_core_service", "name": "create_imported_nren_l3_core_service",
"target": "CREATE", "target": "CREATE",
"description": "Import G\u00c9ANT IP", "description": "Create imported NREN L3 Core Service",
"product_type": "ImportedNRENL3CoreService" "product_type": "ImportedNRENL3CoreService"
}, },
{ {
"name": "import_nren_l3_core_service", "name": "import_nren_l3_core_service",
"target": "MODIFY", "target": "MODIFY",
"description": "Import G\u00c9ANT IP", "description": "Import NREN L3 Core Service",
"product_type": "ImportedNRENL3CoreService" "product_type": "ImportedNRENL3CoreService"
}, },
{ {
"name": "migrate_nren_l3_core_service", "name": "migrate_nren_l3_core_service",
"target": "MODIFY", "target": "MODIFY",
"description": "Migrate G\u00c9ANT IP", "description": "Migrate NREN L3 Core Service",
"product_type": "NRENL3CoreService" "product_type": "NRENL3CoreService"
} }
] ]
......
...@@ -36,7 +36,7 @@ INSERT INTO products (name, description, product_type, tag, status) VALUES ('IAS ...@@ -36,7 +36,7 @@ INSERT INTO products (name, description, product_type, tag, status) VALUES ('IAS
INSERT INTO products (name, description, product_type, tag, status) VALUES ('Imported IAS', 'A pre-existing Internet Access Service that is imported into the service database', 'ImportedNRENL3CoreService', 'IMP_IAS', 'active') RETURNING products.product_id INSERT INTO products (name, description, product_type, tag, status) VALUES ('Imported IAS', 'A pre-existing Internet Access Service that is imported into the service database', 'ImportedNRENL3CoreService', 'IMP_IAS', 'active') RETURNING products.product_id
""")) """))
conn.execute(sa.text(""" conn.execute(sa.text("""
INSERT INTO fixed_inputs (name, value, product_id) VALUES ('nren_l3_core_service_type', 'IAS', (SELECT products.product_id FROM products WHERE products.name IN ('IAS'))), ('nren_l3_core_service_type', 'IMPORTED_IAS', (SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS'))), ('nren_l3_core_service_type', 'GEANT_IP', (SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP'))), ('nren_l3_core_service_type', 'IMPORTED_GEANT_IP', (SELECT products.product_id FROM products WHERE products.name IN ('Imported GÉANT IP'))) INSERT INTO fixed_inputs (name, value, product_id) VALUES ('nren_l3_core_service_type', 'IAS', (SELECT products.product_id FROM products WHERE products.name IN ('IAS'))), ('nren_l3_core_service_type', 'IMPORTED IAS', (SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS'))), ('nren_l3_core_service_type', 'GÉANT IP', (SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP'))), ('nren_l3_core_service_type', 'IMPORTEDANT IP', (SELECT products.product_id FROM products WHERE products.name IN ('Imported GÉANT IP')))
""")) """))
conn.execute(sa.text(""" conn.execute(sa.text("""
INSERT INTO product_blocks (name, description, tag, status) VALUES ('EdgePortBlock', 'The product block with all attributes of an Edge Port', 'EP_BLOCK', 'active') RETURNING product_blocks.product_block_id INSERT INTO product_blocks (name, description, tag, status) VALUES ('EdgePortBlock', 'The product block with all attributes of an Edge Port', 'EP_BLOCK', 'active') RETURNING product_blocks.product_block_id
......
...@@ -17,8 +17,10 @@ class NRENL3CoreServiceType(strEnum): ...@@ -17,8 +17,10 @@ class NRENL3CoreServiceType(strEnum):
The core services offered include GÉANT IP for R&E access, and the Internet Access Service. The core services offered include GÉANT IP for R&E access, and the Internet Access Service.
""" """
GEANT_IP = "GEANT_IP" GEANT_IP = "GÉANT IP"
IMPORTED_GEANT_IP = "IMPORTED GÉANT IP"
IAS = "IAS" IAS = "IAS"
IMPORTED_IAS = "IMPORTED IAS"
class NRENL3CoreServiceInactive(SubscriptionModel, is_base=True): class NRENL3CoreServiceInactive(SubscriptionModel, is_base=True):
......
...@@ -16,7 +16,7 @@ from gso.products.product_blocks.bgp_session import BGPSession, IPFamily ...@@ -16,7 +16,7 @@ from gso.products.product_blocks.bgp_session import BGPSession, IPFamily
from gso.products.product_blocks.nren_l3_core_service import NRENAccessPortInactive from gso.products.product_blocks.nren_l3_core_service import NRENAccessPortInactive
from gso.products.product_blocks.service_binding_port import VLAN_ID, ServiceBindingPortInactive from gso.products.product_blocks.service_binding_port import VLAN_ID, ServiceBindingPortInactive
from gso.products.product_types.edge_port import EdgePort from gso.products.product_types.edge_port import EdgePort
from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreServiceInactive from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreServiceInactive, NRENL3CoreServiceType
from gso.services.partners import get_partner_by_name from gso.services.partners import get_partner_by_name
from gso.services.subscriptions import get_product_id_by_name from gso.services.subscriptions import get_product_id_by_name
from gso.utils.shared_enums import SBPType from gso.utils.shared_enums import SBPType
...@@ -56,20 +56,24 @@ def initial_input_form_generator() -> FormGenerator: ...@@ -56,20 +56,24 @@ def initial_input_form_generator() -> FormGenerator:
is_multi_hop: bool = True is_multi_hop: bool = True
bgp_peers: list[BaseBGPPeer] bgp_peers: list[BaseBGPPeer]
class ImportGeantIPForm(FormPage): class ImportNRENL3CoreServiceForm(FormPage):
partner: str partner: str
service_binding_ports: list[ServiceBindingPort] service_binding_ports: list[ServiceBindingPort]
nren_l3_core_service_type: NRENL3CoreServiceType
user_input = yield ImportGeantIPForm user_input = yield ImportNRENL3CoreServiceForm
return user_input.model_dump() return user_input.model_dump()
@step("Create subscription") @step("Create subscription")
def create_subscription(partner: str) -> dict: def create_subscription(partner: str, nren_l3_core_service_type: NRENL3CoreServiceType) -> dict:
"""Create a new subscription object in the database.""" """Create a new subscription object in the database."""
partner_id = get_partner_by_name(partner)["partner_id"] partner_id = get_partner_by_name(partner)["partner_id"]
product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) if nren_l3_core_service_type == NRENL3CoreServiceType.GEANT_IP:
product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP)
elif nren_l3_core_service_type == NRENL3CoreServiceType.IAS:
product_id = get_product_id_by_name(ProductName.IMPORTED_IAS)
subscription = ImportedNRENL3CoreServiceInactive.from_product_id(product_id, partner_id) subscription = ImportedNRENL3CoreServiceInactive.from_product_id(product_id, partner_id)
return {"subscription": subscription, "subscription_id": subscription.subscription_id} return {"subscription": subscription, "subscription_id": subscription.subscription_id}
...@@ -96,13 +100,13 @@ def initialize_subscription(subscription: ImportedNRENL3CoreServiceInactive, ser ...@@ -96,13 +100,13 @@ def initialize_subscription(subscription: ImportedNRENL3CoreServiceInactive, ser
) )
) )
subscription.description = "GEANT IP service" subscription.description = f"{subscription.product} service"
return {"subscription": subscription} return {"subscription": subscription}
@workflow( @workflow(
"Import GÉANT IP", "Create imported NREN L3 Core Service",
initial_input_form=initial_input_form_generator, initial_input_form=initial_input_form_generator,
target=Target.CREATE, target=Target.CREATE,
) )
......
...@@ -2,26 +2,44 @@ ...@@ -2,26 +2,44 @@
from orchestrator.targets import Target from orchestrator.targets import Target
from orchestrator.types import State, UUIDstr from orchestrator.types import State, UUIDstr
from orchestrator.utils.errors import ProcessFailureError
from orchestrator.workflow import StepList, done, init, step, workflow from orchestrator.workflow import StepList, done, init, step, workflow
from orchestrator.workflows.steps import resync, store_process_subscription, unsync from orchestrator.workflows.steps import resync, store_process_subscription, unsync
from orchestrator.workflows.utils import wrap_modify_initial_input_form from orchestrator.workflows.utils import wrap_modify_initial_input_form
from gso.products import ProductName from gso.products import ProductName
from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreService, NRENL3CoreService from gso.products.product_types.nren_l3_core_service import (
ImportedNRENL3CoreService,
NRENL3CoreService,
NRENL3CoreServiceType,
)
from gso.services.subscriptions import get_product_id_by_name from gso.services.subscriptions import get_product_id_by_name
@step("Create new IP trunk subscription") @step("Create imported subscription")
def import_geant_ip_subscription(subscription_id: UUIDstr) -> State: def import_nren_l3_core_service_subscription(subscription_id: UUIDstr) -> State:
"""Take an ImportedGeantIP subscription, and turn it into an GeantIP subscription.""" """Take an imported subscription, and turn it into an :term:`NREN` L3 Core Service subscription."""
old_geant_ip = ImportedNRENL3CoreService.from_subscription(subscription_id) old_nren_l3_core_service = ImportedNRENL3CoreService.from_subscription(subscription_id)
new_subscription_id = get_product_id_by_name(ProductName.GEANT_IP) if old_nren_l3_core_service.nren_l3_core_service_type == NRENL3CoreServiceType.IMPORTED_GEANT_IP:
new_subscription = NRENL3CoreService.from_other_product(old_geant_ip, new_subscription_id) # type: ignore[arg-type] new_subscription_id = get_product_id_by_name(ProductName.GEANT_IP)
elif old_nren_l3_core_service.nren_l3_core_service_type == NRENL3CoreServiceType.IMPORTED_IAS:
new_subscription_id = get_product_id_by_name(ProductName.IAS)
else:
msg = f"This {old_nren_l3_core_service.nren_l3_core_service_type} is already imported, nothing to do."
raise ProcessFailureError(message=msg, details=old_nren_l3_core_service)
new_subscription = NRENL3CoreService.from_other_product(old_nren_l3_core_service, new_subscription_id) # type: ignore[arg-type]
return {"subscription": new_subscription} return {"subscription": new_subscription}
@workflow("Import GÉANT IP", target=Target.MODIFY, initial_input_form=wrap_modify_initial_input_form(None)) @workflow("Import NREN L3 Core Service", target=Target.MODIFY, initial_input_form=wrap_modify_initial_input_form(None))
def import_nren_l3_core_service() -> StepList: def import_nren_l3_core_service() -> StepList:
"""Modify an ImportedGeantIP subscription into an GeantIP subscription to complete the import.""" """Modify an imported subscription into an :term:`NREN` L3 Core Service subscription to complete the import."""
return init >> store_process_subscription(Target.MODIFY) >> unsync >> import_geant_ip_subscription >> resync >> done return (
init
>> store_process_subscription(Target.MODIFY)
>> unsync
>> import_nren_l3_core_service_subscription
>> resync
>> done
)
...@@ -280,7 +280,7 @@ def create_new_sbp_blocks(subscription: NRENL3CoreService, added_service_binding ...@@ -280,7 +280,7 @@ def create_new_sbp_blocks(subscription: NRENL3CoreService, added_service_binding
@workflow( @workflow(
"Modify :term:`NREN` L3 Core Service", "Modify NREN L3 Core Service",
initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator), initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator),
target=Target.MODIFY, target=Target.MODIFY,
) )
......
...@@ -13,11 +13,12 @@ from gso.cli.imports import ( ...@@ -13,11 +13,12 @@ from gso.cli.imports import (
import_sites, import_sites,
import_super_pop_switches, import_super_pop_switches,
) )
from gso.products import Router, Site
from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType
from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.iptrunk import IptrunkType
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_blocks.site import SiteTier from gso.products.product_blocks.site import SiteTier
from gso.products.product_types.router import Router
from gso.products.product_types.site import Site
from gso.utils.helpers import iso_from_ipv4 from gso.utils.helpers import iso_from_ipv4
from gso.utils.shared_enums import Vendor from gso.utils.shared_enums import Vendor
from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.interfaces import PhysicalPortCapacity
......
...@@ -38,12 +38,12 @@ from gso.utils.types.interfaces import LAGMember, LAGMemberList ...@@ -38,12 +38,12 @@ from gso.utils.types.interfaces import LAGMember, LAGMemberList
from test.fixtures import ( # noqa: F401 from test.fixtures import ( # noqa: F401
bgp_session_subscription_factory, bgp_session_subscription_factory,
edge_port_subscription_factory, edge_port_subscription_factory,
geant_ip_subscription_factory,
iptrunk_side_subscription_factory, iptrunk_side_subscription_factory,
iptrunk_subscription_factory, iptrunk_subscription_factory,
juniper_router_subscription_factory, juniper_router_subscription_factory,
nokia_router_subscription_factory, nokia_router_subscription_factory,
nren_access_port_factory, nren_access_port_factory,
nren_l3_core_service_subscription_factory,
office_router_subscription_factory, office_router_subscription_factory,
opengear_subscription_factory, opengear_subscription_factory,
service_binding_port_factory, service_binding_port_factory,
......
from test.fixtures.edge_port_fixtures import edge_port_subscription_factory from test.fixtures.edge_port_fixtures import edge_port_subscription_factory
from test.fixtures.geant_ip_fixtures import ( from test.fixtures.iptrunk_fixtures import iptrunk_side_subscription_factory, iptrunk_subscription_factory
from test.fixtures.nren_l3_core_service_fixtures import (
bgp_session_subscription_factory, bgp_session_subscription_factory,
geant_ip_subscription_factory,
nren_access_port_factory, nren_access_port_factory,
nren_l3_core_service_subscription_factory,
service_binding_port_factory, service_binding_port_factory,
) )
from test.fixtures.iptrunk_fixtures import iptrunk_side_subscription_factory, iptrunk_subscription_factory
from test.fixtures.office_router_fixtures import office_router_subscription_factory from test.fixtures.office_router_fixtures import office_router_subscription_factory
from test.fixtures.opengear_fixtures import opengear_subscription_factory from test.fixtures.opengear_fixtures import opengear_subscription_factory
from test.fixtures.router_fixtures import juniper_router_subscription_factory, nokia_router_subscription_factory from test.fixtures.router_fixtures import juniper_router_subscription_factory, nokia_router_subscription_factory
...@@ -15,12 +15,12 @@ from test.fixtures.super_pop_switch_fixtures import super_pop_switch_subscriptio ...@@ -15,12 +15,12 @@ from test.fixtures.super_pop_switch_fixtures import super_pop_switch_subscriptio
__all__ = [ __all__ = [
"bgp_session_subscription_factory", "bgp_session_subscription_factory",
"edge_port_subscription_factory", "edge_port_subscription_factory",
"geant_ip_subscription_factory",
"iptrunk_side_subscription_factory", "iptrunk_side_subscription_factory",
"iptrunk_subscription_factory", "iptrunk_subscription_factory",
"juniper_router_subscription_factory", "juniper_router_subscription_factory",
"nokia_router_subscription_factory", "nokia_router_subscription_factory",
"nren_access_port_factory", "nren_access_port_factory",
"nren_l3_core_service_subscription_factory",
"office_router_subscription_factory", "office_router_subscription_factory",
"opengear_subscription_factory", "opengear_subscription_factory",
"service_binding_port_factory", "service_binding_port_factory",
......
...@@ -5,13 +5,14 @@ from orchestrator.db import ( ...@@ -5,13 +5,14 @@ from orchestrator.db import (
from orchestrator.domain import SubscriptionModel from orchestrator.domain import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle, UUIDstr from orchestrator.types import SubscriptionLifecycle, UUIDstr
from gso.products import ProductName, Router from gso.products import ProductName
from gso.products.product_blocks.edge_port import ( from gso.products.product_blocks.edge_port import (
EdgePortAEMemberBlock, EdgePortAEMemberBlock,
EdgePortType, EdgePortType,
EncapsulationType, EncapsulationType,
) )
from gso.products.product_types.edge_port import EdgePortInactive, ImportedEdgePortInactive from gso.products.product_types.edge_port import EdgePortInactive, ImportedEdgePortInactive
from gso.products.product_types.router import Router
from gso.services import subscriptions from gso.services import subscriptions
from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.interfaces import PhysicalPortCapacity
......
...@@ -6,11 +6,16 @@ from orchestrator.db import db ...@@ -6,11 +6,16 @@ from orchestrator.db import db
from orchestrator.domain import SubscriptionModel from orchestrator.domain import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle, UUIDstr from orchestrator.types import SubscriptionLifecycle, UUIDstr
from gso.products import EdgePort, ProductName from gso.products import ProductName
from gso.products.product_blocks.bgp_session import BGPSession, IPFamily from gso.products.product_blocks.bgp_session import BGPSession, IPFamily
from gso.products.product_blocks.nren_l3_core_service import NRENAccessPort from gso.products.product_blocks.nren_l3_core_service import NRENAccessPort
from gso.products.product_blocks.service_binding_port import ServiceBindingPort from gso.products.product_blocks.service_binding_port import ServiceBindingPort
from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreService, NRENL3CoreServiceInactive from gso.products.product_types.edge_port import EdgePort
from gso.products.product_types.nren_l3_core_service import (
ImportedNRENL3CoreService,
NRENL3CoreServiceInactive,
NRENL3CoreServiceType,
)
from gso.services import subscriptions from gso.services import subscriptions
from gso.utils.shared_enums import APType, SBPType from gso.utils.shared_enums import APType, SBPType
from gso.utils.types.ip_address import IPAddress from gso.utils.types.ip_address import IPAddress
...@@ -55,7 +60,7 @@ def bgp_session_subscription_factory(faker): ...@@ -55,7 +60,7 @@ def bgp_session_subscription_factory(faker):
@pytest.fixture() @pytest.fixture()
def service_binding_port_factory(faker, bgp_session_subscription_factory, edge_port_subscription_factory): def service_binding_port_factory(faker, bgp_session_subscription_factory, edge_port_subscription_factory):
def create_service_binding_port( def create_service_binding_port(
sbp_bgp_session_list: list | None = None, bgp_session_list: list[BGPSession] | None = None,
geant_sid: str | None = None, geant_sid: str | None = None,
sbp_type: SBPType = SBPType.L3, sbp_type: SBPType = SBPType.L3,
ipv4_address: str | None = None, ipv4_address: str | None = None,
...@@ -79,7 +84,7 @@ def service_binding_port_factory(faker, bgp_session_subscription_factory, edge_p ...@@ -79,7 +84,7 @@ def service_binding_port_factory(faker, bgp_session_subscription_factory, edge_p
ipv6_mask=ipv6_mask or faker.ipv6_netmask(), ipv6_mask=ipv6_mask or faker.ipv6_netmask(),
custom_firewall_filters=custom_firewall_filters, custom_firewall_filters=custom_firewall_filters,
geant_sid=geant_sid or faker.geant_sid(), geant_sid=geant_sid or faker.geant_sid(),
sbp_bgp_session_list=sbp_bgp_session_list bgp_session_list=bgp_session_list
or [ or [
bgp_session_subscription_factory(families=[IPFamily.V4UNICAST]), bgp_session_subscription_factory(families=[IPFamily.V4UNICAST]),
bgp_session_subscription_factory(families=[IPFamily.V6UNICAST], peer_address=faker.ipv6()), bgp_session_subscription_factory(families=[IPFamily.V6UNICAST], peer_address=faker.ipv6()),
...@@ -98,58 +103,71 @@ def nren_access_port_factory(faker, service_binding_port_factory): ...@@ -98,58 +103,71 @@ def nren_access_port_factory(faker, service_binding_port_factory):
): ):
return NRENAccessPort.new( return NRENAccessPort.new(
subscription_id=uuid4(), subscription_id=uuid4(),
nren_ap_type=nren_ap_type or random.choice(list(APType)), # noqa: S311 ap_type=nren_ap_type or random.choice(list(APType)), # noqa: S311
geant_ip_sbp=service_binding_port or service_binding_port_factory(), sbp=service_binding_port or service_binding_port_factory(),
) )
return create_nren_access_port return create_nren_access_port
@pytest.fixture() @pytest.fixture()
def geant_ip_subscription_factory( def nren_l3_core_service_subscription_factory(
faker, faker,
partner_factory, partner_factory,
nren_access_port_factory, nren_access_port_factory,
): ):
def create_geant_ip_subscription( def create_nren_l3_core_service_subscription(
nren_l3_core_service_type: NRENL3CoreServiceType,
description=None, description=None,
partner: dict | None = None, partner: dict | None = None,
nren_ap_list: list[NRENAccessPort] | None = None, nren_ap_list: list[NRENAccessPort] | None = None,
start_date="2023-05-24T00:00:00+00:00", start_date="2023-05-24T00:00:00+00:00",
status: SubscriptionLifecycle | None = None, status: SubscriptionLifecycle | None = None,
*,
is_imported=True,
) -> UUIDstr: ) -> UUIDstr:
partner = partner or partner_factory() partner = partner or partner_factory()
if is_imported: match nren_l3_core_service_type:
product_id = subscriptions.get_product_id_by_name(ProductName.GEANT_IP) case NRENL3CoreServiceType.GEANT_IP:
geant_ip_subscription = NRENL3CoreServiceInactive.from_product_id( product_id = subscriptions.get_product_id_by_name(ProductName.GEANT_IP)
product_id, customer_id=partner["partner_id"], insync=True nren_l3_core_service_subscription = NRENL3CoreServiceInactive.from_product_id(
) product_id, customer_id=partner["partner_id"], insync=True
else: )
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) case NRENL3CoreServiceType.IMPORTED_GEANT_IP:
geant_ip_subscription = ImportedNRENL3CoreService.from_product_id( product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_GEANT_IP)
product_id, customer_id=partner["partner_id"], insync=True nren_l3_core_service_subscription = ImportedNRENL3CoreService.from_product_id(
) product_id, customer_id=partner["partner_id"], insync=True
)
case NRENL3CoreServiceType.IAS:
product_id = subscriptions.get_product_id_by_name(ProductName.IAS)
nren_l3_core_service_subscription = NRENL3CoreServiceInactive.from_product_id(
product_id, customer_id=partner["partner_id"], insync=True
)
case NRENL3CoreServiceType.IMPORTED_IAS:
product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_IAS)
nren_l3_core_service_subscription = ImportedNRENL3CoreService.from_product_id(
product_id, customer_id=partner["partner_id"], insync=True
)
case _:
msg = f"NREN L3 Core Service type not found: {nren_l3_core_service_type}"
raise ValueError(msg)
# Default nren_ap_list creation with primary and backup access ports # Default nren_ap_list creation with primary and backup access ports
geant_ip_subscription.geant_ip.geant_ip_ap_list = nren_ap_list or [ nren_l3_core_service_subscription.nren_l3_core_service.nren_ap_list = nren_ap_list or [
nren_access_port_factory(nren_ap_type=APType.PRIMARY), nren_access_port_factory(nren_ap_type=APType.PRIMARY),
nren_access_port_factory(nren_ap_type=APType.BACKUP), nren_access_port_factory(nren_ap_type=APType.BACKUP),
] ]
# Update subscription with description, start date, and status # Update subscription with description, start date, and status
geant_ip_subscription = SubscriptionModel.from_other_lifecycle( nren_l3_core_service_subscription = SubscriptionModel.from_other_lifecycle(
geant_ip_subscription, nren_l3_core_service_subscription,
SubscriptionLifecycle.ACTIVE, SubscriptionLifecycle.ACTIVE,
) )
geant_ip_subscription.description = description or faker.sentence() nren_l3_core_service_subscription.description = description or faker.sentence()
geant_ip_subscription.start_date = start_date nren_l3_core_service_subscription.start_date = start_date
geant_ip_subscription.status = status or SubscriptionLifecycle.ACTIVE nren_l3_core_service_subscription.status = status or SubscriptionLifecycle.ACTIVE
geant_ip_subscription.save() nren_l3_core_service_subscription.save()
db.session.commit() db.session.commit()
return str(geant_ip_subscription.subscription_id) return str(nren_l3_core_service_subscription.subscription_id)
return create_geant_ip_subscription return create_nren_l3_core_service_subscription
...@@ -3,9 +3,9 @@ from unittest.mock import patch ...@@ -3,9 +3,9 @@ from unittest.mock import patch
import pytest import pytest
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
from gso.products import Router
from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock
from gso.products.product_blocks.router import RouterRole from gso.products.product_blocks.router import RouterRole
from gso.products.product_types.router import Router
from gso.utils.helpers import ( from gso.utils.helpers import (
available_interfaces_choices_including_current_members, available_interfaces_choices_including_current_members,
generate_inventory_for_active_routers, generate_inventory_for_active_routers,
......
...@@ -4,8 +4,10 @@ from unittest.mock import patch ...@@ -4,8 +4,10 @@ from unittest.mock import patch
import pytest import pytest
from pydantic_forms.exceptions import FormValidationError from pydantic_forms.exceptions import FormValidationError
from gso.products import EdgePort, ProductName, Router from gso.products import ProductName
from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType
from gso.products.product_types.edge_port import EdgePort
from gso.products.product_types.router import Router
from gso.services.subscriptions import get_product_id_by_name from gso.services.subscriptions import get_product_id_by_name
from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.interfaces import PhysicalPortCapacity
from test.services.conftest import MockedNetboxClient from test.services.conftest import MockedNetboxClient
......
import pytest import pytest
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
from gso.products import ImportedEdgePort
from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType from gso.products.product_blocks.edge_port import EdgePortType, EncapsulationType
from gso.products.product_types.edge_port import ImportedEdgePort
from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.interfaces import PhysicalPortCapacity
from test.workflows import assert_complete, extract_state, run_workflow from test.workflows import assert_complete, extract_state, run_workflow
......
import pytest import pytest
from orchestrator.types import SubscriptionLifecycle from orchestrator.types import SubscriptionLifecycle
from gso.products import EdgePort, ProductName from gso.products import ProductName
from gso.products.product_types.edge_port import EdgePort
from test.workflows import assert_complete, run_workflow from test.workflows import assert_complete, run_workflow
......
...@@ -2,7 +2,7 @@ from unittest.mock import patch ...@@ -2,7 +2,7 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import EdgePort from gso.products.product_types.edge_port import EdgePort
from gso.utils.types.interfaces import PhysicalPortCapacity from gso.utils.types.interfaces import PhysicalPortCapacity
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
......
...@@ -2,7 +2,7 @@ from unittest.mock import patch ...@@ -2,7 +2,7 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import EdgePort from gso.products.product_types.edge_port import EdgePort
from test.services.conftest import MockedNetboxClient from test.services.conftest import MockedNetboxClient
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
......
...@@ -2,7 +2,7 @@ from unittest.mock import patch ...@@ -2,7 +2,7 @@ from unittest.mock import patch
import pytest import pytest
from gso.products import EdgePort from gso.products.product_types.edge_port import EdgePort
from test.services.conftest import MockedNetboxClient from test.services.conftest import MockedNetboxClient
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
......
import pytest import pytest
from gso.products import Iptrunk from gso.products.product_types.iptrunk import Iptrunk
from test.workflows import ( from test.workflows import (
assert_complete, assert_complete,
assert_suspended, assert_suspended,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment