HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
144 stars 51 forks source link

ce_facts gather_subset: interfaces id failing on undefined LLDP Neighbor Device nema #35

Open rikard0 opened 6 years ago

rikard0 commented 6 years ago

On a switch:

<swt1-rlab>dis lldp neigh brief
Local Interface         Exptime(s) Neighbor Interface      Neighbor Device
-------------------------------------------------------------------------------
10GE1/0/1                     110  10GE1/0/9               sw1
10GE1/0/3                     109  14a0-f89b-1f31

Ansible -vvvv:

"module_stderr": "Traceback (most recent call last):
  File "/tmp/ansible_VRO_qt/ansible_module_ce_facts.py", line 403, in <module>
    main()
  File "/tmp/ansible_VRO_qt/ansible_module_ce_facts.py", line 388, in main
    inst.populate()
  File "/tmp/ansible_VRO_qt/ansible_module_ce_facts.py", line 319, in populate
    neighbors_dict[tmp_item[0]] = tmp_item[3]
IndexError: list index out of range",

in modules/network/cloudengine/ce_facts.py 319:

                neighbors_dict[tmp_item[0]] = tmp_item[3]

tmp_item[3] is '' for neighbor device on '10GE1/0/3' and should be handled. simple patch would be:

diff /usr/local/lib/python2.7/dist-packages/ansible/modules/network/cloudengine/ce_facts.py /usr/local/lib/python2.7/dist-packages/ansible/modules/network/cloudengine/ce_facts.orig.py
319,322c319
<                 if len(tmp_item) > 3:
<                     neighbors_dict[tmp_item[0]] = tmp_item[3]
<                 else:
<                     neighbors_dict[tmp_item[0]] = ''
---
>                 neighbors_dict[tmp_item[0]] = tmp_item[3]

OT: it would be nice to have not only neighbour device in facts, but also o neighbor interface :)