aristanetworks / ansible-cvp

Ansible modules for Arista CloudVision
http://cvp.avd.sh
Apache License 2.0
66 stars 61 forks source link

Bug(cv_device_v3): device decommissioning fails if a device is not streaming and not provisioned #657

Closed noredistribution closed 4 months ago

noredistribution commented 1 year ago

Issue Summary

When trying to decommission devices that are not in Network Provisioning, the decommission fails due to the device checks that we are doing that use older provisioning APIs that always check inventory devices that are in Network Provisioning and disregard devices that are still in telemetry's inventory.

ref: https://github.com/aristanetworks/ansible-cvp/blob/devel/ansible_collections/arista/cvp/plugins/module_utils/device_tools.py#L469 the problem is that all those APIs: get_device_by_name(), get_device_by_mac(), get_device_by_serial() use searchTopology.do which only checks devices that are provisioned

one good way to solve this would be to use the /inventory/devices API call with provisioned=False queryParam aka get_inventory(provisioned=False) from cvprac (not yet merged into mainline) and do lookups locally from memory. That should improve performance and also support decommissioning any device regardless if they are not streaming or not provisioned.

cvprac side PR: https://github.com/aristanetworks/cvprac/pull/253

Which component(s) of AVD impacted

cv_device_v3

How do you run AVD ?

None

Input variables

- name: Decommission device
  hosts: cv_server2
  connection: local
  gather_facts: no
  vars:
    CVP_DEVICES:
      - fqdn: "bii211"
        parentContainerName: ""

  tasks:
  - name: decommission device
    arista.cvp.cv_device_v3:
        devices: '{{CVP_DEVICES}}'
        state: absent

Steps to reproduce

Pick a device that is not streaming, go to Network Provisioning, right click on the device and select remove, click save and then run the above playbook

Relevant log output

TASK [decommission device] **************************************************************************************************************************
Thursday 13 July 2023  23:07:53 +0100 (0:00:01.343)       0:00:25.892 *********
fatal: [cv_server2]: FAILED! => changed=false
  msg: |-
    Error - the following devices do not exist in CVP ['bii211'] but are defined in the playbook.
    Make sure that the devices are provisioned and defined with the full fqdn name                 (including the domain name) if needed.


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 15 days