Skip to content
Snippets Groups Projects
Verified Commit c5063364 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

resolve linting errors in product types and blocks, and schedules

parent 53abc0b5
No related branches found
No related tags found
1 merge request!111Feature/ruff everything party hat emoji
......@@ -50,14 +50,14 @@ class SiteImportModel(BaseModel):
@validator("site_ts_address", allow_reuse=True)
def validate_ts_address(cls, site_ts_address: str) -> str:
"""A terminal server address must be valid."""
"""Validate the terminal server address."""
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:
"""A country code must exist."""
"""Validate the country code such that it exists."""
validate_country_code(country_code)
return country_code
......@@ -126,7 +126,7 @@ class IptrunkImportModel(BaseModel):
@validator("customer")
def check_if_customer_exists(cls, value: str) -> str:
"""The customer must exist."""
"""Validate that the customer exists."""
try:
get_customer_by_name(value)
except CustomerNotFoundError as e:
......
......@@ -31,6 +31,7 @@ class LatitudeCoordinate(ConstrainedStr):
@classmethod
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)
......@@ -50,6 +51,7 @@ class LongitudeCoordinate(ConstrainedStr):
@classmethod
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)
......
"""The product type for IP trunks, does not contain any special variables apart from the corresponding product block."""
from orchestrator.domain.base import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle
......@@ -9,12 +11,18 @@ from gso.products.product_blocks.iptrunk import (
class IptrunkInactive(SubscriptionModel, is_base=True):
"""An IP trunk that is inactive."""
iptrunk: IptrunkBlockInactive
class IptrunkProvisioning(IptrunkInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
"""An IP trunk that is being provisioned."""
iptrunk: IptrunkBlockProvisioning
class Iptrunk(IptrunkProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""An IP trunk that is active."""
iptrunk: IptrunkBlock
"""A router product type."""
from orchestrator.domain.base import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle
......@@ -9,12 +11,18 @@ from gso.products.product_blocks.router import (
class RouterInactive(SubscriptionModel, is_base=True):
"""An inactive router."""
router: RouterBlockInactive
class RouterProvisioning(RouterInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
"""A router that is being provisioned."""
router: RouterBlockProvisioning
class Router(RouterProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""A router that is currently active."""
router: RouterBlock
"""The product type for sites. Used for tying together shared information between the products that reside here."""
from orchestrator.domain.base import SubscriptionModel
from orchestrator.types import SubscriptionLifecycle
......@@ -9,12 +11,18 @@ from gso.products.product_blocks.site import (
class SiteInactive(SubscriptionModel, is_base=True):
"""A site that is inactive."""
site: SiteBlockInactive
class SiteProvisioning(SiteInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
"""A site that is being provisioned."""
site: SiteBlockProvisioning
class Site(SiteProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
"""A site that is currently active."""
site: SiteBlock
"""Tasks that are scheduled to run periodically in :term:`GSO`."""
"""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
......
"""Metatask that runs all cleanup tasks."""
from orchestrator.services.processes import start_process
from gso.schedules.scheduling import scheduler
......@@ -7,4 +9,5 @@ from gso.worker import celery
@celery.task
@scheduler(name="Clean up tasks", hour="*/6")
def vacuum_tasks() -> None:
"""Run all cleanup tasks every 6 hours."""
start_process("task_clean_up_tasks")
"""Scheduled task that validates all products and inactive subscriptions in :term:`GSO`."""
from orchestrator.services.processes import start_process
from gso.schedules.scheduling import scheduler
......@@ -8,5 +10,6 @@ from gso.worker import celery
@celery.task
@scheduler(name="Validate Products and inactive subscriptions", minute="30", hour="2")
def validate_products() -> None:
"""Validate all products."""
if count_incomplete_validate_products() > 0:
start_process("task_validate_products")
"""Scheduled task that runs a validation workflow for all active subscriptions."""
import structlog
from orchestrator.services.processes import get_execution_context
from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP, WF_USABLE_MAP
......@@ -13,6 +15,7 @@ logger = structlog.get_logger(__name__)
@celery.task
@scheduler(name="Subscriptions Validator", minute="10", hour="0")
def validate_subscriptions() -> None:
"""Validate all subscriptions using their corresponding validation workflow."""
subscriptions = get_insync_subscriptions()
if not subscriptions:
logger.info("No subscriptions to validate")
......
......@@ -42,6 +42,7 @@ ignore = [
"D213",
"N805",
"PLR0913",
"PLR0904"
]
line-length = 120
select = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment