diff --git a/gso/workflows/site/__init__.py b/gso/workflows/site/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..330a567f898f226518389a1c096161a19a9b88c6 100644 --- a/gso/workflows/site/__init__.py +++ b/gso/workflows/site/__init__.py @@ -0,0 +1 @@ +"""Workflows for the site subscription object.""" diff --git a/gso/workflows/site/create_site.py b/gso/workflows/site/create_site.py index 6c3a034dccfcc406b682b70a5b7e4198803e2845..5a5f2ed4a96a928d18fe72ddd249e5f63a4d28db 100644 --- a/gso/workflows/site/create_site.py +++ b/gso/workflows/site/create_site.py @@ -1,3 +1,5 @@ +"""A creation workflow for adding a new site to the service database.""" + from orchestrator.forms import FormPage from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr @@ -20,6 +22,7 @@ from gso.utils.helpers import ( def initial_input_form_generator(product_name: str) -> FormGenerator: + """Get input from the operator about the new site subscription.""" class CreateSiteForm(FormPage): class Config: title = product_name @@ -38,17 +41,20 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @validator("site_ts_address", allow_reuse=True) def validate_ts_address(cls, site_ts_address: str) -> str: + """Validate that a terminal server address is valid.""" validate_site_fields_is_unique("site_ts_address", site_ts_address) validate_ipv4_or_ipv6(site_ts_address) return site_ts_address @validator("site_country_code", allow_reuse=True) def country_code_must_exist(cls, country_code: str) -> str: + """Validate that the country code exists.""" validate_country_code(country_code) return country_code @validator("site_internal_id", "site_bgp_community_id", allow_reuse=True) def validate_unique_fields(cls, value: str, field: ModelField) -> str | int: + """Validate that the internal and :term:`BGP` community IDs are unique.""" return validate_site_fields_is_unique(field.name, value) @validator("site_name", allow_reuse=True) @@ -69,6 +75,7 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: @step("Create subscription") def create_subscription(product: UUIDstr, customer: UUIDstr) -> State: + """Create a new subscription object in the service database.""" subscription = site.SiteInactive.from_product_id(product, customer) return { @@ -91,6 +98,7 @@ def initialize_subscription( site_ts_address: str, site_tier: site_pb.SiteTier, ) -> State: + """Initialise the subscription object with all user input.""" subscription.site.site_name = site_name subscription.site.site_city = site_city subscription.site.site_country = site_country @@ -115,6 +123,7 @@ def initialize_subscription( target=Target.CREATE, ) def create_site() -> StepList: + """Create a new site subscription.""" return ( init >> create_subscription diff --git a/gso/workflows/site/modify_site.py b/gso/workflows/site/modify_site.py index 8fc105f1ae3de85116635fc1921404669e2b256c..15b549dbbcf7f357b5aebc28b885a998a18d9daa 100644 --- a/gso/workflows/site/modify_site.py +++ b/gso/workflows/site/modify_site.py @@ -1,3 +1,5 @@ +"""A modification workflow for a site.""" + from orchestrator.forms import FormPage from orchestrator.targets import Target from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr @@ -20,6 +22,7 @@ from gso.utils.helpers import validate_ipv4_or_ipv6, validate_site_fields_is_uni def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: + """Gather input from the operator on what to change about the selected site subscription.""" subscription = Site.from_subscription(subscription_id) class ModifySiteForm(FormPage): @@ -65,6 +68,7 @@ def modify_site_subscription( site_internal_id: int, site_ts_address: str, ) -> State: + """Update the subscription model in the service database.""" subscription.site.site_city = site_city subscription.site.site_latitude = site_latitude subscription.site.site_longitude = site_longitude @@ -83,6 +87,10 @@ def modify_site_subscription( target=Target.MODIFY, ) def modify_site() -> StepList: + """Modify a site subscription. + + * Update the subscription model in the service database + """ return ( init >> store_process_subscription(Target.MODIFY) diff --git a/gso/workflows/site/terminate_site.py b/gso/workflows/site/terminate_site.py index c9d5b662be4d5b3f570c3313d11a93d03dcfdca4..91be194f181f13422cf349d7ca0f65826b3a6a2a 100644 --- a/gso/workflows/site/terminate_site.py +++ b/gso/workflows/site/terminate_site.py @@ -1,3 +1,5 @@ +"""A workflow for terminating a site subscription.""" + from orchestrator.forms import FormPage from orchestrator.forms.validators import Label from orchestrator.targets import Target @@ -15,6 +17,7 @@ from gso.products.product_types.site import Site def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: + """Ask the user for confirmation whether to terminate the selected site.""" Site.from_subscription(subscription_id) class TerminateForm(FormPage): @@ -30,6 +33,7 @@ def initial_input_form_generator(subscription_id: UUIDstr) -> FormGenerator: target=Target.TERMINATE, ) def terminate_site() -> StepList: + """Terminate a site subscription.""" return ( init >> store_process_subscription(Target.TERMINATE) diff --git a/pyproject.toml b/pyproject.toml index bcc10d8c8d8905c55dbe6012385e9693ebfdc58e..7a618cf801ed5b736b408a53da17813cbde36f8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,6 +102,7 @@ ban-relative-imports = "all" [tool.ruff.per-file-ignores] "test/*" = ["ARG001", "D", "S101", "PLR2004"] +"setup.py" = ["D100"] [tool.ruff.isort] known-third-party = ["pydantic", "migrations"] diff --git a/test/services/conftest.py b/test/services/conftest.py index 282ae9edc8521e77cc6b8688670ad5218fa676c2..6d7476817d951a06081b2910351b64e2b382dde7 100644 --- a/test/services/conftest.py +++ b/test/services/conftest.py @@ -7,10 +7,10 @@ class MockedNetboxClient: def get_device_by_name(self): return self.BaseMockObject(id=1, name="test") - def get_available_lags(self) -> list[str]: + def get_available_lags(self) -> list[str]: # noqa: PLR6301 return [f"LAG{lag}" for lag in range(1, 5)] - def get_available_interfaces(self): + def get_available_interfaces(self): # noqa: PLR6301 interfaces = [] for interface in range(5): interface_data = { @@ -30,14 +30,14 @@ class MockedNetboxClient: def reserve_interface(self): return self.BaseMockObject(id=1, name="test") - def allocate_interface(self): + def allocate_interface(self): # noqa: PLR6301 return {"id": 1, "name": "test"} def free_interface(self): return self.BaseMockObject(id=1, name="test") - def detach_interfaces_from_lag(self): + def detach_interfaces_from_lag(self): # noqa: PLR6301 return None - def delete_interface(self): + def delete_interface(self): # noqa: PLR6301 return None