Skip to content
Snippets Groups Projects
Commit 52058e9d authored by Karel van Klink's avatar Karel van Klink :smiley_cat: Committed by Neda Moeini
Browse files

replace calls to += with append

parent 66ac933a
No related branches found
No related tags found
1 merge request!139Feature/add validation workflows
......@@ -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
......
......@@ -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))
......
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