Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anta): use aioeapi to handle a device session #122

Merged
merged 35 commits into from
Jan 4, 2023

Conversation

mtache
Copy link
Collaborator

@mtache mtache commented Sep 19, 2022

Using asyncio framework will help improving performances when running tests on a large network with a high number of tests.
First step is to refactor the anta.inventory module to use an async library, this PR tries an attempt with aio-eapi.
This PR must also refactor all the tests as coroutines and modify the scripts to run the asyncio event loop.


Modifications to anta.inventory

The session attribute of InventoryDevice is now a aioeapi.Device object.
auto_connect is removed from the constructor: this would cause to run an asyncio event loop in an object constructor and prevent fine control from a ANTA user script on the asyncio scheduling.

_is_device_online() uses aioeapi.Device.check_connection() to only tries to open a port on the device.
_ refresh_device_fact() updates all the device flags and reduce the number of API calls compared to the previous implementation.

connect_inventory() is a coroutine that needs to be called in a ANTA user script to establish connection towards the devices.

async def main():
   await anta_inventory.connect_inventory()

When using a containerlab topology on macOS, we need to use port forwarding to localhost to access eAPI endpoints.
The current inventory only supports IP addresses. This PR supports hostnames (DNS names instead of IP), ports and alias names in the inventory.

The following inventory works with this PR:

anta_inventory:
  hosts:
  - name: spine1
    host: localhost
    port: 44301
  - name: spine2
    host: localhost
    port: 44302
  - name: leaf1
    host: localhost
    port: 44311
  - name: leaf1
    host: localhost
    port: 44312
  - name: leaf3
    host: localhost
    port: 44313
  - name: leaf4
    host: localhost
    port: 44314

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

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

@github-actions
Copy link
Contributor

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

… (DNS names, not only IP) and device alias names.
… (DNS names, not only IP) and device alias names.
…odel validator.

feat(anta.inventory): remove eAPIUrl model. Build device session in model validator.

lint inventory
Copy link
Collaborator

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

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

LGTM but someone should try it on some env ;)

@mtache mtache merged commit 6d50ac7 into aristanetworks:master Jan 4, 2023
@mtache mtache deleted the asyncio branch January 4, 2023 17:51
@titom73 titom73 changed the title feat(anta.inventory): use aioeapi to handle a device session feat(anta): use aioeapi to handle a device session Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants