aristanetworks / ansible-cvp

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

cv_facts_v3: Expired CVP token gives unclear error message #675

Closed emilarista closed 7 months ago

emilarista commented 9 months ago

Issue Summary

Trying to authenticate with an expired cvp service account token while using the cv_facts_v3 module causes a misleading error message: "UnboundLocalError: local variable 'cv_devices' referenced before assignment" observed with CVP version 2022.2.2

it would be nice to have a clearer error message to indicate an authentication issue.

This is the environment where it was observed:

$ python3.9 --version
Python 3.9.16

$ pip3 freeze output
cffi==1.11.5
chardet==3.0.4
configobj==5.0.6
cryptography==3.2.1
dbus-python==1.2.4
decorator==4.2.1
ethtool==0.14
file-magic==0.3.0
gpg==1.13.1
idna==2.5
iniparse==0.4
isc==2.0
jmespath==0.9.0
katello-host-tools==4.2.3
libcomps==0.1.18
netifaces==0.10.6
nftables==0.1
pciutils==2.3.6
perf==0.1
pexpect==4.3.1
ply==3.9
psycopg2==2.7.5
ptyprocess==0.5.2
pycparser==2.14
pygobject==3.28.3
pyinotify==0.9.6
pyOpenSSL==19.0.0
pyparsing==2.1.10
PySocks==1.6.8
python-dateutil==2.6.1
python-dmidecode==3.12.2
python-linux-procfs==0.7.0
python-qpid-proton==0.37.0
pyudev==0.21.0
PyYAML==3.12
requests==2.20.0
rhnlib==2.8.6
rpm==4.14.3
selinux==2.9
sepolicy==1.1
setools==4.3.0
six==1.11.0
slip==0.6.4
slip.dbus==0.6.4
sos==4.5.6
subscription-manager==1.28.36
syspurpose==1.28.36
systemd-python==234
urllib3==1.24.2

$ ansible --version

ansible [core 2.13.7]
  config file = /m019962/avd/ansible.cfg
  configured module search path = ['/home/m019962-udm/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/m019962-udm/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/m019962-udm/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/m019962-udm/.local/bin/ansible
  python version = 3.9.16 (main, May 31 2023, 12:21:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18)]
  jinja version = 3.1.2
  libyaml = True

$ ansible-galaxy collection list

Collection               Version
------------------------ ----------
ansible.netcommon        5.1.0
ansible.posix            1.5.1
ansible.utils            2.10.3
arista.avd               4.4.0-dev1
arista.cvp               3.6.1
arista.eos               6.0.1

Which component(s) of AVD impacted

cv_facts_v3

How do you run AVD ?

Ansible CLI (with virtual-env or native python)

Input variables

No response

Steps to reproduce

No response

Relevant log output

fatal: [cvp.x.net]: FAILED! => {"changed": false, "module_stderr": "/home/m019962-udm/.local/lib/python3.9/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'cvp.x.net'. Adding certificate verification is strongly advised. See:https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/m019962-udm/.local/lib/python3.9/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'cvp.x.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\n/home/m019962-udm/.local/lib/python3.9/site-packages/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'cvp.x.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings\n  warnings.warn(\nTraceback (most recent call last):\n  File \"/home/m019962-udm/.ansible/tmp/ansible-local-449075m227c6n9/ansible-tmp-1697011376.2354372-449085-76368703535268/AnsiballZ_cv_facts_v3.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/m019962-udm/.ansible/tmp/ansible-local-449075m227c6n9/ansible-tmp-1697011376.2354372-449085-76368703535268/AnsiballZ_cv_facts_v3.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/m019962-udm/.ansible/tmp/ansible-local-449075m227c6n9/ansible-tmp-1697011376.2354372-449085-76368703535268/AnsiballZ_cv_facts_v3.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.arista.cvp.plugins.modules.cv_facts_v3', init_globals=dict(_module_fqn='ansible_collections.arista.cvp.plugins.modules.cv_facts_v3', _modlib_path=modlib_path),\n  File \"/usr/lib64/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib64/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib64/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_arista.cvp.cv_facts_v3_payload_0lob9mzq/ansible_arista.cvp.cv_facts_v3_payload.zip/ansible_collections/arista/cvp/plugins/modules/cv_facts_v3.py\", line 174, in <module>\n  File \"/tmp/ansible_arista.cvp.cv_facts_v3_payload_0lob9mzq/ansible_arista.cvp.cv_facts_v3_payload.zip/ansible_collections/arista/cvp/plugins/modules/cv_facts_v3.py\", line 164, in main\n  File \"/tmp/ansible_arista.cvp.cv_facts_v3_payload_0lob9mzq/ansible_arista.cvp.cv_facts_v3_payload.zip/ansible_collections/arista/cvp/plugins/module_utils/facts_tools.py\", line 275, in facts\n  File \"/tmp/ansible_arista.cvp.cv_facts_v3_payload_0lob9mzq/ansible_arista.cvp.cv_facts_v3_payload.zip/ansible_collections/arista/cvp/plugins/module_utils/facts_tools.py\", line 490, in __fact_devices\nUnboundLocalError: local variable 'cv_devices' referenced before assignment\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

Code of Conduct