From 383fec8e610184822e0df89f8d5d131051945c30 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Thu, 12 Dec 2024 14:23:46 +0100 Subject: [PATCH] Resolve some issues in SonarQube --- gso/utils/types/interfaces.py | 6 +++--- gso/utils/types/site_name.py | 2 +- gso/workflows/edge_port/create_edge_port.py | 2 +- gso/workflows/iptrunk/migrate_iptrunk.py | 4 ++-- test/fixtures/layer_2_circuit_fixtures.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gso/utils/types/interfaces.py b/gso/utils/types/interfaces.py index 80ac4a5f..f76cd8de 100644 --- a/gso/utils/types/interfaces.py +++ b/gso/utils/types/interfaces.py @@ -54,10 +54,10 @@ def validate_juniper_phy_interface_name(interface_name: str) -> str: Returns: The interface name if match was successful, otherwise it will throw a ValueError exception. """ - pattern = re.compile(r"^(ge|et|xe)-1?[0-9]/[0-9]{1,2}/[0-9]{1,2}$") + pattern = re.compile(r"^(ge|et|xe)-1?\d/\d{1,2}/\d{1,2}$") if not bool(pattern.match(interface_name)): error_msg = ( - f"Invalid interface name. The interface name should be of format: xe-1/0/0. " f"Got: {interface_name}" + f"Invalid interface name. The interface name should be of format: xe-1/0/0, received: {interface_name}" ) raise ValueError(error_msg) return interface_name @@ -113,7 +113,7 @@ def bandwidth_string_is_valid(bandwidth_string: str) -> str: if len(bandwidth_string) < 2: # noqa: PLR2004 not a magic value raise ValueError(msg) - if bandwidth_string[-1:] not in "K" "M" "G" "T": + if bandwidth_string[-1:] not in set("K" "M" "G" "T"): raise ValueError(msg) try: diff --git a/gso/utils/types/site_name.py b/gso/utils/types/site_name.py index 903b3468..48d91dba 100644 --- a/gso/utils/types/site_name.py +++ b/gso/utils/types/site_name.py @@ -11,7 +11,7 @@ def validate_site_name(site_name: str) -> str: The site name must consist of three uppercase letters, optionally followed by a single digit. """ - pattern = re.compile(r"^[A-Z]{3}[0-9]?$") + pattern = re.compile(r"^[A-Z]{3}\d?$") if not pattern.match(site_name): msg = ( "Enter a valid site name. It must consist of three uppercase letters (A-Z), followed by an optional single " diff --git a/gso/workflows/edge_port/create_edge_port.py b/gso/workflows/edge_port/create_edge_port.py index a62c7147..f715e104 100644 --- a/gso/workflows/edge_port/create_edge_port.py +++ b/gso/workflows/edge_port/create_edge_port.py @@ -154,7 +154,7 @@ def initialize_subscription( subscription.edge_port.ga_id = ga_id subscription.edge_port.mac_address = mac_address partner_name = get_partner_by_id(partner).name - subscription.description = f"Edge Port {name} on {router.router_fqdn}, " f"{partner_name}, {ga_id or ""}" + subscription.description = f"Edge Port {name} on {router.router_fqdn}, {partner_name}, {ga_id or ""}" subscription.edge_port.edge_port_description = description for member in ae_members: subscription.edge_port.edge_port_ae_members.append( diff --git a/gso/workflows/iptrunk/migrate_iptrunk.py b/gso/workflows/iptrunk/migrate_iptrunk.py index 1282f636..83e7000c 100644 --- a/gso/workflows/iptrunk/migrate_iptrunk.py +++ b/gso/workflows/iptrunk/migrate_iptrunk.py @@ -445,7 +445,7 @@ def update_remaining_side_bfd_dry( "verb": "update", "config_object": "bfd_update", "dry_run": True, - "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} " f"- Update BFD config.", + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update BFD config.", } return { @@ -473,7 +473,7 @@ def update_remaining_side_bfd_real( "verb": "update", "config_object": "bfd_update", "dry_run": False, - "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} " f"- Update BFD config.", + "commit_comment": f"GSO_PROCESS_ID: {process_id} - TT_NUMBER: {tt_number} - Update BFD config.", } return { diff --git a/test/fixtures/layer_2_circuit_fixtures.py b/test/fixtures/layer_2_circuit_fixtures.py index 2b93a370..b8772cf4 100644 --- a/test/fixtures/layer_2_circuit_fixtures.py +++ b/test/fixtures/layer_2_circuit_fixtures.py @@ -107,7 +107,7 @@ def layer_2_circuit_subscription_factory(faker, geant_partner, edge_port_subscri subscription.layer_2_circuit.bandwidth = None subscription.layer_2_circuit.policer_burst_rate = None subscription.description = description or ( - f"{subscription.product.name} - " f"{subscription.layer_2_circuit.virtual_circuit_id}" + f"{subscription.product.name} - {subscription.layer_2_circuit.virtual_circuit_id}" ) subscription = SubscriptionModel.from_other_lifecycle(subscription, SubscriptionLifecycle.ACTIVE) -- GitLab