From 501326b193f9e5cca45d9dea13464e53769c57e4 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Tue, 26 Nov 2024 11:44:32 +0100 Subject: [PATCH] Rename NRENL3CoreService Rename to L3CoreService, and add Copernicus, LHCOne, and GWS as new L3 core services --- gso/cli/imports.py | 41 ++-- ...65_rename_nrenl3core_service_to_l3core_.py | 213 ++++++++++++++++++ gso/products/__init__.py | 36 ++- .../product_blocks/l3_core_service.py | 56 +++++ .../product_blocks/nren_l3_core_service.py | 60 ----- gso/products/product_types/l3_core_service.py | 66 ++++++ .../product_types/nren_l3_core_service.py | 60 ----- gso/translations/en-GB.json | 10 +- gso/workflows/__init__.py | 14 +- gso/workflows/l3_core_service/__init__.py | 1 + .../create_imported_l3_core_service.py} | 45 ++-- .../create_l3_core_service.py} | 45 ++-- .../l3_core_service/import_l3_core_service.py | 52 +++++ .../migrate_l3_core_service.py} | 26 +-- .../modify_l3_core_service.py} | 40 ++-- .../nren_l3_core_service/__init__.py | 1 - .../import_nren_l3_core_service.py | 45 ---- test/cli/test_imports.py | 36 ++- test/fixtures/__init__.py | 14 +- ...ixtures.py => l3_core_service_fixtures.py} | 106 +++++---- test/services/test_infoblox.py | 2 +- .../__init__.py | 0 .../test_create_imported_l3_core_service.py} | 19 +- .../test_create_l3_core_service.py} | 16 +- .../test_import_l3_core_service.py | 27 +++ .../test_migrate_l3_core_service.py | 56 +++++ .../test_modify_l3_core_service.py} | 157 +++++++------ .../test_import_nren_l3_core_service.py | 23 -- .../test_migrate_nren_l3_core_service.py | 49 ---- 29 files changed, 812 insertions(+), 504 deletions(-) create mode 100644 gso/migrations/versions/2024-11-25_2746f861a765_rename_nrenl3core_service_to_l3core_.py create mode 100644 gso/products/product_blocks/l3_core_service.py delete mode 100644 gso/products/product_blocks/nren_l3_core_service.py create mode 100644 gso/products/product_types/l3_core_service.py delete mode 100644 gso/products/product_types/nren_l3_core_service.py create mode 100644 gso/workflows/l3_core_service/__init__.py rename gso/workflows/{nren_l3_core_service/create_imported_nren_l3_core_service.py => l3_core_service/create_imported_l3_core_service.py} (73%) rename gso/workflows/{nren_l3_core_service/create_nren_l3_core_service.py => l3_core_service/create_l3_core_service.py} (88%) create mode 100644 gso/workflows/l3_core_service/import_l3_core_service.py rename gso/workflows/{nren_l3_core_service/migrate_nren_l3_core_service.py => l3_core_service/migrate_l3_core_service.py} (79%) rename gso/workflows/{nren_l3_core_service/modify_nren_l3_core_service.py => l3_core_service/modify_l3_core_service.py} (90%) delete mode 100644 gso/workflows/nren_l3_core_service/__init__.py delete mode 100644 gso/workflows/nren_l3_core_service/import_nren_l3_core_service.py rename test/fixtures/{nren_l3_core_service_fixtures.py => l3_core_service_fixtures.py} (59%) rename test/workflows/{nren_l3_core_service => l3_core_service}/__init__.py (100%) rename test/workflows/{nren_l3_core_service/test_create_imported_nren_l3_core_service.py => l3_core_service/test_create_imported_l3_core_service.py} (84%) rename test/workflows/{nren_l3_core_service/test_create_nren_l3_core_service.py => l3_core_service/test_create_l3_core_service.py} (83%) create mode 100644 test/workflows/l3_core_service/test_import_l3_core_service.py create mode 100644 test/workflows/l3_core_service/test_migrate_l3_core_service.py rename test/workflows/{nren_l3_core_service/test_modify_nren_l3_core_service.py => l3_core_service/test_modify_l3_core_service.py} (53%) delete mode 100644 test/workflows/nren_l3_core_service/test_import_nren_l3_core_service.py delete mode 100644 test/workflows/nren_l3_core_service/test_migrate_nren_l3_core_service.py diff --git a/gso/cli/imports.py b/gso/cli/imports.py index bb20c4f4..85eba733 100644 --- a/gso/cli/imports.py +++ b/gso/cli/imports.py @@ -238,8 +238,8 @@ class EdgePortImportModel(BaseModel): return self -class NRENL3CoreServiceImportModel(BaseModel): - """Import :term:`NREN` L3 Core Service model.""" +class L3CoreServiceImportModel(BaseModel): + """Import L3 Core Service model.""" class BaseBGPPeer(BaseModel): """Base BGP Peer model.""" @@ -278,9 +278,9 @@ class NRENL3CoreServiceImportModel(BaseModel): ipv6_address: IPv6AddressType ipv6_mask: IPV6Netmask is_multi_hop: bool = True - bgp_peers: list["NRENL3CoreServiceImportModel.BaseBGPPeer"] - v4_bfd_settings: "NRENL3CoreServiceImportModel.BFDSettingsModel" - v6_bfd_settings: "NRENL3CoreServiceImportModel.BFDSettingsModel" + bgp_peers: list["L3CoreServiceImportModel.BaseBGPPeer"] + v4_bfd_settings: "L3CoreServiceImportModel.BFDSettingsModel" + v6_bfd_settings: "L3CoreServiceImportModel.BFDSettingsModel" partner: str service_binding_ports: list[ServiceBindingPort] @@ -390,7 +390,7 @@ T = TypeVar( OfficeRouterImportModel, OpenGearImportModel, EdgePortImportModel, - NRENL3CoreServiceImportModel, + L3CoreServiceImportModel, LanSwitchInterconnectImportModel, Layer2CircuitServiceImportModel, ) @@ -655,20 +655,20 @@ def import_partners(file_path: str = typer.Argument(..., help="Path to the CSV f @app.command() -def import_nren_l3_core_service(filepath: str = common_filepath_option) -> None: - """Import :term:`NREN` L3 Core Services into :term:`GSO`.""" +def import_l3_core_service(filepath: str = common_filepath_option) -> None: + """Import L3 Core Services into :term:`GSO`.""" successfully_imported_data = [] - nren_l3_core_service_list = _read_data(Path(filepath)) + l3_core_service_list = _read_data(Path(filepath)) - for nren_l3_core_service in nren_l3_core_service_list: - partner = nren_l3_core_service["partner"] - service_type = nren_l3_core_service["service_type"] + for l3_core_service in l3_core_service_list: + partner = l3_core_service["partner"] + service_type = l3_core_service["service_type"] typer.echo(f"Creating imported {service_type} for {partner}") try: - initial_data = NRENL3CoreServiceImportModel(**nren_l3_core_service) - start_process("create_imported_nren_l3_core_service", [initial_data.model_dump()]) - edge_ports = [sbp["edge_port"] for sbp in nren_l3_core_service["service_binding_ports"]] + initial_data = L3CoreServiceImportModel(**l3_core_service) + start_process("create_imported_l3_core_service", [initial_data.model_dump()]) + edge_ports = [sbp["edge_port"] for sbp in l3_core_service["service_binding_ports"]] successfully_imported_data.append(edge_ports) typer.echo(f"Successfully created imported {service_type} for {partner}") except ValidationError as e: @@ -679,17 +679,22 @@ def import_nren_l3_core_service(filepath: str = common_filepath_option) -> None: # Migrate new products from imported to "full" counterpart. imported_products = get_subscriptions( - product_types=[ProductType.IMPORTED_GEANT_IP, ProductType.IMPORTED_IAS], + product_types=[ + ProductType.IMPORTED_GEANT_IP, + ProductType.IMPORTED_IAS, + ProductType.IMPORTED_LHCONE, + ProductType.IMPORTED_COPERNICUS, + ], lifecycles=[SubscriptionLifecycle.ACTIVE], includes=["subscription_id"], ) for subscription_id in imported_products: typer.echo(f"Importing {subscription_id}") - start_process("import_nren_l3_core_service", [subscription_id]) + start_process("import_l3_core_service", [subscription_id]) if successfully_imported_data: - typer.echo("Successfully created imported NREN L3 Core Services:") + typer.echo("Successfully created imported L3 Core Services:") for item in successfully_imported_data: typer.echo(f"- {item}") diff --git a/gso/migrations/versions/2024-11-25_2746f861a765_rename_nrenl3core_service_to_l3core_.py b/gso/migrations/versions/2024-11-25_2746f861a765_rename_nrenl3core_service_to_l3core_.py new file mode 100644 index 00000000..0655d9a4 --- /dev/null +++ b/gso/migrations/versions/2024-11-25_2746f861a765_rename_nrenl3core_service_to_l3core_.py @@ -0,0 +1,213 @@ +"""Rename NRENL3Core service to L3Core service and add LHCOne, GWS, and Copernicus. + +Revision ID: 2746f861a765 +Revises: f6ceec1af371 +Create Date: 2024-11-25 09:47:08.419689 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = '2746f861a765' +down_revision = 'f6ceec1af371' +branch_labels = None +depends_on = None + +from orchestrator.migrations.helpers import create_workflow, delete_workflow + +new_workflows = [ + { + "name": "create_l3_core_service", + "target": "CREATE", + "description": "Create L3 Core Service", + "product_type": "L3CoreService" + }, + { + "name": "modify_l3_core_service", + "target": "MODIFY", + "description": "Modify L3 Core Service", + "product_type": "L3CoreService" + }, + { + "name": "create_imported_l3_core_service", + "target": "CREATE", + "description": "Create imported L3 Core Service", + "product_type": "ImportedL3CoreService" + }, + { + "name": "import_l3_core_service", + "target": "MODIFY", + "description": "Import L3 Core Service", + "product_type": "ImportedL3CoreService" + }, + { + "name": "migrate_l3_core_service", + "target": "MODIFY", + "description": "Migrate L3 Core Service", + "product_type": "L3CoreService" + } +] + +old_workflows = [ + { + "name": "create_nren_l3_core_service", + "target": "CREATE", + "description": "Create NREN L3 Core Service", + "product_type": "NRENL3CoreService" + }, + { + "name": "modify_nren_l3_core_service", + "target": "MODIFY", + "description": "Modify NREN L3 Core Service", + "product_type": "NRENL3CoreService" + }, + { + "name": "create_imported_nren_l3_core_service", + "target": "CREATE", + "description": "Create imported NREN L3 Core Service", + "product_type": "ImportedNRENL3CoreService" + }, + { + "name": "import_nren_l3_core_service", + "target": "MODIFY", + "description": "Import NREN L3 Core Service", + "product_type": "ImportedNRENL3CoreService" + }, + { + "name": "migrate_nren_l3_core_service", + "target": "MODIFY", + "description": "Migrate NREN L3 Core Service", + "product_type": "NRENL3CoreService" + } +] + + +def upgrade() -> None: + conn = op.get_bind() + for workflow in old_workflows: + delete_workflow(conn, workflow["name"]) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP')) AND fixed_inputs.name = 'nren_l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('Imported GÉANT IP')) AND fixed_inputs.name = 'nren_l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('IAS')) AND fixed_inputs.name = 'nren_l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS')) AND fixed_inputs.name = 'nren_l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE products SET product_type='L3CoreService' WHERE product_type='NRENL3CoreService' + """)) + conn.execute(sa.text(""" +UPDATE products SET product_type='ImportedL3CoreService' WHERE product_type='ImportedNRENL3CoreService' + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('LHCOne', 'LHCOne', 'L3CoreService', 'LHC', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('Imported LHCOne', 'Imported LHCOne', 'ImportedL3CoreService', 'IMP_LHC', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('Copernicus', 'Copernicus', 'L3CoreService', 'COP', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('Imported Copernicus', 'Imported Copernicus', 'ImportedL3CoreService', 'IMP_COP', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('GWS', 'GWS', 'L3CoreService', 'GWS', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO products (name, description, product_type, tag, status) VALUES ('Imported GWS', 'Imported GWS', 'ImportedL3CoreService', 'IMP_GWS', 'active') RETURNING products.product_id + """)) + conn.execute(sa.text(""" +INSERT INTO fixed_inputs (name, value, product_id) VALUES ('l3_core_service_type', 'LHCONE', (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne'))), ('l3_core_service_type', 'IMPORTED COPERNICUS', (SELECT products.product_id FROM products WHERE products.name IN ('Imported Copernicus'))), ('l3_core_service_type', 'COPERNICUS', (SELECT products.product_id FROM products WHERE products.name IN ('Copernicus'))), ('l3_core_service_type', 'IMPORTED LHCONE', (SELECT products.product_id FROM products WHERE products.name IN ('Imported LHCOne'))), ('l3_core_service_type', 'IMPORTED GWS', (SELECT products.product_id FROM products WHERE products.name IN ('Imported GWS'))), ('l3_core_service_type', 'GWS', (SELECT products.product_id FROM products WHERE products.name IN ('GWS'))) + """)) + conn.execute(sa.text(""" +INSERT INTO product_blocks (name, description, tag, status) VALUES ('L3CoreServiceBlock', 'A Core network service on Layer 3', 'L3CORE', 'active') RETURNING product_blocks.product_block_id + """)) + conn.execute(sa.text(""" +INSERT INTO product_blocks (name, description, tag, status) VALUES ('AccessPort', 'An Access Port where a Layer 3 service terminates', 'AP', 'active') RETURNING product_blocks.product_block_id + """)) + conn.execute(sa.text(""" +INSERT INTO product_product_blocks (product_id, product_block_id) VALUES ((SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('LHCOne')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('Imported LHCOne')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('IAS')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('Imported GÉANT IP')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('Copernicus')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('Imported Copernicus')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))),((SELECT products.product_id FROM products WHERE products.name IN ('GWS')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))), ((SELECT products.product_id FROM products WHERE products.name IN ('Imported GWS')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock'))) + """)) + conn.execute(sa.text(""" +INSERT INTO product_block_relations (in_use_by_id, depends_on_id) VALUES ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('ServiceBindingPort'))) + """)) + conn.execute(sa.text(""" +INSERT INTO product_block_relations (in_use_by_id, depends_on_id) VALUES ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort'))) + """)) + conn.execute(sa.text(""" +INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VALUES ((SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('ap_type'))) + """)) + for workflow in new_workflows: + create_workflow(conn, workflow) + + +def downgrade() -> None: + conn = op.get_bind() + for workflow in new_workflows: + delete_workflow(conn, workflow["name"]) + conn.execute(sa.text(""" +DELETE FROM product_block_resource_types WHERE product_block_resource_types.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('ap_type')) + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instance_values USING product_block_resource_types WHERE subscription_instance_values.subscription_instance_id IN (SELECT subscription_instances.subscription_instance_id FROM subscription_instances WHERE subscription_instances.subscription_instance_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('ap_type')) + """)) + conn.execute(sa.text(""" +DELETE FROM product_product_blocks WHERE product_product_blocks.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS', 'GÉANT IP', 'LHCOne', 'Imported LHCOne', 'IAS', 'Imported GÉANT IP', 'Copernicus', 'Imported Copernicus', 'GWS', 'Imported GWS')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock')) + """)) + conn.execute(sa.text(""" +DELETE FROM product_block_relations WHERE product_block_relations.in_use_by_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('ServiceBindingPort')) + """)) + conn.execute(sa.text(""" +DELETE FROM product_block_relations WHERE product_block_relations.in_use_by_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('L3CoreServiceBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort')) + """)) + conn.execute(sa.text(""" +DELETE FROM fixed_inputs WHERE fixed_inputs.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS')) AND fixed_inputs.name = 'l3_core_service_type' + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instances WHERE subscription_instances.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('AccessPort', 'L3CoreServiceBlock')) + """)) + conn.execute(sa.text(""" +DELETE FROM product_blocks WHERE product_blocks.name IN ('AccessPort', 'L3CoreServiceBlock') + """)) + conn.execute(sa.text(""" +DELETE FROM processes WHERE processes.pid IN (SELECT processes_subscriptions.pid FROM processes_subscriptions WHERE processes_subscriptions.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS')))) + """)) + conn.execute(sa.text(""" +DELETE FROM processes_subscriptions WHERE processes_subscriptions.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS'))) + """)) + conn.execute(sa.text(""" +DELETE FROM subscription_instances WHERE subscription_instances.subscription_id IN (SELECT subscriptions.subscription_id FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS'))) + """)) + conn.execute(sa.text(""" +DELETE FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS')) + """)) + conn.execute(sa.text(""" +DELETE FROM products WHERE products.name IN ('LHCOne', 'Imported Copernicus', 'Copernicus', 'Imported LHCOne', 'GWS', 'Imported GWS') + """)) + conn.execute(sa.text(""" +UPDATE products SET product_type='NRENL3CoreService' WHERE product_type='L3CoreService' + """)) + conn.execute(sa.text(""" +UPDATE products SET product_type='ImportedNRENL3CoreService' WHERE product_type='ImportedL3CoreService' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='nren_l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('GÉANT IP')) AND fixed_inputs.name = 'l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='nren_l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('Imported GÉANT IP')) AND fixed_inputs.name = 'l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='nren_l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('IAS')) AND fixed_inputs.name = 'l3_core_service_type' + """)) + conn.execute(sa.text(""" +UPDATE fixed_inputs SET name='nren_l3_core_service_type' WHERE fixed_inputs.product_id = (SELECT products.product_id FROM products WHERE products.name IN ('Imported IAS')) AND fixed_inputs.name = 'l3_core_service_type' + """)) + for workflow in old_workflows: + create_workflow(conn, workflow) diff --git a/gso/products/__init__.py b/gso/products/__init__.py index 51c1cf6e..4b472c9f 100644 --- a/gso/products/__init__.py +++ b/gso/products/__init__.py @@ -10,9 +10,9 @@ from pydantic_forms.types import strEnum from gso.products.product_types.edge_port import EdgePort, ImportedEdgePort from gso.products.product_types.iptrunk import ImportedIptrunk, Iptrunk +from gso.products.product_types.l3_core_service import ImportedL3CoreService, L3CoreService from gso.products.product_types.lan_switch_interconnect import ImportedLanSwitchInterconnect, LanSwitchInterconnect from gso.products.product_types.layer_2_circuit import ImportedLayer2Circuit, Layer2Circuit, Layer2CircuitServiceType -from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreService, NRENL3CoreService from gso.products.product_types.office_router import ImportedOfficeRouter, OfficeRouter from gso.products.product_types.opengear import ImportedOpengear, Opengear from gso.products.product_types.pop_vlan import PopVlan @@ -48,6 +48,12 @@ class ProductName(strEnum): IMPORTED_GEANT_IP = "Imported GÉANT IP" IAS = "IAS" IMPORTED_IAS = "Imported IAS" + GWS = "GWS" + IMPORTED_GWS = "Imported GWS" + LHCONE = "LHCOne" + IMPORTED_LHCONE = "Imported LHCOne" + COPERNICUS = "Copernicus" + IMPORTED_COPERNICUS = "Imported Copernicus" GEANT_PLUS = Layer2CircuitServiceType.GEANT_PLUS IMPORTED_GEANT_PLUS = Layer2CircuitServiceType.IMPORTED_GEANT_PLUS EXPRESSROUTE = Layer2CircuitServiceType.EXPRESSROUTE @@ -76,10 +82,16 @@ class ProductType(strEnum): IMPORTED_OPENGEAR = Opengear.__name__ EDGE_PORT = EdgePort.__name__ IMPORTED_EDGE_PORT = ImportedEdgePort.__name__ - GEANT_IP = NRENL3CoreService.__name__ - IMPORTED_GEANT_IP = ImportedNRENL3CoreService.__name__ - IAS = NRENL3CoreService.__name__ - IMPORTED_IAS = ImportedNRENL3CoreService.__name__ + GEANT_IP = L3CoreService.__name__ + IMPORTED_GEANT_IP = ImportedL3CoreService.__name__ + IAS = L3CoreService.__name__ + IMPORTED_IAS = ImportedL3CoreService.__name__ + GWS = L3CoreService.__name__ + IMPORTED_GWS = ImportedL3CoreService.__name__ + LHCONE = L3CoreService.__name__ + IMPORTED_LHCONE = ImportedL3CoreService.__name__ + COPERNICUS = L3CoreService.__name__ + IMPORTED_COPERNICUS = ImportedL3CoreService.__name__ GEANT_PLUS = Layer2Circuit.__name__ IMPORTED_GEANT_PLUS = ImportedLayer2Circuit.__name__ EXPRESSROUTE = Layer2Circuit.__name__ @@ -107,10 +119,16 @@ SUBSCRIPTION_MODEL_REGISTRY.update( ProductName.IMPORTED_OPENGEAR.value: ImportedOpengear, ProductName.EDGE_PORT.value: EdgePort, ProductName.IMPORTED_EDGE_PORT.value: ImportedEdgePort, - ProductName.GEANT_IP.value: NRENL3CoreService, - ProductName.IMPORTED_GEANT_IP.value: ImportedNRENL3CoreService, - ProductName.IAS.value: NRENL3CoreService, - ProductName.IMPORTED_IAS.value: ImportedNRENL3CoreService, + ProductName.GEANT_IP.value: L3CoreService, + ProductName.IMPORTED_GEANT_IP.value: ImportedL3CoreService, + ProductName.IAS.value: L3CoreService, + ProductName.IMPORTED_IAS.value: ImportedL3CoreService, + ProductName.GWS.value: L3CoreService, + ProductName.IMPORTED_GWS.value: ImportedL3CoreService, + ProductName.LHCONE.value: L3CoreService, + ProductName.IMPORTED_LHCONE.value: ImportedL3CoreService, + ProductName.COPERNICUS.value: L3CoreService, + ProductName.IMPORTED_COPERNICUS.value: ImportedL3CoreService, ProductName.GEANT_PLUS.value: Layer2Circuit, ProductName.IMPORTED_GEANT_PLUS.value: ImportedLayer2Circuit, ProductName.EXPRESSROUTE.value: Layer2Circuit, diff --git a/gso/products/product_blocks/l3_core_service.py b/gso/products/product_blocks/l3_core_service.py new file mode 100644 index 00000000..add0724b --- /dev/null +++ b/gso/products/product_blocks/l3_core_service.py @@ -0,0 +1,56 @@ +"""Product blocks for Layer 3 Core Service products.""" + +from orchestrator.domain.base import ProductBlockModel +from orchestrator.types import SubscriptionLifecycle +from pydantic import Field + +from gso.products.product_blocks.service_binding_port import ( + ServiceBindingPort, + ServiceBindingPortInactive, + ServiceBindingPortProvisioning, +) +from gso.utils.shared_enums import APType + + +class AccessPortInactive(ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="AccessPort"): + """An access port for an R&E service that is inactive.""" + + ap_type: APType | None = None + sbp: ServiceBindingPortInactive + + +class AccessPortProvisioning(AccessPortInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): + """An access port for an R&E service that is being provisioned.""" + + ap_type: APType + sbp: ServiceBindingPortProvisioning + + +class AccessPort(AccessPortProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): + """An access port for an R&E service.""" + + #: The type of Access Port + ap_type: APType + #: The corresponding :term:`SBP` of this Access Port. + sbp: ServiceBindingPort + + +class L3CoreServiceBlockInactive( + ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="L3CoreServiceBlock" +): + """An inactive L3 Core service subscription. See :class:`L3CoreServiceBlock`.""" + + ap_list: list[AccessPortInactive] = Field(default_factory=list) + + +class L3CoreServiceBlockProvisioning(L3CoreServiceBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): + """A provisioning L3 Core Service subscription. See :class:`L3CoreServiceBlock`.""" + + ap_list: list[AccessPortProvisioning] # type: ignore[assignment] + + +class L3CoreServiceBlock(L3CoreServiceBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): + """An active L3 Core Service subscription block.""" + + #: The list of Access Points where this service is present. + ap_list: list[AccessPort] # type: ignore[assignment] diff --git a/gso/products/product_blocks/nren_l3_core_service.py b/gso/products/product_blocks/nren_l3_core_service.py deleted file mode 100644 index 37eb7616..00000000 --- a/gso/products/product_blocks/nren_l3_core_service.py +++ /dev/null @@ -1,60 +0,0 @@ -"""Product blocks for :class:`NREN` Layer 3 Core Service products.""" - -from orchestrator.domain.base import ProductBlockModel -from orchestrator.types import SubscriptionLifecycle -from pydantic import Field - -from gso.products.product_blocks.service_binding_port import ( - ServiceBindingPort, - ServiceBindingPortInactive, - ServiceBindingPortProvisioning, -) -from gso.utils.shared_enums import APType - - -class NRENAccessPortInactive( - ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="NRENAccessPort" -): - """An access port for an R&E :term:`NREN` service that is inactive.""" - - ap_type: APType | None = None - sbp: ServiceBindingPortInactive - - -class NRENAccessPortProvisioning(NRENAccessPortInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): - """An access port for an R&E :term:`NREN` service that is being provisioned.""" - - ap_type: APType - sbp: ServiceBindingPortProvisioning - - -class NRENAccessPort(NRENAccessPortProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): - """An access port for an R&E :term:`NREN` service.""" - - #: The type of Access Port - ap_type: APType - #: The corresponding :term:`SBP` of this Access Port. - sbp: ServiceBindingPort - - -class NRENL3CoreServiceBlockInactive( - ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="NRENL3CoreServiceBlock" -): - """An inactive :term:`NREN` L3 Core service subscription. See :class:`NRENL3CoreServiceBlock`.""" - - nren_ap_list: list[NRENAccessPortInactive] = Field(default_factory=list) - - -class NRENL3CoreServiceBlockProvisioning( - NRENL3CoreServiceBlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING] -): - """A provisioning :term:`NREN` L3 Core Service subscription. See :class:`NRENL3CoreServiceBlock`.""" - - nren_ap_list: list[NRENAccessPortProvisioning] # type: ignore[assignment] - - -class NRENL3CoreServiceBlock(NRENL3CoreServiceBlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): - """An active :term:`NREN` L3 Core Service subscription block.""" - - #: The list of Access Points where this service is present. - nren_ap_list: list[NRENAccessPort] # type: ignore[assignment] diff --git a/gso/products/product_types/l3_core_service.py b/gso/products/product_types/l3_core_service.py new file mode 100644 index 00000000..8d4c96d5 --- /dev/null +++ b/gso/products/product_types/l3_core_service.py @@ -0,0 +1,66 @@ +"""L3 Core Service product type.""" + +from orchestrator.domain import SubscriptionModel +from orchestrator.types import SubscriptionLifecycle +from pydantic_forms.types import strEnum + +from gso.products.product_blocks.l3_core_service import ( + L3CoreServiceBlock, + L3CoreServiceBlockInactive, + L3CoreServiceBlockProvisioning, +) + + +class L3CoreServiceType(strEnum): + """Available types of Layer 3 Core Services. + + The core services offered include GÉANT IP for R&E access, and the Internet Access Service. + """ + + GEANT_IP = "GÉANT IP" + IMPORTED_GEANT_IP = "IMPORTED GÉANT IP" + IAS = "IAS" + IMPORTED_IAS = "IMPORTED IAS" + GWS = "GWS" + IMPORTED_GWS = "IMPORTED GWS" + LHCONE = "LHCONE" + IMPORTED_LHCONE = "IMPORTED LHCONE" + COPERNICUS = "COPERNICUS" + IMPORTED_COPERNICUS = "IMPORTED COPERNICUS" + + +class L3CoreServiceInactive(SubscriptionModel, is_base=True): + """An inactive L3 Core Service subscription.""" + + l3_core_service_type: L3CoreServiceType + l3_core_service: L3CoreServiceBlockInactive + + +class L3CoreServiceProvisioning(L3CoreServiceInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): + """A L3 Core Service subscription that's being provisioned.""" + + l3_core_service_type: L3CoreServiceType + l3_core_service: L3CoreServiceBlockProvisioning + + +class L3CoreService(L3CoreServiceProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): + """An active L3 Core Service subscription.""" + + l3_core_service_type: L3CoreServiceType + l3_core_service: L3CoreServiceBlock + + +class ImportedL3CoreServiceInactive(SubscriptionModel, is_base=True): + """An imported, inactive L3 Core Service subscription.""" + + l3_core_service_type: L3CoreServiceType + l3_core_service: L3CoreServiceBlockInactive + + +class ImportedL3CoreService( + ImportedL3CoreServiceInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] +): + """An imported L3 Core Service subscription.""" + + l3_core_service_type: L3CoreServiceType + l3_core_service: L3CoreServiceBlock diff --git a/gso/products/product_types/nren_l3_core_service.py b/gso/products/product_types/nren_l3_core_service.py deleted file mode 100644 index 20aa5ab2..00000000 --- a/gso/products/product_types/nren_l3_core_service.py +++ /dev/null @@ -1,60 +0,0 @@ -""":term:`NREN` L3 Core Service product type.""" - -from orchestrator.domain import SubscriptionModel -from orchestrator.types import SubscriptionLifecycle -from pydantic_forms.types import strEnum - -from gso.products.product_blocks.nren_l3_core_service import ( - NRENL3CoreServiceBlock, - NRENL3CoreServiceBlockInactive, - NRENL3CoreServiceBlockProvisioning, -) - - -class NRENL3CoreServiceType(strEnum): - """Available types of :term:`NREN` Layer 3 Core Services. - - The core services offered include GÉANT IP for R&E access, and the Internet Access Service. - """ - - GEANT_IP = "GÉANT IP" - IMPORTED_GEANT_IP = "IMPORTED GÉANT IP" - IAS = "IAS" - IMPORTED_IAS = "IMPORTED IAS" - - -class NRENL3CoreServiceInactive(SubscriptionModel, is_base=True): - """An inactive :term:`NREN` L3 Core Service subscription.""" - - nren_l3_core_service_type: NRENL3CoreServiceType - nren_l3_core_service: NRENL3CoreServiceBlockInactive - - -class NRENL3CoreServiceProvisioning(NRENL3CoreServiceInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]): - """A :term:`NREN` L3 Core Service subscription that's being provisioned.""" - - nren_l3_core_service_type: NRENL3CoreServiceType - nren_l3_core_service: NRENL3CoreServiceBlockProvisioning - - -class NRENL3CoreService(NRENL3CoreServiceProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]): - """An active :term:`NREN` L3 Core Service subscription.""" - - nren_l3_core_service_type: NRENL3CoreServiceType - nren_l3_core_service: NRENL3CoreServiceBlock - - -class ImportedNRENL3CoreServiceInactive(SubscriptionModel, is_base=True): - """An imported, inactive :term:`NREN` L3 Core Service subscription.""" - - nren_l3_core_service_type: NRENL3CoreServiceType - nren_l3_core_service: NRENL3CoreServiceBlockInactive - - -class ImportedNRENL3CoreService( - ImportedNRENL3CoreServiceInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] -): - """An imported :term:`NREN` L3 Core Service subscription.""" - - nren_l3_core_service_type: NRENL3CoreServiceType - nren_l3_core_service: NRENL3CoreServiceBlock diff --git a/gso/translations/en-GB.json b/gso/translations/en-GB.json index af958b3e..a871e339 100644 --- a/gso/translations/en-GB.json +++ b/gso/translations/en-GB.json @@ -52,18 +52,18 @@ "create_site": "Create Site", "create_switch": "Create Switch", "create_edge_port": "Create Edge Port", - "create_nren_l3_core_service": "Create NREN L3 Core Service", + "create_l3_core_service": "Create L3 Core Service", "create_lan_switch_interconnect": "Create LAN Switch Interconnect", "deploy_twamp": "Deploy TWAMP", "migrate_iptrunk": "Migrate IP Trunk", - "migrate_nren_l3_core_service": "Migrate NREN L3 Core Service", + "migrate_l3_core_service": "Migrate L3 Core Service", "modify_isis_metric": "Modify the ISIS metric", "modify_site": "Modify Site", "modify_trunk_interface": "Modify IP Trunk interface", "modify_connection_strategy": "Modify connection strategy", "modify_router_kentik_license": "Modify device license in Kentik", "modify_edge_port": "Modify Edge Port", - "modify_nren_l3_core_service": "Modify NREN L3 Core Service", + "modify_l3_core_service": "Modify L3 Core Service", "terminate_iptrunk": "Terminate IP Trunk", "terminate_router": "Terminate Router", "terminate_site": "Terminate Site", @@ -79,7 +79,7 @@ "create_imported_office_router": "NOT FOR HUMANS -- Import existing office router", "create_imported_opengear": "NOT FOR HUMANS -- Import existing OpenGear", "create_imported_edge_port": "NOT FOR HUMANS -- Import existing Edge Port", - "create_imported_nren_l3_core_service": "NOT FOR HUMANS -- Import existing NREN L3 Core Service", + "create_imported_l3_core_service": "NOT FOR HUMANS -- Import existing L3 Core Service", "create_imported_switch": "NOT FOR HUMANS -- Import existing Switch", "create_imported_lan_switch_interconnect": "NOT FOR HUMANS -- Import existing LAN Switch Interconnect", "import_site": "NOT FOR HUMANS -- Finalize import into a Site product", @@ -89,7 +89,7 @@ "import_super_pop_switch": "NOT FOR HUMANS -- Finalize import into a Super PoP switch", "import_opengear": "NOT FOR HUMANS -- Finalize import into an OpenGear", "import_edge_port": "NOT FOR HUMANS -- Finalize import into an Edge Port", - "import_nren_l3_core_service": "NOT FOR HUMANS -- Finalize import into a NREN L3 Core Service", + "import_l3_core_service": "NOT FOR HUMANS -- Finalize import into an L3 Core Service", "import_switch": "NOT FOR HUMANS -- Finalize import into a Switch", "import_lan_switch_interconnect": "NOT FOR HUMANS -- Finalize import into a LAN Switch Interconnect", "validate_iptrunk": "Validate IP Trunk configuration", diff --git a/gso/workflows/__init__.py b/gso/workflows/__init__.py index 94ce262a..c5c3e1ef 100644 --- a/gso/workflows/__init__.py +++ b/gso/workflows/__init__.py @@ -116,14 +116,12 @@ LazyWorkflowInstance("gso.workflows.edge_port.validate_edge_port", "validate_edg LazyWorkflowInstance("gso.workflows.edge_port.create_imported_edge_port", "create_imported_edge_port") LazyWorkflowInstance("gso.workflows.edge_port.import_edge_port", "import_edge_port") -# NREN L3 Core Service workflows -LazyWorkflowInstance("gso.workflows.nren_l3_core_service.create_nren_l3_core_service", "create_nren_l3_core_service") -LazyWorkflowInstance("gso.workflows.nren_l3_core_service.modify_nren_l3_core_service", "modify_nren_l3_core_service") -LazyWorkflowInstance( - "gso.workflows.nren_l3_core_service.create_imported_nren_l3_core_service", "create_imported_nren_l3_core_service" -) -LazyWorkflowInstance("gso.workflows.nren_l3_core_service.import_nren_l3_core_service", "import_nren_l3_core_service") -LazyWorkflowInstance("gso.workflows.nren_l3_core_service.migrate_nren_l3_core_service", "migrate_nren_l3_core_service") +# L3 Core Service workflows +LazyWorkflowInstance("gso.workflows.l3_core_service.create_l3_core_service", "create_l3_core_service") +LazyWorkflowInstance("gso.workflows.l3_core_service.modify_l3_core_service", "modify_l3_core_service") +LazyWorkflowInstance("gso.workflows.l3_core_service.create_imported_l3_core_service", "create_imported_l3_core_service") +LazyWorkflowInstance("gso.workflows.l3_core_service.import_l3_core_service", "import_l3_core_service") +LazyWorkflowInstance("gso.workflows.l3_core_service.migrate_l3_core_service", "migrate_l3_core_service") # Layer 2 Circuit workflows LazyWorkflowInstance("gso.workflows.l2_circuit.create_layer_2_circuit", "create_layer_2_circuit") diff --git a/gso/workflows/l3_core_service/__init__.py b/gso/workflows/l3_core_service/__init__.py new file mode 100644 index 00000000..6143fba1 --- /dev/null +++ b/gso/workflows/l3_core_service/__init__.py @@ -0,0 +1 @@ +"""Layer 3 core service workflows.""" diff --git a/gso/workflows/nren_l3_core_service/create_imported_nren_l3_core_service.py b/gso/workflows/l3_core_service/create_imported_l3_core_service.py similarity index 73% rename from gso/workflows/nren_l3_core_service/create_imported_nren_l3_core_service.py rename to gso/workflows/l3_core_service/create_imported_l3_core_service.py index 66456732..f63fcec0 100644 --- a/gso/workflows/nren_l3_core_service/create_imported_nren_l3_core_service.py +++ b/gso/workflows/l3_core_service/create_imported_l3_core_service.py @@ -1,4 +1,4 @@ -"""A creation workflow for adding an existing NREN L3 Core Service to the service database.""" +"""A creation workflow for adding an existing L3 Core Service to the service database.""" from uuid import uuid4 @@ -6,6 +6,7 @@ from orchestrator import workflow from orchestrator.forms import FormPage from orchestrator.targets import Target from orchestrator.types import FormGenerator, SubscriptionLifecycle +from orchestrator.utils.errors import ProcessFailureError from orchestrator.workflow import StepList, begin, done, step from orchestrator.workflows.steps import resync, set_status, store_process_subscription from pydantic import BaseModel @@ -13,10 +14,10 @@ from pydantic_forms.types import UUIDstr from gso.products import ProductName from gso.products.product_blocks.bgp_session import BGPSession, IPFamily, IPTypes -from gso.products.product_blocks.nren_l3_core_service import NRENAccessPortInactive +from gso.products.product_blocks.l3_core_service import AccessPortInactive from gso.products.product_blocks.service_binding_port import BFDSettings, ServiceBindingPortInactive from gso.products.product_types.edge_port import EdgePort -from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreServiceInactive, NRENL3CoreServiceType +from gso.products.product_types.l3_core_service import ImportedL3CoreServiceInactive, L3CoreServiceType from gso.services.partners import get_partner_by_name from gso.services.subscriptions import get_product_id_by_name from gso.utils.shared_enums import SBPType @@ -63,30 +64,40 @@ def initial_input_form_generator() -> FormGenerator: v4_bfd_settings: BFDSettingsModel v6_bfd_settings: BFDSettingsModel - class ImportNRENL3CoreServiceForm(FormPage): + class ImportL3CoreServiceForm(FormPage): partner: str service_binding_ports: list[ServiceBindingPort] - service_type: NRENL3CoreServiceType + service_type: L3CoreServiceType - user_input = yield ImportNRENL3CoreServiceForm + user_input = yield ImportL3CoreServiceForm return user_input.model_dump() @step("Create subscription") -def create_subscription(partner: str, service_type: NRENL3CoreServiceType) -> dict: +def create_subscription(partner: str, service_type: L3CoreServiceType) -> dict: """Create a new subscription object in the database.""" partner_id = get_partner_by_name(partner)["partner_id"] - if service_type == NRENL3CoreServiceType.GEANT_IP: - product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) - elif service_type == NRENL3CoreServiceType.IAS: - product_id = get_product_id_by_name(ProductName.IMPORTED_IAS) - subscription = ImportedNRENL3CoreServiceInactive.from_product_id(product_id, partner_id) + match service_type: + case L3CoreServiceType.GEANT_IP: + product_id = get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) + case L3CoreServiceType.IAS: + product_id = get_product_id_by_name(ProductName.IMPORTED_IAS) + case L3CoreServiceType.GWS: + product_id = get_product_id_by_name(ProductName.IMPORTED_GWS) + case L3CoreServiceType.LHCONE: + product_id = get_product_id_by_name(ProductName.IMPORTED_LHCONE) + case L3CoreServiceType.COPERNICUS: + product_id = get_product_id_by_name(ProductName.IMPORTED_COPERNICUS) + case _: + msg = "L3 Core service type not defined. Cannot create subscription." + raise ProcessFailureError(msg, details=service_type) + subscription = ImportedL3CoreServiceInactive.from_product_id(product_id, partner_id) return {"subscription": subscription, "subscription_id": subscription.subscription_id} @step("Initialize subscription") -def initialize_subscription(subscription: ImportedNRENL3CoreServiceInactive, service_binding_ports: list) -> dict: +def initialize_subscription(subscription: ImportedL3CoreServiceInactive, service_binding_ports: list) -> dict: """Initialize the subscription with the user input.""" for service_binding_port in service_binding_ports: edge_port_subscription = EdgePort.from_subscription(service_binding_port.pop("edge_port")) @@ -109,8 +120,8 @@ def initialize_subscription(subscription: ImportedNRENL3CoreServiceInactive, ser v6_bfd_settings=BFDSettings.new(subscription_id=uuid4(), **(service_binding_port.pop("v6_bfd_settings"))), **service_binding_port, ) - subscription.nren_l3_core_service.nren_ap_list.append( - NRENAccessPortInactive.new( + subscription.l3_core_service.ap_list.append( + AccessPortInactive.new( subscription_id=uuid4(), ap_type=service_binding_port["ap_type"], sbp=service_binding_port_subscription, @@ -123,11 +134,11 @@ def initialize_subscription(subscription: ImportedNRENL3CoreServiceInactive, ser @workflow( - "Create imported NREN L3 Core Service", + "Create imported L3 Core Service", initial_input_form=initial_input_form_generator, target=Target.CREATE, ) -def create_imported_nren_l3_core_service() -> StepList: +def create_imported_l3_core_service() -> StepList: """Import a GÉANT IP without provisioning it.""" return ( begin diff --git a/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py b/gso/workflows/l3_core_service/create_l3_core_service.py similarity index 88% rename from gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py rename to gso/workflows/l3_core_service/create_l3_core_service.py index 9fb5d7c7..67723553 100644 --- a/gso/workflows/nren_l3_core_service/create_nren_l3_core_service.py +++ b/gso/workflows/l3_core_service/create_l3_core_service.py @@ -1,4 +1,4 @@ -"""Create a new NREN L3 Core Service subscription including GÉANT IP and IAS.""" +"""Create a new L3 Core Service subscription including GÉANT IP and IAS.""" from typing import Any from uuid import uuid4 @@ -14,10 +14,10 @@ from pydantic import BaseModel, ConfigDict, Field, computed_field from pydantic_forms.validators import Divider from gso.products.product_blocks.bgp_session import BGPSession, IPFamily, IPTypes -from gso.products.product_blocks.nren_l3_core_service import NRENAccessPortInactive +from gso.products.product_blocks.l3_core_service import AccessPortInactive from gso.products.product_blocks.service_binding_port import BFDSettings, ServiceBindingPortInactive from gso.products.product_types.edge_port import EdgePort -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService, NRENL3CoreServiceInactive +from gso.products.product_types.l3_core_service import L3CoreService, L3CoreServiceInactive from gso.services.lso_client import LSOState, lso_interaction from gso.services.partners import get_partner_by_id from gso.utils.helpers import ( @@ -33,13 +33,13 @@ from gso.utils.types.virtual_identifiers import VLAN_ID def initial_input_form_generator(product_name: str) -> FormGenerator: """Gather input from the operator to build a new subscription object.""" - class CreateNRENCoreServiceForm(FormPage): + class CreateL3CoreServiceForm(FormPage): model_config = ConfigDict(title=f"{product_name} - Select partner") tt_number: TTNumber partner: partner_choice() # type: ignore[valid-type] - initial_user_input = yield CreateNRENCoreServiceForm + initial_user_input = yield CreateL3CoreServiceForm class EdgePortSelection(BaseModel): edge_port: active_edge_port_selector(partner_id=initial_user_input.partner) # type: ignore[valid-type] @@ -146,25 +146,20 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @step("Create subscription") def create_subscription(product: UUIDstr, partner: str) -> State: """Create a new subscription object in the database.""" - subscription = NRENL3CoreServiceInactive.from_product_id(product, partner) + subscription = L3CoreServiceInactive.from_product_id(product, partner) return {"subscription": subscription, "subscription_id": subscription.subscription_id} @step("Initialize subscription") def initialize_subscription( - subscription: NRENL3CoreServiceInactive, edge_port: dict, binding_port_input: dict, product_name: str + subscription: L3CoreServiceInactive, edge_port: dict, binding_port_input: dict, product_name: str ) -> State: """Take all user inputs and use them to populate the subscription model.""" edge_port_fqdn_list = [] edge_port_subscription = EdgePort.from_subscription(edge_port["edge_port"]) sbp_bgp_session_list = [ - BGPSession.new( - subscription_id=uuid4(), - rtbh_enabled=True, - is_multi_hop=True, - **session, - ) + BGPSession.new(subscription_id=uuid4(), rtbh_enabled=True, is_multi_hop=True, **session) for session in binding_port_input["bgp_peers"] ] service_binding_port = ServiceBindingPortInactive.new( @@ -176,8 +171,8 @@ def initialize_subscription( sbp_type=SBPType.L3, edge_port=edge_port_subscription.edge_port, ) - subscription.nren_l3_core_service.nren_ap_list.append( - NRENAccessPortInactive.new( + subscription.l3_core_service.ap_list.append( + AccessPortInactive.new( subscription_id=uuid4(), ap_type=edge_port["ap_type"], sbp=service_binding_port, @@ -206,7 +201,7 @@ def provision_sbp_dry( } return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @@ -228,7 +223,7 @@ def provision_sbp_real( } return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @@ -240,7 +235,7 @@ def check_sbp_functionality(subscription: dict[str, Any], edge_port_fqdn_list: l extra_vars = {"subscription": subscription, "verb": "check", "object": "sbp"} return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @@ -262,7 +257,7 @@ def deploy_bgp_peers_dry( } return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @@ -284,7 +279,7 @@ def deploy_bgp_peers_real( } return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @@ -296,26 +291,26 @@ def check_bgp_peers(subscription: dict[str, Any], edge_port_fqdn_list: list[str] extra_vars = {"subscription": subscription, "verb": "check", "object": "bgp"} return { - "playbook_name": "gap_ansible/playbooks/nren_l3_core_service.yaml", + "playbook_name": "gap_ansible/playbooks/l3_core_service.yaml", "inventory": {"all": {"hosts": dict.fromkeys(edge_port_fqdn_list)}}, "extra_vars": extra_vars, } @step("Update Infoblox") -def update_dns_records(subscription: NRENL3CoreService) -> State: +def update_dns_records(subscription: L3CoreService) -> State: """Update :term:`DNS` records in Infoblox.""" # TODO: implement return {"subscription": subscription} @workflow( - "Create NREN L3 Core Service", + "Create L3 Core Service", initial_input_form=wrap_create_initial_input_form(initial_input_form_generator), target=Target.CREATE, ) -def create_nren_l3_core_service() -> StepList: - """Create a new :term:`NREN` L3 Core Service subscription including GÉANT IP and IAS. +def create_l3_core_service() -> StepList: + """Create a new L3 Core Service subscription including GÉANT IP and IAS. * Create subscription object in the service database * Deploy service binding ports diff --git a/gso/workflows/l3_core_service/import_l3_core_service.py b/gso/workflows/l3_core_service/import_l3_core_service.py new file mode 100644 index 00000000..974c379d --- /dev/null +++ b/gso/workflows/l3_core_service/import_l3_core_service.py @@ -0,0 +1,52 @@ +"""A modification workflow for migrating an ImportedGeantIP to an GeantIP subscription.""" + +from orchestrator.targets import Target +from orchestrator.types import State, UUIDstr +from orchestrator.utils.errors import ProcessFailureError +from orchestrator.workflow import StepList, done, init, step, workflow +from orchestrator.workflows.steps import resync, store_process_subscription, unsync +from orchestrator.workflows.utils import wrap_modify_initial_input_form + +from gso.products import ProductName +from gso.products.product_types.l3_core_service import ( + ImportedL3CoreService, + L3CoreService, + L3CoreServiceType, +) +from gso.services.subscriptions import get_product_id_by_name + + +@step("Create imported subscription") +def import_l3_core_service_subscription(subscription_id: UUIDstr) -> State: + """Take an imported subscription, and turn it into an L3 Core Service subscription.""" + old_l3_core_service = ImportedL3CoreService.from_subscription(subscription_id) + match old_l3_core_service.l3_core_service_type: + case L3CoreServiceType.IMPORTED_GEANT_IP: + new_subscription_id = get_product_id_by_name(ProductName.GEANT_IP) + case L3CoreServiceType.IMPORTED_IAS: + new_subscription_id = get_product_id_by_name(ProductName.IAS) + case L3CoreServiceType.IMPORTED_GWS: + new_subscription_id = get_product_id_by_name(ProductName.GWS) + case L3CoreServiceType.IMPORTED_LHCONE: + new_subscription_id = get_product_id_by_name(ProductName.LHCONE) + case L3CoreServiceType.IMPORTED_COPERNICUS: + new_subscription_id = get_product_id_by_name(ProductName.COPERNICUS) + case _: + msg = f"This {old_l3_core_service.l3_core_service_type} is already imported, nothing to do." + raise ProcessFailureError(message=msg, details=old_l3_core_service) + new_subscription = L3CoreService.from_other_product(old_l3_core_service, new_subscription_id) # type: ignore[arg-type] + + return {"subscription": new_subscription} + + +@workflow("Import L3 Core Service", target=Target.MODIFY, initial_input_form=wrap_modify_initial_input_form(None)) +def import_l3_core_service() -> StepList: + """Modify an imported subscription into an L3 Core Service subscription to complete the import.""" + return ( + init + >> store_process_subscription(Target.MODIFY) + >> unsync + >> import_l3_core_service_subscription + >> resync + >> done + ) diff --git a/gso/workflows/nren_l3_core_service/migrate_nren_l3_core_service.py b/gso/workflows/l3_core_service/migrate_l3_core_service.py similarity index 79% rename from gso/workflows/nren_l3_core_service/migrate_nren_l3_core_service.py rename to gso/workflows/l3_core_service/migrate_l3_core_service.py index 6ecd489b..d8902530 100644 --- a/gso/workflows/nren_l3_core_service/migrate_nren_l3_core_service.py +++ b/gso/workflows/l3_core_service/migrate_l3_core_service.py @@ -14,21 +14,19 @@ from pydantic_forms.types import FormGenerator, State, UUIDstr from pydantic_forms.validators import Choice, Divider from gso.products.product_types.edge_port import EdgePort -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService +from gso.products.product_types.l3_core_service import L3CoreService from gso.services.subscriptions import get_active_edge_port_subscriptions from gso.utils.types.tt_number import TTNumber def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: """Gather input from the operator on what new Edge Ports this L3 Core Service should be migrated to.""" - subscription = NRENL3CoreService.from_subscription(subscription_id) + subscription = L3CoreService.from_subscription(subscription_id) partner_id = subscription.customer_id - edge_port_count = len(subscription.nren_l3_core_service.nren_ap_list) + edge_port_count = len(subscription.l3_core_service.ap_list) def _new_edge_port_selector(pid: UUIDstr) -> Choice: - existing_ep_name_list = [ - ap.sbp.edge_port.owner_subscription_id for ap in subscription.nren_l3_core_service.nren_ap_list - ] + existing_ep_name_list = [ap.sbp.edge_port.owner_subscription_id for ap in subscription.l3_core_service.ap_list] edge_port_subscriptions = list( filter( lambda ep: bool(ep["customer_id"] == pid) and ep["subscription_id"] not in existing_ep_name_list, @@ -54,7 +52,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: raise ValueError(msg) return edge_ports - class NRENL3CoreServiceEdgePortSelectionForm(FormPage): + class L3CoreServiceEdgePortSelectionForm(FormPage): model_config = ConfigDict(title=f"Migrating {subscription.product.name} to a new set of Edge Ports") tt_number: TTNumber @@ -70,19 +68,19 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: })", new_edge_port="", ) - for ap in subscription.nren_l3_core_service.nren_ap_list + for ap in subscription.l3_core_service.ap_list ] - ep_user_input = yield NRENL3CoreServiceEdgePortSelectionForm + ep_user_input = yield L3CoreServiceEdgePortSelectionForm return {"subscription_id": subscription_id, "subscription": subscription} | ep_user_input.model_dump() @step("Update subscription model") -def update_subscription_model(subscription: NRENL3CoreService, edge_port_selection: list[dict]) -> State: +def update_subscription_model(subscription: L3CoreService, edge_port_selection: list[dict]) -> State: """Update the subscription model with the new list of Access Ports.""" for index, selected_port in enumerate(edge_port_selection): - subscription.nren_l3_core_service.nren_ap_list[index].sbp.edge_port = EdgePort.from_subscription( + subscription.l3_core_service.ap_list[index].sbp.edge_port = EdgePort.from_subscription( selected_port["new_edge_port"] ).edge_port @@ -90,10 +88,10 @@ def update_subscription_model(subscription: NRENL3CoreService, edge_port_selecti @workflow( - "Migrate NREN L3 Core Service", + "Migrate L3 Core Service", initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator), target=Target.MODIFY, ) -def migrate_nren_l3_core_service() -> StepList: - """Migrate a :term:`NREN` L3 Core Service to a new set of Edge Ports.""" +def migrate_l3_core_service() -> StepList: + """Migrate a L3 Core Service to a new set of Edge Ports.""" return begin >> store_process_subscription(Target.MODIFY) >> unsync >> update_subscription_model >> resync >> done diff --git a/gso/workflows/nren_l3_core_service/modify_nren_l3_core_service.py b/gso/workflows/l3_core_service/modify_l3_core_service.py similarity index 90% rename from gso/workflows/nren_l3_core_service/modify_nren_l3_core_service.py rename to gso/workflows/l3_core_service/modify_l3_core_service.py index 7eaf2e6f..f165424b 100644 --- a/gso/workflows/nren_l3_core_service/modify_nren_l3_core_service.py +++ b/gso/workflows/l3_core_service/modify_l3_core_service.py @@ -1,4 +1,4 @@ -"""A modification workflow for a :term:`NREN` L3 Core Service subscription.""" +"""A modification workflow for a L3 Core Service subscription.""" from typing import Annotated, Any from uuid import uuid4 @@ -15,10 +15,10 @@ from pydantic_forms.types import State from pydantic_forms.validators import Divider, Label from gso.products.product_blocks.bgp_session import BGPSession, IPFamily, IPTypes -from gso.products.product_blocks.nren_l3_core_service import NRENAccessPort +from gso.products.product_blocks.l3_core_service import AccessPort from gso.products.product_blocks.service_binding_port import BFDSettings, ServiceBindingPort from gso.products.product_types.edge_port import EdgePort -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService +from gso.products.product_types.l3_core_service import L3CoreService from gso.utils.helpers import active_edge_port_selector from gso.utils.shared_enums import APType, SBPType from gso.utils.types.ip_address import IPv4AddressType, IPV4Netmask, IPv6AddressType, IPV6Netmask @@ -27,7 +27,7 @@ from gso.utils.types.virtual_identifiers import VLAN_ID def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: """Get input about added, removed, and modified Access Ports.""" - subscription = NRENL3CoreService.from_subscription(subscription_id) + subscription = L3CoreService.from_subscription(subscription_id) product_name = subscription.product.name class AccessPortSelection(BaseModel): @@ -49,15 +49,13 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: edge_port=str(access_port.sbp.edge_port.owner_subscription_id), ap_type=access_port.ap_type, ) - for access_port in subscription.nren_l3_core_service.nren_ap_list + for access_port in subscription.l3_core_service.ap_list ] access_port_input = yield ModifyAccessPortsForm input_ap_list = access_port_input.access_ports input_ep_list = [str(ap.edge_port) for ap in input_ap_list] - existing_ep_list = [ - str(ap.sbp.edge_port.owner_subscription_id) for ap in subscription.nren_l3_core_service.nren_ap_list - ] + existing_ep_list = [str(ap.sbp.edge_port.owner_subscription_id) for ap in subscription.l3_core_service.ap_list] class BFDInputModel(BaseModel): bfd_enabled: bool = False @@ -109,7 +107,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: # modified. removed_ap_list = [ access_port.subscription_instance_id - for access_port in subscription.nren_l3_core_service.nren_ap_list + for access_port in subscription.l3_core_service.ap_list if str(access_port.sbp.edge_port.owner_subscription_id) not in input_ep_list ] modified_ap_list = [ @@ -124,7 +122,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: None, ), ) - for access_port in subscription.nren_l3_core_service.nren_ap_list + for access_port in subscription.l3_core_service.ap_list if str(access_port.sbp.edge_port.owner_subscription_id) in input_ep_list ] added_ap_list = [ @@ -245,11 +243,11 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: @step("Clean up removed Edge Ports") -def remove_old_sbp_blocks(subscription: NRENL3CoreService, removed_access_ports: list[UUIDstr]) -> State: +def remove_old_sbp_blocks(subscription: L3CoreService, removed_access_ports: list[UUIDstr]) -> State: """Remove old :term:`SBP` product blocks from the GÉANT IP subscription.""" - subscription.nren_l3_core_service.nren_ap_list = [ + subscription.l3_core_service.ap_list = [ ap - for ap in subscription.nren_l3_core_service.nren_ap_list + for ap in subscription.l3_core_service.ap_list if str(ap.subscription_instance_id) not in removed_access_ports ] @@ -257,9 +255,9 @@ def remove_old_sbp_blocks(subscription: NRENL3CoreService, removed_access_ports: @step("Modify existing Service Binding Ports") -def modify_existing_sbp_blocks(subscription: NRENL3CoreService, modified_sbp_list: list[dict[str, Any]]) -> State: +def modify_existing_sbp_blocks(subscription: L3CoreService, modified_sbp_list: list[dict[str, Any]]) -> State: """Update the subscription model.""" - for access_port in subscription.nren_l3_core_service.nren_ap_list: + for access_port in subscription.l3_core_service.ap_list: current_sbp = access_port.sbp modified_sbp_data = next( sbp for sbp in modified_sbp_list if sbp["current_sbp_id"] == str(current_sbp.subscription_instance_id) @@ -290,8 +288,8 @@ def modify_existing_sbp_blocks(subscription: NRENL3CoreService, modified_sbp_lis @step("Instantiate new Service Binding Ports") -def create_new_sbp_blocks(subscription: NRENL3CoreService, added_service_binding_ports: list[dict[str, Any]]) -> State: - """Add new two :term:`SBP` to the :term:`NREN` L3 Core Service subscription.""" +def create_new_sbp_blocks(subscription: L3CoreService, added_service_binding_ports: list[dict[str, Any]]) -> State: + """Add new two :term:`SBP` to the L3 Core Service subscription.""" for sbp_input in added_service_binding_ports: edge_port = EdgePort.from_subscription(sbp_input["edge_port_id"]) bgp_session_list = [ @@ -309,8 +307,8 @@ def create_new_sbp_blocks(subscription: NRENL3CoreService, added_service_binding sbp_type=SBPType.L3, edge_port=edge_port.edge_port, ) - subscription.nren_l3_core_service.nren_ap_list.append( - NRENAccessPort.new( + subscription.l3_core_service.ap_list.append( + AccessPort.new( subscription_id=uuid4(), ap_type=sbp_input["ap_type"], sbp=service_binding_port, @@ -321,11 +319,11 @@ def create_new_sbp_blocks(subscription: NRENL3CoreService, added_service_binding @workflow( - "Modify NREN L3 Core Service", + "Modify L3 Core Service", initial_input_form=wrap_modify_initial_input_form(initial_input_form_generator), target=Target.MODIFY, ) -def modify_nren_l3_core_service() -> StepList: +def modify_l3_core_service() -> StepList: """Modify a NRN L3 Core Service subscription.""" access_ports_are_removed = conditional(lambda state: bool(len(state["removed_access_ports"]) > 0)) access_ports_are_modified = conditional(lambda state: bool(len(state["modified_sbp_list"]) > 0)) diff --git a/gso/workflows/nren_l3_core_service/__init__.py b/gso/workflows/nren_l3_core_service/__init__.py deleted file mode 100644 index fb652fbe..00000000 --- a/gso/workflows/nren_l3_core_service/__init__.py +++ /dev/null @@ -1 +0,0 @@ -""":term:`NREN` layer 3 core service workflows.""" diff --git a/gso/workflows/nren_l3_core_service/import_nren_l3_core_service.py b/gso/workflows/nren_l3_core_service/import_nren_l3_core_service.py deleted file mode 100644 index 39519246..00000000 --- a/gso/workflows/nren_l3_core_service/import_nren_l3_core_service.py +++ /dev/null @@ -1,45 +0,0 @@ -"""A modification workflow for migrating an ImportedGeantIP to an GeantIP subscription.""" - -from orchestrator.targets import Target -from orchestrator.types import State, UUIDstr -from orchestrator.utils.errors import ProcessFailureError -from orchestrator.workflow import StepList, done, init, step, workflow -from orchestrator.workflows.steps import resync, store_process_subscription, unsync -from orchestrator.workflows.utils import wrap_modify_initial_input_form - -from gso.products import ProductName -from gso.products.product_types.nren_l3_core_service import ( - ImportedNRENL3CoreService, - NRENL3CoreService, - NRENL3CoreServiceType, -) -from gso.services.subscriptions import get_product_id_by_name - - -@step("Create imported subscription") -def import_nren_l3_core_service_subscription(subscription_id: UUIDstr) -> State: - """Take an imported subscription, and turn it into an :term:`NREN` L3 Core Service subscription.""" - old_nren_l3_core_service = ImportedNRENL3CoreService.from_subscription(subscription_id) - if old_nren_l3_core_service.nren_l3_core_service_type == NRENL3CoreServiceType.IMPORTED_GEANT_IP: - 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} - - -@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: - """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_nren_l3_core_service_subscription - >> resync - >> done - ) diff --git a/test/cli/test_imports.py b/test/cli/test_imports.py index 0048df8e..17a1bc13 100644 --- a/test/cli/test_imports.py +++ b/test/cli/test_imports.py @@ -7,9 +7,9 @@ import pytest from gso.cli.imports import ( import_edge_port, import_iptrunks, + import_l3_core_service, import_lan_switch_interconnect, import_layer_2_circuit_service, - import_nren_l3_core_service, import_office_routers, import_opengear, import_routers, @@ -296,9 +296,9 @@ def edge_port_data(temp_file, faker, router_subscription_factory, partner_factor @pytest.fixture() -def nren_l3_core_service_data(temp_file, faker, partner_factory, edge_port_subscription_factory): - def _nren_l3_core_service_data(**kwargs): - nren_l3_core_service_data = { +def l3_core_service_data(temp_file, faker, partner_factory, edge_port_subscription_factory): + def _l3_core_service_data(**kwargs): + l3_core_service_data = { "partner": partner_factory()["name"], "service_type": "IMPORTED IAS", "service_binding_ports": [ @@ -400,12 +400,12 @@ def nren_l3_core_service_data(temp_file, faker, partner_factory, edge_port_subsc }, ], } - nren_l3_core_service_data.update(**kwargs) + l3_core_service_data.update(**kwargs) - temp_file.write_text(json.dumps([nren_l3_core_service_data])) - return {"path": str(temp_file), "data": nren_l3_core_service_data} + temp_file.write_text(json.dumps([l3_core_service_data])) + return {"path": str(temp_file), "data": l3_core_service_data} - return _nren_l3_core_service_data + return _l3_core_service_data @pytest.fixture() @@ -670,18 +670,16 @@ def test_import_edge_port_with_invalid_partner(mock_start_process, mock_sleep, e @patch("gso.cli.imports.time.sleep") @patch("gso.cli.imports.start_process") -def test_import_nren_l3_core_service_success(mock_start_process, mock_sleep, nren_l3_core_service_data, capfd): - import_nren_l3_core_service(nren_l3_core_service_data()["path"]) +def test_import_l3_core_service_success(mock_start_process, mock_sleep, l3_core_service_data, capfd): + import_l3_core_service(l3_core_service_data()["path"]) assert mock_start_process.call_count == 1 @patch("gso.cli.imports.time.sleep") @patch("gso.cli.imports.start_process") -def test_import_nren_l3_core_service_with_invalid_partner( - mock_start_process, mock_sleep, nren_l3_core_service_data, capfd -): - broken_data = nren_l3_core_service_data(partner="INVALID") - import_nren_l3_core_service(broken_data["path"]) +def test_import_l3_core_service_with_invalid_partner(mock_start_process, mock_sleep, l3_core_service_data, capfd): + broken_data = l3_core_service_data(partner="INVALID") + import_l3_core_service(broken_data["path"]) captured_output, _ = capfd.readouterr() assert "Partner INVALID not found" in captured_output @@ -690,11 +688,11 @@ def test_import_nren_l3_core_service_with_invalid_partner( @patch("gso.cli.imports.time.sleep") @patch("gso.cli.imports.start_process") -def test_import_nren_l3_core_service_with_invalid_edge_port( - mock_start_process, mock_sleep, faker, nren_l3_core_service_data, edge_port_subscription_factory, capfd +def test_import_l3_core_service_with_invalid_edge_port( + mock_start_process, mock_sleep, faker, l3_core_service_data, edge_port_subscription_factory, capfd ): fake_uuid = faker.uuid4() - broken_data = nren_l3_core_service_data( + broken_data = l3_core_service_data( service_binding_ports=[ { "edge_port": fake_uuid, @@ -778,7 +776,7 @@ def test_import_nren_l3_core_service_with_invalid_edge_port( }, ] ) - import_nren_l3_core_service(broken_data["path"]) + import_l3_core_service(broken_data["path"]) captured_output, _ = capfd.readouterr() assert f"Edge Port {fake_uuid} not found" in captured_output diff --git a/test/fixtures/__init__.py b/test/fixtures/__init__.py index 71535c89..8ecda8a7 100644 --- a/test/fixtures/__init__.py +++ b/test/fixtures/__init__.py @@ -1,14 +1,14 @@ from test.fixtures.edge_port_fixtures import edge_port_subscription_factory from test.fixtures.iptrunk_fixtures import iptrunk_side_subscription_factory, iptrunk_subscription_factory -from test.fixtures.lan_switch_interconnect_fixtures import lan_switch_interconnect_subscription_factory -from test.fixtures.layer_2_circuit_fixtures import layer_2_circuit_subscription_factory -from test.fixtures.nren_l3_core_service_fixtures import ( +from test.fixtures.l3_core_service_fixtures import ( + access_port_factory, bfd_settings_factory, bgp_session_subscription_factory, - nren_access_port_factory, - nren_l3_core_service_subscription_factory, + l3_core_service_subscription_factory, service_binding_port_factory, ) +from test.fixtures.lan_switch_interconnect_fixtures import lan_switch_interconnect_subscription_factory +from test.fixtures.layer_2_circuit_fixtures import layer_2_circuit_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.router_fixtures import router_subscription_factory @@ -17,15 +17,15 @@ from test.fixtures.super_pop_switch_fixtures import super_pop_switch_subscriptio from test.fixtures.switch_fixtures import switch_subscription_factory __all__ = [ + "access_port_factory", "bfd_settings_factory", "bgp_session_subscription_factory", "edge_port_subscription_factory", "iptrunk_side_subscription_factory", "iptrunk_subscription_factory", + "l3_core_service_subscription_factory", "lan_switch_interconnect_subscription_factory", "layer_2_circuit_subscription_factory", - "nren_access_port_factory", - "nren_l3_core_service_subscription_factory", "office_router_subscription_factory", "opengear_subscription_factory", "router_subscription_factory", diff --git a/test/fixtures/nren_l3_core_service_fixtures.py b/test/fixtures/l3_core_service_fixtures.py similarity index 59% rename from test/fixtures/nren_l3_core_service_fixtures.py rename to test/fixtures/l3_core_service_fixtures.py index 64c01463..b37d71f7 100644 --- a/test/fixtures/nren_l3_core_service_fixtures.py +++ b/test/fixtures/l3_core_service_fixtures.py @@ -8,13 +8,13 @@ from orchestrator.types import SubscriptionLifecycle, UUIDstr from gso.products import ProductName from gso.products.product_blocks.bgp_session import BGPSession, IPFamily, IPTypes -from gso.products.product_blocks.nren_l3_core_service import NRENAccessPort +from gso.products.product_blocks.l3_core_service import AccessPort from gso.products.product_blocks.service_binding_port import BFDSettings, ServiceBindingPort from gso.products.product_types.edge_port import EdgePort -from gso.products.product_types.nren_l3_core_service import ( - ImportedNRENL3CoreService, - NRENL3CoreServiceInactive, - NRENL3CoreServiceType, +from gso.products.product_types.l3_core_service import ( + ImportedL3CoreService, + L3CoreServiceInactive, + L3CoreServiceType, ) from gso.services import subscriptions from gso.utils.shared_enums import APType, SBPType @@ -120,78 +120,108 @@ def service_binding_port_factory( @pytest.fixture() -def nren_access_port_factory(faker, service_binding_port_factory): - def create_nren_access_port( - nren_ap_type: APType | None = None, +def access_port_factory(faker, service_binding_port_factory): + def create_access_port( + ap_type: APType | None = None, service_binding_port: ServiceBindingPort | None = None, ): - return NRENAccessPort.new( + return AccessPort.new( subscription_id=uuid4(), - ap_type=nren_ap_type or random.choice(list(APType)), # noqa: S311 + ap_type=ap_type or random.choice(list(APType)), # noqa: S311 sbp=service_binding_port or service_binding_port_factory(), ) - return create_nren_access_port + return create_access_port @pytest.fixture() -def nren_l3_core_service_subscription_factory( +def l3_core_service_subscription_factory( faker, partner_factory, - nren_access_port_factory, + access_port_factory, ): - def create_nren_l3_core_service_subscription( - nren_l3_core_service_type: NRENL3CoreServiceType, + def create_l3_core_service_subscription( + l3_core_service_type: L3CoreServiceType, description=None, partner: dict | None = None, - nren_ap_list: list[NRENAccessPort] | None = None, + ap_list: list[AccessPort] | None = None, start_date="2023-05-24T00:00:00+00:00", status: SubscriptionLifecycle | None = None, ) -> UUIDstr: partner = partner or partner_factory() - match nren_l3_core_service_type: - case NRENL3CoreServiceType.GEANT_IP: + match l3_core_service_type: + case L3CoreServiceType.GEANT_IP: product_id = subscriptions.get_product_id_by_name(ProductName.GEANT_IP) - nren_l3_core_service_subscription = NRENL3CoreServiceInactive.from_product_id( + l3_core_service_subscription = L3CoreServiceInactive.from_product_id( product_id, customer_id=partner["partner_id"], insync=True ) - case NRENL3CoreServiceType.IMPORTED_GEANT_IP: + case L3CoreServiceType.IMPORTED_GEANT_IP: product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_GEANT_IP) - nren_l3_core_service_subscription = ImportedNRENL3CoreService.from_product_id( + l3_core_service_subscription = ImportedL3CoreService.from_product_id( product_id, customer_id=partner["partner_id"], insync=True ) - case NRENL3CoreServiceType.IAS: + case L3CoreServiceType.IAS: product_id = subscriptions.get_product_id_by_name(ProductName.IAS) - nren_l3_core_service_subscription = NRENL3CoreServiceInactive.from_product_id( + l3_core_service_subscription = L3CoreServiceInactive.from_product_id( product_id, customer_id=partner["partner_id"], insync=True ) - case NRENL3CoreServiceType.IMPORTED_IAS: + case L3CoreServiceType.IMPORTED_IAS: product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_IAS) - nren_l3_core_service_subscription = ImportedNRENL3CoreService.from_product_id( + l3_core_service_subscription = ImportedL3CoreService.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.GWS: + product_id = subscriptions.get_product_id_by_name(ProductName.GWS) + l3_core_service_subscription = L3CoreServiceInactive.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.IMPORTED_GWS: + product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_GWS) + l3_core_service_subscription = ImportedL3CoreService.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.LHCONE: + product_id = subscriptions.get_product_id_by_name(ProductName.LHCONE) + l3_core_service_subscription = L3CoreServiceInactive.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.IMPORTED_LHCONE: + product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_LHCONE) + l3_core_service_subscription = ImportedL3CoreService.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.COPERNICUS: + product_id = subscriptions.get_product_id_by_name(ProductName.COPERNICUS) + l3_core_service_subscription = L3CoreServiceInactive.from_product_id( + product_id, customer_id=partner["partner_id"], insync=True + ) + case L3CoreServiceType.IMPORTED_COPERNICUS: + product_id = subscriptions.get_product_id_by_name(ProductName.IMPORTED_COPERNICUS) + l3_core_service_subscription = ImportedL3CoreService.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}" + msg = f"L3 Core Service type not found: {l3_core_service_type}" raise ValueError(msg) - # Default nren_ap_list creation with primary and backup access ports - 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.BACKUP), + # Default ap_list creation with primary and backup access ports + l3_core_service_subscription.l3_core_service.ap_list = ap_list or [ + access_port_factory(ap_type=APType.PRIMARY), + access_port_factory(ap_type=APType.BACKUP), ] # Update subscription with description, start date, and status - nren_l3_core_service_subscription = SubscriptionModel.from_other_lifecycle( - nren_l3_core_service_subscription, + l3_core_service_subscription = SubscriptionModel.from_other_lifecycle( + l3_core_service_subscription, SubscriptionLifecycle.ACTIVE, ) - nren_l3_core_service_subscription.description = description or faker.sentence() - nren_l3_core_service_subscription.start_date = start_date - nren_l3_core_service_subscription.status = status or SubscriptionLifecycle.ACTIVE - nren_l3_core_service_subscription.save() + l3_core_service_subscription.description = description or faker.sentence() + l3_core_service_subscription.start_date = start_date + l3_core_service_subscription.status = status or SubscriptionLifecycle.ACTIVE + l3_core_service_subscription.save() db.session.commit() - return str(nren_l3_core_service_subscription.subscription_id) + return str(l3_core_service_subscription.subscription_id) - return create_nren_l3_core_service_subscription + return create_l3_core_service_subscription diff --git a/test/services/test_infoblox.py b/test/services/test_infoblox.py index 3a733260..93d526db 100644 --- a/test/services/test_infoblox.py +++ b/test/services/test_infoblox.py @@ -62,7 +62,7 @@ def _set_up_host_responses(): responses.add( method=responses.GET, url="https://10.0.0.1/wapi/v2.12/record%3Ahost?name=test.lo.geant.net&_return_fields=extattrs%2Cipv4addrs%2Cnam" - "e%2Cview%2Caliases", + "e%2Cview%2Ciases", json=[], ) diff --git a/test/workflows/nren_l3_core_service/__init__.py b/test/workflows/l3_core_service/__init__.py similarity index 100% rename from test/workflows/nren_l3_core_service/__init__.py rename to test/workflows/l3_core_service/__init__.py diff --git a/test/workflows/nren_l3_core_service/test_create_imported_nren_l3_core_service.py b/test/workflows/l3_core_service/test_create_imported_l3_core_service.py similarity index 84% rename from test/workflows/nren_l3_core_service/test_create_imported_nren_l3_core_service.py rename to test/workflows/l3_core_service/test_create_imported_l3_core_service.py index f27ca3a9..626c6237 100644 --- a/test/workflows/nren_l3_core_service/test_create_imported_nren_l3_core_service.py +++ b/test/workflows/l3_core_service/test_create_imported_l3_core_service.py @@ -2,13 +2,22 @@ import pytest from orchestrator.types import SubscriptionLifecycle from gso.products.product_blocks.bgp_session import IPFamily -from gso.products.product_types.nren_l3_core_service import ImportedNRENL3CoreService, NRENL3CoreServiceType +from gso.products.product_types.l3_core_service import ImportedL3CoreService, L3CoreServiceType from gso.utils.shared_enums import SBPType from test.workflows import assert_complete, extract_state, run_workflow -@pytest.mark.parametrize("l3_core_service_type", [NRENL3CoreServiceType.GEANT_IP, NRENL3CoreServiceType.IAS]) -def test_create_imported_nren_l3_core_service_success( +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.GEANT_IP, + L3CoreServiceType.IAS, + L3CoreServiceType.GWS, + L3CoreServiceType.LHCONE, + L3CoreServiceType.COPERNICUS, + ], +) +def test_create_imported_l3_core_service_success( faker, partner_factory, edge_port_subscription_factory, l3_core_service_type ): creation_form_input_data = { @@ -69,8 +78,8 @@ def test_create_imported_nren_l3_core_service_success( ], } - result, _, _ = run_workflow("create_imported_nren_l3_core_service", [creation_form_input_data]) + result, _, _ = run_workflow("create_imported_l3_core_service", [creation_form_input_data]) state = extract_state(result) - subscription = ImportedNRENL3CoreService.from_subscription(state["subscription_id"]) + subscription = ImportedL3CoreService.from_subscription(state["subscription_id"]) assert_complete(result) assert subscription.status == SubscriptionLifecycle.ACTIVE diff --git a/test/workflows/nren_l3_core_service/test_create_nren_l3_core_service.py b/test/workflows/l3_core_service/test_create_l3_core_service.py similarity index 83% rename from test/workflows/nren_l3_core_service/test_create_nren_l3_core_service.py rename to test/workflows/l3_core_service/test_create_l3_core_service.py index ae62f2f5..149fdf20 100644 --- a/test/workflows/nren_l3_core_service/test_create_nren_l3_core_service.py +++ b/test/workflows/l3_core_service/test_create_l3_core_service.py @@ -4,7 +4,7 @@ import pytest from orchestrator.types import SubscriptionLifecycle from gso.products import ProductName -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService +from gso.products.product_types.l3_core_service import L3CoreService from gso.services.subscriptions import get_product_id_by_name from gso.utils.shared_enums import APType from test.workflows import assert_complete, assert_lso_interaction_success, extract_state, run_workflow @@ -26,10 +26,12 @@ def base_bgp_peer_input(faker): return _base_bgp_peer_input -@pytest.mark.parametrize("l3_core_type", [ProductName.GEANT_IP, ProductName.IAS]) +@pytest.mark.parametrize( + "l3_core_type", [ProductName.GEANT_IP, ProductName.IAS, ProductName.GWS, ProductName.LHCONE, ProductName.COPERNICUS] +) @pytest.mark.workflow() @patch("gso.services.lso_client._send_request") -def test_create_nren_l3_core_service_success( +def test_create_l3_core_service_success( mock_lso_client, l3_core_type, faker, @@ -73,18 +75,18 @@ def test_create_nren_l3_core_service_success( ] lso_interaction_count = 6 - result, process_stat, step_log = run_workflow("create_nren_l3_core_service", form_input_data) + result, process_stat, step_log = run_workflow("create_l3_core_service", form_input_data) for _ in range(lso_interaction_count): result, step_log = assert_lso_interaction_success(result, process_stat, step_log) assert_complete(result) state = extract_state(result) - subscription = NRENL3CoreService.from_subscription(state["subscription_id"]) + subscription = L3CoreService.from_subscription(state["subscription_id"]) assert mock_lso_client.call_count == lso_interaction_count assert subscription.status == SubscriptionLifecycle.ACTIVE - assert len(subscription.nren_l3_core_service.nren_ap_list) == 1 + assert len(subscription.l3_core_service.ap_list) == 1 assert ( - str(subscription.nren_l3_core_service.nren_ap_list[0].sbp.edge_port.owner_subscription_id) + str(subscription.l3_core_service.ap_list[0].sbp.edge_port.owner_subscription_id) == form_input_data[2]["edge_port"]["edge_port"] ) diff --git a/test/workflows/l3_core_service/test_import_l3_core_service.py b/test/workflows/l3_core_service/test_import_l3_core_service.py new file mode 100644 index 00000000..e3293e61 --- /dev/null +++ b/test/workflows/l3_core_service/test_import_l3_core_service.py @@ -0,0 +1,27 @@ +import pytest +from orchestrator.types import SubscriptionLifecycle + +from gso.products.product_types.l3_core_service import L3CoreService, L3CoreServiceType +from test.workflows import assert_complete, run_workflow + + +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.IMPORTED_GEANT_IP, + L3CoreServiceType.IMPORTED_IAS, + L3CoreServiceType.IMPORTED_LHCONE, + L3CoreServiceType.IMPORTED_COPERNICUS, + ], +) +@pytest.mark.workflow() +def test_import_l3_core_service_success(l3_core_service_subscription_factory, l3_core_service_type): + imported_l3_core_service = l3_core_service_subscription_factory(l3_core_service_type=l3_core_service_type) + result, _, _ = run_workflow("import_l3_core_service", [{"subscription_id": imported_l3_core_service}]) + subscription = L3CoreService.from_subscription(imported_l3_core_service) + + assert_complete(result) + # Remove the "IMPORTED_" prefix with ``[9:]`` + assert subscription.l3_core_service_type == L3CoreServiceType(l3_core_service_type.value[9:]) + assert subscription.status == SubscriptionLifecycle.ACTIVE + assert subscription.insync is True diff --git a/test/workflows/l3_core_service/test_migrate_l3_core_service.py b/test/workflows/l3_core_service/test_migrate_l3_core_service.py new file mode 100644 index 00000000..6109dcca --- /dev/null +++ b/test/workflows/l3_core_service/test_migrate_l3_core_service.py @@ -0,0 +1,56 @@ +import pytest + +from gso.products.product_types.l3_core_service import L3CoreService, L3CoreServiceType +from test.workflows import assert_complete, extract_state, run_workflow + + +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.GEANT_IP, + L3CoreServiceType.IAS, + L3CoreServiceType.GWS, + L3CoreServiceType.LHCONE, + L3CoreServiceType.COPERNICUS, + ], +) +@pytest.mark.workflow() +def test_migrate_l3_core_service_success( + faker, + edge_port_subscription_factory, + partner_factory, + l3_core_service_subscription_factory, + l3_core_service_type, +): + partner = partner_factory() + subscription_id = l3_core_service_subscription_factory(partner=partner, l3_core_service_type=l3_core_service_type) + new_edge_port_1 = edge_port_subscription_factory(partner=partner) + new_edge_port_2 = edge_port_subscription_factory(partner=partner) + subscription = L3CoreService.from_subscription(subscription_id) + + form_input_data = [ + {"subscription_id": subscription_id}, + { + "tt_number": faker.tt_number(), + "edge_port_selection": [ + { + "old_edge_port": subscription.l3_core_service.ap_list[0].sbp.edge_port.description, + "new_edge_port": new_edge_port_1, + }, + { + "old_edge_port": subscription.l3_core_service.ap_list[1].sbp.edge_port.description, + "new_edge_port": new_edge_port_2, + }, + ], + }, + ] + + result, _, _ = run_workflow("migrate_l3_core_service", form_input_data) + + assert_complete(result) + state = extract_state(result) + subscription = L3CoreService.from_subscription(state["subscription_id"]) + assert subscription.insync is True + assert len(subscription.l3_core_service.ap_list) == 2 + assert str(subscription.l3_core_service.ap_list[0].sbp.edge_port.owner_subscription_id) == new_edge_port_1 + assert str(subscription.l3_core_service.ap_list[1].sbp.edge_port.owner_subscription_id) == new_edge_port_2 diff --git a/test/workflows/nren_l3_core_service/test_modify_nren_l3_core_service.py b/test/workflows/l3_core_service/test_modify_l3_core_service.py similarity index 53% rename from test/workflows/nren_l3_core_service/test_modify_nren_l3_core_service.py rename to test/workflows/l3_core_service/test_modify_l3_core_service.py index 32238512..2b84f59b 100644 --- a/test/workflows/nren_l3_core_service/test_modify_nren_l3_core_service.py +++ b/test/workflows/l3_core_service/test_modify_l3_core_service.py @@ -1,19 +1,26 @@ import pytest from gso.products.product_blocks.bgp_session import IPFamily -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService, NRENL3CoreServiceType +from gso.products.product_types.l3_core_service import L3CoreService, L3CoreServiceType from gso.utils.shared_enums import APType from test.workflows import extract_state, run_workflow -@pytest.mark.parametrize("l3_core_service_type", [NRENL3CoreServiceType.GEANT_IP, NRENL3CoreServiceType.IAS]) +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.GEANT_IP, + L3CoreServiceType.IAS, + L3CoreServiceType.GWS, + L3CoreServiceType.LHCONE, + L3CoreServiceType.COPERNICUS, + ], +) @pytest.mark.workflow() -def test_modify_nren_l3_core_service_remove_edge_port_success( - nren_l3_core_service_subscription_factory, l3_core_service_type -): - subscription_id = nren_l3_core_service_subscription_factory(nren_l3_core_service_type=l3_core_service_type) - subscription = NRENL3CoreService.from_subscription(subscription_id) - access_port = subscription.nren_l3_core_service.nren_ap_list[0] +def test_modify_l3_core_service_remove_edge_port_success(l3_core_service_subscription_factory, l3_core_service_type): + subscription_id = l3_core_service_subscription_factory(l3_core_service_type=l3_core_service_type) + subscription = L3CoreService.from_subscription(subscription_id) + access_port = subscription.l3_core_service.ap_list[0] input_form_data = [ {"subscription_id": subscription_id}, { @@ -27,18 +34,27 @@ def test_modify_nren_l3_core_service_remove_edge_port_success( {}, ] - result, _, _ = run_workflow("modify_nren_l3_core_service", input_form_data) + result, _, _ = run_workflow("modify_l3_core_service", input_form_data) state = extract_state(result) - subscription = NRENL3CoreService.from_subscription(state["subscription_id"]) - assert len(subscription.nren_l3_core_service.nren_ap_list) == 1 - assert subscription.nren_l3_core_service.nren_ap_list[0].ap_type == APType.LOAD_BALANCED + subscription = L3CoreService.from_subscription(state["subscription_id"]) + assert len(subscription.l3_core_service.ap_list) == 1 + assert subscription.l3_core_service.ap_list[0].ap_type == APType.LOAD_BALANCED -@pytest.mark.parametrize("l3_core_service_type", [NRENL3CoreServiceType.GEANT_IP, NRENL3CoreServiceType.IAS]) +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.GEANT_IP, + L3CoreServiceType.IAS, + L3CoreServiceType.GWS, + L3CoreServiceType.LHCONE, + L3CoreServiceType.COPERNICUS, + ], +) @pytest.mark.workflow() -def test_modify_nren_l3_core_service_add_new_edge_port_success( - nren_l3_core_service_subscription_factory, +def test_modify_l3_core_service_add_new_edge_port_success( + l3_core_service_subscription_factory, edge_port_subscription_factory, partner_factory, faker, @@ -46,10 +62,8 @@ def test_modify_nren_l3_core_service_add_new_edge_port_success( ): partner = partner_factory() new_edge_port = edge_port_subscription_factory(partner=partner) - subscription_id = nren_l3_core_service_subscription_factory( - partner=partner, nren_l3_core_service_type=l3_core_service_type - ) - subscription = NRENL3CoreService.from_subscription(subscription_id) + subscription_id = l3_core_service_subscription_factory(partner=partner, l3_core_service_type=l3_core_service_type) + subscription = L3CoreService.from_subscription(subscription_id) input_form_data = [ {"subscription_id": subscription_id}, { @@ -58,7 +72,7 @@ def test_modify_nren_l3_core_service_add_new_edge_port_success( "edge_port": str(port.sbp.edge_port.owner_subscription_id), "ap_type": port.ap_type, } - for port in subscription.nren_l3_core_service.nren_ap_list + for port in subscription.l3_core_service.ap_list ] + [ { @@ -89,11 +103,11 @@ def test_modify_nren_l3_core_service_add_new_edge_port_success( }, ] - result, _, _ = run_workflow("modify_nren_l3_core_service", input_form_data) + result, _, _ = run_workflow("modify_l3_core_service", input_form_data) state = extract_state(result) - subscription = NRENL3CoreService.from_subscription(state["subscription_id"]) - assert len(subscription.nren_l3_core_service.nren_ap_list) == 3 + subscription = L3CoreService.from_subscription(state["subscription_id"]) + assert len(subscription.l3_core_service.ap_list) == 3 @pytest.fixture() @@ -143,13 +157,22 @@ def sbp_input_form_data(faker): return _generate_form_data -@pytest.mark.parametrize("l3_core_service_type", [NRENL3CoreServiceType.GEANT_IP, NRENL3CoreServiceType.IAS]) +@pytest.mark.parametrize( + "l3_core_service_type", + [ + L3CoreServiceType.GEANT_IP, + L3CoreServiceType.IAS, + L3CoreServiceType.GWS, + L3CoreServiceType.LHCONE, + L3CoreServiceType.COPERNICUS, + ], +) @pytest.mark.workflow() -def test_modify_nren_l3_core_service_modify_edge_port_success( - faker, nren_l3_core_service_subscription_factory, l3_core_service_type, sbp_input_form_data +def test_modify_l3_core_service_modify_edge_port_success( + faker, l3_core_service_subscription_factory, l3_core_service_type, sbp_input_form_data ): - subscription_id = nren_l3_core_service_subscription_factory(nren_l3_core_service_type=l3_core_service_type) - subscription = NRENL3CoreService.from_subscription(subscription_id) + subscription_id = l3_core_service_subscription_factory(l3_core_service_type=l3_core_service_type) + subscription = L3CoreService.from_subscription(subscription_id) new_sbp_data = [sbp_input_form_data(), sbp_input_form_data()] input_form_data = [ {"subscription_id": subscription_id}, @@ -159,134 +182,124 @@ def test_modify_nren_l3_core_service_modify_edge_port_success( "edge_port": str(port.sbp.edge_port.owner_subscription_id), "ap_type": port.ap_type, } - for port in subscription.nren_l3_core_service.nren_ap_list + for port in subscription.l3_core_service.ap_list ] }, {**new_sbp_data[0]}, {**new_sbp_data[1]}, ] - result, _, _ = run_workflow("modify_nren_l3_core_service", input_form_data) + result, _, _ = run_workflow("modify_l3_core_service", input_form_data) state = extract_state(result) - subscription = NRENL3CoreService.from_subscription(state["subscription_id"]) - assert len(subscription.nren_l3_core_service.nren_ap_list) == 2 + subscription = L3CoreService.from_subscription(state["subscription_id"]) + assert len(subscription.l3_core_service.ap_list) == 2 for i in range(2): - assert subscription.nren_l3_core_service.nren_ap_list[i].sbp.geant_sid == new_sbp_data[i]["geant_sid"] - assert subscription.nren_l3_core_service.nren_ap_list[i].sbp.is_tagged == new_sbp_data[i]["is_tagged"] - assert subscription.nren_l3_core_service.nren_ap_list[i].sbp.vlan_id == new_sbp_data[i]["vlan_id"] - assert ( - str(subscription.nren_l3_core_service.nren_ap_list[i].sbp.ipv4_address) == new_sbp_data[i]["ipv4_address"] - ) - assert ( - str(subscription.nren_l3_core_service.nren_ap_list[i].sbp.ipv6_address) == new_sbp_data[i]["ipv6_address"] - ) + assert subscription.l3_core_service.ap_list[i].sbp.geant_sid == new_sbp_data[i]["geant_sid"] + assert subscription.l3_core_service.ap_list[i].sbp.is_tagged == new_sbp_data[i]["is_tagged"] + assert subscription.l3_core_service.ap_list[i].sbp.vlan_id == new_sbp_data[i]["vlan_id"] + assert str(subscription.l3_core_service.ap_list[i].sbp.ipv4_address) == new_sbp_data[i]["ipv4_address"] + assert str(subscription.l3_core_service.ap_list[i].sbp.ipv6_address) == new_sbp_data[i]["ipv6_address"] assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.custom_firewall_filters + subscription.l3_core_service.ap_list[i].sbp.custom_firewall_filters == new_sbp_data[i]["custom_firewall_filters"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].bfd_enabled + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].bfd_enabled == new_sbp_data[i]["v4_bgp_peer"]["bfd_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].has_custom_policies + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].has_custom_policies == new_sbp_data[i]["v4_bgp_peer"]["has_custom_policies"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].authentication_key + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].authentication_key == new_sbp_data[i]["v4_bgp_peer"]["authentication_key"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].multipath_enabled + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].multipath_enabled == new_sbp_data[i]["v4_bgp_peer"]["multipath_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].send_default_route + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].send_default_route == new_sbp_data[i]["v4_bgp_peer"]["send_default_route"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].is_passive + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].is_passive == new_sbp_data[i]["v4_bgp_peer"]["is_passive"] ) assert ( - str(subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].peer_address) + str(subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].peer_address) == new_sbp_data[i]["v4_bgp_peer"]["peer_address"] ) assert ( - bool( - IPFamily.V4MULTICAST - in subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[0].families - ) + bool(IPFamily.V4MULTICAST in subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[0].families) == new_sbp_data[i]["v4_bgp_peer"]["add_v4_multicast"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].bfd_enabled + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].bfd_enabled == new_sbp_data[i]["v6_bgp_peer"]["bfd_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].has_custom_policies + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].has_custom_policies == new_sbp_data[i]["v6_bgp_peer"]["has_custom_policies"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].authentication_key + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].authentication_key == new_sbp_data[i]["v6_bgp_peer"]["authentication_key"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].multipath_enabled + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].multipath_enabled == new_sbp_data[i]["v6_bgp_peer"]["multipath_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].send_default_route + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].send_default_route == new_sbp_data[i]["v6_bgp_peer"]["send_default_route"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].is_passive + subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].is_passive == new_sbp_data[i]["v6_bgp_peer"]["is_passive"] ) assert ( - str(subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].peer_address) + str(subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].peer_address) == new_sbp_data[i]["v6_bgp_peer"]["peer_address"] ) assert ( - bool( - IPFamily.V6MULTICAST - in subscription.nren_l3_core_service.nren_ap_list[i].sbp.bgp_session_list[1].families - ) + bool(IPFamily.V6MULTICAST in subscription.l3_core_service.ap_list[i].sbp.bgp_session_list[1].families) == new_sbp_data[i]["v6_bgp_peer"]["add_v6_multicast"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v4_bfd_settings.bfd_enabled + subscription.l3_core_service.ap_list[i].sbp.v4_bfd_settings.bfd_enabled == new_sbp_data[i]["v4_bfd_settings"]["bfd_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v4_bfd_settings.bfd_interval_rx + subscription.l3_core_service.ap_list[i].sbp.v4_bfd_settings.bfd_interval_rx == new_sbp_data[i]["v4_bfd_settings"]["bfd_interval_rx"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v4_bfd_settings.bfd_interval_tx + subscription.l3_core_service.ap_list[i].sbp.v4_bfd_settings.bfd_interval_tx == new_sbp_data[i]["v4_bfd_settings"]["bfd_interval_tx"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v4_bfd_settings.bfd_multiplier + subscription.l3_core_service.ap_list[i].sbp.v4_bfd_settings.bfd_multiplier == new_sbp_data[i]["v4_bfd_settings"]["bfd_multiplier"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v6_bfd_settings.bfd_enabled + subscription.l3_core_service.ap_list[i].sbp.v6_bfd_settings.bfd_enabled == new_sbp_data[i]["v6_bfd_settings"]["bfd_enabled"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v6_bfd_settings.bfd_interval_rx + subscription.l3_core_service.ap_list[i].sbp.v6_bfd_settings.bfd_interval_rx == new_sbp_data[i]["v6_bfd_settings"]["bfd_interval_rx"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v6_bfd_settings.bfd_interval_tx + subscription.l3_core_service.ap_list[i].sbp.v6_bfd_settings.bfd_interval_tx == new_sbp_data[i]["v6_bfd_settings"]["bfd_interval_tx"] ) assert ( - subscription.nren_l3_core_service.nren_ap_list[i].sbp.v6_bfd_settings.bfd_multiplier + subscription.l3_core_service.ap_list[i].sbp.v6_bfd_settings.bfd_multiplier == new_sbp_data[i]["v6_bfd_settings"]["bfd_multiplier"] ) diff --git a/test/workflows/nren_l3_core_service/test_import_nren_l3_core_service.py b/test/workflows/nren_l3_core_service/test_import_nren_l3_core_service.py deleted file mode 100644 index 13095de6..00000000 --- a/test/workflows/nren_l3_core_service/test_import_nren_l3_core_service.py +++ /dev/null @@ -1,23 +0,0 @@ -import pytest -from orchestrator.types import SubscriptionLifecycle - -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService, NRENL3CoreServiceType -from test.workflows import assert_complete, run_workflow - - -@pytest.mark.parametrize( - "l3_core_service_type", [NRENL3CoreServiceType.IMPORTED_GEANT_IP, NRENL3CoreServiceType.IMPORTED_IAS] -) -@pytest.mark.workflow() -def test_import_nren_l3_core_service_success(nren_l3_core_service_subscription_factory, l3_core_service_type): - imported_nren_l3_core_service = nren_l3_core_service_subscription_factory( - nren_l3_core_service_type=l3_core_service_type - ) - result, _, _ = run_workflow("import_nren_l3_core_service", [{"subscription_id": imported_nren_l3_core_service}]) - subscription = NRENL3CoreService.from_subscription(imported_nren_l3_core_service) - - assert_complete(result) - # Remove the "IMPORTED_" prefix with ``[9:]`` - assert subscription.nren_l3_core_service_type == NRENL3CoreServiceType(l3_core_service_type.value[9:]) - assert subscription.status == SubscriptionLifecycle.ACTIVE - assert subscription.insync is True diff --git a/test/workflows/nren_l3_core_service/test_migrate_nren_l3_core_service.py b/test/workflows/nren_l3_core_service/test_migrate_nren_l3_core_service.py deleted file mode 100644 index a4ad8a9f..00000000 --- a/test/workflows/nren_l3_core_service/test_migrate_nren_l3_core_service.py +++ /dev/null @@ -1,49 +0,0 @@ -import pytest - -from gso.products.product_types.nren_l3_core_service import NRENL3CoreService, NRENL3CoreServiceType -from test.workflows import assert_complete, extract_state, run_workflow - - -@pytest.mark.parametrize("l3_core_service_type", [NRENL3CoreServiceType.GEANT_IP, NRENL3CoreServiceType.IAS]) -@pytest.mark.workflow() -def test_migrate_nren_l3_core_service_success( - faker, - edge_port_subscription_factory, - partner_factory, - nren_l3_core_service_subscription_factory, - l3_core_service_type, -): - partner = partner_factory() - subscription_id = nren_l3_core_service_subscription_factory( - partner=partner, nren_l3_core_service_type=l3_core_service_type - ) - new_edge_port_1 = edge_port_subscription_factory(partner=partner) - new_edge_port_2 = edge_port_subscription_factory(partner=partner) - subscription = NRENL3CoreService.from_subscription(subscription_id) - - form_input_data = [ - {"subscription_id": subscription_id}, - { - "tt_number": faker.tt_number(), - "edge_port_selection": [ - { - "old_edge_port": subscription.nren_l3_core_service.nren_ap_list[0].sbp.edge_port.description, - "new_edge_port": new_edge_port_1, - }, - { - "old_edge_port": subscription.nren_l3_core_service.nren_ap_list[1].sbp.edge_port.description, - "new_edge_port": new_edge_port_2, - }, - ], - }, - ] - - result, _, _ = run_workflow("migrate_nren_l3_core_service", form_input_data) - - assert_complete(result) - state = extract_state(result) - subscription = NRENL3CoreService.from_subscription(state["subscription_id"]) - assert subscription.insync is True - assert len(subscription.nren_l3_core_service.nren_ap_list) == 2 - assert str(subscription.nren_l3_core_service.nren_ap_list[0].sbp.edge_port.owner_subscription_id) == new_edge_port_1 - assert str(subscription.nren_l3_core_service.nren_ap_list[1].sbp.edge_port.owner_subscription_id) == new_edge_port_2 -- GitLab