aristanetworks / ansible-cvp

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

facts_tools.py crashes out if there are stale devices in the inventory #568

Closed colinmacgiolla closed 1 year ago

colinmacgiolla commented 1 year ago

Issue Summary

When decommissioned devices are in the device inventory, the facts module crashes as the cvprac API call api.get_device_image_info(key) returns type None, and this causes an error when returning the info. (Line 465, __device_get_image_bundle_name()).

Simple to fix - we just need an extra check on facts_tools.py, line 465 to handle if cvprac returns type None

Which component(s) of AVD impacted

cv_facts_v3

How do you run AVD ?

Ansible CLI (with virtual-env or native python)

Input variables

{'architecture': '',
 'bootupTimeStamp': 0,
 'bootupTimestamp': 0,
 'complianceCode': '0000',
 'complianceIndication': '',
 'containerName': 'Undefined',
 'danzEnabled': False,
 'dcaKey': None,
 'deviceInfo': 'Registered',
 'deviceStatus': 'Registered',
 'deviceType': '',
 'domainName': '',
 'fqdn': '',
 'hardwareRevision': '',
 'hostname': '',
 'internalBuild': '',
 'internalBuildId': '',
 'internalVersion': '',
 'ipAddress': '10.178.137.231',
 'isDANZEnabled': False,
 'isMLAGEnabled': False,
 'key': '',
 'lastSyncUp': 0,
 'memFree': 0,
 'memTotal': 0,
 'mlagEnabled': False,
 'modelName': '',
 'parentContainerId': 'undefined_container',
 'parentContainerKey': 'undefined_container',
 'serialNumber': 'SCRUBBED',
 'sslConfigAvailable': False,
 'sslEnabledByCVP': False,
 'status': 'Registered',
 'streamingStatus': 'inactive',
 'systemMacAddress': '',
 'taskIdList': [],
 'tempAction': None,
 'type': 'netelement',
 'unAuthorized': False,
 'version': '',
 'ztpMode': True}

Steps to reproduce

>>> for device in inventory:
...    resp = clnt.api.get_device_image_info(device['systemMacAddress'])
...    if resp is None:
...       pprint(device)

Relevant log output

>>> if resp['bundleName'] is not None:
...    print("won't get here")
...
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not subscriptable

Code of Conduct

colinmacgiolla commented 1 year ago

Simple fix e.g. if bundle is not None and bundle['bundleName'] is not None: Will submit the PR later