From 6dd2b5e8ed838842804e67264635678c29721d76 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 19 Apr 2024 16:50:00 +0200 Subject: [PATCH] Apply renaming to reflect changes in import workflows --- gso/api/v1/imports.py | 30 ++++++++-------- gso/cli/imports.py | 30 ++++++++-------- gso/products/product_types/iptrunk.py | 4 ++- gso/products/product_types/office_router.py | 4 ++- gso/products/product_types/router.py | 4 ++- gso/products/product_types/site.py | 2 +- .../product_types/super_pop_switch.py | 4 ++- test/api/test_imports.py | 36 ++++++++++--------- 8 files changed, 63 insertions(+), 51 deletions(-) diff --git a/gso/api/v1/imports.py b/gso/api/v1/imports.py index 643b4bc0..6bfa786f 100644 --- a/gso/api/v1/imports.py +++ b/gso/api/v1/imports.py @@ -178,8 +178,8 @@ def _start_process(process_name: str, data: dict) -> UUID: @router.post("/sites", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_site(site: SiteImportModel) -> dict[str, Any]: - """Import a site by running the import_site workflow. +def create_imported_site(site: SiteImportModel) -> dict[str, Any]: + """Import a site by running the create_imported_site workflow. :param site: The site information to be imported. :type site: SiteImportModel @@ -189,13 +189,13 @@ def import_site(site: SiteImportModel) -> dict[str, Any]: :raises HTTPException: If the site already exists or if there's an error in the process. """ - pid = _start_process("import_site", site.dict()) + pid = _start_process("create_imported_site", site.dict()) return {"detail": "Site added successfully.", "pid": pid} @router.post("/routers", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_router(router_data: RouterImportModel) -> dict[str, Any]: - """Import a router by running the import_router workflow. +def create_imported_router(router_data: RouterImportModel) -> dict[str, Any]: + """Import a router by running the create_imported_router workflow. :param router_data: The router information to be imported. :type router_data: RouterImportModel @@ -205,13 +205,13 @@ 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()) + pid = _start_process("create_imported_router", router_data.dict()) return {"detail": "Router has been added successfully", "pid": pid} @router.post("/iptrunks", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_iptrunk(iptrunk_data: IptrunkImportModel) -> dict[str, Any]: - """Import an iptrunk by running the import_iptrunk workflow. +def create_imported_iptrunk(iptrunk_data: IptrunkImportModel) -> dict[str, Any]: + """Import an iptrunk by running the create_imported_iptrunk workflow. :param iptrunk_data: The iptrunk information to be imported. :type iptrunk_data: IptrunkImportModel @@ -221,13 +221,13 @@ 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()) + pid = _start_process("create_imported_iptrunk", iptrunk_data.dict()) return {"detail": "Iptrunk has been added successfully", "pid": pid} @router.post("/super-pop-switches", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_super_pop_switch(super_pop_switch_data: SuperPopSwitchImportModel) -> dict[str, Any]: - """Import a Super PoP switch by running the import_super_pop_switch workflow. +def create_imported_super_pop_switch(super_pop_switch_data: SuperPopSwitchImportModel) -> dict[str, Any]: + """Import a Super PoP switch by running the create_imported_super_pop_switch workflow. :param super_pop_switch_data: The Super PoP switch information to be imported. :type super_pop_switch_data: SuperPopSwitchImportModel @@ -237,13 +237,13 @@ def import_super_pop_switch(super_pop_switch_data: SuperPopSwitchImportModel) -> :raises HTTPException: If there's an error in the process. """ - pid = _start_process("import_super_pop_switch", super_pop_switch_data.dict()) + pid = _start_process("create_imported_super_pop_switch", super_pop_switch_data.dict()) return {"detail": "Super PoP switch has been added successfully", "pid": pid} @router.post("/office-routers", status_code=status.HTTP_201_CREATED, response_model=ImportResponseModel) -def import_office_router(office_router_data: OfficeRouterImportModel) -> dict[str, Any]: - """Import a office router by running the import_office_router workflow. +def create_imported_office_router(office_router_data: OfficeRouterImportModel) -> dict[str, Any]: + """Import an office router by running the create_imported_office_router workflow. :param office_router_data: The office router information to be imported. :type office_router_data: OfficeRouterImportModel @@ -253,5 +253,5 @@ def import_office_router(office_router_data: OfficeRouterImportModel) -> dict[st :raises HTTPException: If there's an error in the process. """ - pid = _start_process("import_office_router", office_router_data.dict()) + pid = _start_process("create_imported_office_router", office_router_data.dict()) return {"detail": "Office router has been added successfully", "pid": pid} diff --git a/gso/cli/imports.py b/gso/cli/imports.py index 64a6af56..fc8253a2 100644 --- a/gso/cli/imports.py +++ b/gso/cli/imports.py @@ -19,11 +19,11 @@ from gso.api.v1.imports import ( RouterImportModel, SiteImportModel, SuperPopSwitchImportModel, - import_iptrunk, - import_office_router, - import_router, - import_site, - import_super_pop_switch, + create_imported_iptrunk, + create_imported_office_router, + create_imported_router, + create_imported_site, + create_imported_super_pop_switch, ) from gso.db.models import PartnerTable from gso.services.subscriptions import get_active_subscriptions_by_field_and_value @@ -87,31 +87,31 @@ def generic_import_data( @app.command() -def import_sites(filepath: str = common_filepath_option) -> None: +def create_imported_sites(filepath: str = common_filepath_option) -> None: """Import sites into GSO.""" # Use the import_data function to handle common import logic - generic_import_data(filepath, SiteImportModel, import_site, "site_name") + generic_import_data(filepath, SiteImportModel, create_imported_site, "site_name") @app.command() -def import_routers(filepath: str = common_filepath_option) -> None: +def create_imported_routers(filepath: str = common_filepath_option) -> None: """Import routers into GSO.""" # Use the import_data function to handle common import logic - generic_import_data(filepath, RouterImportModel, import_router, "hostname") + generic_import_data(filepath, RouterImportModel, create_imported_router, "hostname") @app.command() -def import_super_pop_switches(filepath: str = common_filepath_option) -> None: +def create_imported_super_pop_switches(filepath: str = common_filepath_option) -> None: """Import Super PoP Switches into GSO.""" # Use the import_data function to handle common import logic - generic_import_data(filepath, SuperPopSwitchImportModel, import_super_pop_switch, "hostname") + generic_import_data(filepath, SuperPopSwitchImportModel, create_imported_super_pop_switch, "hostname") @app.command() -def import_office_routers(filepath: str = common_filepath_option) -> None: +def create_imported_office_routers(filepath: str = common_filepath_option) -> None: """Import office routers into GSO.""" # Use the import_data function to handle common import logic - generic_import_data(filepath, OfficeRouterImportModel, import_office_router, "office_router_fqdn") + generic_import_data(filepath, OfficeRouterImportModel, create_imported_office_router, "office_router_fqdn") def get_router_subscription_id(node_name: str) -> str | None: @@ -126,7 +126,7 @@ def get_router_subscription_id(node_name: str) -> str | None: @app.command() -def import_iptrunks(filepath: str = common_filepath_option) -> None: +def create_imported_iptrunks(filepath: str = common_filepath_option) -> None: """Import IP trunks into GSO.""" successfully_imported_data = [] data = read_data(filepath) @@ -192,7 +192,7 @@ def import_iptrunks(filepath: str = common_filepath_option) -> None: iptrunk_ipv4_network=iptrunk_ipv4_network, # type:ignore[arg-type] iptrunk_ipv6_network=iptrunk_ipv6_network, # type:ignore[arg-type] ) - import_iptrunk(initial_data) + create_imported_iptrunk(initial_data) successfully_imported_data.append(trunk["id"]) typer.echo(f"Successfully imported IP Trunk: {trunk['id']}") except ValidationError as e: diff --git a/gso/products/product_types/iptrunk.py b/gso/products/product_types/iptrunk.py index 82c912bf..6f6b85b1 100644 --- a/gso/products/product_types/iptrunk.py +++ b/gso/products/product_types/iptrunk.py @@ -34,7 +34,9 @@ class ImportedIptrunkInactive(SubscriptionModel, is_base=True): iptrunk: IptrunkBlockInactive -class ImportedIptrunk(ImportedIptrunkInactive, lifecycle=[SubscriptionLifecycle.ACTIVE]): +class ImportedIptrunk( + ImportedIptrunkInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] +): """An IP trunk that is active.""" iptrunk: IptrunkBlock diff --git a/gso/products/product_types/office_router.py b/gso/products/product_types/office_router.py index 04c47dfb..cfb98cdb 100644 --- a/gso/products/product_types/office_router.py +++ b/gso/products/product_types/office_router.py @@ -34,7 +34,9 @@ class ImportedOfficeRouterInactive(SubscriptionModel, is_base=True): office_router: OfficeRouterBlockInactive -class ImportedOfficeRouter(ImportedOfficeRouterInactive, lifecycle=[SubscriptionLifecycle.ACTIVE]): +class ImportedOfficeRouter( + ImportedOfficeRouterInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] +): """An imported office router that is currently active.""" office_router: OfficeRouterBlock diff --git a/gso/products/product_types/router.py b/gso/products/product_types/router.py index e24df3e7..973abc90 100644 --- a/gso/products/product_types/router.py +++ b/gso/products/product_types/router.py @@ -34,7 +34,9 @@ class ImportedRouterInactive(SubscriptionModel, is_base=True): router: RouterBlockInactive -class ImportedRouter(ImportedRouterInactive, lifecycle=[SubscriptionLifecycle.ACTIVE]): +class ImportedRouter( + ImportedRouterInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] +): """An imported router that is currently active.""" router: RouterBlock diff --git a/gso/products/product_types/site.py b/gso/products/product_types/site.py index 0fb16a57..be5c90b0 100644 --- a/gso/products/product_types/site.py +++ b/gso/products/product_types/site.py @@ -34,7 +34,7 @@ class ImportedSiteInactive(SubscriptionModel, is_base=True): site: SiteBlockInactive -class ImportedSite(ImportedSiteInactive, lifecycle=[SubscriptionLifecycle.ACTIVE]): +class ImportedSite(ImportedSiteInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE]): """An imported site that is currently active.""" site: SiteBlock diff --git a/gso/products/product_types/super_pop_switch.py b/gso/products/product_types/super_pop_switch.py index 3c80e364..298627ae 100644 --- a/gso/products/product_types/super_pop_switch.py +++ b/gso/products/product_types/super_pop_switch.py @@ -34,7 +34,9 @@ class ImportedSuperPopSwitchInactive(SubscriptionModel, is_base=True): super_pop_switch: SuperPopSwitchBlockInactive -class ImportedSuperPopSwitch(ImportedSuperPopSwitchInactive, lifecycle=[SubscriptionLifecycle.ACTIVE]): +class ImportedSuperPopSwitch( + ImportedSuperPopSwitchInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING, SubscriptionLifecycle.ACTIVE] +): """An imported Super PoP switch that is currently active.""" super_pop_switch: SuperPopSwitchBlock diff --git a/test/api/test_imports.py b/test/api/test_imports.py index f7b58f72..1752ea61 100644 --- a/test/api/test_imports.py +++ b/test/api/test_imports.py @@ -86,7 +86,9 @@ def mock_routers(iptrunk_data): @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_successful_with_mocked_process(mock_start_process, test_client, mock_routers, iptrunk_data): +def test_create_imported_iptrunk_successful_with_mocked_process( + mock_start_process, test_client, mock_routers, iptrunk_data +): mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) @@ -151,7 +153,7 @@ def office_router_data(faker, site_data): } -def test_import_site_endpoint(test_client, site_data): +def test_create_imported_site_endpoint(test_client, site_data): assert SubscriptionTable.query.all() == [] # Post data to the endpoint response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) @@ -165,7 +167,7 @@ def test_import_site_endpoint(test_client, site_data): assert subscription is not None -def test_import_site_endpoint_with_existing_site(test_client, site_data): +def test_create_imported_site_endpoint_with_existing_site(test_client, site_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert SubscriptionTable.query.count() == 1 assert response.status_code == 201 @@ -175,7 +177,7 @@ def test_import_site_endpoint_with_existing_site(test_client, site_data): assert SubscriptionTable.query.count() == 1 -def test_import_site_endpoint_with_invalid_data(test_client, site_data): +def test_create_imported_site_endpoint_with_invalid_data(test_client, site_data): # invalid data, missing site_latitude and invalid site_longitude site_data.pop("site_latitude") site_data["site_longitude"] = "invalid" @@ -190,7 +192,7 @@ def test_import_site_endpoint_with_invalid_data(test_client, site_data): assert response["detail"][1]["msg"] == "value is not a valid float" -def test_import_router_endpoint(test_client, site_data, router_data): +def test_create_imported_router_endpoint(test_client, site_data, router_data): # Create a site first response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 @@ -201,7 +203,7 @@ def test_import_router_endpoint(test_client, site_data, router_data): assert SubscriptionTable.query.count() == 2 -def test_import_router_endpoint_with_invalid_data(test_client, site_data, router_data): +def test_create_imported_router_endpoint_with_invalid_data(test_client, site_data, router_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 assert SubscriptionTable.query.count() == 1 @@ -219,7 +221,7 @@ def test_import_router_endpoint_with_invalid_data(test_client, site_data, router assert response["detail"][1]["msg"] == "value is not a valid IPv6 address" -def test_import_iptrunk_successful_with_real_process(test_client, mock_routers, iptrunk_data): +def test_create_imported_iptrunk_successful_with_real_process(test_client, mock_routers, iptrunk_data): response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) assert response.status_code == 201 @@ -235,7 +237,7 @@ def test_import_iptrunk_successful_with_real_process(test_client, mock_routers, @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_invalid_partner(mock_start_process, test_client, mock_routers, iptrunk_data): +def test_create_imported_iptrunk_invalid_partner(mock_start_process, test_client, mock_routers, iptrunk_data): iptrunk_data["partner"] = "not_existing_partner" mock_start_process.return_value = "123e4567-e89b-12d3-a456-426655440000" response = test_client.post(IPTRUNK_IMPORT_API_URL, json=iptrunk_data) @@ -253,7 +255,7 @@ def test_import_iptrunk_invalid_partner(mock_start_process, test_client, mock_ro @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_client, iptrunk_data): +def test_create_imported_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_client, iptrunk_data): iptrunk_data["side_a_node_id"] = "NOT FOUND" iptrunk_data["side_b_node_id"] = "NOT FOUND" @@ -278,7 +280,9 @@ def test_import_iptrunk_invalid_router_id_side_a_and_b(mock_start_process, test_ @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_client, mock_routers, iptrunk_data, faker): +def test_create_imported_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 = { @@ -317,7 +321,7 @@ def test_import_iptrunk_non_unique_members_side_a(mock_start_process, test_clien @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_fails_on_side_a_member_count_mismatch( +def test_create_imported_iptrunk_fails_on_side_a_member_count_mismatch( mock_start_process, test_client, mock_routers, @@ -342,7 +346,7 @@ def test_import_iptrunk_fails_on_side_a_member_count_mismatch( @patch("gso.api.v1.imports._start_process") -def test_import_iptrunk_fails_on_side_a_and_b_members_mismatch( +def test_create_imported_iptrunk_fails_on_side_a_and_b_members_mismatch( mock_start_process, test_client, iptrunk_data, @@ -366,7 +370,7 @@ def test_import_iptrunk_fails_on_side_a_and_b_members_mismatch( } -def test_import_super_pop_switch_endpoint(test_client, site_data, super_pop_switch_data): +def test_create_imported_super_pop_switch_endpoint(test_client, site_data, super_pop_switch_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 assert SubscriptionTable.query.count() == 1 @@ -376,7 +380,7 @@ def test_import_super_pop_switch_endpoint(test_client, site_data, super_pop_swit assert SubscriptionTable.query.count() == 2 -def test_import_super_pop_switch_endpoint_with_invalid_data(test_client, site_data, super_pop_switch_data): +def test_create_imported_super_pop_switch_endpoint_with_invalid_data(test_client, site_data, super_pop_switch_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 assert SubscriptionTable.query.count() == 1 @@ -394,7 +398,7 @@ def test_import_super_pop_switch_endpoint_with_invalid_data(test_client, site_da assert response["detail"][1]["msg"] == "value is not a valid IPv4 address" -def test_import_office_router_endpoint(test_client, site_data, office_router_data): +def test_create_imported_office_router_endpoint(test_client, site_data, office_router_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 assert SubscriptionTable.query.count() == 1 @@ -404,7 +408,7 @@ def test_import_office_router_endpoint(test_client, site_data, office_router_dat assert SubscriptionTable.query.count() == 2 -def test_import_office_router_endpoint_with_invalid_data(test_client, site_data, office_router_data): +def test_create_imported_office_router_endpoint_with_invalid_data(test_client, site_data, office_router_data): response = test_client.post(SITE_IMPORT_ENDPOINT, json=site_data) assert response.status_code == 201 assert SubscriptionTable.query.count() == 1 -- GitLab