From 5a61647ab391dff74221bf3b04e4fa7b3f43a417 Mon Sep 17 00:00:00 2001 From: Neda Moeini <neda.moeini@geant.org> Date: Thu, 28 Nov 2024 14:30:21 +0100 Subject: [PATCH] Remove unique vrf name validation and use UniqueField custom type instead. --- gso/services/subscriptions.py | 13 ------------- gso/workflows/vrf/create_vrf.py | 13 +++---------- test/workflows/vrf/test_create_vrf.py | 2 +- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/gso/services/subscriptions.py b/gso/services/subscriptions.py index b3b8a66d..2c5ffba4 100644 --- a/gso/services/subscriptions.py +++ b/gso/services/subscriptions.py @@ -321,16 +321,3 @@ def is_virtual_circuit_id_available(virtual_circuit_id: str) -> bool: :rtype: bool """ return is_resource_type_value_unique("virtual_circuit_id", virtual_circuit_id) - - -def is_vrf_name_unique(vrf_name: str) -> bool: - """Check if the given VRF name is unique in the database. - - This function verifies if the specified VRF name is not already present in the core database. - - :param vrf_name: The VRF name to check. - :type vrf_name: str - :return: True if the VRF name is unique (not found), False if it exists. - :rtype: bool - """ - return is_resource_type_value_unique("vrf_name", vrf_name) diff --git a/gso/workflows/vrf/create_vrf.py b/gso/workflows/vrf/create_vrf.py index a555457e..c11aa731 100644 --- a/gso/workflows/vrf/create_vrf.py +++ b/gso/workflows/vrf/create_vrf.py @@ -6,13 +6,13 @@ from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUID from orchestrator.workflow import StepList, begin, done, step, workflow from orchestrator.workflows.steps import resync, set_status, store_process_subscription from orchestrator.workflows.utils import wrap_create_initial_input_form -from pydantic import ConfigDict, field_validator +from pydantic import ConfigDict from pydantic_forms.validators import ReadOnlyField from gso.products.product_types.vrf import VRFInactive from gso.services.partners import get_partner_by_name -from gso.services.subscriptions import is_vrf_name_unique from gso.utils.types.tt_number import TTNumber +from gso.utils.types.unique_field import UniqueField from gso.workflows.shared import create_summary_form @@ -24,18 +24,11 @@ def initial_input_form_generator(product_name: str) -> FormGenerator: tt_number: TTNumber partner: ReadOnlyField("GEANT", default_type=str) # type: ignore[valid-type] - vrf_name: str + vrf_name: UniqueField[str] route_distinguisher: str route_target: str vrf_as_number: int - @field_validator("vrf_name") - def vrf_name_must_be_unique(cls, vrf_name: str) -> str: - if not is_vrf_name_unique(vrf_name): - msg = "VRF name must be unique." - raise ValueError(msg) - return vrf_name - user_input = yield CreateVRFForm user_input = user_input.model_dump() summary_fields = ["vrf_name", "route_distinguisher", "route_target", "vrf_as_number"] diff --git a/test/workflows/vrf/test_create_vrf.py b/test/workflows/vrf/test_create_vrf.py index f2e082e8..8936178e 100644 --- a/test/workflows/vrf/test_create_vrf.py +++ b/test/workflows/vrf/test_create_vrf.py @@ -51,5 +51,5 @@ def test_create_vrf_with_duplicate_vrf_name( data_config_filename, ): vrf_subscription_factory(vrf_name=vrf_input[1]["vrf_name"]) - with pytest.raises(FormValidationError, match="VRF name must be unique."): + with pytest.raises(FormValidationError, match="vrf_name must be unique."): run_workflow("create_vrf", vrf_input) -- GitLab