diff --git a/docs/source/conf.py b/docs/source/conf.py index 74502fb22f8ea416e23b894aae62d6e1d7727368..3f4d36bd86b823b9fe642011cd62c8efa55ee16a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,27 +1,28 @@ # -- Project information ----------------------------------------------------- -project = "GÉANT Service Orchestrator" -copyright = "2023, GÉANT Vereniging" -author = "GÉANT Orchestration and Automation Team" +project = 'GÉANT Service Orchestrator' +copyright = '2023, GÉANT Vereniging' +author = 'GÉANT Orchestration and Automation Team' # -- General configuration --------------------------------------------------- -extensions = ["sphinx_rtd_theme", "sphinx.ext.autodoc", "sphinxcontrib.jquery"] +extensions = ['sphinx_rtd_theme', 'sphinx.ext.autodoc', 'sphinxcontrib.jquery'] -templates_path = ["templates"] -exclude_patterns = ["build", "Thumbs.db", ".DS_Store", "venv", "vale", "__init__.py"] +templates_path = ['templates'] +exclude_patterns = ['build', 'Thumbs.db', '.DS_Store', 'venv', 'vale', '__init__.py'] # -- Options for HTML output ------------------------------------------------- -html_theme = "sphinx_rtd_theme" -html_static_path = ["static"] +html_theme = 'sphinx_rtd_theme' +html_static_path = ['static'] html_theme_options = { - "style_nav_header_background": "rgb(0 63 95)", + 'style_nav_header_background': 'rgb(0 63 95)', } -html_css_files = ["custom.css"] -html_js_files = ["custom.js"] -html_logo = "static/geant_logo_white.svg" +html_css_files = ['custom.css'] +html_js_files = ['custom.js'] +html_logo = 'static/geant_logo_white.svg' # Both the class' and the ``__init__`` method's docstring are concatenated and inserted. -autoclass_content = "both" -autodoc_typehints = "none" +autoclass_content = 'both' +autodoc_typehints = 'none' # Display todos by setting to True todo_include_todos = True + diff --git a/gso/__init__.py b/gso/__init__.py index c92a6db2c3fb4820db8d3cb6f7a4e2ae6c3e7146..c2ff8c531a2a9cbf79a5b1b1138b5157c022a1f1 100644 --- a/gso/__init__.py +++ b/gso/__init__.py @@ -4,8 +4,7 @@ import typer from orchestrator import OrchestratorCore, app_settings from orchestrator.cli.main import app as cli_app -# noinspection PyUnresolvedReferences -import gso.products +import gso.products # noqa: F401 import gso.workflows # noqa: F401 from gso.api import router as api_router from gso.cli import netbox diff --git a/gso/api/v1/imports.py b/gso/api/v1/imports.py index e87f4ad8ed30cef561ee943ff525c40006a07f52..8c92831f7724d21a88b15d71788a4695a0ae8996 100644 --- a/gso/api/v1/imports.py +++ b/gso/api/v1/imports.py @@ -130,9 +130,8 @@ class IptrunkImportModel(BaseModel): """Validate that the customer exists.""" try: get_customer_by_name(value) - except CustomerNotFoundError as e: - msg = f"Customer {value} not found" - raise ValueError(msg) from e + except CustomerNotFoundError: + raise ValueError(f"Customer {value} not found") return value @@ -140,8 +139,7 @@ class IptrunkImportModel(BaseModel): def check_if_router_side_is_available(cls, value: str) -> str: """Both sides of the trunk must exist in :term:`GSO`.""" if value not in cls._get_active_routers(): - msg = f"Router {value} not found" - raise ValueError(msg) + raise ValueError(f"Router {value} not found") return value @@ -149,8 +147,7 @@ class IptrunkImportModel(BaseModel): def check_side_uniqueness(cls, value: list[str]) -> list[str]: """:term:`LAG` members must be unique.""" if len(value) != len(set(value)): - msg = "Items must be unique" - raise ValueError(msg) + raise ValueError("Items must be unique") return value @@ -165,24 +162,20 @@ class IptrunkImportModel(BaseModel): len_b = len(side_b_members) if len_a < min_links: - msg = f"Side A members should be at least {min_links} (iptrunk_minimum_links)" - raise ValueError(msg) + raise ValueError(f"Side A members should be at least {min_links} (iptrunk_minimum_links)") if len_a != len_b: - msg = "Mismatch between Side A and B members" - raise ValueError(msg) + raise ValueError("Mismatch between Side A and B members") return values def _start_process(process_name: str, data: dict) -> UUID: """Start a process and handle common exceptions.""" + pid: UUID = processes.start_process(process_name, [data]) if pid is None: - raise HTTPException( - status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, - detail="Failed to start the process.", - ) + raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Failed to start the process.") process = processes._get_process(pid) # noqa: SLF001 if process.last_status == "failed": @@ -222,6 +215,7 @@ def import_router(router_data: RouterImportModel) -> dict[str, Any]: :raises HTTPException: If there's an error in the process. """ + pid = _start_process("import_router", router_data.dict()) return {"detail": "Router added successfully", "pid": pid} @@ -238,5 +232,6 @@ def import_iptrunk(iptrunk_data: IptrunkImportModel) -> dict[str, Any]: :raises HTTPException: If there's an error in the process. """ + pid = _start_process("import_iptrunk", iptrunk_data.dict()) return {"detail": "Iptrunk added successfully", "pid": pid} diff --git a/gso/api/v1/subscriptions.py b/gso/api/v1/subscriptions.py index 4e6e3d2a8c10bb15df204727de00501b551efd59..55672297c7bce90b31bcec1f1789ace616d61bab 100644 --- a/gso/api/v1/subscriptions.py +++ b/gso/api/v1/subscriptions.py @@ -11,18 +11,10 @@ from orchestrator.services.subscriptions import build_extended_domain_model from gso.services.subscriptions import get_active_router_subscriptions -router = APIRouter( - prefix="/subscriptions", - tags=["Subscriptions"], - dependencies=[Depends(opa_security_default)], -) +router = APIRouter(prefix="/subscriptions", tags=["Subscriptions"], dependencies=[Depends(opa_security_default)]) -@router.get( - "/routers", - status_code=status.HTTP_200_OK, - response_model=list[SubscriptionDomainModelSchema], -) +@router.get("/routers", status_code=status.HTTP_200_OK, response_model=list[SubscriptionDomainModelSchema]) def subscription_routers() -> list[dict[str, Any]]: """Retrieve all active routers subscriptions.""" subscriptions = [] diff --git a/gso/migrations/env.py b/gso/migrations/env.py index ba4d2a664eaa3dd6e6a3d49ed125faa63078c7d3..4d84cfb15787fc357dd96857fb97b4cee13b80a8 100644 --- a/gso/migrations/env.py +++ b/gso/migrations/env.py @@ -32,10 +32,7 @@ def run_migrations_offline() -> None: """ url = config.get_main_option("sqlalchemy.url") context.configure( - url=url, - target_metadata=target_metadata, - literal_binds=True, - dialect_opts={"paramstyle": "named"}, + url=url, target_metadata=target_metadata, literal_binds=True, dialect_opts={"paramstyle": "named"} ) with context.begin_transaction(): diff --git a/gso/migrations/versions/2023-08-14_3657611f0dfc_add_router_workflows.py b/gso/migrations/versions/2023-08-14_3657611f0dfc_add_router_workflows.py index 86157af6ab6bc3128af28f6af26b62aea70ab324..153d5433579308b23e2d06b394b5d9f4a620158e 100644 --- a/gso/migrations/versions/2023-08-14_3657611f0dfc_add_router_workflows.py +++ b/gso/migrations/versions/2023-08-14_3657611f0dfc_add_router_workflows.py @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "3657611f0dfc" -down_revision = "91047dd30b40" +revision = '3657611f0dfc' +down_revision = '91047dd30b40' branch_labels = None depends_on = None @@ -22,14 +22,14 @@ new_workflows = [ "name": "create_router", "target": "CREATE", "description": "Create router", - "product_type": "Router", + "product_type": "Router" }, { "name": "terminate_router", "target": "TERMINATE", "description": "Terminate router", - "product_type": "Router", - }, + "product_type": "Router" + } ] diff --git a/gso/migrations/versions/2023-08-14_91047dd30b40_add_site_workflows.py b/gso/migrations/versions/2023-08-14_91047dd30b40_add_site_workflows.py index 7c69717cf235d2d7533bee9268ac9a30f6cf969e..f39467eadecc248717f851bea8b221cd5b5d378e 100644 --- a/gso/migrations/versions/2023-08-14_91047dd30b40_add_site_workflows.py +++ b/gso/migrations/versions/2023-08-14_91047dd30b40_add_site_workflows.py @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "91047dd30b40" -down_revision = "97436160a422" +revision = '91047dd30b40' +down_revision = '97436160a422' branch_labels = None depends_on = None @@ -22,7 +22,7 @@ new_workflows = [ "name": "create_site", "target": "CREATE", "description": "Create Site", - "product_type": "Site", + "product_type": "Site" } ] diff --git a/gso/migrations/versions/2023-08-14_97436160a422_add_initial_products.py b/gso/migrations/versions/2023-08-14_97436160a422_add_initial_products.py index 7243674ab9e44bada15348e6d072a354eeb6f230..e3bdc2fa74f3688b590af92a3cf4d4144f1d526d 100644 --- a/gso/migrations/versions/2023-08-14_97436160a422_add_initial_products.py +++ b/gso/migrations/versions/2023-08-14_97436160a422_add_initial_products.py @@ -9,1254 +9,546 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "97436160a422" +revision = '97436160a422' down_revision = None -branch_labels = ("data",) -depends_on = "a09ac125ea73" +branch_labels = ('data',) +depends_on = 'a09ac125ea73' def upgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + conn.execute(sa.text(""" INSERT INTO products (name, description, product_type, tag, status) VALUES ('Site', 'A GÉANT Site', 'Site', 'SITE', 'active') RETURNING products.product_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO products (name, description, product_type, tag, status) VALUES ('Router', 'A GÉANT Router', 'Router', 'ROUTER', 'active') RETURNING products.product_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO products (name, description, product_type, tag, status) VALUES ('IP trunk', 'A GÉANT IP Trunk', 'Iptrunk', 'IPTRUNK', 'active') RETURNING products.product_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO product_blocks (name, description, tag, status) VALUES ('SiteBlock', 'Site PB', 'SITEPB', 'active') RETURNING product_blocks.product_block_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO product_blocks (name, description, tag, status) VALUES ('RouterBlock', 'Router PB', 'ROUTERPB', 'active') RETURNING product_blocks.product_block_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO product_blocks (name, description, tag, status) VALUES ('IptrunkBlock', 'IP Trunk PB', 'IPTRUNKPB', 'active') RETURNING product_blocks.product_block_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_name', 'Name of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_minimum_links', 'Minimum amount of members in a LAG') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_description', 'Description of an IP Trunk') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_ias_lt_ipv4_network', 'IPv4 network for a logical tunnel between master routing table and IAS') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('geant_s_sid', 'GÉANT Service ID') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_isis_metric', 'ISIS metric') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideA_ae_geant_a_sid', 'GÉANT Service ID for access port') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideB_ae_geant_a_sid', 'GÉANT Service ID for access port') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_lo_ipv6_address', 'IPv6 address of loopback interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideB_ae_members', 'LAG members on side B') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_lo_ipv4_address', 'IPv4 address of loopback interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_city', 'City of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_tier', 'Tier of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_role', 'Role of a Router') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_type', 'Type of an IP Trunk') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_bgp_community_id', 'BGP Community ID') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideA_ae_iface', 'LAG interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_ipv4_network', 'IPv4 network of an IP Trunk') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideB_ae_members_description', 'Descriptions of LAG members') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_speed', 'Speed of LAG members') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_country_code', 'Country code of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_access_via_ts', 'Whether a router should get accessed through terminal server') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_internal_id', 'Third octet of a Site''s private network') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_si_ipv4_network', 'IPv4 network for SI interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_ias_lt_ipv6_network', 'IPv6 network for a logical tunnel between master routing table and IAS') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_latitude', 'Latitude of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_country', 'Country of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_ts_address', 'Terminal Server address') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideB_ae_iface', 'LAG interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_is_ias_connected', 'Whether a Logical Tunnel between master routing table and IAS is needed') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_ipv6_network', 'IPv6 network of an IP Trunk') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('site_longitude', 'Longitude of a Site') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_lo_iso_address', 'ISO address of a loopback interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideA_ae_members', 'LAG members on side A') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_fqdn', 'FQDN of a Router') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_sideA_ae_members_description', 'Descriptions of LAG members') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_ts_port', 'Port number of the Terminal Server') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('router_vendor', 'Vendor of a Router') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Site')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Router')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IP trunk')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_fqdn'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ts_port'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_access_via_ts'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv4_address'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv6_address'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_iso_address'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_si_ipv4_network'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv4_network'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv6_network'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_vendor'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_role'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_is_ias_connected'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('geant_s_sid'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_description'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_type'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_speed'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_minimum_links'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv4_network'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv6_network'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_iface'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_geant_a_sid'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members_description'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_iface'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_geant_a_sid'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members_description'))) - """ - ) - ) + """)) def downgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_city')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_country_code')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_latitude')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_longitude')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_internal_id')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_bgp_community_id')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_tier')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('SiteBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_ts_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_fqdn')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_fqdn')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ts_port')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ts_port')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_access_via_ts')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_access_via_ts')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv4_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv4_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv6_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_ipv6_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_iso_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_lo_iso_address')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_si_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_si_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv6_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_ias_lt_ipv6_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_vendor')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_vendor')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_role')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_role')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_is_ias_connected')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('router_is_ias_connected')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('geant_s_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('geant_s_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_type')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_type')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_speed')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_speed')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_minimum_links')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_minimum_links')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_isis_metric')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv4_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv6_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_ipv6_network')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('site_name', 'iptrunk_minimum_links', 'iptrunk_description', 'router_ias_lt_ipv4_network', 'geant_s_sid', 'iptrunk_isis_metric', 'iptrunk_sideA_ae_geant_a_sid', 'iptrunk_sideB_ae_geant_a_sid', 'router_lo_ipv6_address', 'iptrunk_sideB_ae_members', 'router_lo_ipv4_address', 'site_city', 'site_tier', 'router_role', 'iptrunk_type', 'site_bgp_community_id', 'iptrunk_sideA_ae_iface', 'iptrunk_ipv4_network', 'iptrunk_sideB_ae_members_description', 'iptrunk_speed', 'site_country_code', 'router_access_via_ts', 'site_internal_id', 'router_si_ipv4_network', 'router_ias_lt_ipv6_network', 'site_latitude', 'site_country', 'site_ts_address', 'iptrunk_sideB_ae_iface', 'router_is_ias_connected', 'iptrunk_ipv6_network', 'site_longitude', 'router_lo_iso_address', 'iptrunk_sideA_ae_members', 'router_fqdn', 'iptrunk_sideA_ae_members_description', 'router_ts_port', 'router_vendor')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM resource_types WHERE resource_types.resource_type IN ('site_name', 'iptrunk_minimum_links', 'iptrunk_description', 'router_ias_lt_ipv4_network', 'geant_s_sid', 'iptrunk_isis_metric', 'iptrunk_sideA_ae_geant_a_sid', 'iptrunk_sideB_ae_geant_a_sid', 'router_lo_ipv6_address', 'iptrunk_sideB_ae_members', 'router_lo_ipv4_address', 'site_city', 'site_tier', 'router_role', 'iptrunk_type', 'site_bgp_community_id', 'iptrunk_sideA_ae_iface', 'iptrunk_ipv4_network', 'iptrunk_sideB_ae_members_description', 'iptrunk_speed', 'site_country_code', 'router_access_via_ts', 'site_internal_id', 'router_si_ipv4_network', 'router_ias_lt_ipv6_network', 'site_latitude', 'site_country', 'site_ts_address', 'iptrunk_sideB_ae_iface', 'router_is_ias_connected', 'iptrunk_ipv6_network', 'site_longitude', 'router_lo_iso_address', 'iptrunk_sideA_ae_members', 'router_fqdn', 'iptrunk_sideA_ae_members_description', 'router_ts_port', 'router_vendor') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Site')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Router')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IP trunk')) AND product_product_blocks.product_block_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('RouterBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('SiteBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock', 'RouterBlock', 'SiteBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM product_blocks WHERE product_blocks.name IN ('IptrunkBlock', 'RouterBlock', 'SiteBlock') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Router', 'IP trunk', 'Site')))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Router', 'IP trunk', 'Site'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('Router', 'IP trunk', 'Site'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscriptions WHERE subscriptions.product_id IN (SELECT products.product_id FROM products WHERE products.name IN ('Router', 'IP trunk', 'Site')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM products WHERE products.name IN ('Router', 'IP trunk', 'Site') - """ - ) - ) + """)) diff --git a/gso/migrations/versions/2023-08-14_a6eefd32c4f7_add_ip_trunk_workflows.py b/gso/migrations/versions/2023-08-14_a6eefd32c4f7_add_ip_trunk_workflows.py index 89ddbdde88f820e1facff9a7743ff7753e8e671f..b341eb7c8c9061959febac45181b1a70028e6236 100644 --- a/gso/migrations/versions/2023-08-14_a6eefd32c4f7_add_ip_trunk_workflows.py +++ b/gso/migrations/versions/2023-08-14_a6eefd32c4f7_add_ip_trunk_workflows.py @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "a6eefd32c4f7" -down_revision = "3657611f0dfc" +revision = 'a6eefd32c4f7' +down_revision = '3657611f0dfc' branch_labels = None depends_on = None @@ -22,26 +22,26 @@ new_workflows = [ "name": "create_iptrunk", "target": "CREATE", "description": "Create IP trunk", - "product_type": "Iptrunk", + "product_type": "Iptrunk" }, { "name": "terminate_iptrunk", "target": "TERMINATE", "description": "Terminate IPtrunk", - "product_type": "Iptrunk", + "product_type": "Iptrunk" }, { "name": "modify_trunk_interface", "target": "MODIFY", "description": "Modify IP Trunk interface", - "product_type": "Iptrunk", + "product_type": "Iptrunk" }, { "name": "modify_isis_metric", "target": "MODIFY", "description": "Modify IP trunk", - "product_type": "Iptrunk", - }, + "product_type": "Iptrunk" + } ] diff --git a/gso/migrations/versions/2023-08-16_e68720f2ec32_add_ip_trunk_migration_workflow.py b/gso/migrations/versions/2023-08-16_e68720f2ec32_add_ip_trunk_migration_workflow.py index 0fe19e739d0b8db2dabe366eda7da6ffd8be8e30..f2ad05f776ede60ab8c2d4f696454347a48f4e57 100644 --- a/gso/migrations/versions/2023-08-16_e68720f2ec32_add_ip_trunk_migration_workflow.py +++ b/gso/migrations/versions/2023-08-16_e68720f2ec32_add_ip_trunk_migration_workflow.py @@ -9,8 +9,8 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "e68720f2ec32" -down_revision = "a6eefd32c4f7" +revision = 'e68720f2ec32' +down_revision = 'a6eefd32c4f7' branch_labels = None depends_on = None @@ -22,7 +22,7 @@ new_workflows = [ "name": "migrate_iptrunk", "target": "MODIFY", "description": "Migrate an IP Trunk", - "product_type": "Iptrunk", + "product_type": "Iptrunk" } ] diff --git a/gso/migrations/versions/2023-08-23_01e42c100448_update_ip_trunk_model.py b/gso/migrations/versions/2023-08-23_01e42c100448_update_ip_trunk_model.py index 3fadabca869db85a58784f2401243356ffbed251..99979d8c15cd47b7251a17c1f54fc46be398cdb0 100644 --- a/gso/migrations/versions/2023-08-23_01e42c100448_update_ip_trunk_model.py +++ b/gso/migrations/versions/2023-08-23_01e42c100448_update_ip_trunk_model.py @@ -9,227 +9,105 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "01e42c100448" -down_revision = "e68720f2ec32" +revision = '01e42c100448' +down_revision = 'e68720f2ec32' branch_labels = None depends_on = None def upgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideB_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members', 'iptrunk_sideB_ae_geant_a_sid', 'iptrunk_sideB_ae_members', 'iptrunk_sideA_ae_members_description', 'iptrunk_sideA_ae_geant_a_sid', 'iptrunk_sideB_ae_members_description', 'iptrunk_sideB_ae_iface', 'iptrunk_sideA_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_sideA_ae_members', 'iptrunk_sideB_ae_geant_a_sid', 'iptrunk_sideB_ae_members', 'iptrunk_sideA_ae_members_description', 'iptrunk_sideA_ae_geant_a_sid', 'iptrunk_sideB_ae_members_description', 'iptrunk_sideB_ae_iface', 'iptrunk_sideA_ae_iface') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO product_blocks (name, description, tag, status) VALUES ('IptrunkSideBlock', 'IP Trunk side', 'IPTSIDE', 'active') RETURNING product_blocks.product_block_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_side_ae_members_description', 'LAG member descriptions') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_side_ae_iface', 'LAG interfaces') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_side_ae_members', 'LAG interface names') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('iptrunk_side_ae_geant_a_sid', 'GÉANT SID') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkSideBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_iface'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_geant_a_sid'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" WITH subscription_instance_ids AS ( SELECT subscription_instances.subscription_instance_id @@ -251,12 +129,8 @@ INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VA CROSS JOIN subscription_instance_ids WHERE resource_types.resource_type = 'iptrunk_side_ae_members_description' - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" WITH subscription_instance_ids AS ( SELECT subscription_instances.subscription_instance_id @@ -278,12 +152,8 @@ INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VA CROSS JOIN subscription_instance_ids WHERE resource_types.resource_type = 'iptrunk_side_ae_iface' - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" WITH subscription_instance_ids AS ( SELECT subscription_instances.subscription_instance_id @@ -305,12 +175,8 @@ INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VA CROSS JOIN subscription_instance_ids WHERE resource_types.resource_type = 'iptrunk_side_ae_members' - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" WITH subscription_instance_ids AS ( SELECT subscription_instances.subscription_instance_id @@ -332,108 +198,50 @@ INSERT INTO product_block_resource_types (product_block_id, resource_type_id) VA CROSS JOIN subscription_instance_ids WHERE resource_types.resource_type = 'iptrunk_side_ae_geant_a_sid' - """ - ) - ) + """)) def downgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_iface')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description', 'iptrunk_side_ae_iface', 'iptrunk_side_ae_members', 'iptrunk_side_ae_geant_a_sid')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description', 'iptrunk_side_ae_iface', 'iptrunk_side_ae_members', 'iptrunk_side_ae_geant_a_sid') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('RouterBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkSideBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM product_blocks WHERE product_blocks.name IN ('IptrunkSideBlock') - """ - ) - ) + """)) diff --git a/gso/migrations/versions/2023-10-11_394dc60d5c02_modify_ip_trunk_model.py b/gso/migrations/versions/2023-10-11_394dc60d5c02_modify_ip_trunk_model.py index 51be3c59acc0641a3cce2058d60f4c650708bf25..ce76bb6d3cb8d701bda8d69e0f474a81ec2e288e 100644 --- a/gso/migrations/versions/2023-10-11_394dc60d5c02_modify_ip_trunk_model.py +++ b/gso/migrations/versions/2023-10-11_394dc60d5c02_modify_ip_trunk_model.py @@ -9,162 +9,78 @@ import sqlalchemy as sa from alembic import op # revision identifiers, used by Alembic. -revision = "394dc60d5c02" -down_revision = "01e42c100448" +revision = '394dc60d5c02' +down_revision = '01e42c100448' branch_labels = None depends_on = None def upgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description', 'iptrunk_side_ae_members')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM resource_types WHERE resource_types.resource_type IN ('iptrunk_side_ae_members_description', 'iptrunk_side_ae_members') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO product_blocks (name, description, tag, status) VALUES ('IptrunkInterfaceBlock', 'Interface in a LAG as part of an IP trunk', 'IPTINT', 'active') RETURNING product_blocks.product_block_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('interface_description', 'Description of a LAG interface') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" INSERT INTO resource_types (resource_type, description) VALUES ('interface_name', 'Interface name of a LAG member') RETURNING resource_types.resource_type_id - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')), (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkInterfaceBlock'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_description'))) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock')), (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_name'))) - """ - ) - ) + """)) def downgrade() -> None: conn = op.get_bind() - conn.execute( - sa.text( - """ + 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 ('IptrunkInterfaceBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_description')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock')) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_name')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock'))) AND product_block_resource_types.resource_type_id = (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_name')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM subscription_instance_values WHERE subscription_instance_values.resource_type_id IN (SELECT resource_types.resource_type_id FROM resource_types WHERE resource_types.resource_type IN ('interface_description', 'interface_name')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM resource_types WHERE resource_types.resource_type IN ('interface_description', 'interface_name') - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkSideBlock')) AND product_block_relations.depends_on_id IN (SELECT product_blocks.product_block_id FROM product_blocks WHERE product_blocks.name IN ('IptrunkInterfaceBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + 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 ('IptrunkInterfaceBlock')) - """ - ) - ) - conn.execute( - sa.text( - """ + """)) + conn.execute(sa.text(""" DELETE FROM product_blocks WHERE product_blocks.name IN ('IptrunkInterfaceBlock') - """ - ) - ) + """)) diff --git a/gso/migrations/versions/2023-11-02_259c320235f5_add_site_modification_and_termination_.py b/gso/migrations/versions/2023-11-02_259c320235f5_add_site_modification_and_termination_.py index 996e169fb94f6014df8a06a1bf85252963f363f8..32a9db91d428494340cf1c7678360fcac567d71e 100644 --- a/gso/migrations/versions/2023-11-02_259c320235f5_add_site_modification_and_termination_.py +++ b/gso/migrations/versions/2023-11-02_259c320235f5_add_site_modification_and_termination_.py @@ -16,18 +16,8 @@ branch_labels = None depends_on = None new_workflows = [ - { - "name": "modify_site", - "target": "MODIFY", - "description": "Modify site", - "product_type": "Site", - }, - { - "name": "terminate_site", - "target": "TERMINATE", - "description": "Terminate site", - "product_type": "Site", - }, + {"name": "modify_site", "target": "MODIFY", "description": "Modify site", "product_type": "Site"}, + {"name": "terminate_site", "target": "TERMINATE", "description": "Terminate site", "product_type": "Site"}, ] diff --git a/gso/products/__init__.py b/gso/products/__init__.py index 74f8fa1586975e48a53e094198be95aceaf13e99..087d8836b2712171826a356b2e4e1c3ad8a70a54 100644 --- a/gso/products/__init__.py +++ b/gso/products/__init__.py @@ -26,5 +26,5 @@ SUBSCRIPTION_MODEL_REGISTRY.update( "Site": Site, "Router": Router, "IP trunk": Iptrunk, - }, + } ) diff --git a/gso/products/product_blocks/iptrunk.py b/gso/products/product_blocks/iptrunk.py index 3bf5266bc7ab6531f39cf553073b8724880e2304..9d8bcf81d73c6fe6e385837aec61440e82c52a43 100644 --- a/gso/products/product_blocks/iptrunk.py +++ b/gso/products/product_blocks/iptrunk.py @@ -7,11 +7,7 @@ from orchestrator.domain.base import ProductBlockModel from orchestrator.forms.validators import UniqueConstrainedList from orchestrator.types import SubscriptionLifecycle, strEnum -from gso.products.product_blocks.router import ( - RouterBlock, - RouterBlockInactive, - RouterBlockProvisioning, -) +from gso.products.product_blocks.router import RouterBlock, RouterBlockInactive, RouterBlockProvisioning class PhyPortCapacity(strEnum): @@ -41,9 +37,7 @@ class LAGMemberList(UniqueConstrainedList[T_co]): # type: ignore[type-var] class IptrunkInterfaceBlockInactive( - ProductBlockModel, - lifecycle=[SubscriptionLifecycle.INITIAL], - product_block_name="IptrunkInterfaceBlock", + ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="IptrunkInterfaceBlock" ): """An inactive IP trunk interface.""" @@ -74,9 +68,7 @@ class IptrunkSides(UniqueConstrainedList[T_co]): # type: ignore[type-var] class IptrunkSideBlockInactive( - ProductBlockModel, - lifecycle=[SubscriptionLifecycle.INITIAL], - product_block_name="IptrunkSideBlock", + ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="IptrunkSideBlock" ): """An inactive IP trunk side.""" @@ -105,9 +97,7 @@ class IptrunkSideBlock(IptrunkSideBlockProvisioning, lifecycle=[SubscriptionLife class IptrunkBlockInactive( - ProductBlockModel, - lifecycle=[SubscriptionLifecycle.INITIAL], - product_block_name="IptrunkBlock", + ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="IptrunkBlock" ): """A trunk that's currently inactive, see :class:`IptrunkBlock`.""" diff --git a/gso/products/product_blocks/router.py b/gso/products/product_blocks/router.py index 8f0896a56777769583b6ce4d0ebaabb8630e10b3..f1aea644f2db19383e927fdbd1c9adf88b0b22ad 100644 --- a/gso/products/product_blocks/router.py +++ b/gso/products/product_blocks/router.py @@ -6,11 +6,7 @@ from orchestrator.domain.base import ProductBlockModel from orchestrator.types import SubscriptionLifecycle, strEnum from pydantic import ConstrainedInt -from gso.products.product_blocks.site import ( - SiteBlock, - SiteBlockInactive, - SiteBlockProvisioning, -) +from gso.products.product_blocks.site import SiteBlock, SiteBlockInactive, SiteBlockProvisioning class RouterVendor(strEnum): @@ -39,9 +35,7 @@ class PortNumber(ConstrainedInt): class RouterBlockInactive( - ProductBlockModel, - lifecycle=[SubscriptionLifecycle.INITIAL], - product_block_name="RouterBlock", + ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="RouterBlock" ): """A router that's being currently inactive. See :class:`RouterBlock`.""" diff --git a/gso/products/product_blocks/site.py b/gso/products/product_blocks/site.py index 1950d2973cf3113bea8ba5f2f85793bd3a056fef..5840ba2abeaa51af37863e9190ebebf09872201a 100644 --- a/gso/products/product_blocks/site.py +++ b/gso/products/product_blocks/site.py @@ -34,8 +34,7 @@ class LatitudeCoordinate(ConstrainedStr): def validate(cls, value: str) -> str: """Validate that a latitude coordinate is valid.""" if not cls.regex.match(value): - msg = "Invalid latitude coordinate. Valid examples: '40.7128', '-74.0060', '90', '-90', '0'." - raise ValueError(msg) + raise ValueError("Invalid latitude coordinate. Valid examples: '40.7128', '-74.0060', '90', '-90', '0'.") return value @@ -54,17 +53,12 @@ class LongitudeCoordinate(ConstrainedStr): def validate(cls, value: str) -> str: """Validate that a longitude coordinate is valid.""" if not cls.regex.match(value): - msg = "Invalid longitude coordinate. Valid examples: '40.7128', '-74.0060', '180', '-180'" - raise ValueError(msg) + raise ValueError("Invalid longitude coordinate. Valid examples: '40.7128', '-74.0060', '180', '-180'") return value -class SiteBlockInactive( - ProductBlockModel, - lifecycle=[SubscriptionLifecycle.INITIAL], - product_block_name="SiteBlock", -): +class SiteBlockInactive(ProductBlockModel, lifecycle=[SubscriptionLifecycle.INITIAL], product_block_name="SiteBlock"): """A site that's currently inactive, see :class:`SiteBlock`.""" site_name: str | None = None diff --git a/gso/products/product_types/iptrunk.py b/gso/products/product_types/iptrunk.py index 70612d49216fa6f00fb47835bbbc1b772b818dc1..117336ae62a06e6493b86ac51b8f41cd543d60d3 100644 --- a/gso/products/product_types/iptrunk.py +++ b/gso/products/product_types/iptrunk.py @@ -3,11 +3,7 @@ from orchestrator.domain.base import SubscriptionModel from orchestrator.types import SubscriptionLifecycle -from gso.products.product_blocks.iptrunk import ( - IptrunkBlock, - IptrunkBlockInactive, - IptrunkBlockProvisioning, -) +from gso.products.product_blocks.iptrunk import IptrunkBlock, IptrunkBlockInactive, IptrunkBlockProvisioning class IptrunkInactive(SubscriptionModel, is_base=True): diff --git a/gso/products/product_types/router.py b/gso/products/product_types/router.py index d6a59c12ccd14dea0dac8852a7748810359718b7..c53ecef0878ca6a78cd3838947731cdfc287655f 100644 --- a/gso/products/product_types/router.py +++ b/gso/products/product_types/router.py @@ -3,11 +3,7 @@ from orchestrator.domain.base import SubscriptionModel from orchestrator.types import SubscriptionLifecycle -from gso.products.product_blocks.router import ( - RouterBlock, - RouterBlockInactive, - RouterBlockProvisioning, -) +from gso.products.product_blocks.router import RouterBlock, RouterBlockInactive, RouterBlockProvisioning class RouterInactive(SubscriptionModel, is_base=True): diff --git a/gso/products/product_types/site.py b/gso/products/product_types/site.py index ec09962e33521d82bd5c05b6fa3bccd6dbb6e8bf..308063a99f6b3c5970d78482d27f3ebf30702bea 100644 --- a/gso/products/product_types/site.py +++ b/gso/products/product_types/site.py @@ -3,11 +3,7 @@ from orchestrator.domain.base import SubscriptionModel from orchestrator.types import SubscriptionLifecycle -from gso.products.product_blocks.site import ( - SiteBlock, - SiteBlockInactive, - SiteBlockProvisioning, -) +from gso.products.product_blocks.site import SiteBlock, SiteBlockInactive, SiteBlockProvisioning class SiteInactive(SubscriptionModel, is_base=True): diff --git a/gso/schedules/scheduling.py b/gso/schedules/scheduling.py index d7044351b1493b154961eaa67c421a98290cff10..1551cfc82bd38632d18523963af5753f8529cc52 100644 --- a/gso/schedules/scheduling.py +++ b/gso/schedules/scheduling.py @@ -1,9 +1,8 @@ """Definition of the decorator that allows for scheduling tasks in :term:`GSO` that are to run periodically.""" import inspect -from collections.abc import Callable from functools import wraps -from typing import Any +from typing import Any, Callable from celery import current_app from celery.schedules import crontab @@ -38,8 +37,7 @@ def scheduler( module = inspect.getmodule(task_func) if module is None: - msg = f"Module for the task function {task_func.__name__} could not be found." - raise ValueError(msg) + raise ValueError(f"Module for the task function {task_func.__name__} could not be found.") task_path = f"{module.__name__}.{task_func.__name__}" current_app.conf.beat_schedule[task_func.__name__] = { diff --git a/gso/services/crm.py b/gso/services/crm.py index e656d6cdaa5690035a847b899fb61578ae0c607d..6584cdb947418002bb3a621f6b9756d7ff156f24 100644 --- a/gso/services/crm.py +++ b/gso/services/crm.py @@ -11,6 +11,8 @@ from pydantic_forms.validators import Choice class CustomerNotFoundError(Exception): """Exception raised when a customer is not found.""" + pass + def all_customers() -> list[dict]: """Hardcoded list of customers available in :term:`GSO`.""" @@ -28,8 +30,7 @@ def get_customer_by_name(name: str) -> dict[str, Any]: if customer["name"] == name: return customer - msg = f"Customer {name} not found" - raise CustomerNotFoundError(msg) + raise CustomerNotFoundError(f"Customer {name} not found") def customer_selector() -> Choice: @@ -38,4 +39,4 @@ def customer_selector() -> Choice: for customer in all_customers(): customers[customer["id"]] = customer["name"] - return Choice("Select a customer", zip(customers.keys(), customers.items(), strict=True)) # type: ignore[arg-type] + return Choice("Select a customer", zip(customers.keys(), customers.items())) # type: ignore[arg-type] diff --git a/gso/services/infoblox.py b/gso/services/infoblox.py index 1dbc29ebdc2eb14f44f635711f1c58f50e998168..f53f2efa6e4cd54e9641c4849c6ddffec0115d4f 100644 --- a/gso/services/infoblox.py +++ b/gso/services/infoblox.py @@ -4,10 +4,7 @@ import ipaddress from logging import getLogger from infoblox_client import connector, objects -from infoblox_client.exceptions import ( - InfobloxCannotCreateObject, - InfobloxCannotUpdateObject, -) +from infoblox_client.exceptions import InfobloxCannotCreateObject, InfobloxCannotUpdateObject from gso.settings import IPAMParams, load_oss_params @@ -34,7 +31,7 @@ def _setup_connection() -> tuple[connector.Connector, IPAMParams]: "username": oss.INFOBLOX.username, "password": oss.INFOBLOX.password, "wapi_version": oss.INFOBLOX.wapi_version, - "ssl_verify": oss.INFOBLOX.scheme == "https", + "ssl_verify": True if oss.INFOBLOX.scheme == "https" else False, } return connector.Connector(options), oss @@ -72,8 +69,7 @@ def _allocate_network( msg = f"IP container {container} appears to be full." logger.warning(msg) - msg = f"Cannot allocate anything in {containers}, check whether any IP space is available." - raise AllocationError(msg) + raise AllocationError(f"Cannot allocate anything in {containers}, check whether any IP space is available.") def hostname_available(hostname: str) -> bool: @@ -130,9 +126,7 @@ def allocate_v6_network(service_type: str, comment: str | None = "") -> ipaddres return ipaddress.IPv6Network(_allocate_network(conn, dns_view, netmask, containers, comment)) -def find_network_by_cidr( - ip_network: ipaddress.IPv4Network | ipaddress.IPv6Network, -) -> objects.Network | None: +def find_network_by_cidr(ip_network: ipaddress.IPv4Network | ipaddress.IPv6Network) -> objects.Network | None: """Find a network in Infoblox by its :term:`CIDR`. :param ip_network: The :term:`CIDR` that is searched. @@ -155,15 +149,11 @@ def delete_network(ip_network: ipaddress.IPv4Network | ipaddress.IPv6Network) -> if network: network.delete() else: - msg = f"Could not find network {ip_network}, nothing has been deleted." - raise DeletionError(msg) + raise DeletionError(f"Could not find network {ip_network}, nothing has been deleted.") def allocate_host( - hostname: str, - service_type: str, - cname_aliases: list[str], - comment: str, + hostname: str, service_type: str, cname_aliases: list[str], comment: str ) -> tuple[ipaddress.IPv4Address, ipaddress.IPv6Address]: """Allocate a new host record in Infoblox. @@ -183,8 +173,7 @@ def allocate_host( :type comment: str """ if not hostname_available(hostname): - msg = f"Cannot allocate new host, FQDN {hostname} already taken." - raise AllocationError(msg) + raise AllocationError(f"Cannot allocate new host, FQDN {hostname} already taken.") conn, oss = _setup_connection() allocation_networks_v4 = getattr(oss, service_type).V4.networks @@ -197,12 +186,7 @@ def allocate_host( ipv6_object = objects.IP.create(ip=v6_alloc, mac="00:00:00:00:00:00", configure_for_dhcp=False) try: new_host = objects.HostRecord.create( - conn, - ip=ipv6_object, - name=hostname, - aliases=cname_aliases, - comment=comment, - dns_view=dns_view, + conn, ip=ipv6_object, name=hostname, aliases=cname_aliases, comment=comment, dns_view=dns_view ) created_v6 = ipaddress.IPv6Address(new_host.ipv6addr) except InfobloxCannotCreateObject: @@ -210,8 +194,7 @@ def allocate_host( logger.warning(msg) if created_v6 is None: - msg = f"Cannot find 1 available IP address in networks {allocation_networks_v6}." - raise AllocationError(msg) + raise AllocationError(f"Cannot find 1 available IP address in networks {allocation_networks_v6}.") created_v4 = None for ipv4_range in allocation_networks_v4: @@ -228,15 +211,12 @@ def allocate_host( logger.warning(msg) if created_v4 is None: - msg = f"Cannot find 1 available IP address in networks {allocation_networks_v4}." - raise AllocationError(msg) + raise AllocationError(f"Cannot find 1 available IP address in networks {allocation_networks_v4}.") return created_v4, created_v6 -def find_host_by_ip( - ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address, -) -> objects.HostRecord | None: +def find_host_by_ip(ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address) -> objects.HostRecord | None: """Find a host record in Infoblox by its associated IP address. :param ip_addr: The IP address of a host that is searched for. @@ -245,14 +225,10 @@ def find_host_by_ip( conn, _ = _setup_connection() if ip_addr.version == 4: # noqa: PLR2004, the 4 in IPv4 is well-known and not a "magic value." return objects.HostRecord.search( - conn, - ipv4addr=ip_addr, - return_fields=["ipv4addrs", "name", "view", "aliases", "comment"], + conn, ipv4addr=ip_addr, return_fields=["ipv4addrs", "name", "view", "aliases", "comment"] ) return objects.HostRecord.search( - conn, - ipv6addr=ip_addr, - return_fields=["ipv6addrs", "name", "view", "aliases", "comment"], + conn, ipv6addr=ip_addr, return_fields=["ipv6addrs", "name", "view", "aliases", "comment"] ) @@ -263,11 +239,7 @@ def find_host_by_fqdn(fqdn: str) -> objects.HostRecord | None: :type fqdn: str """ conn, _ = _setup_connection() - return objects.HostRecord.search( - conn, - name=fqdn, - return_fields=["ipv4addrs", "name", "view", "aliases", "comment"], - ) + return objects.HostRecord.search(conn, name=fqdn, return_fields=["ipv4addrs", "name", "view", "aliases", "comment"]) def delete_host_by_ip(ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address) -> None: @@ -283,8 +255,7 @@ def delete_host_by_ip(ip_addr: ipaddress.IPv4Address | ipaddress.IPv6Address) -> if host: host.delete() else: - msg = f"Could not find host at {ip_addr}, nothing has been deleted." - raise DeletionError(msg) + raise DeletionError(f"Could not find host at {ip_addr}, nothing has been deleted.") def delete_host_by_fqdn(fqdn: str) -> None: @@ -300,5 +271,4 @@ def delete_host_by_fqdn(fqdn: str) -> None: if host: host.delete() else: - msg = f"Could not find host at {fqdn}, nothing has been deleted." - raise DeletionError(msg) + raise DeletionError(f"Could not find host at {fqdn}, nothing has been deleted.") diff --git a/gso/services/netbox_client.py b/gso/services/netbox_client.py index e8e2bdf4605e14fac01cdba2dd96c030d08446c8..cfc035fc982369b2a814e1e529842824a88c4469 100644 --- a/gso/services/netbox_client.py +++ b/gso/services/netbox_client.py @@ -9,12 +9,7 @@ from pynetbox.models.dcim import Devices, DeviceTypes, Interfaces from gso.products.product_types.router import Router from gso.settings import load_oss_params -from gso.utils.device_info import ( - DEFAULT_SITE, - FEASIBLE_IP_TRUNK_LAG_RANGE, - ROUTER_ROLE, - TierInfo, -) +from gso.utils.device_info import DEFAULT_SITE, FEASIBLE_IP_TRUNK_LAG_RANGE, ROUTER_ROLE, TierInfo from gso.utils.exceptions import NotFoundError, WorkflowStateError @@ -64,20 +59,17 @@ class NetboxClient: def get_allocated_interfaces_by_gso_subscription(self, device_name: str, subscription_id: UUID) -> list[Interfaces]: """Return all allocated interfaces of a device by name.""" + device = self.get_device_by_name(device_name) return self.netbox.dcim.interfaces.filter( - device_id=device.id, - enabled=True, - mark_connected=True, - description=subscription_id, + device_id=device.id, enabled=True, mark_connected=True, description=subscription_id ) def get_device_by_name(self, device_name: str) -> Devices: """Return the device object by name from netbox, or raise not found.""" device = self.netbox.dcim.devices.get(name=device_name) if device is None: - msg = f"Device: {device_name} not found." - raise NotFoundError(msg) + raise NotFoundError(f"Device: {device_name} not found.") return device def get_interface_by_name_and_device(self, iface_name: str, device_name: str) -> Interfaces: @@ -85,15 +77,14 @@ class NetboxClient: device = self.get_device_by_name(device_name) interface = self.netbox.dcim.interfaces.get(device_id=device.id, name=iface_name) if interface is None: - msg = f"Interface: {iface_name} on device with id: {device.id} not found." - raise NotFoundError(msg) + raise NotFoundError(f"Interface: {iface_name} on device with id: {device.id} not found.") return interface def get_interfaces_by_device(self, device_name: str, speed: str) -> list[Interfaces]: """Get all interfaces of a device by name and speed that are not reserved and not allocated.""" device = self.get_device_by_name(device_name) return list( - self.netbox.dcim.interfaces.filter(device_id=device.id, enabled=False, mark_connected=False, speed=speed), + self.netbox.dcim.interfaces.filter(device_id=device.id, enabled=False, mark_connected=False, speed=speed) ) def create_interface( @@ -124,11 +115,13 @@ class NetboxClient: def delete_interface(self, device_name: str, iface_name: str) -> None: """Delete an interface from a device by name.""" + interface = self.get_interface_by_name_and_device(iface_name, device_name) return interface.delete() def create_device_type(self, manufacturer: str, model: str, slug: str) -> DeviceTypes: """Create a new device type in Netbox.""" + # First get manufacturer id manufacturer_id = int(self.netbox.dcim.manufacturers.get(name=manufacturer).id) device_type = DeviceType(manufacturer=manufacturer_id, model=model, slug=slug) @@ -152,6 +145,7 @@ class NetboxClient: @staticmethod def calculate_interface_speed(interface: Interfaces) -> int | None: """Calculate the interface speed in bits per second.""" + type_parts = interface.type.value.split("-") if "gbase" in type_parts[0]: return int("".join(filter(str.isdigit, type_parts[0]))) * 1000000 @@ -159,6 +153,7 @@ class NetboxClient: def create_device(self, device_name: str, site_tier: str) -> Devices: """Create a new device in Netbox.""" + # Get device type id tier_info = TierInfo().get_module_by_name(f"Tier{site_tier}") device_type = self.netbox.dcim.device_types.get(model=tier_info.device_type) @@ -171,10 +166,7 @@ class NetboxClient: # Create new device device = self.netbox.dcim.devices.create( - name=device_name, - device_type=device_type.id, - role=device_role.id, - site=device_site.id, + name=device_name, device_type=device_type.id, role=device_role.id, site=device_site.id ) module_bays = list(self.netbox.dcim.module_bays.filter(device_id=device.id)) card_type = self.netbox.dcim.module_types.get(model=tier_info.module_type) @@ -201,11 +193,7 @@ class NetboxClient: self.netbox.dcim.devices.get(name=device_name).delete() def attach_interface_to_lag( - self, - device_name: str, - lag_name: str, - iface_name: str, - description: str | None = None, + self, device_name: str, lag_name: str, iface_name: str, description: str | None = None ) -> Interfaces: """Assign a given interface to a :term:`LAG`. @@ -218,9 +206,8 @@ class NetboxClient: # Assign interface to LAG, ensuring it doesn't already belong to a LAG if iface.lag: - msg = f"The interface: {iface_name} on device: {device_name} already belongs to a LAG: {iface.lag.name}." raise WorkflowStateError( - msg, + f"The interface: {iface_name} on device: {device_name} already belongs to a LAG: {iface.lag.name}." ) iface.lag = lag.id @@ -233,13 +220,13 @@ class NetboxClient: def reserve_interface(self, device_name: str, iface_name: str) -> Interfaces: """Reserve an interface by enabling it.""" + # First get interface from device interface = self.get_interface_by_name_and_device(iface_name, device_name) # Check if interface is reserved if interface.enabled: - msg = f"The interface: {iface_name} on device: {device_name} is already reserved." - raise WorkflowStateError(msg) + raise WorkflowStateError(f"The interface: {iface_name} on device: {device_name} is already reserved.") # Reserve interface by enabling it interface.enabled = True @@ -249,13 +236,13 @@ class NetboxClient: def allocate_interface(self, device_name: str, iface_name: str) -> Interfaces: """Allocate an interface by marking it as connected.""" + # First get interface from device interface = self.get_interface_by_name_and_device(iface_name, device_name) # Check if interface is reserved if interface.mark_connected: - msg = f"The interface: {iface_name} on device: {device_name} is already allocated." - raise WorkflowStateError(msg) + raise WorkflowStateError(f"The interface: {iface_name} on device: {device_name} is already allocated.") # Allocate interface by marking it as connected interface.mark_connected = True @@ -265,6 +252,7 @@ class NetboxClient: def free_interface(self, device_name: str, iface_name: str) -> Interfaces: """Free interface by marking disconnect and disable it.""" + # First get interface from device interface = self.get_interface_by_name_and_device(iface_name, device_name) interface.mark_connected = False @@ -279,16 +267,15 @@ class NetboxClient: device = self.get_device_by_name(device_name) lag = self.netbox.dcim.interfaces.get(device_id=device.id, name=lag_name) for interface in self.netbox.dcim.interfaces.filter( - device_id=device.id, - lag_id=lag.id, - enabled=False, - mark_connected=False, + device_id=device.id, lag_id=lag.id, enabled=False, mark_connected=False ): interface.lag = None interface.save() + return def get_available_lags(self, router_id: UUID) -> list[str]: """Return all available :term:`LAG`s not assigned to a device.""" + router_name = Router.from_subscription(router_id).router.router_fqdn device = self.get_device_by_name(router_name) @@ -306,18 +293,17 @@ class NetboxClient: @staticmethod def calculate_speed_bits_per_sec(speed: str) -> int: """Extract the numeric part from the speed.""" + numeric_part = int("".join(filter(str.isdigit, speed))) # Convert to bits per second return numeric_part * 1000000 def get_available_interfaces(self, router_id: UUID | UUIDstr, speed: str) -> Interfaces: """Return all available interfaces of a device filtered by speed.""" + router = Router.from_subscription(router_id).router.router_fqdn device = self.get_device_by_name(router) speed_bps = self.calculate_speed_bits_per_sec(speed) return self.netbox.dcim.interfaces.filter( - device=device.name, - enabled=False, - mark_connected=False, - speed=speed_bps, + device=device.name, enabled=False, mark_connected=False, speed=speed_bps ) diff --git a/gso/services/provisioning_proxy.py b/gso/services/provisioning_proxy.py index 51e942abd88b3bf99728323305cb41bd97ba8037..48f75db64bcc851996f613346c3901ad482fc103 100644 --- a/gso/services/provisioning_proxy.py +++ b/gso/services/provisioning_proxy.py @@ -54,6 +54,7 @@ def _send_request(operation: CUDOperation, endpoint: str, parameters: dict, call """ oss = settings.load_oss_params() pp_params = oss.PROVISIONING_PROXY + assert pp_params # Build up a callback URL of the Provisioning Proxy to return its results to. callback_url = f"{oss.GENERAL.public_hostname}{callback_route}" @@ -157,11 +158,7 @@ def provision_ip_trunk( def check_ip_trunk( - subscription: IptrunkProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - check_name: str, + subscription: IptrunkProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str, check_name: str ) -> None: """Provision an IP trunk service using :term:`LSO`. @@ -316,10 +313,6 @@ def pp_interaction(provisioning_step: Step) -> StepList: """ return ( begin - >> callback_step( - name=provisioning_step.name, - action_step=provisioning_step, - validate_step=_evaluate_pp_results, - ) + >> callback_step(name=provisioning_step.name, action_step=provisioning_step, validate_step=_evaluate_pp_results) >> _show_pp_results ) diff --git a/gso/services/subscriptions.py b/gso/services/subscriptions.py index 8198c7c586869d6ecc203aaf0ea58173e9eab1a2..7cf3af3d2b866b66fce3553d7e22d9197ac14495 100644 --- a/gso/services/subscriptions.py +++ b/gso/services/subscriptions.py @@ -54,12 +54,10 @@ def get_active_subscriptions( results = query.with_entities(*dynamic_fields).all() - return [dict(zip(includes, result, strict=True)) for result in results] + return [dict(zip(includes, result)) for result in results] -def get_active_site_subscriptions( - includes: list[str] | None = None, -) -> list[SubscriptionType]: +def get_active_site_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]: """Retrieve active subscriptions specifically for sites. :param includes: The fields to be included in the returned Subscription objects. @@ -71,9 +69,7 @@ def get_active_site_subscriptions( return get_active_subscriptions(product_type=ProductType.SITE, includes=includes) -def get_active_router_subscriptions( - includes: list[str] | None = None, -) -> list[SubscriptionType]: +def get_active_router_subscriptions(includes: list[str] | None = None) -> list[SubscriptionType]: """Retrieve active subscriptions specifically for routers. :param includes: The fields to be included in the returned Subscription objects. @@ -130,8 +126,7 @@ def count_incomplete_validate_products() -> int: The count of incomplete 'validate_products' processes. """ return ProcessTable.query.filter( - ProcessTable.workflow_name == "validate_products", - ProcessTable.last_status != "completed", + ProcessTable.workflow_name == "validate_products", ProcessTable.last_status != "completed" ).count() diff --git a/gso/utils/exceptions.py b/gso/utils/exceptions.py index 66ce6d9e7f70679a7f813f5f7f24d8ec0c53fa31..480e938445390a2358a283a43f11c9c992a481e1 100644 --- a/gso/utils/exceptions.py +++ b/gso/utils/exceptions.py @@ -4,6 +4,10 @@ class NotFoundError(Exception): """Exception raised for not found search.""" + pass + class WorkflowStateError(Exception): """Exception raised on problems during workflow.""" + + pass diff --git a/gso/utils/helpers.py b/gso/utils/helpers.py index 44cb8fe3eff1fa31037b39915af2617357bfb890..cf8783441fa2db904d4aedc27b9332f49247bc9c 100644 --- a/gso/utils/helpers.py +++ b/gso/utils/helpers.py @@ -69,13 +69,11 @@ def available_interfaces_choices(router_id: UUID, speed: str) -> Choice | None: interface["name"]: f"{interface['name']} - {interface['module']['display']} - {interface['description']}" for interface in NetboxClient().get_available_interfaces(router_id, speed) } - return Choice("ae member", zip(interfaces.keys(), interfaces.items(), strict=True)) # type: ignore[arg-type] + return Choice("ae member", zip(interfaces.keys(), interfaces.items())) # type: ignore[arg-type] def available_interfaces_choices_including_current_members( - router_id: UUID | UUIDstr, - speed: str, - interfaces: list[IptrunkInterfaceBlock], + router_id: UUID | UUIDstr, speed: str, interfaces: list[IptrunkInterfaceBlock] ) -> Choice | None: """Return a list of available interfaces for a given router and speed including the current members. @@ -89,17 +87,16 @@ def available_interfaces_choices_including_current_members( available_interfaces.extend( [ NetboxClient().get_interface_by_name_and_device( - interface.interface_name, - Router.from_subscription(router_id).router.router_fqdn, + interface.interface_name, Router.from_subscription(router_id).router.router_fqdn ) for interface in interfaces - ], + ] ) options = { interface["name"]: f"{interface['name']} - {interface['module']['display']} - {interface['description']}" for interface in available_interfaces } - return Choice("ae member", zip(options.keys(), options.items(), strict=True)) # type: ignore[arg-type] + return Choice("ae member", zip(options.keys(), options.items())) # type: ignore[arg-type] def available_lags_choices(router_id: UUID) -> Choice | None: @@ -108,10 +105,11 @@ def available_lags_choices(router_id: UUID) -> Choice | None: For Nokia routers, return a list of available lags. For Juniper routers, return a string. """ + if Router.from_subscription(router_id).router.router_vendor != RouterVendor.NOKIA: return None side_a_ae_iface_list = NetboxClient().get_available_lags(router_id) - return Choice("ae iface", zip(side_a_ae_iface_list, side_a_ae_iface_list, strict=True)) # type: ignore[arg-type] + return Choice("ae iface", zip(side_a_ae_iface_list, side_a_ae_iface_list)) # type: ignore[arg-type] def get_router_vendor(router_id: UUID) -> str: @@ -137,7 +135,7 @@ def iso_from_ipv4(ipv4_address: IPv4Address) -> str: padded_octets = [f"{x:>03}" for x in str(ipv4_address).split(".")] joined_octets = "".join(padded_octets) re_split = ".".join(re.findall("....", joined_octets)) - return f"49.51e5.0001.{re_split}.00" + return ".".join(["49.51e5.0001", re_split, "00"]) def validate_router_in_netbox(subscription_id: UUIDstr) -> UUIDstr | None: @@ -155,8 +153,7 @@ def validate_router_in_netbox(subscription_id: UUIDstr) -> UUIDstr | None: if router.router_vendor == RouterVendor.NOKIA: device = NetboxClient().get_device_by_name(router.router_fqdn) if not device: - msg = "The selected router does not exist in Netbox." - raise ValueError(msg) + raise ValueError("The selected router does not exist in Netbox.") return subscription_id @@ -173,16 +170,14 @@ def validate_iptrunk_unique_interface(interfaces: list[LAGMember]) -> list[LAGMe """ interface_names = [member.interface_name for member in interfaces] if len(interface_names) != len(set(interface_names)): - msg = "Interfaces must be unique." - raise ValueError(msg) + raise ValueError("Interfaces must be unique.") return interfaces def validate_site_fields_is_unique(field_name: str, value: str | int) -> str | int: """Validate that a site field is unique.""" if len(get_active_subscriptions_by_field_and_value(field_name, str(value))) > 0: - msg = f"{field_name} must be unique" - raise ValueError(msg) + raise ValueError(f"{field_name} must be unique") return value diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index a0a5af27121c2f0b4ea8385b1d6abc34a09dc891..a6afce096ced5b82eadeaab4ecc051b0bbc8eb7c 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -12,11 +12,7 @@ from orchestrator.workflows.utils import wrap_create_initial_input_form from pydantic import validator from pynetbox.models.dcim import Interfaces -from gso.products.product_blocks.iptrunk import ( - IptrunkInterfaceBlockInactive, - IptrunkType, - PhyPortCapacity, -) +from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlockInactive, IptrunkType, PhyPortCapacity from gso.products.product_blocks.router import RouterVendor from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvisioning from gso.products.product_types.router import Router @@ -58,7 +54,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: initial_user_input = yield CreateIptrunkForm - router_enum_a = Choice("Select a router", zip(routers.keys(), routers.items(), strict=True)) # type: ignore[arg-type] + router_enum_a = Choice("Select a router", zip(routers.keys(), routers.items())) # type: ignore[arg-type] class SelectRouterSideA(FormPage): class Config: @@ -80,8 +76,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: class NokiaLAGMemberA(LAGMember): interface_name: available_interfaces_choices( # type: ignore[valid-type] - router_a, - initial_user_input.iptrunk_speed, + router_a, initial_user_input.iptrunk_speed ) class NokiaAeMembersA(UniqueConstrainedList[NokiaLAGMemberA]): @@ -106,7 +101,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: user_input_side_a = yield CreateIptrunkSideAForm # Remove the selected router for side A, to prevent any loops routers.pop(str(router_a)) - router_enum_b = Choice("Select a router", zip(routers.keys(), routers.items(), strict=True)) # type: ignore[arg-type] + router_enum_b = Choice("Select a router", zip(routers.keys(), routers.items())) # type: ignore[arg-type] class SelectRouterSideB(FormPage): class Config: @@ -125,8 +120,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: class NokiaLAGMemberB(LAGMember): interface_name: available_interfaces_choices( # type: ignore[valid-type] - router_b, - initial_user_input.iptrunk_speed, + router_b, initial_user_input.iptrunk_speed ) class NokiaAeMembersB(UniqueConstrainedList): @@ -176,12 +170,10 @@ def create_subscription(product: UUIDstr, customer: UUIDstr) -> State: def get_info_from_ipam(subscription: IptrunkProvisioning) -> State: """Allocate IP resources in :term:`IPAM`.""" subscription.iptrunk.iptrunk_ipv4_network = infoblox.allocate_v4_network( - "TRUNK", - subscription.iptrunk.iptrunk_description, + "TRUNK", subscription.iptrunk.iptrunk_description ) subscription.iptrunk.iptrunk_ipv6_network = infoblox.allocate_v6_network( - "TRUNK", - subscription.iptrunk.iptrunk_description, + "TRUNK", subscription.iptrunk.iptrunk_description ) return {"subscription": subscription} @@ -217,7 +209,7 @@ def initialize_subscription( subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_geant_a_sid = side_a_ae_geant_a_sid for member in side_a_ae_members: subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members.append( - IptrunkInterfaceBlockInactive.new(subscription_id=uuid4(), **member), + IptrunkInterfaceBlockInactive.new(subscription_id=uuid4(), **member) ) subscription.iptrunk.iptrunk_sides[1].iptrunk_side_node = Router.from_subscription(side_b_node_id).router @@ -225,7 +217,7 @@ def initialize_subscription( subscription.iptrunk.iptrunk_sides[1].iptrunk_side_ae_geant_a_sid = side_b_ae_geant_a_sid for member in side_b_ae_members: subscription.iptrunk.iptrunk_sides[1].iptrunk_side_ae_members.append( - IptrunkInterfaceBlockInactive.new(subscription_id=uuid4(), **member), + IptrunkInterfaceBlockInactive.new(subscription_id=uuid4(), **member) ) subscription.description = f"IP trunk, geant_s_sid:{geant_s_sid}" @@ -236,10 +228,7 @@ def initialize_subscription( @step("Provision IP trunk interface [DRY RUN]") def provision_ip_trunk_iface_dry( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Perform a dry run of deploying configuration on both sides of the trunk.""" provisioning_proxy.provision_ip_trunk( @@ -256,10 +245,7 @@ def provision_ip_trunk_iface_dry( @step("Provision IP trunk interface [FOR REAL]") def provision_ip_trunk_iface_real( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Deploy IP trunk configuration on both sides.""" provisioning_proxy.provision_ip_trunk( @@ -276,10 +262,7 @@ def provision_ip_trunk_iface_real( @step("Check IP connectivity of the trunk") def check_ip_trunk_connectivity( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Check successful connectivity across the new trunk.""" provisioning_proxy.check_ip_trunk(subscription, process_id, callback_route, tt_number, "ping") @@ -289,10 +272,7 @@ def check_ip_trunk_connectivity( @step("Provision IP trunk ISIS interface [DRY RUN]") def provision_ip_trunk_isis_iface_dry( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Perform a dry run of deploying :term:`ISIS` configuration.""" provisioning_proxy.provision_ip_trunk(subscription, process_id, callback_route, tt_number, "isis_interface") @@ -302,10 +282,7 @@ def provision_ip_trunk_isis_iface_dry( @step("Provision IP trunk ISIS interface [FOR REAL]") def provision_ip_trunk_isis_iface_real( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Deploy :term:`ISIS` configuration on both sides.""" provisioning_proxy.provision_ip_trunk( @@ -322,10 +299,7 @@ def provision_ip_trunk_isis_iface_real( @step("Check ISIS adjacency") def check_ip_trunk_isis( - subscription: IptrunkProvisioning, - callback_route: str, - process_id: UUIDstr, - tt_number: str, + subscription: IptrunkProvisioning, callback_route: str, process_id: UUIDstr, tt_number: str ) -> State: """Run an Ansible playbook to confirm :term:`ISIS` adjacency.""" provisioning_proxy.check_ip_trunk(subscription, process_id, callback_route, tt_number, "isis") @@ -336,6 +310,7 @@ def check_ip_trunk_isis( @step("NextBox integration") def reserve_interfaces_in_netbox(subscription: IptrunkProvisioning) -> State: """Create the LAG interfaces in NetBox and attach the lag interfaces to the physical interfaces.""" + nbclient = NetboxClient() for trunk_side in subscription.iptrunk.iptrunk_sides: if trunk_side.iptrunk_side_node.router_vendor == RouterVendor.NOKIA: diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py index 383a8189a150097aa6c0a361997c2b31a50761a8..bb2d35f92749c13e317aa181a15b3862d781d699 100644 --- a/gso/workflows/iptrunk/migrate_iptrunk.py +++ b/gso/workflows/iptrunk/migrate_iptrunk.py @@ -57,7 +57,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: replaced_side_enum = Choice( "Select the side of the IP trunk to be replaced", - zip(sides_dict.keys(), sides_dict.items(), strict=True), # type: ignore[arg-type] + zip(sides_dict.keys(), sides_dict.items()), # type: ignore[arg-type] ) class IPTrunkMigrateForm(FormPage): @@ -88,7 +88,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: continue routers[str(router_id)] = router["description"] - new_router_enum = Choice("Select a new router", zip(routers.keys(), routers.items(), strict=True)) # type: ignore[arg-type] + new_router_enum = Choice("Select a new router", zip(routers.keys(), routers.items())) # type: ignore[arg-type] class NewSideIPTrunkRouterForm(FormPage): class Config: @@ -104,8 +104,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: class NokiaLAGMember(LAGMember): interface_name: available_interfaces_choices( # type: ignore[valid-type] - new_router, - subscription.iptrunk.iptrunk_speed, + new_router, subscription.iptrunk.iptrunk_speed ) class NokiaAeMembers(UniqueConstrainedList[NokiaLAGMember]): @@ -128,10 +127,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: else 1 ) existing_lag_ae_members = [ - { - "interface_name": iface.interface_name, - "interface_description": iface.interface_description, - } + {"interface_name": iface.interface_name, "interface_description": iface.interface_description} for iface in subscription.iptrunk.iptrunk_sides[replace_index].iptrunk_side_ae_members ] @@ -148,8 +144,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: if get_router_vendor(new_router) == RouterVendor.JUNIPER: juniper_lag_re = re.compile("^ae\\d{1,2}$") if not juniper_lag_re.match(new_lag_interface): - msg = "Invalid LAG name, please try again." - raise ValueError(msg) + raise ValueError("Invalid LAG name, please try again.") return new_lag_interface new_side_input = yield NewSideIPTrunkForm @@ -352,7 +347,9 @@ def confirm_continue_restore_isis() -> FormGenerator: class Config: title = "Please confirm before continuing" - info_label: Label = "ISIS config has been deployed, confirm if you want to restore the old metric." # type: ignore[assignment] + info_label: Label = ( + "ISIS config has been deployed, confirm if you want to restore the old metric." # type: ignore[assignment] + ) yield ProvisioningResultPage @@ -361,11 +358,7 @@ def confirm_continue_restore_isis() -> FormGenerator: @step("Restore ISIS metric to original value") def restore_isis_metric( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - old_isis_metric: int, + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str, old_isis_metric: int ) -> State: """Restore the :term:`ISIS` metric to its original value.""" subscription.iptrunk.iptrunk_isis_metric = old_isis_metric @@ -479,7 +472,7 @@ def update_subscription_model( # And update the list to only include the new member interfaces for member in new_lag_member_interfaces: subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members.append( - IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member), + IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member) ) return {"subscription": subscription, "old_side_data": old_side_data} @@ -539,15 +532,11 @@ def update_netbox( if old_side_data["iptrunk_side_node"]["router_vendor"] == RouterVendor.NOKIA: # Set interfaces to free for iface in old_side_data["iptrunk_side_ae_members"]: - nbclient.free_interface( - old_side_data["iptrunk_side_node"]["router_fqdn"], - iface["interface_name"], - ) + nbclient.free_interface(old_side_data["iptrunk_side_node"]["router_fqdn"], iface["interface_name"]) # Delete LAG interfaces nbclient.delete_interface( - old_side_data["iptrunk_side_node"]["router_fqdn"], - old_side_data["iptrunk_side_ae_iface"], + old_side_data["iptrunk_side_node"]["router_fqdn"], old_side_data["iptrunk_side_ae_iface"] ) return {"subscription": subscription} diff --git a/gso/workflows/iptrunk/modify_isis_metric.py b/gso/workflows/iptrunk/modify_isis_metric.py index 3ae91edf1b94b5705560947616a8812afe548dc2..61843f6af3e3d96424d51e74143fa1753aa6f54d 100644 --- a/gso/workflows/iptrunk/modify_isis_metric.py +++ b/gso/workflows/iptrunk/modify_isis_metric.py @@ -35,10 +35,7 @@ def modify_iptrunk_subscription(subscription: Iptrunk, isis_metric: int) -> Stat @step("Provision IP trunk ISIS interface [DRY RUN]") def provision_ip_trunk_isis_iface_dry( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str ) -> State: """Perform a dry run of deploying the new :term:`ISIS` metric on both sides of the trunk.""" provisioning_proxy.provision_ip_trunk(subscription, process_id, callback_route, tt_number, "isis_interface") @@ -48,10 +45,7 @@ def provision_ip_trunk_isis_iface_dry( @step("Provision IP trunk ISIS interface [FOR REAL]") def provision_ip_trunk_isis_iface_real( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str ) -> State: """Deploy the new :term:`ISIS` metric on both sides of the trunk.""" provisioning_proxy.provision_ip_trunk( diff --git a/gso/workflows/iptrunk/modify_trunk_interface.py b/gso/workflows/iptrunk/modify_trunk_interface.py index 3c3e5662d7e73ed758c332c3f9c8e9b3ea38326d..813e9466f5426a56e75a3399a1a28bb198dcd728 100644 --- a/gso/workflows/iptrunk/modify_trunk_interface.py +++ b/gso/workflows/iptrunk/modify_trunk_interface.py @@ -1,6 +1,7 @@ """A modification workflow that updates the :term:`LAG` interfaces that are part of an existing IP trunk.""" import ipaddress +from typing import List, Type from uuid import uuid4 from orchestrator.forms import FormPage, ReadOnlyField @@ -13,11 +14,7 @@ from orchestrator.workflows.utils import wrap_modify_initial_input_form from pydantic import validator from pydantic_forms.validators import Label -from gso.products.product_blocks.iptrunk import ( - IptrunkInterfaceBlock, - IptrunkType, - PhyPortCapacity, -) +from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock, IptrunkType, PhyPortCapacity from gso.products.product_blocks.router import RouterVendor from gso.products.product_types.iptrunk import Iptrunk from gso.services import provisioning_proxy @@ -31,7 +28,7 @@ from gso.utils.helpers import ( ) -def initialize_ae_members(subscription: Iptrunk, initial_user_input: dict, side_index: int) -> type[LAGMember]: +def initialize_ae_members(subscription: Iptrunk, initial_user_input: dict, side_index: int) -> Type[LAGMember]: """Initialize the list of AE members.""" router = subscription.iptrunk.iptrunk_sides[side_index].iptrunk_side_node iptrunk_minimum_link = initial_user_input["iptrunk_minimum_links"] @@ -150,10 +147,7 @@ def modify_iptrunk_subscription( removed_ae_members = {} for side_index in range(2): previous_ae_members[side_index] = [ - { - "interface_name": member.interface_name, - "interface_description": member.interface_description, - } + {"interface_name": member.interface_name, "interface_description": member.interface_description} for member in subscription.iptrunk.iptrunk_sides[side_index].iptrunk_side_ae_members ] for side_index in range(2): @@ -174,14 +168,14 @@ def modify_iptrunk_subscription( # And update the list to only include the new member interfaces for member in side_a_ae_members: subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members.append( - IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member), + IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member) ) subscription.iptrunk.iptrunk_sides[1].iptrunk_side_ae_geant_a_sid = side_b_ae_geant_a_sid subscription.iptrunk.iptrunk_sides[1].iptrunk_side_ae_members.clear() for member in side_b_ae_members: subscription.iptrunk.iptrunk_sides[1].iptrunk_side_ae_members.append( - IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member), + IptrunkInterfaceBlock.new(subscription_id=uuid4(), **member) ) subscription.description = f"IP trunk, geant_s_sid:{geant_s_sid}" @@ -195,11 +189,7 @@ def modify_iptrunk_subscription( @step("Provision IP trunk interface [DRY RUN]") def provision_ip_trunk_iface_dry( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - removed_ae_members: list[str], + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str, removed_ae_members: List[str] ) -> State: """Perform a dry run of deploying the updated IP trunk.""" provisioning_proxy.provision_ip_trunk( @@ -217,11 +207,7 @@ def provision_ip_trunk_iface_dry( @step("Provision IP trunk interface [FOR REAL]") def provision_ip_trunk_iface_real( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, - removed_ae_members: list[str], + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str, removed_ae_members: List[str] ) -> State: """Provision the new IP trunk with updated interfaces.""" provisioning_proxy.provision_ip_trunk( @@ -241,7 +227,7 @@ def provision_ip_trunk_iface_real( def update_interfaces_in_netbox(subscription: Iptrunk, removed_ae_members: dict, previous_ae_members: dict) -> State: """Update Netbox such that it contains the new interfaces.""" nbclient = NetboxClient() - for side in range(2): + for side in range(0, 2): if subscription.iptrunk.iptrunk_sides[side].iptrunk_side_node.router_vendor == RouterVendor.NOKIA: lag_interface = subscription.iptrunk.iptrunk_sides[side].iptrunk_side_ae_iface router_name = subscription.iptrunk.iptrunk_sides[side].iptrunk_side_node.router_fqdn @@ -278,7 +264,8 @@ def allocate_interfaces_in_netbox(subscription: Iptrunk, previous_ae_members: di Attach the :term:`LAG` interfaces to the physical interfaces detach old ones from the :term:`LAG`. """ - for side in range(2): + + for side in range(0, 2): nbclient = NetboxClient() if subscription.iptrunk.iptrunk_sides[side].iptrunk_side_node.router_vendor == RouterVendor.NOKIA: for interface in subscription.iptrunk.iptrunk_sides[side].iptrunk_side_ae_members: diff --git a/gso/workflows/iptrunk/terminate_iptrunk.py b/gso/workflows/iptrunk/terminate_iptrunk.py index b4eb75cbaa0b72bc7c0d4f9ccec4f14386a943bd..60b4c955e3628c7431a1ae5d4f0a12356f99d602 100644 --- a/gso/workflows/iptrunk/terminate_iptrunk.py +++ b/gso/workflows/iptrunk/terminate_iptrunk.py @@ -7,12 +7,7 @@ from orchestrator.forms.validators import Label from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr from orchestrator.workflow import StepList, conditional, done, init, step, workflow -from orchestrator.workflows.steps import ( - resync, - set_status, - store_process_subscription, - unsync, -) +from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form from gso.products.product_blocks.router import RouterVendor @@ -41,10 +36,7 @@ def initial_input_form_generator() -> FormGenerator: @step("Drain traffic from trunk") def drain_traffic_from_ip_trunk( - subscription: Iptrunk, - process_id: UUIDstr, - callback_route: str, - tt_number: str, + subscription: Iptrunk, process_id: UUIDstr, callback_route: str, tt_number: str ) -> State: """Drain all traffic from the trunk. @@ -93,10 +85,7 @@ def free_interfaces_in_netbox(subscription: Iptrunk) -> State: for member in subscription.iptrunk.iptrunk_sides[side].iptrunk_side_ae_members: nbclient.free_interface(router_fqdn, member.interface_name) # Delete LAGs - nbclient.delete_interface( - router_fqdn, - subscription.iptrunk.iptrunk_sides[side].iptrunk_side_ae_iface, - ) + nbclient.delete_interface(router_fqdn, subscription.iptrunk.iptrunk_sides[side].iptrunk_side_ae_iface) return {"subscription": subscription} diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py index 1ec7f8222cc59c6417b747c7bbfaf69cde398408..e703820d65b4b676cff8e5870a5fece38cfdaff3 100644 --- a/gso/workflows/router/create_router.py +++ b/gso/workflows/router/create_router.py @@ -13,12 +13,7 @@ from orchestrator.workflows.steps import resync, set_status, store_process_subsc from orchestrator.workflows.utils import wrap_create_initial_input_form from pydantic import validator -from gso.products.product_blocks.router import ( - PortNumber, - RouterRole, - RouterVendor, - generate_fqdn, -) +from gso.products.product_blocks.router import PortNumber, RouterRole, RouterVendor, generate_fqdn from gso.products.product_types.router import RouterInactive, RouterProvisioning from gso.products.product_types.site import Site from gso.services import infoblox, provisioning_proxy, subscriptions @@ -34,7 +29,7 @@ def _site_selector() -> Choice: site_subscriptions[str(site["subscription_id"])] = site["description"] # noinspection PyTypeChecker - return Choice("Select a site", zip(site_subscriptions.keys(), site_subscriptions.items(), strict=True)) # type: ignore[arg-type] + return Choice("Select a site", zip(site_subscriptions.keys(), site_subscriptions.items())) # type: ignore[arg-type] def initial_input_form_generator(product_name: str) -> FormGenerator: @@ -57,14 +52,12 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: def hostname_must_be_available(cls, hostname: str, **kwargs: dict[str, Any]) -> str: router_site = kwargs["values"].get("router_site") if not router_site: - msg = "Please select a site before setting the hostname." - raise ValueError(msg) + raise ValueError("Please select a site before setting the hostname.") selected_site = Site.from_subscription(router_site).site input_fqdn = generate_fqdn(hostname, selected_site.site_name, selected_site.site_country_code) if not infoblox.hostname_available(f"lo0.{input_fqdn}"): - msg = f'FQDN "{input_fqdn}" is not available.' - raise ValueError(msg) + raise ValueError(f'FQDN "{input_fqdn}" is not available.') return hostname @@ -98,9 +91,7 @@ def initialize_subscription( subscription.router.router_vendor = router_vendor subscription.router.router_site = Site.from_subscription(router_site).site fqdn = generate_fqdn( - hostname, - subscription.router.router_site.site_name, - subscription.router.router_site.site_country_code, + hostname, subscription.router.router_site.site_name, subscription.router.router_site.site_country_code ) subscription.router.router_fqdn = fqdn subscription.router.router_role = router_role @@ -132,16 +123,13 @@ def ipam_allocate_ias_networks(subscription: RouterProvisioning) -> State: fqdn = subscription.router.router_fqdn subscription.router.router_si_ipv4_network = infoblox.allocate_v4_network( - "SI", - f"SI for {fqdn} - {subscription.subscription_id}", + "SI", f"SI for {fqdn} - {subscription.subscription_id}" ) subscription.router.router_ias_lt_ipv4_network = infoblox.allocate_v4_network( - "LT_IAS", - f"LT for {fqdn} - {subscription.subscription_id}", + "LT_IAS", f"LT for {fqdn} - {subscription.subscription_id}" ) subscription.router.router_ias_lt_ipv6_network = infoblox.allocate_v6_network( - "LT_IAS", - f"LT for {fqdn} - {subscription.subscription_id}", + "LT_IAS", f"LT for {fqdn} - {subscription.subscription_id}" ) return {"subscription": subscription} @@ -149,10 +137,7 @@ def ipam_allocate_ias_networks(subscription: RouterProvisioning) -> State: @step("Provision router [DRY RUN]") def provision_router_dry( - subscription: RouterProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, + subscription: RouterProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str ) -> State: """Perform a dry run of deploying configuration on the router.""" provisioning_proxy.provision_router(subscription, process_id, callback_route, tt_number) @@ -162,10 +147,7 @@ def provision_router_dry( @step("Provision router [FOR REAL]") def provision_router_real( - subscription: RouterProvisioning, - process_id: UUIDstr, - callback_route: str, - tt_number: str, + subscription: RouterProvisioning, process_id: UUIDstr, callback_route: str, tt_number: str ) -> State: """Deploy configuration on the router.""" provisioning_proxy.provision_router(subscription, process_id, callback_route, tt_number, dry_run=False) @@ -210,19 +192,19 @@ def verify_ipam_ias(subscription: RouterProvisioning) -> State: if not si_ipv4_network or str(subscription.subscription_id) not in si_ipv4_network.comment: new_state = { "ipam_si_warning": f"SI IPv4 network expected at {subscription.router.router_si_ipv4_network}, " - f"but it was not found or misconfigured, please investigate and adjust if necessary.", + f"but it was not found or misconfigured, please investigate and adjust if necessary." } if not ias_lt_ipv4_network or str(subscription.subscription_id) not in ias_lt_ipv4_network.comment: new_state = new_state | { "ipam_ias_lt_ipv4_warning": "IAS/LT IPv4 network expected at " f"{subscription.router.router_ias_lt_ipv4_network}, but it was not found or misconfigured, please " - "investigate and adjust if necessary.", + "investigate and adjust if necessary." } if not ias_lt_ipv6_network or str(subscription.subscription_id) not in ias_lt_ipv6_network.comment: new_state = new_state | { "ipam_ias_lt_ipv6_warning": f"IAS/LT IPv6 network expected at " f"{subscription.router.router_ias_lt_ipv6_network}, but it was not found or misconfigured, please " - "investigate and adjust if necessary.", + "investigate and adjust if necessary." } return new_state diff --git a/gso/workflows/router/terminate_router.py b/gso/workflows/router/terminate_router.py index e22823977c775937bc0fb45e740a75de9278ce42..f3d5ae72d7270989b687f9c8556ccb14c5a578f8 100644 --- a/gso/workflows/router/terminate_router.py +++ b/gso/workflows/router/terminate_router.py @@ -8,12 +8,7 @@ from orchestrator.forms.validators import Label from orchestrator.targets import Target from orchestrator.types import FormGenerator, SubscriptionLifecycle, UUIDstr from orchestrator.workflow import StepList, conditional, done, init, step, workflow -from orchestrator.workflows.steps import ( - resync, - set_status, - store_process_subscription, - unsync, -) +from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form from gso.products.product_blocks.router import RouterVendor diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py index ac4fbb7ed62dca473349fbe089ba637f2ddd4582..6226d16422f8af3a7f8c028e605be81615b30b4d 100644 --- a/gso/workflows/site/create_site.py +++ b/gso/workflows/site/create_site.py @@ -21,7 +21,7 @@ from gso.utils.helpers import ( ) -def initial_input_form_generator(product_name: str) -> FormGenerator: +def initial_input_form_generator(product_name: str) -> FormGenerator: # noqa: C901 """Get input from the operator about the new site subscription.""" class CreateSiteForm(FormPage): diff --git a/gso/workflows/site/modify_site.py b/gso/workflows/site/modify_site.py index 15b549dbbcf7f357b5aebc28b885a998a18d9daa..83e3a4e0af9a6e79ac7987ed5ab31f787dfbbe2d 100644 --- a/gso/workflows/site/modify_site.py +++ b/gso/workflows/site/modify_site.py @@ -4,12 +4,7 @@ from orchestrator.forms import FormPage from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr from orchestrator.workflow import StepList, done, init, step, workflow -from orchestrator.workflows.steps import ( - resync, - set_status, - store_process_subscription, - unsync, -) +from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form from pydantic import validator from pydantic.fields import ModelField diff --git a/gso/workflows/site/terminate_site.py b/gso/workflows/site/terminate_site.py index 91be194f181f13422cf349d7ca0f65826b3a6a2a..2543b3154b1f2846caed51ca001ae2b49473c7d4 100644 --- a/gso/workflows/site/terminate_site.py +++ b/gso/workflows/site/terminate_site.py @@ -5,12 +5,7 @@ from orchestrator.forms.validators import Label from orchestrator.targets import Target from orchestrator.types import FormGenerator, SubscriptionLifecycle, UUIDstr from orchestrator.workflow import StepList, done, init, workflow -from orchestrator.workflows.steps import ( - resync, - set_status, - store_process_subscription, - unsync, -) +from orchestrator.workflows.steps import resync, set_status, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form from gso.products.product_types.site import Site diff --git a/gso/workflows/tasks/import_iptrunk.py b/gso/workflows/tasks/import_iptrunk.py index ef2f20c7db8ba39b20973ae40c1e8b9a851e1d7a..4afb715b9d75a386cecbce8414d04386790d4f84 100644 --- a/gso/workflows/tasks/import_iptrunk.py +++ b/gso/workflows/tasks/import_iptrunk.py @@ -31,7 +31,7 @@ def _generate_routers() -> dict[str, str]: def initial_input_form_generator() -> FormGenerator: """Take all information passed to this workflow by the :term:`API` endpoint that was called.""" routers = _generate_routers() - router_enum = Choice("Select a router", zip(routers.keys(), routers.items(), strict=True)) # type: ignore[arg-type] + router_enum = Choice("Select a router", zip(routers.keys(), routers.items())) # type: ignore[arg-type] class CreateIptrunkForm(FormPage): class Config: diff --git a/gso/workflows/tasks/import_router.py b/gso/workflows/tasks/import_router.py index 7be387eb83f9163503c64bd614c8d0e64e621626..bde820b7aa2980c2f49c9e8209a4d595ab786c4c 100644 --- a/gso/workflows/tasks/import_router.py +++ b/gso/workflows/tasks/import_router.py @@ -29,8 +29,7 @@ def _get_site_by_name(site_name: str) -> Site: """ subscription = subscriptions.get_active_subscriptions_by_field_and_value("site_name", site_name)[0] if not subscription: - msg = f"Site with name {site_name} not found." - raise ValueError(msg) + raise ValueError(f"Site with name {site_name} not found.") return Site.from_subscription(subscription.subscription_id) diff --git a/gso/workflows/tasks/import_site.py b/gso/workflows/tasks/import_site.py index e0ea0cd7e8258c65241f705a4fa23e7e1d93bbbd..bd620e55a6a5b7440573fef400a3f120e5ff9f2f 100644 --- a/gso/workflows/tasks/import_site.py +++ b/gso/workflows/tasks/import_site.py @@ -62,6 +62,7 @@ def generate_initial_input_form() -> FormGenerator: ) def import_site() -> StepList: """Workflow to import a site without provisioning it.""" + return ( init >> create_subscription diff --git a/test/__init__.py b/test/__init__.py index 433e89b0fcb66b0730237cc78cded4048140751c..17c55014877312ca91ee846b5639eda4a36597eb 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -6,7 +6,7 @@ LSO_RESULT_SUCCESS = { "job_id": str(uuid4()), "output": "parsed_output", "return_code": 0, - }, + } } LSO_RESULT_FAILURE = { @@ -15,7 +15,7 @@ LSO_RESULT_FAILURE = { "job_id": str(uuid4()), "output": "parsed_output", "return_code": 1, - }, + } } USER_CONFIRM_EMPTY_FORM = [{}] diff --git a/test/conftest.py b/test/conftest.py index 262ed33f562e55b3dc1c809ef37bc9e8169b3673..37e4978c8a66e22c67f55d1cabbc28d7a5a66667 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -97,68 +97,32 @@ def configuration_data() -> dict: "password": "robot-user-password", }, "LO": { - "V4": { - "containers": [], - "networks": ["10.255.255.0/26"], - "mask": 32, - }, - "V6": { - "containers": [], - "networks": ["dead:beef::/80"], - "mask": 128, - }, + "V4": {"containers": [], "networks": ["10.255.255.0/26"], "mask": 32}, + "V6": {"containers": [], "networks": ["dead:beef::/80"], "mask": 128}, "domain_name": ".lo", "dns_view": "default", }, "TRUNK": { - "V4": { - "containers": ["10.255.255.0/24", "10.255.254.0/24"], - "networks": [], - "mask": 31, - }, - "V6": { - "containers": ["dead:beef::/64", "dead:beee::/64"], - "networks": [], - "mask": 126, - }, + "V4": {"containers": ["10.255.255.0/24", "10.255.254.0/24"], "networks": [], "mask": 31}, + "V6": {"containers": ["dead:beef::/64", "dead:beee::/64"], "networks": [], "mask": 126}, "domain_name": ".trunk", "dns_view": "default", }, "GEANT_IP": { - "V4": { - "containers": ["10.255.255.0/24", "10.255.254.0/24"], - "networks": [], - "mask": 31, - }, - "V6": { - "containers": ["dead:beef::/64", "dead:beee::/64"], - "networks": [], - "mask": 126, - }, + "V4": {"containers": ["10.255.255.0/24", "10.255.254.0/24"], "networks": [], "mask": 31}, + "V6": {"containers": ["dead:beef::/64", "dead:beee::/64"], "networks": [], "mask": 126}, "domain_name": ".geantip", "dns_view": "default", }, "SI": { - "V4": { - "containers": ["10.255.253.128/25"], - "networks": [], - "mask": 31, - }, + "V4": {"containers": ["10.255.253.128/25"], "networks": [], "mask": 31}, "V6": {"containers": [], "networks": [], "mask": 126}, "domain_name": ".geantip", "dns_view": "default", }, "LT_IAS": { - "V4": { - "containers": ["10.255.255.0/24"], - "networks": [], - "mask": 31, - }, - "V6": { - "containers": ["dead:beef:cc::/48"], - "networks": [], - "mask": 126, - }, + "V4": {"containers": ["10.255.255.0/24"], "networks": [], "mask": 31}, + "V6": {"containers": ["dead:beef:cc::/48"], "networks": [], "mask": 126}, "domain_name": ".geantip", "dns_view": "default", }, @@ -206,6 +170,7 @@ def run_migrations(db_uri: str) -> None: ------- None """ + path = Path(__file__).resolve().parent app_settings.DATABASE_URI = db_uri alembic_cfg = Config(file_=path / "../gso/alembic.ini") @@ -229,6 +194,7 @@ def _database(db_uri): ---- db_uri: The database uri configuration to run the migration on. """ + db.update(Database(db_uri)) url = make_url(db_uri) db_to_create = url.database @@ -239,8 +205,8 @@ def _database(db_uri): conn.execute(text("COMMIT;")) conn.execute( text("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=:db_name").bindparams( - db_name=db_to_create, - ), + db_name=db_to_create + ) ) conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";')) @@ -260,7 +226,7 @@ def _database(db_uri): conn.execute( text(f"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='{db_to_create}';"), # noqa: S608 ) - conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";')) + conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";')) # noqa @pytest.fixture(autouse=True) @@ -284,6 +250,7 @@ def _db_session(_database): ---- database: A fixture reference that initializes the database. """ + with contextlib.closing(db.wrapped_database.engine.connect()) as test_connection: # Create a new session factory for this context. session_factory = sessionmaker(bind=test_connection, **SESSION_ARGUMENTS) diff --git a/test/fixtures.py b/test/fixtures.py index 86927813112733379d00ce55ab94cf7c27b217f2..34124f4f7e4baba9131d32f876a55c1089bb06f2 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -6,12 +6,7 @@ from orchestrator.domain import SubscriptionModel from orchestrator.types import SubscriptionLifecycle, UUIDstr from gso.products import ProductType -from gso.products.product_blocks.iptrunk import ( - IptrunkInterfaceBlock, - IptrunkSideBlock, - IptrunkType, - PhyPortCapacity, -) +from gso.products.product_blocks.iptrunk import IptrunkInterfaceBlock, IptrunkSideBlock, IptrunkType, PhyPortCapacity from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_blocks.site import SiteTier from gso.products.product_types.iptrunk import IptrunkInactive @@ -22,7 +17,7 @@ from gso.services import subscriptions CUSTOMER_ID: UUIDstr = "2f47f65a-0911-e511-80d0-005056956c1a" -@pytest.fixture() +@pytest.fixture def site_subscription_factory(faker): def subscription_create( description=None, @@ -73,7 +68,7 @@ def site_subscription_factory(faker): return subscription_create -@pytest.fixture() +@pytest.fixture def router_subscription_factory(site_subscription_factory, faker): def subscription_create( description=None, @@ -136,7 +131,7 @@ def router_subscription_factory(site_subscription_factory, faker): return subscription_create -@pytest.fixture() +@pytest.fixture def iptrunk_side_subscription_factory(router_subscription_factory, faker): def subscription_create( iptrunk_side_node=None, @@ -151,14 +146,10 @@ def iptrunk_side_subscription_factory(router_subscription_factory, faker): iptrunk_side_ae_geant_a_sid = iptrunk_side_ae_geant_a_sid or faker.geant_sid() iptrunk_side_ae_members = iptrunk_side_ae_members or [ IptrunkInterfaceBlock.new( - faker.uuid4(), - interface_name=faker.network_interface(), - interface_description=faker.sentence(), + faker.uuid4(), interface_name=faker.network_interface(), interface_description=faker.sentence() ), IptrunkInterfaceBlock.new( - faker.uuid4(), - interface_name=faker.network_interface(), - interface_description=faker.sentence(), + faker.uuid4(), interface_name=faker.network_interface(), interface_description=faker.sentence() ), ] @@ -174,7 +165,7 @@ def iptrunk_side_subscription_factory(router_subscription_factory, faker): return subscription_create -@pytest.fixture() +@pytest.fixture def iptrunk_subscription_factory(iptrunk_side_subscription_factory, faker): def subscription_create( description=None, @@ -213,8 +204,7 @@ def iptrunk_subscription_factory(iptrunk_side_subscription_factory, faker): iptrunk_subscription.iptrunk.iptrunk_sides = iptrunk_sides iptrunk_subscription = SubscriptionModel.from_other_lifecycle( - iptrunk_subscription, - SubscriptionLifecycle.ACTIVE, + iptrunk_subscription, SubscriptionLifecycle.ACTIVE ) iptrunk_subscription.description = description iptrunk_subscription.start_date = start_date diff --git a/test/imports/test_imports.py b/test/imports/test_imports.py index 9a70dfdfa9f9bacda93e5e7d9b30b1d39ebae176..82a8eae6cc75bbe0374a6696b3acd0dc72b15ba9 100644 --- a/test/imports/test_imports.py +++ b/test/imports/test_imports.py @@ -15,7 +15,7 @@ ROUTER_IMPORT_ENDPOINT = "/api/v1/imports/routers" IPTRUNK_IMPORT_API_URL = "/api/v1/imports/iptrunks" -@pytest.fixture() +@pytest.fixture def iptrunk_data(router_subscription_factory, faker): router_side_a = router_subscription_factory() router_side_b = router_subscription_factory() @@ -30,28 +30,20 @@ def iptrunk_data(router_subscription_factory, faker): "side_a_ae_iface": faker.network_interface(), "side_a_ae_geant_a_sid": faker.geant_sid(), "side_a_ae_members": [ - { - "interface_name": faker.network_interface(), - "interface_description": faker.sentence(), - } - for _ in range(5) + {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5) ], "side_b_node_id": router_side_b, "side_b_ae_iface": faker.network_interface(), "side_b_ae_geant_a_sid": faker.geant_sid(), "side_b_ae_members": [ - { - "interface_name": faker.network_interface(), - "interface_description": faker.sentence(), - } - for _ in range(5) + {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} for _ in range(5) ], "iptrunk_ipv4_network": str(faker.ipv4_network()), "iptrunk_ipv6_network": str(faker.ipv6_network()), } -@pytest.fixture() +@pytest.fixture def mock_routers(iptrunk_data): with patch("gso.services.subscriptions.get_active_router_subscriptions") as mock_get_active_router_subscriptions: @@ -66,10 +58,7 @@ def mock_routers(iptrunk_data): "subscription_id": iptrunk_data["side_b_node_id"], "description": "iptrunk_sideB_node_id description", }, - { - "subscription_id": str(uuid4()), - "description": "random description", - }, + {"subscription_id": str(uuid4()), "description": "random description"}, ] return [ {"subscription_id": iptrunk_data["side_a_node_id"]}, @@ -90,7 +79,7 @@ def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_ assert response.json()["pid"] == "123e4567-e89b-12d3-a456-426655440000" -@pytest.fixture() +@pytest.fixture def site_data(faker): return { "site_name": faker.site_name(), @@ -107,7 +96,7 @@ def site_data(faker): } -@pytest.fixture() +@pytest.fixture def router_data(faker, site_data): mock_ipv4 = faker.ipv4() return { @@ -132,8 +121,7 @@ def test_import_site_endpoint(test_client, site_data): assert "detail" in response.json() assert "pid" in response.json() subscription = subscriptions.retrieve_subscription_by_subscription_instance_value( - resource_type="site_name", - value=site_data["site_name"], + resource_type="site_name", value=site_data["site_name"] ) assert subscription is not None @@ -201,8 +189,7 @@ def test_import_iptrunk_successful_with_real_process(test_client, mock_routers, assert "pid" in response subscription = subscriptions.retrieve_subscription_by_subscription_instance_value( - resource_type="geant_s_sid", - value=iptrunk_data["geant_s_sid"], + resource_type="geant_s_sid", value=iptrunk_data["geant_s_sid"] ) assert subscription is not None @@ -216,12 +203,8 @@ def test_import_iptrunk_invalid_customer(mock_start_process, test_client, mock_r assert response.status_code == 422 assert response.json() == { "detail": [ - { - "loc": ["body", "customer"], - "msg": "Customer not_existing_customer not found", - "type": "value_error", - }, - ], + {"loc": ["body", "customer"], "msg": "Customer not_existing_customer not found", "type": "value_error"} + ] } @@ -246,7 +229,7 @@ def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_ "msg": f"Router {iptrunk_data['side_b_node_id']} not found", "type": "value_error", }, - ], + ] } @@ -254,14 +237,8 @@ def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_ def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_client, mock_routers, iptrunk_data, faker): mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" - repeat_interface_a = { - "interface_name": faker.network_interface(), - "interface_description": faker.sentence(), - } - repeat_interface_b = { - "interface_name": faker.network_interface(), - "interface_description": faker.sentence(), - } + repeat_interface_a = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} + repeat_interface_b = {"interface_name": faker.network_interface(), "interface_description": faker.sentence()} iptrunk_data["side_a_ae_members"] = [repeat_interface_a for _ in range(5)] iptrunk_data["side_b_ae_members"] = [repeat_interface_b for _ in range(5)] @@ -270,31 +247,20 @@ def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_clien assert response.status_code == 422 assert response.json() == { "detail": [ - { - "loc": ["body", "side_a_ae_members"], - "msg": "Items must be unique", - "type": "value_error", - }, - { - "loc": ["body", "side_b_ae_members"], - "msg": "Items must be unique", - "type": "value_error", - }, + {"loc": ["body", "side_a_ae_members"], "msg": "Items must be unique", "type": "value_error"}, + {"loc": ["body", "side_b_ae_members"], "msg": "Items must be unique", "type": "value_error"}, { "loc": ["body", "__root__"], "msg": "Side A members should be at least 5 (iptrunk_minimum_links)", "type": "value_error", }, - ], + ] } @patch("gso.api.v1.imports._start_process") def test_import_iptrunk_fails_on_side_a_member_count_mismatch( - mock_start_process, - test_client, - mock_routers, - iptrunk_data, + mock_start_process, test_client, mock_routers, iptrunk_data ): mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" @@ -309,17 +275,14 @@ def test_import_iptrunk_fails_on_side_a_member_count_mismatch( "loc": ["body", "__root__"], "msg": "Side A members should be at least 5 (iptrunk_minimum_links)", "type": "value_error", - }, - ], + } + ] } @patch("gso.api.v1.imports._start_process") def test_import_iptrunk_fails_on_side_a_and_b_members_mismatch( - mock_start_process, - test_client, - iptrunk_data, - mock_routers, + mock_start_process, test_client, iptrunk_data, mock_routers ): mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" @@ -329,11 +292,5 @@ def test_import_iptrunk_fails_on_side_a_and_b_members_mismatch( assert response.status_code == 422 assert response.json() == { - "detail": [ - { - "loc": ["body", "__root__"], - "msg": "Mismatch between Side A and B members", - "type": "value_error", - }, - ], + "detail": [{"loc": ["body", "__root__"], "msg": "Mismatch between Side A and B members", "type": "value_error"}] } diff --git a/test/schedules/test_scheduling.py b/test/schedules/test_scheduling.py index 5ed2ad01e14a00e9e0785e9ee9a31518325f4bea..79003caa2fd34a07819118c6a163372f5de24461 100644 --- a/test/schedules/test_scheduling.py +++ b/test/schedules/test_scheduling.py @@ -13,20 +13,20 @@ def validate_subscriptions(): return vs -@pytest.fixture() +@pytest.fixture def mock_get_insync_subscriptions(): with patch("gso.schedules.validate_subscriptions.get_insync_subscriptions") as mock: yield mock -@pytest.fixture() +@pytest.fixture def mock_get_execution_context(): with patch("gso.schedules.validate_subscriptions.get_execution_context") as mock: mock.return_value = {"validate": MagicMock()} yield mock -@pytest.fixture() +@pytest.fixture def mock_logger(): with patch("gso.schedules.validate_subscriptions.logger") as mock: yield mock @@ -41,14 +41,7 @@ def mock_celery(): def test_scheduler_updates_beat_schedule(mock_celery): mock_celery.conf.beat_schedule = {} - @scheduler( - name="A cool task", - minute="0", - hour="0", - day_of_week="*", - day_of_month="*", - month_of_year="*", - ) + @scheduler(name="A cool task", minute="0", hour="0", day_of_week="*", day_of_month="*", month_of_year="*") def mock_task(): return "task result" @@ -63,14 +56,7 @@ def test_scheduler_updates_beat_schedule(mock_celery): def test_scheduled_task_still_works(): """Ensure that the scheduler decorator does not change the behavior of the function it decorates.""" - @scheduler( - name="A cool task", - minute="0", - hour="0", - day_of_week="*", - day_of_month="*", - month_of_year="*", - ) + @scheduler(name="A cool task", minute="0", hour="0", day_of_week="*", day_of_month="*", month_of_year="*") def mock_task(): return "task result" diff --git a/test/schemas/test_types.py b/test/schemas/test_types.py index 2e90123f3d96f3c0e5c86294780ba4539a9660c1..9493e80cf8861e86d0d0ac33c66ea2bd0e683d65 100644 --- a/test/schemas/test_types.py +++ b/test/schemas/test_types.py @@ -4,7 +4,7 @@ from gso.products.product_blocks.site import LatitudeCoordinate, LongitudeCoordi @pytest.mark.parametrize( - ("input_value", "is_valid"), + "input_value, is_valid", [ ("40.7128", True), ("-74.0060", True), @@ -29,7 +29,7 @@ def test_latitude(input_value, is_valid): @pytest.mark.parametrize( - ("input_value", "is_valid"), + "input_value, is_valid", [ ("40.7128", True), ("-74.0060", True), diff --git a/test/services/test_infoblox.py b/test/services/test_infoblox.py index 64bf43fdb5917d53a1e06cc95405ce34b0f0bdd0..003107a3cb5feb6696d40c791582ecfd966f920e 100644 --- a/test/services/test_infoblox.py +++ b/test/services/test_infoblox.py @@ -11,17 +11,9 @@ from gso.services.infoblox import AllocationError, DeletionError def _set_up_network_responses(): - responses.add( - method=responses.GET, - url=re.compile(r".+/wapi/v2\.12/network\?network=10\.255\.255\.0.+"), - json=[], - ) + responses.add(method=responses.GET, url=re.compile(r".+/wapi/v2\.12/network\?network=10\.255\.255\.0.+"), json=[]) - responses.add( - method=responses.GET, - url=re.compile(r".+/wapi/v2\.12/ipv6network\?network=dead%3Abeef.+"), - json=[], - ) + responses.add(method=responses.GET, url=re.compile(r".+/wapi/v2\.12/ipv6network\?network=dead%3Abeef.+"), json=[]) responses.add( method=responses.POST, @@ -76,7 +68,7 @@ def _set_up_host_responses(): method=responses.GET, url=re.compile( r"https://10.0.0.1/wapi/v2.12/record%3Ahost\?name=broken&ipv6addr=func%3Anextavailableip%3Adead%3Abeef%3A%3" - r"A%2F80%2Cdefault.*", + r"A%2F80%2Cdefault.*" ), json=[], status=codes.BAD, @@ -95,7 +87,7 @@ def _set_up_host_responses(): "duid": "00:00:00:00:00:00:00:00:00:00", "host": "test.lo.geant.net", "ipv6addr": "dead:beef::1", - }, + } ], "ip": "dead:beef::1", "name": "test.lo.geant.net", @@ -117,7 +109,7 @@ def _set_up_host_responses(): "host": "test.lo.geant.net", "ipv4addr": "10.255.255.129", "mac": "00:00:00:00:00:00", - }, + } ], "name": "test.lo.geant.net", "view": "default", @@ -140,11 +132,11 @@ def _set_up_host_responses(): "host": "test.lo.geant.net", "ipv4addr": "10.255.255.129", "mac": "00:00:00:00:00:00", - }, + } ], "name": "test.lo.geant.net", "view": "default", - }, + } ], ) @@ -177,10 +169,7 @@ def test_allocate_bad_network(data_config_filename: PathLike): def test_allocate_good_host(data_config_filename: PathLike): _set_up_host_responses() new_host = infoblox.allocate_host("test.lo.geant.net", "LO", [], "test host") - assert new_host == ( - ipaddress.ip_address("10.255.255.129"), - ipaddress.ip_address("dead:beef::1"), - ) + assert new_host == (ipaddress.ip_address("10.255.255.129"), ipaddress.ip_address("dead:beef::1")) @responses.activate @@ -202,7 +191,7 @@ def test_delete_good_network(data_config_filename: PathLike): "_ref": "network/ZG5zLm5ldHdvcmskNjIuNDAuOTYuMC8yNC8w:10.255.255.0/26/default", "network": "10.255.255.0/26", "network_view": "default", - }, + } ], ) @@ -234,7 +223,7 @@ def test_delete_good_host(data_config_filename: PathLike): responses.add( method=responses.GET, url=re.compile( - r"https://10\.0\.0\.1/wapi/v2\.12/record%3Ahost\?(?:name=ha_lo\.gso|ipv4addr=10\.255\.255\.1)?.+", + r"https://10\.0\.0\.1/wapi/v2\.12/record%3Ahost\?(?:name=ha_lo\.gso|ipv4addr=10\.255\.255\.1)?.+" ), json=[ { @@ -246,7 +235,7 @@ def test_delete_good_host(data_config_filename: PathLike): "configure_for_dhcp": False, "host": "ha_lo.gso", "ipv4addr": "10.255.255.1", - }, + } ], "ipv6addrs": [ { @@ -255,18 +244,18 @@ def test_delete_good_host(data_config_filename: PathLike): "configure_for_dhcp": False, "host": "ha_lo.gso", "ipv6addr": "dead:beef::1", - }, + } ], "name": "ha_lo.gso", "view": "default", - }, + } ], ) responses.add( method=responses.DELETE, url=re.compile( - r"https://10\.0\.0\.1/wapi/v2\.12/record%3Ahost/.+(ha_lo\.gso|dead:beef::1|10\.255\.255\.1)/default", + r"https://10\.0\.0\.1/wapi/v2\.12/record%3Ahost/.+(ha_lo\.gso|dead:beef::1|10\.255\.255\.1)/default" ), json=[], ) diff --git a/test/services/test_netbox.py b/test/services/test_netbox.py index 7df6320a22bc73ac8aa6c8ae5b7a60d51954f2a1..58a40d754f4e61b0a47a0bb57843522aa6f0308c 100644 --- a/test/services/test_netbox.py +++ b/test/services/test_netbox.py @@ -76,14 +76,7 @@ def lag(): @patch("gso.services.netbox_client.pynetbox.api") def test_create_device( - mock_api, - device, - device_type, - device_role, - site, - device_bay, - card_type, - data_config_filename: PathLike, + mock_api, device, device_type, device_role, site, device_bay, card_type, data_config_filename: PathLike ): device_name = "mx1.lab.geant.net" device.name = device_name diff --git a/test/workflows/__init__.py b/test/workflows/__init__.py index c4852e9dcffc3b3c0e286d3851481398d1731cf0..8939a0cd655eb18ae963852c533ef978c54cf052 100644 --- a/test/workflows/__init__.py +++ b/test/workflows/__init__.py @@ -1,9 +1,8 @@ import difflib import pprint -from collections.abc import Callable from copy import deepcopy from itertools import chain, repeat -from typing import cast +from typing import Callable, cast from uuid import uuid4 import structlog @@ -34,19 +33,19 @@ def assert_success(result): def assert_waiting(result): assert result.on_failed( - _raise_exception, + _raise_exception ).iswaiting(), f"Unexpected process status. Expected Waiting, but was: {result}" def assert_suspended(result): assert result.on_failed( - _raise_exception, + _raise_exception ).issuspend(), f"Unexpected process status. Expected Suspend, but was: {result}" def assert_awaiting_callback(result): assert result.on_failed( - _raise_exception, + _raise_exception ).isawaitingcallback(), f"Unexpected process status. Expected Awaiting Callback, but was: {result}" @@ -60,14 +59,14 @@ def assert_failed(result): def assert_complete(result): assert result.on_failed( - _raise_exception, + _raise_exception ).iscomplete(), f"Unexpected process status. Expected Complete, but was: {result}" def assert_state(result, expected): state = result.unwrap() actual = {} - for key in expected: + for key in expected.keys(): actual[key] = state[key] assert expected == actual, f"Invalid state. Expected superset of: {expected}, but was: {actual}" @@ -85,10 +84,7 @@ def assert_state_equal(result: ProcessTable, expected: dict, excluded_keys: list del expected_state[key] assert state == expected_state, "Unexpected state:\n" + "\n".join( - difflib.ndiff( - pprint.pformat(state).splitlines(), - pprint.pformat(expected_state).splitlines(), - ), + difflib.ndiff(pprint.pformat(state).splitlines(), pprint.pformat(expected_state).splitlines()) ) @@ -107,7 +103,7 @@ def extract_state(result): def extract_error(result): - assert isinstance(result, Process), f"Expected a Process, but got {result!r} of type {type(result)}" + assert isinstance(result, Process), f"Expected a Process, but got {repr(result)} of type {type(result)}" assert not isinstance(result.s, Process), "Result contained a Process in a Process, this should not happen" return extract_state(result).get("error") @@ -161,7 +157,7 @@ def _store_step(step_log: list[tuple[Step, Process]]) -> Callable[[ProcessStat, state = process.unwrap() state.pop("__step_name_override", None) - for k in [*state.get("__remove_keys", []), "__remove_keys"]: + for k in state.get("__remove_keys", []) + ["__remove_keys"]: state.pop(k, None) if state.pop("__replace_last_state", None): step_log[-1] = (step, process) @@ -208,9 +204,7 @@ def run_workflow(workflow_key: str, input_data: State | list[State]) -> tuple[Pr def resume_workflow( - process: ProcessStat, - step_log: list[tuple[Step, Process]], - input_data: State | list[State], + process: ProcessStat, step_log: list[tuple[Step, Process]], input_data: State | list[State] ) -> tuple[Process, list]: # ATTENTION!! This code needs to be as similar as possible to `server.services.processes.resume_process` # The main differences are: we use a different step log function, and we don't run in a separate thread @@ -218,7 +212,7 @@ def resume_workflow( filter( lambda p: not (p[1].isfailed() or p[1].issuspend() or p[1].iswaiting() or p[1].isawaitingcallback()), step_log, - ), + ) ) nr_of_steps_done = len(persistent) remaining_steps = process.workflow.steps[nr_of_steps_done:] @@ -245,8 +239,7 @@ def resume_workflow( def run_form_generator( - form_generator: FormGenerator, - extra_inputs: list[State] | None = None, + form_generator: FormGenerator, extra_inputs: list[State] | None = None ) -> tuple[list[dict], State]: """Run a form generator to get the resulting forms and result. @@ -329,6 +322,7 @@ def assert_pp_interaction_success(result: Process, process_stat: ProcessStat, st confirmation input step. Two assertions are made: the workflow is awaiting callback at first, and suspended when waiting for the user to confirm the results received. """ + assert_awaiting_callback(result) result, step_log = resume_workflow(process_stat, step_log, input_data=LSO_RESULT_SUCCESS) assert_suspended(result) diff --git a/test/workflows/iptrunk/test_create_iptrunk.py b/test/workflows/iptrunk/test_create_iptrunk.py index bc6cf64d1a26a9e09fdba7945a1a3562b882d419..0d88f8cee189d266a32946d1a2d3a2ed69b34321 100644 --- a/test/workflows/iptrunk/test_create_iptrunk.py +++ b/test/workflows/iptrunk/test_create_iptrunk.py @@ -41,7 +41,7 @@ def _netbox_client_mock(): yield -@pytest.fixture() +@pytest.fixture def input_form_wizard_data(router_subscription_factory, faker): router_side_a = router_subscription_factory() router_side_b = router_subscription_factory() @@ -60,10 +60,7 @@ def input_form_wizard_data(router_subscription_factory, faker): "side_a_ae_iface": "LAG1", "side_a_ae_geant_a_sid": faker.geant_sid(), "side_a_ae_members": [ - LAGMember( - interface_name=f"Interface{interface}", - interface_description=faker.sentence(), - ) + LAGMember(interface_name=f"Interface{interface}", interface_description=faker.sentence()) for interface in range(5) ], } @@ -72,10 +69,7 @@ def input_form_wizard_data(router_subscription_factory, faker): "side_b_ae_iface": "LAG4", "side_b_ae_geant_a_sid": faker.geant_sid(), "side_b_ae_members": [ - LAGMember( - interface_name=f"Interface{interface}", - interface_description=faker.sentence(), - ) + LAGMember(interface_name=f"Interface{interface}", interface_description=faker.sentence()) for interface in range(5) ], } @@ -89,7 +83,7 @@ def input_form_wizard_data(router_subscription_factory, faker): ] -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.create_iptrunk.provisioning_proxy.check_ip_trunk") @patch("gso.workflows.iptrunk.create_iptrunk.provisioning_proxy.provision_ip_trunk") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") @@ -121,14 +115,14 @@ def test_successful_iptrunk_creation_with_standard_lso_result( subscription_id = state["subscription_id"] subscription = Iptrunk.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert subscription.description == f"IP trunk, geant_s_sid:{input_form_wizard_data[0]['geant_s_sid']}" assert mock_provision_ip_trunk.call_count == 4 assert mock_check_ip_trunk.call_count == 2 -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.create_iptrunk.provisioning_proxy.check_ip_trunk") @patch("gso.workflows.iptrunk.create_iptrunk.provisioning_proxy.provision_ip_trunk") @patch("gso.workflows.iptrunk.create_iptrunk.infoblox.allocate_v6_network") diff --git a/test/workflows/iptrunk/test_migrate_iptrunk.py b/test/workflows/iptrunk/test_migrate_iptrunk.py index d1383e41e8b2066753718ebf81a5d611a38c472f..8285ffb9bb840ec586f0cde12adc0f24c849c4bd 100644 --- a/test/workflows/iptrunk/test_migrate_iptrunk.py +++ b/test/workflows/iptrunk/test_migrate_iptrunk.py @@ -17,7 +17,7 @@ from test.workflows import ( from test.workflows.iptrunk.test_create_iptrunk import MockedNetboxClient -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.migrate_ip_trunk") @patch("gso.workflows.iptrunk.migrate_iptrunk.provisioning_proxy.provision_ip_trunk") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @@ -65,7 +65,7 @@ def test_migrate_iptrunk_success( { "tt_number": faker.tt_number(), "replace_side": str( - old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id, + old_subscription.iptrunk.iptrunk_sides[0].iptrunk_side_node.subscription.subscription_id ), }, { @@ -74,10 +74,7 @@ def test_migrate_iptrunk_success( { "new_lag_interface": "LAG1", "new_lag_member_interfaces": [ - LAGMember( - interface_name=f"Interface{interface}", - interface_description=faker.sentence(), - ) + LAGMember(interface_name=f"Interface{interface}", interface_description=faker.sentence()) for interface in range(2) ], }, @@ -105,7 +102,7 @@ def test_migrate_iptrunk_success( subscription_id = state["subscription_id"] subscription = Iptrunk.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert mock_provision_ip_trunk.call_count == 2 assert mock_migrate_ip_trunk.call_count == 7 # Assert all Netbox calls have been made diff --git a/test/workflows/iptrunk/test_modify_isis_metric.py b/test/workflows/iptrunk/test_modify_isis_metric.py index d26eded3abcdf104e7dc64a20cb36384f58fe398..0a303fb51151da3577dadfeac96892ba6c116dee 100644 --- a/test/workflows/iptrunk/test_modify_isis_metric.py +++ b/test/workflows/iptrunk/test_modify_isis_metric.py @@ -3,15 +3,10 @@ from unittest.mock import patch import pytest from gso.products import Iptrunk -from test.workflows import ( - assert_complete, - assert_pp_interaction_success, - extract_state, - run_workflow, -) +from test.workflows import assert_complete, assert_pp_interaction_success, extract_state, run_workflow -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.modify_isis_metric.provisioning_proxy.provision_ip_trunk") def test_iptrunk_modify_isis_metric_success( mock_provision_ip_trunk, @@ -38,6 +33,6 @@ def test_iptrunk_modify_isis_metric_success( subscription_id = state["subscription_id"] subscription = Iptrunk.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert mock_provision_ip_trunk.call_count == 2 assert subscription.iptrunk.iptrunk_isis_metric == new_isis_metric diff --git a/test/workflows/iptrunk/test_modify_trunk_interface.py b/test/workflows/iptrunk/test_modify_trunk_interface.py index 8601b8ad675bc0c287b98ad277f58bf3cc52c81e..2cb048c3cfa39ae0c7b5c677ace2ffce48e05fcd 100644 --- a/test/workflows/iptrunk/test_modify_trunk_interface.py +++ b/test/workflows/iptrunk/test_modify_trunk_interface.py @@ -4,16 +4,11 @@ import pytest from gso.products import Iptrunk from gso.products.product_blocks.iptrunk import IptrunkType, PhyPortCapacity -from test.workflows import ( - assert_complete, - assert_pp_interaction_success, - extract_state, - run_workflow, -) +from test.workflows import assert_complete, assert_pp_interaction_success, extract_state, run_workflow from test.workflows.iptrunk.test_create_iptrunk import MockedNetboxClient -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.modify_trunk_interface.provisioning_proxy.provision_ip_trunk") @patch("gso.services.netbox_client.NetboxClient.get_available_interfaces") @patch("gso.services.netbox_client.NetboxClient.attach_interface_to_lag") @@ -91,7 +86,7 @@ def test_iptrunk_modify_trunk_interface_success( subscription_id = state["subscription_id"] subscription = Iptrunk.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert mock_provision_ip_trunk.call_count == 2 # Assert all Netbox calls have been made assert mocked_reserve_interface.call_count == 10 # 5 interfaces per side @@ -112,8 +107,7 @@ def test_iptrunk_modify_trunk_interface_success( for interface in interfaces: if interface["interface_name"] == name: return interface - msg = f"Interface {name} not found!" - raise IndexError(msg) + raise IndexError(f"Interface {name} not found!") for member in subscription.iptrunk.iptrunk_sides[0].iptrunk_side_ae_members: assert ( diff --git a/test/workflows/iptrunk/test_terminate_iptrunk.py b/test/workflows/iptrunk/test_terminate_iptrunk.py index 1e17b34a631fc0a5f50b4d87945ef594c36b4af0..a3ac220a268f228373914b4e67446b6fa02d519f 100644 --- a/test/workflows/iptrunk/test_terminate_iptrunk.py +++ b/test/workflows/iptrunk/test_terminate_iptrunk.py @@ -4,15 +4,10 @@ import pytest from gso.products import Iptrunk from test.services.conftest import MockedNetboxClient -from test.workflows import ( - assert_complete, - assert_pp_interaction_success, - extract_state, - run_workflow, -) +from test.workflows import assert_complete, assert_pp_interaction_success, extract_state, run_workflow -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.iptrunk.terminate_iptrunk.provisioning_proxy.provision_ip_trunk") @patch("gso.workflows.iptrunk.terminate_iptrunk.provisioning_proxy.deprovision_ip_trunk") @patch("gso.workflows.iptrunk.terminate_iptrunk.infoblox.delete_network") @@ -37,11 +32,7 @@ def test_successful_iptrunk_termination( # Run workflow initial_iptrunk_data = [ {"subscription_id": product_id}, - { - "tt_number": faker.tt_number(), - "remove_configuration": True, - "clean_up_ipam": True, - }, + {"tt_number": faker.tt_number(), "remove_configuration": True, "clean_up_ipam": True}, ] result, process_stat, step_log = run_workflow("terminate_iptrunk", initial_iptrunk_data) @@ -58,7 +49,7 @@ def test_successful_iptrunk_termination( subscription_id = state["subscription_id"] subscription = Iptrunk.from_subscription(subscription_id) - assert subscription.status == "terminated" + assert "terminated" == subscription.status assert mock_provision_ip_trunk.call_count == 1 assert mock_deprovision_ip_trunk.call_count == 2 assert mock_infoblox_delete_network.call_count == 2 diff --git a/test/workflows/router/test_create_router.py b/test/workflows/router/test_create_router.py index 67c6496cfb0b3f088a106d1d5737b66a49166b4a..460541a81b11a049aeccfdc307336434e35b7ff6 100644 --- a/test/workflows/router/test_create_router.py +++ b/test/workflows/router/test_create_router.py @@ -17,7 +17,7 @@ from test.workflows import ( ) -@pytest.fixture() +@pytest.fixture def router_creation_input_form_data(site_subscription_factory, faker): router_site = site_subscription_factory() @@ -33,7 +33,7 @@ def router_creation_input_form_data(site_subscription_factory, faker): } -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.router.create_router.provisioning_proxy.provision_router") @patch("gso.workflows.router.create_router.NetboxClient.create_device") @patch("gso.workflows.router.create_router.infoblox.hostname_available") @@ -87,7 +87,7 @@ def test_create_router_success( mac="00:00:00:00:00:00", ip=str(mock_v4), host=f"lo0.{mock_fqdn}", - ), + ) ], name=mock_fqdn, ) @@ -107,23 +107,18 @@ def test_create_router_success( state = extract_state(result) subscription = Router.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert subscription.description == f"Router {mock_fqdn}" assert mock_provision_router.call_count == 2 assert mock_netbox_create_device.call_count == 1 assert mock_find_host_by_fqdn.call_count == 1 assert mock_find_network_by_cidr.call_count == 3 - for error in [ - "ipam_warning", - "ipam_si_warning", - "ipam_ias_lt_ipv4_warning", - "ipam_ias_lt_ipv6_warning", - ]: + for error in ["ipam_warning", "ipam_si_warning", "ipam_ias_lt_ipv4_warning", "ipam_ias_lt_ipv6_warning"]: assert error not in state -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.router.create_router.provisioning_proxy.provision_router") @patch("gso.workflows.router.create_router.NetboxClient.create_device") @patch("gso.workflows.router.create_router.infoblox.hostname_available") @@ -168,7 +163,7 @@ def test_create_router_lso_failure( mac="00:00:00:00:00:00", ip=str(mock_v4), host=f"lo0.{mock_fqdn}", - ), + ) ], name=mock_fqdn, ) @@ -193,7 +188,7 @@ def test_create_router_lso_failure( assert_pp_interaction_failure(result, process_stat, step_log) - assert subscription.status == "provisioning" + assert "provisioning" == subscription.status assert subscription.description == f"Router {mock_fqdn}" assert mock_provision_router.call_count == 2 diff --git a/test/workflows/router/test_terminate_router.py b/test/workflows/router/test_terminate_router.py index 0b8af2b2e8bbe2ab8679c5c5e815a1aa5db390ed..f66d0e66b325c931c7a62019f6290603480edb54 100644 --- a/test/workflows/router/test_terminate_router.py +++ b/test/workflows/router/test_terminate_router.py @@ -6,16 +6,12 @@ from gso.products import Router from test.workflows import assert_complete, extract_state, run_workflow -@pytest.fixture() +@pytest.fixture def router_termination_input_form_data(site_subscription_factory, faker): - return { - "tt_number": faker.tt_number(), - "remove_configuration": True, - "clean_up_ipam": True, - } + return {"tt_number": faker.tt_number(), "remove_configuration": True, "clean_up_ipam": True} -@pytest.mark.workflow() +@pytest.mark.workflow @patch("gso.workflows.router.terminate_router.NetboxClient.delete_device") @patch("gso.workflows.router.terminate_router.infoblox.delete_host_by_ip") @patch("gso.workflows.router.terminate_router.infoblox.delete_network") @@ -32,10 +28,7 @@ def test_terminate_router_success( product_id = router_subscription_factory() # Run workflow - initial_router_data = [ - {"subscription_id": product_id}, - router_termination_input_form_data, - ] + initial_router_data = [{"subscription_id": product_id}, router_termination_input_form_data] result, _, _ = run_workflow("terminate_router", initial_router_data) assert_complete(result) @@ -43,7 +36,7 @@ def test_terminate_router_success( subscription_id = state["subscription_id"] subscription = Router.from_subscription(subscription_id) - assert subscription.status == "terminated" + assert "terminated" == subscription.status assert mock_delete_network.call_count == 3 assert mock_delete_device.call_count == 1 assert mock_delete_host_by_ip.call_count == 1 diff --git a/test/workflows/site/test_create_site.py b/test/workflows/site/test_create_site.py index 0ddb06b0e082126d685893951517a41da5730967..f80063c43bedc44f171f8993962872ab20078680 100644 --- a/test/workflows/site/test_create_site.py +++ b/test/workflows/site/test_create_site.py @@ -9,7 +9,7 @@ from gso.services.subscriptions import get_product_id_by_name from test.workflows import assert_complete, extract_state, run_workflow -@pytest.mark.workflow() +@pytest.mark.workflow def test_create_site(responses, faker): product_id = get_product_id_by_name(ProductType.SITE) initial_site_data = [ @@ -34,14 +34,14 @@ def test_create_site(responses, faker): state = extract_state(result) subscription_id = state["subscription_id"] subscription = Site.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert ( subscription.description == f"Site in {initial_site_data[1]['site_city']}, {initial_site_data[1]['site_country']}" ) -@pytest.mark.workflow() +@pytest.mark.workflow def test_site_name_is_incorrect(responses, faker): """Test validate site name on site creation. diff --git a/test/workflows/site/test_modify_site.py b/test/workflows/site/test_modify_site.py index 0db1a50fcd9f7880aeb574fa465afc08e832e808..5f9b8e1b74c7a7347819c1765b6a18cd82acd9d8 100644 --- a/test/workflows/site/test_modify_site.py +++ b/test/workflows/site/test_modify_site.py @@ -5,7 +5,7 @@ from gso.products.product_types.site import Site from test.workflows import assert_complete, extract_state, run_workflow -@pytest.mark.workflow() +@pytest.mark.workflow def test_modify_site(responses, site_subscription_factory): subscription_id = site_subscription_factory() initial_site_data = [ @@ -22,12 +22,12 @@ def test_modify_site(responses, site_subscription_factory): state = extract_state(result) subscription_id = state["subscription_id"] subscription = Site.from_subscription(subscription_id) - assert subscription.status == "active" + assert "active" == subscription.status assert subscription.site.site_bgp_community_id == initial_site_data[1]["site_bgp_community_id"] assert subscription.site.site_internal_id == initial_site_data[1]["site_internal_id"] -@pytest.mark.workflow() +@pytest.mark.workflow def test_modify_site_with_invalid_data(responses, site_subscription_factory): subscription_a = Site.from_subscription(site_subscription_factory()) subscription_b = Site.from_subscription(site_subscription_factory()) diff --git a/test/workflows/site/test_terminate_site.py b/test/workflows/site/test_terminate_site.py index 26cad9e28c90524bfc586bd6f628a9278923f726..8c504dc118f1c5daec84026a5fdc8308feb9e6b9 100644 --- a/test/workflows/site/test_terminate_site.py +++ b/test/workflows/site/test_terminate_site.py @@ -4,7 +4,7 @@ from gso.products.product_types.site import Site from test.workflows import assert_complete, extract_state, run_workflow -@pytest.mark.workflow() +@pytest.mark.workflow def test_terminate_site(responses, site_subscription_factory): subscription_id = site_subscription_factory() initial_site_data = [{"subscription_id": subscription_id}, {}] @@ -14,4 +14,4 @@ def test_terminate_site(responses, site_subscription_factory): state = extract_state(result) subscription_id = state["subscription_id"] subscription = Site.from_subscription(subscription_id) - assert subscription.status == "terminated" + assert "terminated" == subscription.status diff --git a/utils/netboxcli.py b/utils/netboxcli.py index 2cf2c1d7bf0c79c3221a13a497cfc499b3813852..8c723f4da1f0b1f419ec8da0b25a59e611d7a71c 100644 --- a/utils/netboxcli.py +++ b/utils/netboxcli.py @@ -110,23 +110,12 @@ def list() -> None: # noqa: A001 @list.command() @click.option("--fqdn", help="Device name to list interfaces") -@click.option( - "--speed", - default="1000", - help="Interface speed to list interfaces (default 1000=1G)", -) +@click.option("--speed", default="1000", help="Interface speed to list interfaces (default 1000=1G)") def interfaces(fqdn: str, speed: str) -> None: """List all interfaces that belong to a given :term:`FQDN`.""" click.echo(f"Listing all interfaces for: device with fqdn={fqdn}, speed={speed}") interface_list = NetboxClient().get_interfaces_by_device(fqdn, speed) - display_fields = [ - "name", - "enabled", - "mark_connected", - "custom_fields", - "lag", - "speed", - ] + display_fields = ["name", "enabled", "mark_connected", "custom_fields", "lag", "speed"] iface_list = [dict(iface) for iface in interface_list] table = convert_to_table(iface_list, display_fields)