Skip to content

Fix(eos_designs): Centralize injection of host-specific info for AristaAvdError and child classes - #6603

Closed
alexeygorbunov wants to merge 17 commits into
aristanetworks:develfrom
alexeygorbunov:specify-host-when-node_type-not-found
Closed

alexeygorbunov wants to merge 17 commits into
aristanetworks:develfrom
alexeygorbunov:specify-host-when-node_type-not-found

Conversation

@alexeygorbunov

@alexeygorbunov alexeygorbunov commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

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 by run_once task 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_designs

Proposed changes

  • Add host_context_set: bool flag to AristaAvdError and use it as a trigger hor appending host-related suffix to the messages
  • Modify some message patterns

How to test

Pytest: eos_designs_negative_unit_tests

Checklist

User Checklist

  • N/A

Repository Checklist

  • My code has been rebased from devel before I start
  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation and documentation have been updated accordingly.
  • I have updated molecule CI testing accordingly. (check the box if not applicable)

@github-actions

Copy link
Copy Markdown

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 ...`

@github-actions github-actions Bot added the state: CI Updated CI scenario have been updated in the PR label Feb 25, 2026
@alexeygorbunov
alexeygorbunov marked this pull request as ready for review February 25, 2026 05:17
@alexeygorbunov
alexeygorbunov requested review from a team as code owners February 25, 2026 05:17

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ClausHolbechArista ClausHolbechArista Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alexeygorbunov alexeygorbunov changed the title Fix(eos_designs): Expose hostnames for hosts with no found type Fix(eos_designs): Centralize injection of host-specific info for AristaAvdError and child classes Feb 26, 2026
Comment thread python-avd/pyavd/_errors/__init__.py Outdated
self.host_context_set = True
else:
self.host_context_set = host_context_set
self.message = message

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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):
+    pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except AristaAvdError as e:
except AristaAvdHostError:
raise
except AristaAvdError as e:
# keep what's there

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can remove all the try / except here and let's see the changes in the error messages

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed try/except



def __init__(self, message: str, host: str | None = None) -> None:
class AristaAvdInvalidInputsError(AristaAvdHostError):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the AristaAvdMissingVariableError should also inherit from the AristaAvdHostError

Comment thread python-avd/pyavd/_errors/__init__.py Outdated
class AristaAvdInvalidInputsError(AristaAvdError):
host: str | None
class AristaAvdHostError(AristaAvdError):
def __init__(self, message: str, host: str = "") -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need a default here? (maybe thats required but just checking :) )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :) )

@github-actions github-actions Bot added the state: conflict PR with conflict label Mar 3, 2026
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

github-actions Bot commented Mar 4, 2026

Copy link
Copy Markdown

Conflicts have been resolved. A maintainer will review the pull request shortly.

@github-actions github-actions Bot removed the state: conflict PR with conflict label Mar 4, 2026
@carl-baillargeon
carl-baillargeon requested a review from gmuloc March 5, 2026 18:37
@sonarqubecloud

Copy link
Copy Markdown

@github-actions github-actions Bot added the state: conflict PR with conflict label Mar 17, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@ClausHolbechArista

Copy link
Copy Markdown
Contributor

please address comments and resolve conflicts. Moving to draft for now, so please set it ready for review when done.

@ClausHolbechArista
ClausHolbechArista marked this pull request as draft April 14, 2026 08:24
@github-actions github-actions Bot removed the state: conflict PR with conflict label May 7, 2026
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Conflicts have been resolved. A maintainer will review the pull request shortly.

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

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 ☂️

@github-actions github-actions Bot added the state: conflict PR with conflict label May 12, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: CI Updated CI scenario have been updated in the PR state: conflict PR with conflict

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants