sonic-net / sonic-mgmt

Configuration management examples for SONiC
Other
196 stars 723 forks source link

py.test run failed for lldp_neighbour with KeyError: 'ansible_facts' #1948

Closed stephengzh closed 4 years ago

stephengzh commented 4 years ago
py.test lldp/test_lldp.py --testbed=vms-kvm-t0 --inventory=/var/johnar/sonic-mgmt/ansible/lab --testbed_file=../ansible/testbed.csv --host-pattern=vms-kvm-t0 --module-path=../ansible/library -v

platform linux2 -- Python 2.7.12, pytest-4.6.5, py-1.8.1, pluggy-0.13.1 -- /usr/bin/python
cachedir: .pytest_cache
ansible: 2.8.7
rootdir: /var/johnar/sonic-mgmt/tests, inifile: pytest.ini
plugins: repeat-0.8.0, xdist-1.28.0, ansible-2.2.2, forked-1.1.3
collected 2 items                                                                                                                                                                                     

lldp/test_lldp.py::test_lldp PASSED                                                                                                                                                             [ 50%]
lldp/test_lldp.py::test_lldp_neighbor FAILED                                                                                                                                                    [100%]

============================================================================================== FAILURES ===============================================================================================
_________________________________________________________________________________________ test_lldp_neighbor __________________________________________________________________________________________

duthost = <tests.common.devices.SonicHost object at 0x7f1896914b10>, localhost = <tests.common.devices.Localhost object at 0x7f1896914a50>
eos = {'bgp_gr_timer': 700, 'ceos_image_mount_dir': '/data/ceos', 'snmp_location': 'str', 'snmp_rocommunity': 'strcommunity'}, collect_techsupport = None

    def test_lldp_neighbor(duthost, localhost, eos, collect_techsupport):
        """ verify LLDP information on neighbors """

        mg_facts  = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts']
        res = duthost.shell("docker exec -i lldp lldpcli show chassis | grep \"SysDescr:\" | sed -e 's/^\\s*SysDescr:\\s*//g'")
        dut_system_description = res['stdout']
        lldp_facts = duthost.lldp()['ansible_facts']
        host_facts  = duthost.setup()['ansible_facts']

        config_facts  = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts']
        nei_meta = config_facts.get('DEVICE_NEIGHBOR_METADATA', {})

        for k, v in lldp_facts['lldp'].items():
            if k == 'eth0':
                # skip test on management interface
                continue

            try:
                hostip = v['chassis']['mgmt-ip']
            except:
                logger.info("Neighbor device {} does not sent management IP via lldp".format(v['chassis']['name']))
                hostip = nei_meta[v['chassis']['name']]['mgmt_addr']
    #   print localhost.lldp_facts
    #   print hostip
    #   print logger.info
    #   raise Exception, 'test "%s"'%
>           nei_lldp_facts = localhost.lldp_facts(host=hostip, version='v2c', community=eos['snmp_rocommunity'])['ansible_facts']
E           KeyError: 'ansible_facts'

lldp/test_lldp.py:70: KeyError
======================================================================================= short test summary info =======================================================================================
FAILED lldp/test_lldp.py::test_lldp_neighbor - KeyError: 'ansible_facts'

Actually, anyone knows the location about "localhost"? It only shows the KeyError: 'ansible facts', but it should better print the error exact position. For me, if not very very familiar with the pytest structure, I will feel difficult to locate the source of each parameter...

wangxin commented 4 years ago

KeyError: 'ansible_facts' means that calling lldp_facts ansible module on localhost somehow failed and didn't return results.

You can add pytest argument --log-cli-level debug to output more detailed logs to console. If you need detailed log file, please add argument --log-file-level debug --log-file test_lldp.log.

The log should contain detailed information of calling ansible modules and their returned results. For example: https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-mgmt-testing/job/sonic-mgmt-pr/795/artifact/sonic-mgmt/tests/logs/1vlan/lldp/test_lldp.log

07/08/2020 08:09:47 DEBUG devices.py:_run:55: /data/sonic-mgmt/tests/lldp/test_lldp.py::test_lldp_neighbor#62: [localhost] AnsibleModule::lldp_facts, args=[], kwargs={"host": "10.250.0.52", "version": "v2c", "community": "strcommunity"}
07/08/2020 08:09:48 DEBUG devices.py:_run:69: /data/sonic-mgmt/tests/lldp/test_lldp.py::test_lldp_neighbor#62: [localhost] AnsibleModule::lldp_facts Result => {"invocation": {"module_args": {"username": null, "privacy": null, "level": null, "community": "strcommunity", "authkey": null, "host": "10.250.0.52", "version": "v2c", "integrity": null, "removeplaceholder": null, "privkey": null}}, "changed": false, "_ansible_no_log": false, "ansible_facts": {"ansible_lldp_facts": {"Ethernet1": {"neighbor_port_id": "fortyGigE0/116", "neighbor_port_desc": "ARISTA02T1:Ethernet1", "neighbor_sys_desc": "Debian GNU/Linux 10 (buster) Linux 4.19.0-9-2-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64", "neighbor_chassis_id": "0x525400f9b224", "neighbor_sys_name": "vlab-01"}}}}