From 52058e9d3567577d0103b4b4c5a82ad0bd731b47 Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Tue, 30 Apr 2024 12:35:49 +0200 Subject: [PATCH] replace calls to += with append --- gso/services/librenms_client.py | 4 +- gso/workflows/iptrunk/validate_iptrunk.py | 80 ++++++++++------------- 2 files changed, 35 insertions(+), 49 deletions(-) diff --git a/gso/services/librenms_client.py b/gso/services/librenms_client.py index 749974f1..5ade04c6 100644 --- a/gso/services/librenms_client.py +++ b/gso/services/librenms_client.py @@ -102,10 +102,10 @@ class LibreNMSClient: device = self.get_device(fqdn) if device["devices"][0]["hostname"] != fqdn: - errors += ["Device hostname in LibreNMS does not match FQDN."] + errors.append("Device hostname in LibreNMS does not match FQDN.") except HTTPError as e: if e.response.status_code == HTTPStatus.NOT_FOUND: - errors += ["Device does not exist in LibreNMS."] + errors.append("Device does not exist in LibreNMS.") else: raise diff --git a/gso/workflows/iptrunk/validate_iptrunk.py b/gso/workflows/iptrunk/validate_iptrunk.py index 4f3327de..f03dbb7e 100644 --- a/gso/workflows/iptrunk/validate_iptrunk.py +++ b/gso/workflows/iptrunk/validate_iptrunk.py @@ -42,13 +42,11 @@ def verify_ipam_records(subscription: Iptrunk) -> None: ipam_v6_network = infoblox.find_network_by_cidr(subscription.iptrunk.iptrunk_ipv6_network) if not ipam_v4_network or not ipam_v6_network: - ipam_errors += [ - ( - "Missing IP trunk IPAM records, found the following instead.\n" - f"IPv4 expected '{subscription.iptrunk.iptrunk_ipv4_network}', actual: '{ipam_v4_network}'\n" - f"IPv6 expected '{subscription.iptrunk.iptrunk_ipv6_network}', actual: '{ipam_v6_network}'" - ) - ] + ipam_errors.append( + "Missing IP trunk IPAM records, found the following instead.\n" + f"IPv4 expected '{subscription.iptrunk.iptrunk_ipv4_network}', actual: '{ipam_v4_network}'\n" + f"IPv6 expected '{subscription.iptrunk.iptrunk_ipv6_network}', actual: '{ipam_v6_network}'" + ) for index, side in enumerate(subscription.iptrunk.iptrunk_sides): lag_fqdn = f"{side.iptrunk_side_ae_iface}.{side.iptrunk_side_node.router_fqdn}" @@ -57,48 +55,40 @@ def verify_ipam_records(subscription: Iptrunk) -> None: # Validate IPv4 address allocation record = infoblox.find_host_by_fqdn(lag_fqdn) if not record: - ipam_errors += [f"No IPv4 host record found with FQDN '{lag_fqdn}'"] + ipam_errors.append(f"No IPv4 host record found with FQDN '{lag_fqdn}'") else: # Allocation inside IPv4 network must be correct if str(side_v4) != record.ipv4addr: - ipam_errors += [ - ( - f"Incorrectly allocated host record for FQDN '{lag_fqdn}'.\n" - f"Expected '{side_v4}', actual: '{record.ipv4addr}'" - ) - ] + ipam_errors.append( + f"Incorrectly allocated host record for FQDN '{lag_fqdn}'.\n" + f"Expected '{side_v4}', actual: '{record.ipv4addr}'" + ) # Allocated host record needs to be set correctly if record.comment != str(subscription.subscription_id): - ipam_errors += [ - ( - f"Incorrect host record found for '{lag_fqdn}' at '{side_v4}'. Comment should have been equal " - f"to subscription ID '{subscription.subscription_id}'." - ) - ] + ipam_errors.append( + f"Incorrect host record found for '{lag_fqdn}' at '{side_v4}'. Comment should have been equal " + f"to subscription ID '{subscription.subscription_id}'." + ) # Validate IPv6 address allocation record = infoblox.find_v6_host_by_fqdn(lag_fqdn) if not record: - ipam_errors += [f"No IPv6 host record found with FQDN '{lag_fqdn}'"] + ipam_errors.append(f"No IPv6 host record found with FQDN '{lag_fqdn}'") else: # Allocation inside IPv6 network must be correct if str(side_v6) != record.ipv6addr: - ipam_errors += [ - ( - f"Incorrectly allocated host record for FQDN '{lag_fqdn}'.\n" - f"Expected '{side_v6}', actual: '{record.ipv6addr}'" - ) - ] + ipam_errors.append( + f"Incorrectly allocated host record for FQDN '{lag_fqdn}'.\n" + f"Expected '{side_v6}', actual: '{record.ipv6addr}'" + ) # Allocated host record needs to be set correctly if record.comment != str(subscription.subscription_id): - ipam_errors += [ - ( - f"Incorrect host record found for '{lag_fqdn}' at '{side_v6}'. Comment should have been equal " - f"to subscription ID '{subscription.subscription_id}'." - ) - ] + ipam_errors.append( + f"Incorrect host record found for '{lag_fqdn}' at '{side_v6}'. Comment should have been equal " + f"to subscription ID '{subscription.subscription_id}'." + ) if ipam_errors: raise ProcessFailureError(message="IPAM misconfiguration(s) found", details=str(ipam_errors)) @@ -116,27 +106,23 @@ def verify_netbox_entries(subscription: Iptrunk) -> None: side.iptrunk_side_ae_iface, side.iptrunk_side_node.router_fqdn ) if interface.description != str(subscription.subscription_id): - netbox_errors += [ - ( - f"Incorrect description for '{side.iptrunk_side_ae_iface}', expected " - f"'{subscription.subscription_id}' but got '{interface.description}'" - ) - ] + netbox_errors.append( + f"Incorrect description for '{side.iptrunk_side_ae_iface}', expected " + f"'{subscription.subscription_id}' but got '{interface.description}'" + ) if not interface.enabled: - netbox_errors += [f"NetBox interface '{side.iptrunk_side_ae_iface}' is not enabled."] + netbox_errors.append(f"NetBox interface '{side.iptrunk_side_ae_iface}' is not enabled.") for member in side.iptrunk_side_ae_members: interface = nbclient.get_interface_by_name_and_device( member.interface_name, side.iptrunk_side_node.router_fqdn ) if interface.description != str(subscription.subscription_id): - netbox_errors += [ - ( - f"Incorrect description for '{member.interface_name}', expected " - f"'{subscription.subscription_id}' but got '{interface.description}'" - ) - ] + netbox_errors.append( + f"Incorrect description for '{member.interface_name}', expected " + f"'{subscription.subscription_id}' but got '{interface.description}'" + ) if not interface.enabled: - netbox_errors += [f"NetBox interface '{side.iptrunk_side_ae_iface}' is not enabled."] + netbox_errors.append(f"NetBox interface '{side.iptrunk_side_ae_iface}' is not enabled.") if netbox_errors: raise ProcessFailureError(message="NetBox misconfiguration(s) found", details=str(netbox_errors)) -- GitLab