Repository navigation
Fix(eos_designs): Centralize injection of host-specific info for AristaAvdError and child classes - #6603
Fix(eos_designs): Centralize injection of host-specific info for AristaAvdError and child classes#6603alexeygorbunov wants to merge 17 commits into
Conversation
|
Review docs on Read the Docs To test this pull request: # Create virtual environment for this testing below the current directory
python -m venv test-avd-pr-6603
# Activate the virtual environment
source test-avd-pr-6603/bin/activate
# Install all requirements including PyAVD
pip install "pyavd[ansible] @ git+https://github.com/alexeygorbunov/avd.git@specify-host-when-node_type-not-found#subdirectory=python-avd" --force
# Point Ansible collections path to the Python virtual environment
export ANSIBLE_COLLECTIONS_PATH=$VIRTUAL_ENV/ansible_collections
# Install Ansible collection
python -m ansible.cli.galaxy collection install git+https://github.com/alexeygorbunov/avd.git#/ansible_collections/arista/avd/,specify-host-when-node_type-not-found --force
cd test-avd-pr-6603
# Run your playbook using `python -m ansible.cli.playbook path/to/playbook.yml ...` |
|
|
||
| msg = "No device type found. Either set 'type' or 'default_node_types'." | ||
| msg = f"No device type found for host '{self.hostname}'. Either set 'type' or 'default_node_types'." | ||
| raise AristaAvdInvalidInputsError(msg, host=self.hostname) |
There was a problem hiding this comment.
this showing self.hostname should already have appended the hostname. I am not sure the current fix is the right one. Let me take a further look
There was a problem hiding this comment.
We also seen such thing that when something failed on eos_designs_facts it do not show that which host throw that error. I am saying about eos designs molecule
There was a problem hiding this comment.
we may have missed something in the error handling during the refactoring. Although the expected error in the negative unit test suggests that this has been an issue for a while.
| self.host_context_set = True | ||
| else: | ||
| self.host_context_set = host_context_set | ||
| self.message = message |
There was a problem hiding this comment.
| self.message = message | |
| class AristaAvdHostError(AristaAvdError): | |
| host: str | |
| def __init__(self, message: str, host: str ) -> None: | |
| self.host = host ... | |
| self.message = f"{message} for host {host}." | |
| super().__init__(self.message, host = self.host) |
- class AristaAvdInvalidInputsError(AristaAvdError):
- ...
+ class AristaAvdInvalidInputsError(AristaAvdHostError):
+ passThere was a problem hiding this comment.
Implemented as suggested, except re-defining host for AristaAvdHostError as pyright doesn't like it
| @@ -81,8 +81,7 @@ def get_facts( | |||
| raise AristaAvdMissingVariableError(variable=e.variable, host=e.host or hostname) from e | |||
| except AristaAvdError as e: | |||
There was a problem hiding this comment.
| except AristaAvdError as e: | |
| except AristaAvdHostError: | |
| raise | |
| except AristaAvdError as e: | |
| # keep what's there |
There was a problem hiding this comment.
maybe you can remove all the try / except here and let's see the changes in the error messages
There was a problem hiding this comment.
Removed try/except
for more information, see https://pre-commit.ci
|
|
||
|
|
||
| def __init__(self, message: str, host: str | None = None) -> None: | ||
| class AristaAvdInvalidInputsError(AristaAvdHostError): |
There was a problem hiding this comment.
I think the AristaAvdMissingVariableError should also inherit from the AristaAvdHostError
| class AristaAvdInvalidInputsError(AristaAvdError): | ||
| host: str | None | ||
| class AristaAvdHostError(AristaAvdError): | ||
| def __init__(self, message: str, host: str = "") -> None: |
There was a problem hiding this comment.
why do you need a default here? (maybe thats required but just checking :) )
There was a problem hiding this comment.
This is for the error message cases where "impacted" host is already mentioned in the body of the message and we don't want to prepend it again to the message. I could either pass host="" explicitly on the "calling" sides or just have host="" as a default in error class definition.
But another option is to review all places where we are raising those exceptions and to make sure they all use the same "pattern" (like they shouldn't be mentioning problematic host in the body of the message is we are supposed to prepand it later anyway)
There was a problem hiding this comment.
yup makes sense so a possible way forward is that we do not update the message and in facts and wherever we need to add the hostname (bvecause we are running with run_once and we cannot know) we do it using the e.host to render the error message like we want.
Right now having it everywhere is actually (as we can see in the changes) going to render stuff like this:
fatal: [cv-pathfinder-edge1 -> localhost]: FAILED! => {"changed": false, "msg": "'ipv4_acl_in' must be set on WAN interfaces where 'wan_carrier' is set, unless the carrier is configured as 'trusted' under 'wan_carriers'. 'ipv4_acl_in' is missing on L3 interface 'Ethernet1/49.3' for host cv-pathfinder-edge1 ."}
for every failure in structured config which is a bit overkill today. What do you think? (I know this is going back and forth a bit :) )
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Conflicts have been resolved. A maintainer will review the pull request shortly. |
|
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
please address comments and resolve conflicts. Moving to draft for now, so please set it ready for review when done. |
|
Conflicts have been resolved. A maintainer will review the pull request shortly. |
|
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |



Change Summary
When host is specified in the inventory but it's group/host vars are missing
type- AVD raises AristaAvdInvalidInputsError pointing to the host used byrun_oncetask and not providing any info regarding the host that actually misses type definition:No device type found. Either set 'type' or 'default_node_types'.In some other cases - impacted host is specified twice or incorrect host is specified instead of the one triggering the issue
Related Issue(s)
Fixes #
Component(s) name
arista.avd.avd_designsProposed changes
host_context_set: boolflag to AristaAvdError and use it as a trigger hor appending host-related suffix to the messagesHow to test
Pytest: eos_designs_negative_unit_tests
Checklist
User Checklist
Repository Checklist