Skip to content

Commit

Permalink
Test: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Oct 1, 2024
1 parent df9ae0f commit e1ddc0a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,48 @@
- ansible_failed_result is defined
- ansible_failed_result.msg == expected_error_message

- name: Converge Negative tests for 'eos_designs_facts'
hosts: FAILURE-SVI-PARENT-PROFILE-DOES-NOT-EXIST
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_facts'
hosts: FAILURE-SVI-GRANDPARENT-PROFILE-DOES-NOT-EXIST
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
@@ -1,5 +1,6 @@
---
type: l3leaf
fabric_name: FAILURE-SVI-GRANDPARENT-PROFILE-DOES-NOT-EXIST

svi_profiles:
- profile: PROFILE-1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
type: l3leaf
fabric_name: FAILURE-SVI-PARENT-PROFILE-DOES-NOT-EXIST

svi_profiles:
- profile: PROFILE-1
Expand All @@ -24,5 +25,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 @@ -56,6 +56,12 @@ all:
hosts:
downlink-pools-duplicate-spine:
downlink-pools-duplicate-l3leaf:
FAILURE-SVI-PARENT-PROFILE-DOES-NOT-EXIST:
hosts:
failure-svi-parent-profile-does-not-exist:
FAILURE-SVI-GRANDPARENT-PROFILE-DOES-NOT-EXIST:
hosts:
failure-svi-grandparent-profile-does-not-exist:
EOS_DESIGNS_FAILURES: # Add cases that fail during 'eos_designs_structured_config' phase
children:
EOS_DESIGNS_FAILURES_INCLUDED:
Expand Down Expand Up @@ -97,8 +103,6 @@ all:
failure-duplicate-evpn-vlan-bundle-name:
failure-no-local-path-group-in-default-policy:
failure-l3-interface-profile-does-not-exist:
failure-svi-parent-profile-does-not-exist:
failure-svi-grandparent-profile-does-not-exist:
failure-connected-endpoint-port-profile-does-not-exist:
failure-connected-endpoint-parent-port-profile-does-not-exist:
ipv4-acl-in-missing-on-wan-interface:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def render_avd_switch_facts(self, avd_switch_facts_instances: dict) -> dict:
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}'"
msg = f"{e}" if e.custom_message else f"{e} is required but was not found for host '{host}'"
raise AnsibleActionFail(msg) from e

# If the argument 'template_output' is set, run the output data through jinja2 rendering.
Expand Down
4 changes: 3 additions & 1 deletion python-avd/pyavd/_errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def _json_path_to_string(self, json_path: list[str | int]) -> str:


class AristaAvdMissingVariableError(AristaAvdError):
pass
def __init__(self, message: str, *, custom_message: bool = False) -> None:
self.custom_message = custom_message
super().__init__(message)


class AvdSchemaError(AristaAvdError):
Expand Down
4 changes: 2 additions & 2 deletions python-avd/pyavd/_utils/get_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_item(

if (not isinstance(list_of_dicts, list)) or list_of_dicts == [] or value is None or key is None:
if required is True:
raise AristaAvdMissingVariableError(custom_error_msg or var_name)
raise AristaAvdMissingVariableError(custom_error_msg or var_name, custom_message=bool(custom_error_msg))
return default

for list_item in list_of_dicts:
Expand All @@ -71,5 +71,5 @@ def get_item(

# No Match
if required is True:
raise AristaAvdMissingVariableError(custom_error_msg or var_name)
raise AristaAvdMissingVariableError(custom_error_msg or var_name, custom_message=bool(custom_error_msg))
return default

0 comments on commit e1ddc0a

Please sign in to comment.