Skip to content

Commit

Permalink
Refactor(eos_designs): Better error messages for missing keys (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc authored Oct 7, 2024
1 parent 5abfaec commit 574cc58
Show file tree
Hide file tree
Showing 62 changed files with 296 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,27 @@
- ansible_failed_result is defined
- ansible_failed_result.msg == expected_error_message

- name: Converge Negative tests for 'eos_designs_facts'
hosts: FAILURE_CONNECTED_ENDPOINT_PORT_PROFILE_DOES_NOT_EXIST_IN_FACTS
connection: local
tasks:
- name: Run failure scenario Test
block:
- name: Trigger Error
ansible.builtin.import_role:
name: arista.avd.eos_designs
rescue:
- name: Error message
run_once: true
ansible.builtin.debug:
var: ansible_failed_result.msg
- name: Assert eos_designs failed with the expected error message
run_once: true
ansible.builtin.assert:
that:
- ansible_failed_result is defined
- ansible_failed_result.msg == expected_error_message

- name: Converge Negative tests for 'eos_designs_structured_config'
hosts: EOS_DESIGNS_FAILURES_INCLUDED
gather_facts: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ l3leaf:
uplink_switch_interfaces: [Ethernet3]

expected_error_message: >-
Unexpected failure during module execution: Unable to assign IPs for uplinks. 'uplink_ipv4_pool' (10.0.2.0/24)
on this switch cannot be combined with 'downlink_pools' (10.0.2.0/24) on any uplink switch.
Unable to assign IPs for uplinks. 'uplink_ipv4_pool' (10.0.2.0/24) on this switch cannot be combined with
'downlink_pools' (10.0.2.0/24) on any uplink switch for host 'downlink-pools-duplicate-l3leaf'.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ l3leaf:

expected_error_message: >-
Unable to assign IPs for uplinks. Either 'uplink_ipv4_pool' on this switch or 'downlink_pools' on
all the uplink switches is required but was not found for host 'downlink-pools-missing-l3leaf'
all the uplink switches must be set for host 'downlink-pools-missing-l3leaf'.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ l3leaf:
- group: MLAG_PAIR
bgp_as: 65123
nodes:
- name: invalid-uplink-port-channel-id-l3leaf-1
- name: invalid-uplink-port-channel-id-1-l3leaf-1
id: 1
- name: invalid-uplink-port-channel-id-l3leaf-2
- name: invalid-uplink-port-channel-id-1-l3leaf-2
id: 2

l2leaf:
defaults:
mlag_peer_ipv4_pool: 10.0.2.0/24
mlag_interfaces: [Ethernet3-4]
uplink_interfaces: [Ethernet1-2]
uplink_switches: [invalid-uplink-port-channel-id-l3leaf-1, invalid-uplink-port-channel-id-l3leaf-2]
uplink_switches: [invalid-uplink-port-channel-id-1-l3leaf-1, invalid-uplink-port-channel-id-1-l3leaf-2]
uplink_port_channel_id: 2001 # <<<<< invalid ID
node_groups:
- group: MLAG_PAIR
nodes:
- name: invalid-uplink-port-channel-id-l2leaf-1
- name: invalid-uplink-port-channel-id-1-l2leaf-1
uplink_switch_interfaces: [Ethernet1, Ethernet1]
id: 1
- name: invalid-uplink-port-channel-id-l2leaf-2
- name: invalid-uplink-port-channel-id-1-l2leaf-2
uplink_switch_interfaces: [Ethernet2, Ethernet2]
id: 2

expected_error_message: >-
Unexpected failure during module execution: 'uplink_port_channel_id' must be between 1 and 2000 for MLAG switches.
Got '2001' on 'invalid-uplink-port-channel-id-l2leaf-1'.
'uplink_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '2001' for host 'invalid-uplink-port-channel-id-1-l2leaf-1'.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@ l3leaf:
- group: MLAG_PAIR
bgp_as: 65123
nodes:
- name: invalid-uplink-port-channel-id-l3leaf-1
- name: invalid-uplink-port-channel-id-2-l3leaf-1
id: 1
- name: invalid-uplink-port-channel-id-l3leaf-2
- name: invalid-uplink-port-channel-id-2-l3leaf-2
id: 2

l2leaf:
defaults:
mlag_peer_ipv4_pool: 10.0.2.0/24
mlag_interfaces: [Ethernet3-4]
uplink_interfaces: [Ethernet1-2]
uplink_switches: [invalid-uplink-port-channel-id-l3leaf-1, invalid-uplink-port-channel-id-l3leaf-2]
uplink_switches: [invalid-uplink-port-channel-id-2-l3leaf-1, invalid-uplink-port-channel-id-2-l3leaf-2]
uplink_switch_port_channel_id: 2001 # <<<<< invalid ID
node_groups:
- group: MLAG_PAIR
nodes:
- name: invalid-uplink-port-channel-id-l2leaf-1
- name: invalid-uplink-port-channel-id-2-l2leaf-1
uplink_switch_interfaces: [Ethernet1, Ethernet1]
id: 1
- name: invalid-uplink-port-channel-id-l2leaf-2
- name: invalid-uplink-port-channel-id-2-l2leaf-2
uplink_switch_interfaces: [Ethernet2, Ethernet2]
id: 2

expected_error_message: >-
Unexpected failure during module execution: 'uplink_switch_port_channel_id' must be between 1 and 2000 for MLAG switches.
Got '2001' on 'invalid-uplink-port-channel-id-l2leaf-1'.
'uplink_switch_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '2001' for host 'invalid-uplink-port-channel-id-2-l2leaf-1'.
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,28 @@ l3leaf:
- group: MLAG_PAIR
bgp_as: 65123
nodes:
- name: invalid-uplink-port-channel-id-l3leaf-1
- name: invalid-uplink-port-channel-id-3-l3leaf-1
id: 1
- name: invalid-uplink-port-channel-id-l3leaf-2
- name: invalid-uplink-port-channel-id-3-l3leaf-2
id: 2

l2leaf:
defaults:
mlag_peer_ipv4_pool: 10.0.2.0/24
mlag_interfaces: [Ethernet3-4]
uplink_interfaces: [Ethernet1-2]
uplink_switches: [invalid-uplink-port-channel-id-l3leaf-1, invalid-uplink-port-channel-id-l3leaf-2]
uplink_switches: [invalid-uplink-port-channel-id-3-l3leaf-1, invalid-uplink-port-channel-id-3-l3leaf-2]
node_groups:
- group: MLAG_PAIR
nodes:
- name: invalid-uplink-port-channel-id-l2leaf-1
- name: invalid-uplink-port-channel-id-3-l2leaf-1
uplink_switch_interfaces: [Ethernet1, Ethernet1]
id: 1
- name: invalid-uplink-port-channel-id-l2leaf-2
- name: invalid-uplink-port-channel-id-3-l2leaf-2
uplink_port_channel_id: 1234 # <<<<< valid ID but set to a different value than primary node
uplink_switch_interfaces: [Ethernet2, Ethernet2]
id: 2

expected_error_message: >-
Unexpected failure during module execution: 'uplink_port_channel_id' on 'invalid-uplink-port-channel-id-l2leaf-2'
is set to 1234 and is not matching 1 set on MLAG peer.
The 'uplink_port_channel_id' must be matching on MLAG peers.
'uplink_port_channel_id' is set to 1234 and is not matching 1 set on MLAG peer.
The 'uplink_port_channel_id' must be matching on MLAG peers for host 'invalid-uplink-port-channel-id-3-l2leaf-2'.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ l3leaf:
id: 3
mgmt_ip: 192.168.201.117/24

expected_error_message: "Unexpected failure during module execution: MLAG compact addressing mode requires all MLAG pairs to have a single odd and even ID"
expected_error_message: >-
MLAG compact addressing mode requires all MLAG pairs to have a single odd and even ID for host 'mlag_odd_id_oddodd1'.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ l3leaf:
id: 2
mgmt_ip: 192.168.201.117/24

expected_error_message: "Unexpected failure during module execution: MLAG same_subnet addressing requires the pool to be a /31"
expected_error_message: >-
MLAG same_subnet addressing requires the pool to be a /31 for host 'mlag_same_subnet_1'.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ port_profiles:
native_vlan: 123

expected_error_message: >-
Profile 'INDIVIDUAL_TRUNK' applied under 'server[INDIVIDUAL_1].adapters[0].port_channel.lacp_fallback.individual' does not exist in `port_profiles`.
Profile 'INDIVIDUAL_TRUNK' applied under 'server[name=INDIVIDUAL_1].adapters[0].port_channel.lacp_fallback.individual' does not exist in `port_profiles`.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ servers:
profile: THIS-PROFILE-DOES-NOT-EXIST

expected_error_message: >-
PTP Profile 'THIS-PROFILE-DOES-NOT-EXIST' referenced under server[INDIVIDUAL_1].adapters[0]
PTP Profile 'THIS-PROFILE-DOES-NOT-EXIST' referenced under server[name=INDIVIDUAL_1].adapters[0]
does not exist in `ptp_profiles`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
type: l3leaf
fabric_name: FAILURE_CONNECTED_ENDPOINT_PORT_PROFILE_DOES_NOT_EXIST_IN_FACTS

port_profiles:
- profile: PROFILE-1

l3leaf:
nodes:
- name: failure-connected-endpoint-port-profile-does-not-exist-in-facts
loopback_ipv4_pool: 192.168.42.0/24
vtep_loopback_ipv4_pool: 192.168.255.0/24
bgp_as: 65042
id: 1
filter:
only_vlans_in_use: True

servers:
- name: TEST-ENDPOINT
adapters:
- switches: [failure-connected-endpoint-port-profile-does-not-exist-in-facts]
switch_ports: [Ethernet9]
profile: THIS-PROFILE-DOES-NOT-EXIST
# Setting VLANs to trigger merging of adapters in facts phase
vlans: :42,666"

expected_error_message: >-
Profile 'THIS-PROFILE-DOES-NOT-EXIST' applied under 'servers[name=TEST-ENDPOINT].adapters[0]'
does not exist in `port_profiles` for host 'failure-connected-endpoint-port-profile-does-not-exist-in-facts'.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ servers:
profile: THIS-PROFILE-DOES-NOT-EXIST

expected_error_message: >-
Profile 'THIS-PROFILE-DOES-NOT-EXIST' applied under 'servers[TEST-ENDPOINT].adapters[0]'
Profile 'THIS-PROFILE-DOES-NOT-EXIST' applied under 'servers[name=TEST-ENDPOINT].adapters[0]'
does not exist in `port_profiles`.
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ tenants:
- node: failure-svi-parent-profile-does-not-exist

expected_error_message: >-
Profile 'THIS-PROFILE-DOES-NOT-EXIST' applied under SVI 'TEST-SVI' does
not exist in `svi_profiles`.
Profile 'THIS-PROFILE-DOES-NOT-EXIST' applied under SVI 'TEST-SVI' does not exist in `svi_profiles`.
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ not_underlay_router:
- name: invalid-uplink-type-p2p-vrfs-underlay-router-false

expected_error_message: >-
Unexpected failure during module execution: 'underlay_router' and 'network_services.l3'
must be 'true' for the node_type_key when using 'p2p-vrfs' as 'uplink_type'.
'underlay_router' and 'network_services.l3' must be 'true' for the node_type_key when using
'p2p-vrfs' as 'uplink_type' for host 'invalid-uplink-type-p2p-vrfs-underlay-router-false'.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ application_classification:
- name: TEST

expected_error_message: >-
Missing mandatory `id` in `wan_virtual_topologies.policies[DEFAULT-POLICY].application_virtual_topologies[TEST]` when `wan_mode` is 'cv-pathfinder
Missing mandatory `id` in `wan_virtual_topologies.policies[DEFAULT-POLICY].application_virtual_topologies[TEST]` when `wan_mode` is 'cv-pathfinder.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ l2leaf:
expected_error_message: >-
Facts not found for node 'some-missing-device'. Something in the input vars is pointing to this node.
Check that 'some-missing-device' is in the inventory and is part of the group set by 'fabric_name'.
Node is required but was not found for host 'missing-mlag-peer'
Node is required for host 'missing-mlag-peer'.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ wan_carriers:
path_group: INET
trusted: true

expected_error_message: "ipv4_prefix_list_catalog[name=PL1]"
expected_error_message: >-
'ipv4_prefix_list_catalog[name=PL1]' is required but was not found.
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@ all:
invalid-schema-connected-endpoints:
FABRIC_INVALID_UPLINK_PORT_CHANNEL_ID_1:
hosts:
invalid-uplink-port-channel-id-l3leaf-1:
invalid-uplink-port-channel-id-l3leaf-2:
invalid-uplink-port-channel-id-l2leaf-1:
invalid-uplink-port-channel-id-l2leaf-2:
invalid-uplink-port-channel-id-1-l3leaf-1:
invalid-uplink-port-channel-id-1-l3leaf-2:
invalid-uplink-port-channel-id-1-l2leaf-1:
invalid-uplink-port-channel-id-1-l2leaf-2:
FABRIC_INVALID_UPLINK_PORT_CHANNEL_ID_2:
# Notice the same hosts since all vars are given in group var
hosts:
invalid-uplink-port-channel-id-l3leaf-1:
invalid-uplink-port-channel-id-l3leaf-2:
invalid-uplink-port-channel-id-l2leaf-1:
invalid-uplink-port-channel-id-l2leaf-2:
invalid-uplink-port-channel-id-2-l3leaf-1:
invalid-uplink-port-channel-id-2-l3leaf-2:
invalid-uplink-port-channel-id-2-l2leaf-1:
invalid-uplink-port-channel-id-2-l2leaf-2:
FABRIC_INVALID_UPLINK_PORT_CHANNEL_ID_3:
# Notice the same hosts since all vars are given in group var
hosts:
invalid-uplink-port-channel-id-l3leaf-1:
invalid-uplink-port-channel-id-l3leaf-2:
invalid-uplink-port-channel-id-l2leaf-1:
invalid-uplink-port-channel-id-l2leaf-2:
invalid-uplink-port-channel-id-3-l2leaf-1:
invalid-uplink-port-channel-id-3-l3leaf-1:
invalid-uplink-port-channel-id-3-l3leaf-2:
invalid-uplink-port-channel-id-3-l2leaf-2:
FABRIC_WAN_ROLE_OVERLAY_ROUTING_PROTOCOL:
hosts:
invalid-wan-role-overlay-routing-protocol:
Expand All @@ -56,6 +54,9 @@ all:
hosts:
downlink-pools-duplicate-spine:
downlink-pools-duplicate-l3leaf:
FAILURE_CONNECTED_ENDPOINT_PORT_PROFILE_DOES_NOT_EXIST_IN_FACTS:
hosts:
failure-connected-endpoint-port-profile-does-not-exist-in-facts:
EOS_DESIGNS_FAILURES: # Add cases that fail during 'eos_designs_structured_config' phase
children:
EOS_DESIGNS_FAILURES_INCLUDED:
Expand Down Expand Up @@ -89,20 +90,20 @@ all:
duplicate-interfaces-underlay:
duplicate-ip-address-uplink-switch-router-bgp:
duplicate-tunnel-interface-internet-exit:
failure-adapter-ptp-profile-does-not-exist:
failure-connected-endpoint-port-profile-does-not-exist:
failure-connected-endpoint-parent-port-profile-does-not-exist:
failure-connected-endpoint-port-profile-does-not-exist:
failure-duplicate-evpn-vlan-bundle-name:
failure-l3-interface-profile-does-not-exist:
failure-missing-evpn-vlan-bundle:
failure-missing-evpn-vlan-bundle_svi:
failure-missing-evpn-multicast-l3-with-pim:
failure-missing-evpn-multicast-peg-rps:
failure-missing-evpn-multicast-with-pim:
failure-network-port-ptp-profile-does-not-exist:
failure-no-local-path-group-in-default-policy:
failure-ptp-profile-does-not-exist:
failure-svi-parent-profile-does-not-exist:
failure-adapter-ptp-profile-does-not-exist:
failure-svi-grandparent-profile-does-not-exist:
failure-svi-parent-profile-does-not-exist:
ipv4-acl-in-missing-on-wan-interface:
ipv4-acls:
isis-system-id-format-missing-node-id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
try:
from pyavd._eos_designs.eos_designs_facts import EosDesignsFacts
from pyavd._eos_designs.shared_utils import SharedUtils
from pyavd._errors import AristaAvdMissingVariableError
from pyavd._errors import AristaAvdError
except ImportError as e:
EosDesignsFacts = SharedUtils = RaiseOnUse(
AnsibleActionFail(
Expand Down Expand Up @@ -194,9 +194,9 @@ def render_avd_switch_facts(self, avd_switch_facts_instances: dict) -> dict:
for host in avd_switch_facts_instances:
try:
rendered_facts[host] = {"switch": avd_switch_facts_instances[host]["switch"].render()}
except AristaAvdMissingVariableError as e:
msg = f"{e} is required but was not found for host '{host}'"
raise AnsibleActionFail(msg) from e
except AristaAvdError as e:
message = f"{str(e).removesuffix('.')} for host '{host}'."
raise AnsibleActionFail(message=message) from e

# If the argument 'template_output' is set, run the output data through jinja2 rendering.
# This is to resolve any input values with inline jinja using variables/facts set by eos_designs_facts.
Expand Down
15 changes: 5 additions & 10 deletions python-avd/pyavd/_eos_designs/eos_designs_facts/uplinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def _uplink_port_channel_id(self: EosDesignsFacts) -> int:
# check that port-channel IDs are the same as on primary
if uplink_port_channel_id is not None and uplink_port_channel_id != peer_uplink_port_channel_id:
msg = (
f"'uplink_port_channel_id' on '{self.shared_utils.hostname}' is set to {uplink_port_channel_id} and is not matching"
f" {peer_uplink_port_channel_id} set on MLAG peer."
f"'uplink_port_channel_id' is set to {uplink_port_channel_id} and is not matching {peer_uplink_port_channel_id} set on MLAG peer."
" The 'uplink_port_channel_id' must be matching on MLAG peers."
)
raise AristaAvdError(msg)
Expand All @@ -67,7 +66,7 @@ def _uplink_port_channel_id(self: EosDesignsFacts) -> int:

# produce an error if the switch is MLAG and port-channel ID is above 2000
if self.shared_utils.mlag and not 1 <= uplink_port_channel_id <= 2000:
msg = f"'uplink_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '{uplink_port_channel_id}' on '{self.shared_utils.hostname}'."
msg = f"'uplink_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '{uplink_port_channel_id}'."
raise AristaAvdError(msg)

return uplink_port_channel_id
Expand All @@ -93,9 +92,8 @@ def _uplink_switch_port_channel_id(self: EosDesignsFacts) -> int:
# check that port-channel IDs are the same as on primary
if uplink_switch_port_channel_id is not None and uplink_switch_port_channel_id != peer_uplink_switch_port_channel_id:
msg = (
f"'uplink_switch_port_channel_id'expected_error_message on '{self.shared_utils.hostname}' is set to {uplink_switch_port_channel_id} and"
f" is not matching {peer_uplink_switch_port_channel_id} set on MLAG peer. The 'uplink_switch_port_channel_id' must be matching on MLAG"
" peers."
f"'uplink_switch_port_channel_id' is set to {uplink_switch_port_channel_id} and is not matching {peer_uplink_switch_port_channel_id} "
"set on MLAG peer. The 'uplink_switch_port_channel_id' must be matching on MLAG peers."
)
raise AristaAvdError(msg)
return peer_uplink_switch_port_channel_id
Expand All @@ -109,10 +107,7 @@ def _uplink_switch_port_channel_id(self: EosDesignsFacts) -> int:
uplink_switch_facts: EosDesignsFacts = self.shared_utils.get_peer_facts(self.shared_utils.uplink_switches[0], required=True)

if uplink_switch_facts.shared_utils.mlag and not 1 <= uplink_switch_port_channel_id <= 2000:
msg = (
f"'uplink_switch_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '{uplink_switch_port_channel_id}' on"
f" '{self.shared_utils.hostname}'."
)
msg = f"'uplink_switch_port_channel_id' must be between 1 and 2000 for MLAG switches. Got '{uplink_switch_port_channel_id}'."
raise AristaAvdError(msg)

return uplink_switch_port_channel_id
Expand Down
Loading

0 comments on commit 574cc58

Please sign in to comment.