From b4ee6ab8d4b53ff5c1fff8ee0346f9aca770801a Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Fri, 6 Oct 2023 14:53:02 +0200 Subject: [PATCH] more refactoring restructure test files in test/workflows/iptrunk update import statements for PhyPortCapacity and PortNumber enums --- gso/api/v1/imports.py | 2 +- gso/products/product_blocks/iptrunk.py | 2 +- gso/services/netbox_client.py | 2 +- gso/utils/types/imports.py | 2 +- gso/utils/types/phy_port.py | 2 +- gso/workflows/iptrunk/create_iptrunk.py | 3 +-- gso/workflows/iptrunk/modify_trunk_interface.py | 6 +++--- gso/workflows/router/create_router.py | 2 +- gso/workflows/site/create_site.py | 2 +- gso/workflows/tasks/import_iptrunk.py | 4 ++-- gso/workflows/tasks/import_router.py | 4 ++-- gso/workflows/tasks/import_site.py | 2 +- test/fixtures.py | 2 +- test/imports/test_imports.py | 2 +- test/workflows/iptrunk/__init__.py | 0 .../test_create_iptrunk.py} | 5 ++--- test/workflows/site/test_create_site.py | 2 +- 17 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 test/workflows/iptrunk/__init__.py rename test/workflows/{iptrunks/iptrunks/test_create_iptrunks.py => iptrunk/test_create_iptrunk.py} (98%) diff --git a/gso/api/v1/imports.py b/gso/api/v1/imports.py index de160e2a..242deb5e 100644 --- a/gso/api/v1/imports.py +++ b/gso/api/v1/imports.py @@ -7,7 +7,7 @@ from orchestrator.security import opa_security_default from orchestrator.services import processes, subscriptions from sqlalchemy.exc import MultipleResultsFound -from utils.types.imports import ImportResponseModel, IptrunkImportModel, RouterImportModel, SiteImportModel +from gso.utils.types.imports import ImportResponseModel, IptrunkImportModel, RouterImportModel, SiteImportModel router = APIRouter(prefix="/imports", tags=["Imports"], dependencies=[Depends(opa_security_default)]) diff --git a/gso/products/product_blocks/iptrunk.py b/gso/products/product_blocks/iptrunk.py index 3efd0824..52d28ebf 100644 --- a/gso/products/product_blocks/iptrunk.py +++ b/gso/products/product_blocks/iptrunk.py @@ -8,8 +8,8 @@ from orchestrator.forms.validators import UniqueConstrainedList from orchestrator.types import SubscriptionLifecycle, strEnum from pydantic import Field -from gso.products.product_blocks import PhyPortCapacity from gso.products.product_blocks.router import RouterBlock, RouterBlockInactive, RouterBlockProvisioning +from gso.utils.types.phy_port import PhyPortCapacity class IptrunkType(strEnum): diff --git a/gso/services/netbox_client.py b/gso/services/netbox_client.py index 3ed80592..d583448c 100644 --- a/gso/services/netbox_client.py +++ b/gso/services/netbox_client.py @@ -5,7 +5,7 @@ import pydantic import pynetbox from pynetbox.models.dcim import Devices, DeviceTypes, Interfaces -from gso.products import Router +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 diff --git a/gso/utils/types/imports.py b/gso/utils/types/imports.py index da1e242a..d0ce27c0 100644 --- a/gso/utils/types/imports.py +++ b/gso/utils/types/imports.py @@ -4,12 +4,12 @@ from uuid import UUID from pydantic import BaseModel, root_validator, validator -from gso.products.product_blocks import PhyPortCapacity from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_blocks.site import SiteTier from gso.services import subscriptions from gso.services.crm import CustomerNotFoundError, get_customer_by_name +from gso.utils.types.phy_port import PhyPortCapacity class ImportResponseModel(BaseModel): diff --git a/gso/utils/types/phy_port.py b/gso/utils/types/phy_port.py index 50592c9a..0d55eece 100644 --- a/gso/utils/types/phy_port.py +++ b/gso/utils/types/phy_port.py @@ -10,4 +10,4 @@ class PhyPortCapacity(strEnum): ONE_GIGABIT_PER_SECOND = "1G" TEN_GIGABIT_PER_SECOND = "10G" HUNDRED_GIGABIT_PER_SECOND = "100G" - FOUR_HUNDRED_GIGABIT_PER_SECOND = "400G" \ No newline at end of file + FOUR_HUNDRED_GIGABIT_PER_SECOND = "400G" diff --git a/gso/workflows/iptrunk/create_iptrunk.py b/gso/workflows/iptrunk/create_iptrunk.py index b08da129..a8331d06 100644 --- a/gso/workflows/iptrunk/create_iptrunk.py +++ b/gso/workflows/iptrunk/create_iptrunk.py @@ -8,7 +8,6 @@ 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 import PhyPortCapacity from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.router import RouterVendor from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvisioning @@ -167,7 +166,7 @@ def initialize_subscription( geant_s_sid: str, iptrunk_type: IptrunkType, iptrunk_description: str, - iptrunk_speed: str, + iptrunk_speed: PhyPortCapacity, iptrunk_minimum_links: int, iptrunk_sideA_node_id: str, iptrunk_sideA_ae_iface: str, diff --git a/gso/workflows/iptrunk/modify_trunk_interface.py b/gso/workflows/iptrunk/modify_trunk_interface.py index 87e3b8f5..0dcdbe96 100644 --- a/gso/workflows/iptrunk/modify_trunk_interface.py +++ b/gso/workflows/iptrunk/modify_trunk_interface.py @@ -8,11 +8,11 @@ from orchestrator.workflow import StepList, done, init, step, workflow from orchestrator.workflows.steps import resync, store_process_subscription, unsync from orchestrator.workflows.utils import wrap_modify_initial_input_form -from gso.products.product_blocks import PhyPortCapacity from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_types.iptrunk import Iptrunk from gso.services import provisioning_proxy from gso.services.provisioning_proxy import pp_interaction +from gso.utils.types.phy_port import PhyPortCapacity def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: @@ -23,7 +23,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: geant_s_sid: str = subscription.iptrunk.geant_s_sid iptrunk_description: str = subscription.iptrunk.iptrunk_description iptrunk_type: IptrunkType = subscription.iptrunk.iptrunk_type - iptrunk_speed: PhyPortCapacity = subscription.iptrunk.iptrunk_speed # type: ignore[assignment] + iptrunk_speed: PhyPortCapacity = subscription.iptrunk.iptrunk_speed iptrunk_minimum_links: int = subscription.iptrunk.iptrunk_minimum_links iptrunk_isis_metric: int = ReadOnlyField(subscription.iptrunk.iptrunk_isis_metric) iptrunk_ipv4_network: ipaddress.IPv4Network = ReadOnlyField(subscription.iptrunk.iptrunk_ipv4_network) @@ -75,7 +75,7 @@ def modify_iptrunk_subscription( geant_s_sid: str, iptrunk_type: IptrunkType, iptrunk_description: str, - iptrunk_speed: str, + iptrunk_speed: PhyPortCapacity, iptrunk_minimum_links: int, iptrunk_sideA_ae_geant_a_sid: str, iptrunk_sideA_ae_members: list[str], diff --git a/gso/workflows/router/create_router.py b/gso/workflows/router/create_router.py index 72d7d5e9..ca9b4868 100644 --- a/gso/workflows/router/create_router.py +++ b/gso/workflows/router/create_router.py @@ -14,10 +14,10 @@ from pydantic import validator from gso.products.product_blocks.router import RouterRole, RouterVendor, generate_fqdn from gso.products.product_types.router import RouterInactive, RouterProvisioning from gso.products.product_types.site import Site -from utils.types.ip_port import PortNumber from gso.services import infoblox, provisioning_proxy, subscriptions from gso.services.netbox_client import NetboxClient from gso.services.provisioning_proxy import pp_interaction +from gso.utils.types.ip_port import PortNumber from gso.workflows.utils import customer_selector, iso_from_ipv4 diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py index f5642b73..18aada8f 100644 --- a/gso/workflows/site/create_site.py +++ b/gso/workflows/site/create_site.py @@ -12,8 +12,8 @@ from pydantic import validator from gso.products.product_blocks import site as site_pb from gso.products.product_types import site -from gso.workflows.utils import customer_selector from gso.utils.types.snmp import LatitudeCoordinate, LongitudeCoordinate +from gso.workflows.utils import customer_selector def initial_input_form_generator(product_name: str) -> FormGenerator: # noqa: C901 diff --git a/gso/workflows/tasks/import_iptrunk.py b/gso/workflows/tasks/import_iptrunk.py index fc03382e..f3769aac 100644 --- a/gso/workflows/tasks/import_iptrunk.py +++ b/gso/workflows/tasks/import_iptrunk.py @@ -8,12 +8,12 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle from orchestrator.workflow import StepList, done, init, step from orchestrator.workflows.steps import resync, set_status, store_process_subscription -from gso.products.product_blocks import PhyPortCapacity +from gso.products import ProductType from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_types.iptrunk import IptrunkInactive, IptrunkProvisioning -from gso.products import ProductType from gso.services import subscriptions from gso.services.crm import get_customer_by_name +from gso.utils.types.phy_port import PhyPortCapacity from gso.workflows.iptrunk.create_iptrunk import initialize_subscription diff --git a/gso/workflows/tasks/import_router.py b/gso/workflows/tasks/import_router.py index 1a9c0656..272f2750 100644 --- a/gso/workflows/tasks/import_router.py +++ b/gso/workflows/tasks/import_router.py @@ -8,15 +8,15 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle from orchestrator.workflow import StepList, done, init, step from orchestrator.workflows.steps import resync, set_status, store_process_subscription +from gso.products import ProductType from gso.products.product_blocks import router as router_pb from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_types import router from gso.products.product_types.router import RouterInactive from gso.products.product_types.site import Site -from utils.types.ip_port import PortNumber -from gso.products import ProductType from gso.services import subscriptions from gso.services.crm import get_customer_by_name +from gso.utils.types.ip_port import PortNumber def _get_site_by_name(site_name: str) -> Site: diff --git a/gso/workflows/tasks/import_site.py b/gso/workflows/tasks/import_site.py index b9ea20ed..af96fca2 100644 --- a/gso/workflows/tasks/import_site.py +++ b/gso/workflows/tasks/import_site.py @@ -6,9 +6,9 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle from orchestrator.workflow import StepList, done, init, step, workflow from orchestrator.workflows.steps import resync, set_status, store_process_subscription +from gso.products import ProductType from gso.products.product_blocks.site import SiteTier from gso.products.product_types.site import SiteInactive -from gso.products import ProductType from gso.services import subscriptions from gso.services.crm import get_customer_by_name from gso.workflows.site.create_site import initialize_subscription diff --git a/test/fixtures.py b/test/fixtures.py index 65ad4c0d..24864c5a 100644 --- a/test/fixtures.py +++ b/test/fixtures.py @@ -5,12 +5,12 @@ from orchestrator.db import db from orchestrator.domain import SubscriptionModel from orchestrator.types import SubscriptionLifecycle, UUIDstr +from gso.products import ProductType from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_blocks.site import SiteTier from gso.products.product_types.router import RouterInactive from gso.products.product_types.site import Site, SiteInactive from gso.services import subscriptions -from gso.products import ProductType CUSTOMER_ID: UUIDstr = "2f47f65a-0911-e511-80d0-005056956c1a" diff --git a/test/imports/test_imports.py b/test/imports/test_imports.py index c41497c0..639ace3e 100644 --- a/test/imports/test_imports.py +++ b/test/imports/test_imports.py @@ -5,10 +5,10 @@ import pytest from orchestrator.db import SubscriptionTable from orchestrator.services import subscriptions -from gso.products.product_blocks import PhyPortCapacity from gso.products.product_blocks.iptrunk import IptrunkType from gso.products.product_blocks.router import RouterRole, RouterVendor from gso.products.product_blocks.site import SiteTier +from gso.utils.types.phy_port import PhyPortCapacity SITE_IMPORT_ENDPOINT = "/api/v1/imports/sites" ROUTER_IMPORT_ENDPOINT = "/api/v1/imports/routers" diff --git a/test/workflows/iptrunk/__init__.py b/test/workflows/iptrunk/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py b/test/workflows/iptrunk/test_create_iptrunk.py similarity index 98% rename from test/workflows/iptrunks/iptrunks/test_create_iptrunks.py rename to test/workflows/iptrunk/test_create_iptrunk.py index b38253f1..886c26d5 100644 --- a/test/workflows/iptrunks/iptrunks/test_create_iptrunks.py +++ b/test/workflows/iptrunk/test_create_iptrunk.py @@ -3,12 +3,11 @@ from unittest.mock import patch import pytest -from gso.products import Iptrunk -from gso.products.product_blocks import PhyPortCapacity +from gso.products import Iptrunk, ProductType from gso.products.product_blocks.iptrunk import IptrunkType -from gso.products import ProductType from gso.services.crm import get_customer_by_name from gso.services.subscriptions import get_product_id_by_name +from gso.utils.types.phy_port import PhyPortCapacity from gso.workflows.utils import customer_selector from test.workflows import ( assert_aborted, diff --git a/test/workflows/site/test_create_site.py b/test/workflows/site/test_create_site.py index 6023f05a..20486ec2 100644 --- a/test/workflows/site/test_create_site.py +++ b/test/workflows/site/test_create_site.py @@ -1,8 +1,8 @@ import pytest +from gso.products import ProductType from gso.products.product_blocks.site import SiteTier from gso.products.product_types.site import Site -from gso.products import ProductType from gso.services.crm import get_customer_by_name from gso.services.subscriptions import get_product_id_by_name from test.workflows import assert_complete, extract_state, run_workflow -- GitLab