From eb2e4adbddd894d669e229ba624f0807a3fc239f Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Fri, 6 Dec 2019 08:05:23 +0000 Subject: [PATCH 1/2] Fix more ansible 2.8.7 compability issues Issues fixed in this commit: * Change 'connection: local' to 'delegate_to: localhost' to support configuring ansible_python_interpreter for specific test servers * Add pip_executable configuration option * Fix datetime call in kickstart.py * Fix tags issue of fanout deploy/config * Remove uncesessary tags in vlantb and everflow_testbed testing * Fix some 'with_items' and 'with_dict' * New ansible parses inventory file as full path, fix issue of finding correct inventory file in pytest_runner.yml * Fix issue of creating PTF host in conftest Change-Id: I245ff5c4b2480a9b8153c0b896c7a25a448d5956 Signed-off-by: Xin Wang --- ansible/config_sonic_basedon_testbed.yml | 8 +- ansible/fanout_connect.yml | 4 +- ansible/inventory | 2 +- ansible/library/lldp_facts.py | 26 ++-- ansible/library/testing_port_ip_facts.py | 2 +- ansible/linkstate/up.yml | 8 +- ansible/roles/fanout/tasks/fanout_mlnx.yml | 17 ++- ansible/roles/fanout/tasks/main.yml | 16 ++- .../fanout/tasks/mlnx/deploy_pfcwd_fanout.yml | 1 - .../tasks/mlnx/download_copy_pfcwd_fanout.yml | 2 + .../roles/fanout/tasks/rootfanout_connect.yml | 12 +- ansible/roles/sonic-common/tasks/snmp.yml | 6 +- ansible/roles/test/tasks/advanced-reboot.yml | 2 +- .../advanced_reboot/reboot-image-handle.yml | 2 +- ansible/roles/test/tasks/bgp_entry_flap.yml | 6 +- .../test/tasks/bgp_gr_helper/get_vm_info.yml | 2 +- .../test/tasks/check_fanout_interfaces.yml | 2 +- .../test/tasks/check_sw_vm_interfaces.yml | 2 +- .../roles/test/tasks/continuous_link_flap.yml | 12 +- .../continuous_peer_link_flap_helper.yml | 2 +- .../tasks/everflow_testbed/everflow_main.yml | 4 - ansible/roles/test/tasks/interface.yml | 2 +- .../roles/test/tasks/interface_up_down.yml | 16 +-- ansible/roles/test/tasks/lag.yml | 10 +- ansible/roles/test/tasks/lag_2.yml | 2 +- ansible/roles/test/tasks/link_flap.yml | 2 +- .../test/tasks/link_flap/link_flap_helper.yml | 2 +- ansible/roles/test/tasks/pfc_asym.yml | 6 +- ansible/roles/test/tasks/pfc_wd.yml | 6 +- .../tasks/pfc_wd/config_test/config_test.yml | 22 ++-- .../check_timer_accuracy_test.yml | 6 +- .../functional_test/functional_test.yml | 6 +- .../functional_test_restore.yml | 2 +- .../functional_test/functional_test_storm.yml | 2 +- .../functional_test/storm_all_action.yml | 6 +- .../pfc_wd/functional_test/storm_all_test.yml | 16 +-- .../functional_test/storm_from_neighbor.yml | 2 +- .../pfc_wd/functional_test/timer_test.yml | 4 +- .../test/tasks/pfcwd/config_shape_rate.yml | 10 +- ansible/roles/test/tasks/pytest_runner.yml | 4 +- ansible/roles/test/tasks/qos_get_ports.yml | 4 +- .../roles/test/tasks/resume_fanout_ports.yml | 2 +- ansible/roles/test/tasks/service_acl.yml | 6 +- .../test/tasks/single_lag_lacp_rate_test.yml | 2 +- ansible/roles/test/tasks/single_lag_test.yml | 12 +- ansible/roles/test/tasks/snmp.yml | 8 +- ansible/roles/test/tasks/snmp/cpu.yml | 63 +++++++++- ansible/roles/test/tasks/snmp/interfaces.yml | 41 +++++- ansible/roles/test/tasks/snmp/lldp.yml | 118 +++++++++++++++++- .../roles/test/tasks/snmp/pfc_counters.yml | 19 ++- ansible/roles/test/tasks/snmp/phys_table.yml | 2 +- ansible/roles/test/tasks/snmp/psu.yml | 2 +- ansible/roles/test/tasks/snmp/queues.yml | 13 +- ansible/roles/test/tasks/sonic.yml | 4 +- ansible/roles/test/tasks/syslog.yml | 16 +-- ansible/roles/test/tasks/vlan_configure.yml | 2 +- ansible/roles/test/tasks/vlantb.yml | 3 - ansible/roles/test/tasks/vnet_vxlan.yml | 2 +- ansible/roles/vm_set/library/kickstart.py | 2 +- ansible/roles/vm_set/tasks/docker.yml | 9 +- ansible/roles/vm_set/tasks/start_sid.yml | 6 +- ansible/roles/vm_set/tasks/start_sonic_vm.yml | 2 +- ansible/testbed_add_vm_topology.yml | 4 +- ansible/testbed_connect_vms.yml | 2 +- ansible/testbed_disconnect_vms.yml | 2 +- ansible/testbed_refresh_dut.yml | 4 +- ansible/testbed_remove_vm_topology.yml | 2 +- ansible/testbed_renumber_vm_topology.yml | 2 +- tests/conftest.py | 2 +- 69 files changed, 424 insertions(+), 196 deletions(-) diff --git a/ansible/config_sonic_basedon_testbed.yml b/ansible/config_sonic_basedon_testbed.yml index 6a572eab274..6fd2110aa78 100644 --- a/ansible/config_sonic_basedon_testbed.yml +++ b/ansible/config_sonic_basedon_testbed.yml @@ -42,7 +42,7 @@ - name: Gathering testbed information test_facts: testbed_name="{{ testbed_name }}" testbed_file="{{ testbed_file }}" - connection: local + delegate_to: localhost - fail: msg="The DUT you are trying to run test does not belongs to this testbed" when: testbed_facts['dut'] != inventory_hostname @@ -58,7 +58,7 @@ when: testbed_name is defined - topo_facts: topo={{ topo }} - connection: local + delegate_to: localhost - set_fact: VM_topo: "{% if 'ptf' in topo %}False{% else %}True{% endif %}" @@ -66,7 +66,7 @@ - name: gather testbed VM informations testbed_vm_info: base_vm={{ testbed_facts['vm_base'] }} topo={{ testbed_facts['topo'] }} - connection: local + delegate_to: localhost when: "VM_topo | bool" - name: find interface name mapping and individual interface speed if defined @@ -100,7 +100,7 @@ - name: create minigraph file in ansible minigraph folder template: src=templates/minigraph_template.j2 dest=minigraph/{{ inventory_hostname}}.{{ topo }}.xml - connection: local + delegate_to: localhost when: local_minigraph is defined and local_minigraph|bool == true - block: diff --git a/ansible/fanout_connect.yml b/ansible/fanout_connect.yml index 3856fa85c44..3b34d8bfd9b 100644 --- a/ansible/fanout_connect.yml +++ b/ansible/fanout_connect.yml @@ -4,7 +4,7 @@ gather_facts: no tasks: - fail: msg="Please provide VM server name and server port name, see comment line in playbook" - when: + when: - dut is not defined - block: @@ -16,7 +16,7 @@ - name: get the username running the deploy command: whoami - connection: local + delegate_to: localhost become: no register: calling_username changed_when: false diff --git a/ansible/inventory b/ansible/inventory index d0f58bb61df..c56e6450bd6 100644 --- a/ansible/inventory +++ b/ansible/inventory @@ -1,6 +1,6 @@ [sonic_latest] switch1 ansible_host=10.0.0.100 sonic_version=v2 sonic_hwsku=Force10-S6000 -switch2 ansible_host=10.0.0.101 sonic_version=v2 sonic_hwsku=ACS-MSN2700 +switch2 ansible_host=10.0.0.101 sonic_version=v2 sonic_hwsku=ACS-MSN2700 switch3 ansible_host=10.0.0.102 sonic_version=v2 sonic_hwsku=Force10-S6000 # LAG topo: 8 LAGs x 2 members/lag to spines; 16 ports to Tors switch4 ansible_host=10.0.0.103 sonic_version=v2 sonic_hwsku=AS7512 sonic_portsku=32x40 switch5 ansible_host=10.0.0.104 sonic_version=v2 sonic_hwsku=ACS-MSN2700 # LAG topo: 8 LAGs x 2 members/lag to spines; 16 ports to Tors diff --git a/ansible/library/lldp_facts.py b/ansible/library/lldp_facts.py index 010a9d03d3e..61d6670f9e6 100644 --- a/ansible/library/lldp_facts.py +++ b/ansible/library/lldp_facts.py @@ -57,7 +57,7 @@ EXAMPLES = ''' # Gather LLDP facts with SNMP version 2 - snmp_facts: host={{ inventory_hostname }} version=2c community=public - connection: local + delegate_to: localhost # Gather LLDP facts using SNMP version 3 - lldp_facts: @@ -142,7 +142,7 @@ def main(): supports_check_mode=False) m_args = module.params - + if not has_pysnmp: module.fail_json(msg='Missing required pysnmp module (check docs)') @@ -152,14 +152,14 @@ def main(): if m_args['version'] == "v2" or m_args['version'] == "v2c": if not m_args['community']: module.fail_json(msg='Community not set when using snmp version 2') - + if m_args['version'] == "v3": if m_args['username'] is None: module.fail_json(msg='Username not set when using snmp version 3') if m_args['level'] == "authPriv" and m_args['privacy'] == None: module.fail_json(msg='Privacy algorithm not set when using authPriv') - + if m_args['integrity'] == "sha": integrity_proto = cmdgen.usmHMACSHAAuthProtocol elif m_args['integrity'] == "md5": @@ -169,7 +169,7 @@ def main(): privacy_proto = cmdgen.usmAesCfb128Protocol elif m_args['privacy'] == "des": privacy_proto = cmdgen.usmDESPrivProtocol - + # Use SNMP Version 2 if m_args['version'] == "v2" or m_args['version'] == "v2c": snmp_auth = cmdgen.CommunityData(m_args['community']) @@ -188,7 +188,7 @@ def main(): v = DefineOid(dotprefix=False) Tree = lambda: defaultdict(Tree) - + results = Tree() host = m_args['host'] @@ -222,9 +222,9 @@ def main(): lldp_rem_port_desc = dict() lldp_rem_chassis_id = dict() lldp_rem_sys_desc = dict() - + vbd = [] - + for var_binds in var_table: for oid, val in var_binds: current_oid = oid.prettyPrint() @@ -233,7 +233,7 @@ def main(): vbd.append(current_val) try: - if_name = inverse_if_table[str(current_oid.split(".")[-2])] + if_name = inverse_if_table[str(current_oid.split(".")[-2])] except Exception as e: print json.dumps({ "unbound_interface_index": str(current_oid.split(".")[-2]) @@ -259,10 +259,10 @@ def main(): lldp_data = dict() for intf in lldp_rem_sys.viewkeys(): - lldp_data[intf] = {'neighbor_sys_name': lldp_rem_sys[intf], - 'neighbor_port_desc': lldp_rem_port_desc[intf], - 'neighbor_port_id': lldp_rem_port_id[intf], - 'neighbor_sys_desc': lldp_rem_sys_desc[intf], + lldp_data[intf] = {'neighbor_sys_name': lldp_rem_sys[intf], + 'neighbor_port_desc': lldp_rem_port_desc[intf], + 'neighbor_port_id': lldp_rem_port_id[intf], + 'neighbor_sys_desc': lldp_rem_sys_desc[intf], 'neighbor_chassis_id': lldp_rem_chassis_id[intf]} diff --git a/ansible/library/testing_port_ip_facts.py b/ansible/library/testing_port_ip_facts.py index a7c2fa71a9a..553aebf97fb 100644 --- a/ansible/library/testing_port_ip_facts.py +++ b/ansible/library/testing_port_ip_facts.py @@ -33,7 +33,7 @@ dut_switch_ports: "{{ dut_switch_ports }}" minigraph_bgp: "{{ minigraph_bgp }}" minigraph_neighbors: "{{ minigraph_neighbors }}" - connection: local + delegate_to: localhost ''' diff --git a/ansible/linkstate/up.yml b/ansible/linkstate/up.yml index 9441f6933fa..152930eb411 100644 --- a/ansible/linkstate/up.yml +++ b/ansible/linkstate/up.yml @@ -42,10 +42,10 @@ src: "{{ item }}" dest: /root with_items: - - ../files/lab_connection_graph.xml - - ../veos - - scripts/ptf_proxy.py - - ../vars/topo_{{ topo }}.yml + - "../files/lab_connection_graph.xml" + - "../veos" + - "scripts/ptf_proxy.py" + - "../vars/topo_{{ topo }}.yml" ignore_errors: yes # either sonic_str_*.csv or sonic_lab_*.csv exists - name: Rename topo to common filename command: mv topo_{{ topo }}.yml topo.yaml diff --git a/ansible/roles/fanout/tasks/fanout_mlnx.yml b/ansible/roles/fanout/tasks/fanout_mlnx.yml index 041cedfef62..6025c6108bf 100644 --- a/ansible/roles/fanout/tasks/fanout_mlnx.yml +++ b/ansible/roles/fanout/tasks/fanout_mlnx.yml @@ -28,18 +28,29 @@ vars: action_variable: "deploy" when: peer_hwsku == "MLNX-OS" - tags: deploy + tags: deploy ################################################################### # build, deploy and start docker images for the PFC WD test # ################################################################### -- include_tasks: mlnx/deploy_pfcwd_fanout.yml +- name: build, deploy and start docker images for the PFC WD test + include_tasks: + file: mlnx/deploy_pfcwd_fanout.yml + apply: + tags: + - deploy + - pfcwd_config when: peer_hwsku == "MLNX-OS" tags: deploy,pfcwd_config ################################################################### # check and recover docker images for the PFC WD test # ################################################################### -- include_tasks: mlnx/check_pfcwd_fanout.yml +- name: check and recover docker images for the PFC WD test + include_tasks: + file: mlnx/check_pfcwd_fanout.yml + apply: + tags: + - check_pfcwd_config when: peer_hwsku == "MLNX-OS" tags: check_pfcwd_config diff --git a/ansible/roles/fanout/tasks/main.yml b/ansible/roles/fanout/tasks/main.yml index ee0d881e551..80cfa6fbd75 100644 --- a/ansible/roles/fanout/tasks/main.yml +++ b/ansible/roles/fanout/tasks/main.yml @@ -8,20 +8,22 @@ ################################################################################################ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost + tags: always - set_fact: sw_type="{{ device_info['Type'] }}" - set_fact: os='eos' when: os is not defined + tags: always -- include_tasks: fanout_eos.yml +- import_tasks: fanout_eos.yml when: os == 'eos' -- include_tasks: fanout_sonic.yml +- import_tasks: fanout_sonic.yml when: os == 'sonic' -- include_tasks: fanout_mlnx.yml +- import_tasks: fanout_mlnx.yml when: os == 'mellanox' - block: @@ -29,6 +31,8 @@ leaf_name: "{{ inventory_hostname }}" leaf: "{{ ansible_host }}" - - include_tasks: rootfanout_connect.yml - deploy_leaf=true + - import_tasks: rootfanout_connect.yml + vars: + deploy_leaf: true when: sw_type == 'FanoutLeaf' + tags: always diff --git a/ansible/roles/fanout/tasks/mlnx/deploy_pfcwd_fanout.yml b/ansible/roles/fanout/tasks/mlnx/deploy_pfcwd_fanout.yml index 1c18d9993fb..290e777eb39 100644 --- a/ansible/roles/fanout/tasks/mlnx/deploy_pfcwd_fanout.yml +++ b/ansible/roles/fanout/tasks/mlnx/deploy_pfcwd_fanout.yml @@ -32,7 +32,6 @@ - name: Download pre-built pfcwd dockers if path specified include_tasks: download_copy_pfcwd_fanout.yml with_items: "{{ pfcwd_dockers }}" - delegate_to: localhost when: pfcwd_dockers_url is defined - name: Load and start dockers diff --git a/ansible/roles/fanout/tasks/mlnx/download_copy_pfcwd_fanout.yml b/ansible/roles/fanout/tasks/mlnx/download_copy_pfcwd_fanout.yml index c2a7b92d321..08dd517111e 100644 --- a/ansible/roles/fanout/tasks/mlnx/download_copy_pfcwd_fanout.yml +++ b/ansible/roles/fanout/tasks/mlnx/download_copy_pfcwd_fanout.yml @@ -8,6 +8,7 @@ - name: Download pre-built pfcwd docker image get_url: url={{ pfcwd_dockers_url }}/{{ item | basename }} dest={{ filename }} + delegate_to: localhost - name: Copy the downloaded pfcwd docker image to switch include_tasks: scp_copy.yml @@ -19,3 +20,4 @@ - name: Remove the downloaded pfcwd docker image file: path={{ filename }} state=absent + delegate_to: localhost diff --git a/ansible/roles/fanout/tasks/rootfanout_connect.yml b/ansible/roles/fanout/tasks/rootfanout_connect.yml index ebb1bc017d2..7994e730031 100644 --- a/ansible/roles/fanout/tasks/rootfanout_connect.yml +++ b/ansible/roles/fanout/tasks/rootfanout_connect.yml @@ -9,13 +9,13 @@ - name: Gathering connection facts about the DUT or leaffanout device conn_graph_facts: host={{ dut }} - connection: local + delegate_to: localhost tags: always register: devinfo -- name: Gathering connection facts about the lab - conn_graph_facts: - connection: local +- name: Gathering connection facts about the lab + conn_graph_facts: + delegate_to: localhost tags: always register: lab @@ -26,11 +26,11 @@ - name: Find the root fanout switch set_fact: ansible_host: "{{ lab_devices[item]['mgmtip'] }}" - root_dev: "{{ item }}" + root_dev: "{{ item }}" with_items: "{{ lab_devices }}" when: lab_devices[item]['Type'] == 'FanoutRoot' -- set_fact: +- set_fact: root_conn: "{{ lab.ansible_facts['device_conn'][root_dev] }}" - name: Change root fanout port vlan diff --git a/ansible/roles/sonic-common/tasks/snmp.yml b/ansible/roles/sonic-common/tasks/snmp.yml index 7384e3e8a5d..f328a64a211 100644 --- a/ansible/roles/sonic-common/tasks/snmp.yml +++ b/ansible/roles/sonic-common/tasks/snmp.yml @@ -42,13 +42,13 @@ template: src=snmp.yml.j2 dest=/etc/sonic/snmp.yml mode=0644 - + - name: Setup sonic_version file (for oneimage snmp dockers) become: true template: src=sonic_version.yml.j2 dest=/etc/sonic/sonic_version.yml mode=0644 - + - name: Setup sysDescription file (for legacy snmp dockers) become: true template: src=sysDescription.j2 @@ -60,7 +60,7 @@ - name: Determine if alias mappings are required stat: path="roles/sonicv2/files/ssw/{{ sonic_hwsku }}/alias_map.json" become: false - connection: local + delegate_to: localhost register: snmp_remap - block: diff --git a/ansible/roles/test/tasks/advanced-reboot.yml b/ansible/roles/test/tasks/advanced-reboot.yml index 4da196f61cd..f3fa18742e8 100644 --- a/ansible/roles/test/tasks/advanced-reboot.yml +++ b/ansible/roles/test/tasks/advanced-reboot.yml @@ -4,7 +4,7 @@ - block: - name: figure out vm hosts testbed_vm_info: base_vm={{ vm }} topo={{ testbed_type }} - connection: local + delegate_to: localhost - set_fact: vm_hosts: "{{ neighbor_eosvm_mgmt.values() }}" diff --git a/ansible/roles/test/tasks/advanced_reboot/reboot-image-handle.yml b/ansible/roles/test/tasks/advanced_reboot/reboot-image-handle.yml index 62fd8334c3d..dc2ff29fd46 100755 --- a/ansible/roles/test/tasks/advanced_reboot/reboot-image-handle.yml +++ b/ansible/roles/test/tasks/advanced_reboot/reboot-image-handle.yml @@ -38,7 +38,7 @@ - name: 'Setup restoring initial image {{ current_sonic_image }}' shell: /bin/true - connection: local + delegate_to: localhost notify: - restore current image - reboot sonic diff --git a/ansible/roles/test/tasks/bgp_entry_flap.yml b/ansible/roles/test/tasks/bgp_entry_flap.yml index 4753cbe4e19..16e19c28adf 100644 --- a/ansible/roles/test/tasks/bgp_entry_flap.yml +++ b/ansible/roles/test/tasks/bgp_entry_flap.yml @@ -19,13 +19,13 @@ - block: - name: Assert the particular entry is in nexthopgroup table - assert: + assert: that: nexthop[addr] in nexthopgroup[item] with_items: "{{ nexthopgroup }}" - name: Gathering minigraph facts about neighbor minigraph_facts: host={{ name }} filename="{{ vmhost_num }}-{{ name }}.xml" - connection: local + delegate_to: localhost become: no - name: Shut down BGP session from neighbor @@ -47,7 +47,7 @@ vars: ansible_shell_type: docker ansible_python_interpreter: docker exec -i sswsyncd python - + - name: Poll for updated tables until peer is not in nexthop groups switch_tables: asic="{{asic}}" nexthop=yes nexthopgroup=yes become: yes diff --git a/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml b/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml index b0ba4af0927..58e3bd6d575 100644 --- a/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml +++ b/ansible/roles/test/tasks/bgp_gr_helper/get_vm_info.yml @@ -1,6 +1,6 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ ansible_host }} - connection: local + delegate_to: localhost tags: always - name: Init variables. diff --git a/ansible/roles/test/tasks/check_fanout_interfaces.yml b/ansible/roles/test/tasks/check_fanout_interfaces.yml index 4a4d4e2f43f..32cb8fcc25f 100644 --- a/ansible/roles/test/tasks/check_fanout_interfaces.yml +++ b/ansible/roles/test/tasks/check_fanout_interfaces.yml @@ -1,7 +1,7 @@ - block: - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost - name: Fanout hostname set_fact: fanout_switch={{ device_conn['Ethernet0']['peerdevice'] }} diff --git a/ansible/roles/test/tasks/check_sw_vm_interfaces.yml b/ansible/roles/test/tasks/check_sw_vm_interfaces.yml index 9b4362ddbbf..952a01ae759 100644 --- a/ansible/roles/test/tasks/check_sw_vm_interfaces.yml +++ b/ansible/roles/test/tasks/check_sw_vm_interfaces.yml @@ -23,7 +23,7 @@ - name: Gathering testbed information test_facts: testbed_name="{{ testbed_name }}" - connection: local + delegate_to: localhost ignore_errors: yes - name: Gather vm list from Testbed server diff --git a/ansible/roles/test/tasks/continuous_link_flap.yml b/ansible/roles/test/tasks/continuous_link_flap.yml index e2e60d23af5..a14195cb906 100644 --- a/ansible/roles/test/tasks/continuous_link_flap.yml +++ b/ansible/roles/test/tasks/continuous_link_flap.yml @@ -51,7 +51,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - debug: msg="{{ device_conn }}" @@ -66,7 +66,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - name: include continuous_link_flap_helper.yml @@ -79,7 +79,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - name: include continuous_link_flap_helper.yml @@ -92,7 +92,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - debug: msg="{{ device_conn }}" @@ -110,7 +110,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - set_fact: @@ -126,7 +126,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - set_fact: diff --git a/ansible/roles/test/tasks/continuous_link_flap/continuous_peer_link_flap_helper.yml b/ansible/roles/test/tasks/continuous_link_flap/continuous_peer_link_flap_helper.yml index 2067a42ba5d..5355cdea4ee 100644 --- a/ansible/roles/test/tasks/continuous_link_flap/continuous_peer_link_flap_helper.yml +++ b/ansible/roles/test/tasks/continuous_link_flap/continuous_peer_link_flap_helper.yml @@ -6,7 +6,7 @@ neighbor_interface: "{{neighbors[interface]['peerport']}}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost - set_fact: peer_host: "{{device_info['mgmtip']}}" diff --git a/ansible/roles/test/tasks/everflow_testbed/everflow_main.yml b/ansible/roles/test/tasks/everflow_testbed/everflow_main.yml index 4ce784261e6..9d84d005855 100644 --- a/ansible/roles/test/tasks/everflow_testbed/everflow_main.yml +++ b/ansible/roles/test/tasks/everflow_testbed/everflow_main.yml @@ -12,23 +12,19 @@ - name: Apply Everflow configuration. include_tasks: "roles/test/tasks/everflow_testbed/apply_config.yml" - tags: everflow_tb_configure - name: Run Everflow tests [tor]. include_tasks: "roles/test/tasks/everflow_testbed/run_test.yml" vars: dst_port_type: "tor" - tags: everflow_tb_test - name: Run Everflow tests [spine]. include_tasks: "roles/test/tasks/everflow_testbed/run_test.yml" vars: dst_port_type: "spine" - tags: everflow_tb_test - name: Clear Everflow configuration. include_tasks: "roles/test/tasks/everflow_testbed/del_config.yml" - tags: everflow_tb_cleanup - name: Reload config include_tasks: "roles/test/tasks/common_tasks/reload_config.yml" diff --git a/ansible/roles/test/tasks/interface.yml b/ansible/roles/test/tasks/interface.yml index eeff1dc7a86..2d9f9959393 100644 --- a/ansible/roles/test/tasks/interface.yml +++ b/ansible/roles/test/tasks/interface.yml @@ -12,7 +12,7 @@ - name: figure out fanout switch port in case it was down conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost - set_fact: neighbors="{{device_conn}}" diff --git a/ansible/roles/test/tasks/interface_up_down.yml b/ansible/roles/test/tasks/interface_up_down.yml index 56dcb7ec69e..685bc6f8a92 100644 --- a/ansible/roles/test/tasks/interface_up_down.yml +++ b/ansible/roles/test/tasks/interface_up_down.yml @@ -37,9 +37,9 @@ pause: seconds=5 - name: gather interface facts - setup: + setup: -- name: verify all local interfaces are up +- name: verify all local interfaces are up assert: { that: "ansible_{{ item }}['active'] == true" } with_items: "{{ ansible_interfaces }}" when: @@ -53,7 +53,7 @@ - name: rearrange lldp received data structure for interface up down test interface_up_down_data_struct_facts: data="{{ lldp }}" - connection: local + delegate_to: localhost become: no - name: shutdown neighbor interfaces @@ -64,14 +64,14 @@ skip_default_user: "yes" connection: cisco with_items: "{{ ansible_interface_up_down_data_struct_facts.keys() }}" - + - name: sleep for some time pause: seconds=5 - name: gather interface facts - setup: + setup: -- name: verify all local interfaces are down +- name: verify all local interfaces are down assert: { that: "ansible_{{ item }}['active'] == false" } with_items: "{{ ansible_interfaces }}" when: @@ -90,9 +90,9 @@ pause: seconds=5 - name: gather interface facts - setup: + setup: -- name: verify all local interfaces are up +- name: verify all local interfaces are up assert: { that: "ansible_{{ item }}['active'] == true" } with_items: "{{ ansible_interfaces }}" when: diff --git a/ansible/roles/test/tasks/lag.yml b/ansible/roles/test/tasks/lag.yml index c91bd4c84be..364e8a2f8f9 100644 --- a/ansible/roles/test/tasks/lag.yml +++ b/ansible/roles/test/tasks/lag.yml @@ -18,7 +18,7 @@ # Generate file with BGP routes information - template: src=lag.j2 dest=/tmp/lag.txt - connection: local + delegate_to: localhost - set_fact: testname: lag @@ -28,7 +28,7 @@ test_ignore_file: lag_ignore_messages.txt test_expect_file: lag_expect_messages.txt match_file: loganalyzer_common_match.txt - ignore_file: loganalyzer_common_ignore.txt + ignore_file: loganalyzer_common_ignore.txt tests_location: "{{ 'roles/test/tasks' }}" # Separate set_fact is required to be able to use 'testname' fact. @@ -51,20 +51,20 @@ - name: copy the test to ptf container copy: src=roles/test/files/acstests dest=/root delegate_to: "{{ ptf_host }}" - + - name: "Running test {{ testname }}" shell: ptf --test-dir acstests lag_test.LagAllRoutes --platform remote -t "verbose=True;router_mac='{{ ansible_Ethernet0['macaddress'] }}';lag_info='/tmp/lag.txt'" args: chdir: /root delegate_to: "{{ ptf_host }}" register: out - + - debug: var=out.stdout_lines when: out.rc != 0 - name: PortChannel structure debug: msg="{{ minigraph_portchannel_interfaces }}" - + - name: "Run {{ testname }} with changing member port state to up and down" include_tasks: per_lag_test.yml with_items: "{{ minigraph_portchannel_interfaces }}" diff --git a/ansible/roles/test/tasks/lag_2.yml b/ansible/roles/test/tasks/lag_2.yml index 7f79b4d60b3..65c0da1a607 100644 --- a/ansible/roles/test/tasks/lag_2.yml +++ b/ansible/roles/test/tasks/lag_2.yml @@ -34,7 +34,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost - set_fact: fanout_neighbors: "{{device_conn}}" diff --git a/ansible/roles/test/tasks/link_flap.yml b/ansible/roles/test/tasks/link_flap.yml index a201b56c991..4fe53e0c8dc 100644 --- a/ansible/roles/test/tasks/link_flap.yml +++ b/ansible/roles/test/tasks/link_flap.yml @@ -4,7 +4,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - name: Set neighbor facts diff --git a/ansible/roles/test/tasks/link_flap/link_flap_helper.yml b/ansible/roles/test/tasks/link_flap/link_flap_helper.yml index 6a243adacd3..0cbaab99b49 100644 --- a/ansible/roles/test/tasks/link_flap/link_flap_helper.yml +++ b/ansible/roles/test/tasks/link_flap/link_flap_helper.yml @@ -21,7 +21,7 @@ neighbor_interface: "{{neighbors[interface]['peerport']}}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost - set_fact: peer_host: "{{device_info['mgmtip']}}" diff --git a/ansible/roles/test/tasks/pfc_asym.yml b/ansible/roles/test/tasks/pfc_asym.yml index 0434b40aacc..97a46a25769 100644 --- a/ansible/roles/test/tasks/pfc_asym.yml +++ b/ansible/roles/test/tasks/pfc_asym.yml @@ -27,7 +27,7 @@ - name: Generate IP address in VLAN range for each server port get_ip_in_range: num={{minigraph_vlans[minigraph_vlan_interfaces[0]['attachto']]['members']|length}} prefix="{{minigraph_vlan_interfaces[0]['addr']}}/{{minigraph_vlan_interfaces[0]['prefixlen']}}" exclude_ips="{{minigraph_vlan_interfaces[0]['addr']}}" become: no - connection: local + delegate_to: localhost failed_when: False - name: Get server ports info @@ -139,7 +139,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ ansible_host }} - connection: local + delegate_to: localhost tags: always - set_fact: @@ -153,7 +153,7 @@ with_items: "{{ minigraph_vlans[minigraph_vlan_interfaces[0]['attachto']]['members'] }}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost - set_fact: peer_host: "{{device_info['mgmtip']}}" diff --git a/ansible/roles/test/tasks/pfc_wd.yml b/ansible/roles/test/tasks/pfc_wd.yml index 1738d3e229e..8c8ee6f9851 100644 --- a/ansible/roles/test/tasks/pfc_wd.yml +++ b/ansible/roles/test/tasks/pfc_wd.yml @@ -26,7 +26,7 @@ - name: Gathering lab graph facts about the device conn_graph_facts: host={{ inventory_hostname }} - connection: local + delegate_to: localhost tags: always - name: Gather minigraph facts about the device @@ -72,7 +72,7 @@ - name: Generate ips in VLAN range get_ip_in_range: num=1 prefix="{{minigraph_vlan_interfaces[0]['addr']}}/{{minigraph_vlan_interfaces[0]['prefixlen']}}" exclude_ips="{{minigraph_vlan_interfaces[0]['addr']}}" become: no - connection: local + delegate_to: localhost failed_when: False when: minigraph_vlans | length >0 @@ -199,7 +199,7 @@ file: path: "{{ run_dir }}" state: absent - + - name: Disable asymmetric PFC on all server interfaces command: config interface pfc asymmetric on {{ item.dut_name }} become: yes diff --git a/ansible/roles/test/tasks/pfc_wd/config_test/config_test.yml b/ansible/roles/test/tasks/pfc_wd/config_test/config_test.yml index 9913e2f9d86..7170120b764 100644 --- a/ansible/roles/test/tasks/pfc_wd/config_test/config_test.yml +++ b/ansible/roles/test/tasks/pfc_wd/config_test/config_test.yml @@ -10,7 +10,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_fwd_action.json" - connection: local + delegate_to: localhost become: false - name: Generate config file for invalid action test. @@ -22,7 +22,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_invalid_action.json" - connection: local + delegate_to: localhost become: false - name: Generate config file for invalid detection time test. @@ -34,10 +34,10 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_invalid_detect_time.json" - connection: local + delegate_to: localhost become: false -- name: Generate config file for invalid detection time < lower bound test +- name: Generate config file for invalid detection time < lower bound test vars: pfc_wd_interface_list: "{{ pfc_wd_test_port }}" pfc_wd_action: forward @@ -46,10 +46,10 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_low_detect_time.json" - connection: local + delegate_to: localhost become: false -- name: Generate config file for invalid detection time > higher bound test +- name: Generate config file for invalid detection time > higher bound test vars: pfc_wd_interface_list: "{{ pfc_wd_test_port }}" pfc_wd_action: forward @@ -58,7 +58,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_high_detect_time.json" - connection: local + delegate_to: localhost become: false - name: Generate config file for invalid restoration time test. @@ -70,7 +70,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_invalid_restore_time.json" - connection: local + delegate_to: localhost become: false - name: Generate config file for invalid restoration time < lower bound test. @@ -82,7 +82,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_low_restore_time.json" - connection: local + delegate_to: localhost become: false - name: Generate config file for invalid restoration time > higher bound test. @@ -94,7 +94,7 @@ template: src: "{{ pfc_wd_template }}" dest: "{{ tests_location }}/config_test/pfc_wd_high_restore_time.json" - connection: local + delegate_to: localhost become: false - name: Define variables for test @@ -187,5 +187,5 @@ name: "{{ tests_location }}/config_test/{{ item }}" state: absent with_items: "{{ config_files }}" - connection: local + delegate_to: localhost become: false diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/check_timer_accuracy_test.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/check_timer_accuracy_test.yml index 113839a1e5a..b4ded1639a1 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/check_timer_accuracy_test.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/check_timer_accuracy_test.yml @@ -4,7 +4,7 @@ testname: functional_test - conn_graph_facts: host={{test_ports[pfc_wd_test_port]['peer_device']}} - connection: local + delegate_to: localhost become: no - name: Prepare variables required for PFC test @@ -61,8 +61,8 @@ - debug: var: "{{item}}" with_items: - - detect_time_list - - restore_time_list + - "{{ detect_time_list }}" + - "{{ restore_time_list }}" - name: Verify that real detection time is not greater than configured fail: diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test.yml index 5d1365cebd8..b3f5843a8a7 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test.yml @@ -38,10 +38,10 @@ when: port_type == "vlan" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost become: no -# pfc_frames_number intends to be large enough so that PFC storm keeps happenning until runs pfc_storm_stop command. +# pfc_frames_number intends to be large enough so that PFC storm keeps happenning until runs pfc_storm_stop command. - name: Prepare variables required for PFC test set_fact: pfc_queue_index: 4 @@ -653,7 +653,7 @@ name: "{{ tests_location }}/functional_test/{{ item }}" state: absent with_items: "{{ config_files }}" - connection: local + delegate_to: localhost become: false always: diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_restore.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_restore.yml index 6b0cf1f6ea8..5ecb66ec740 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_restore.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_restore.yml @@ -45,7 +45,7 @@ when: port_type == "vlan" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost become: no - name: Prepare variables required for PFC test diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_storm.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_storm.yml index 9e8bad06621..92946969efd 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_storm.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/functional_test_storm.yml @@ -47,7 +47,7 @@ when: port_type == "vlan" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost become: no - name: Prepare variables required for PFC test diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml index ec355255c6b..e6ef5c6435d 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml @@ -1,5 +1,5 @@ - conn_graph_facts: host={{item.key}} - connection: local + delegate_to: localhost become: no - set_fact: @@ -13,8 +13,8 @@ - name: set pfc storm templates based on fanout platform sku include_tasks: roles/test/tasks/pfc_wd/functional_test/set_pfc_storm_templates.yml - -- set_fact: + +- set_fact: storm_action_template: "{%if storm_action=='start'%}{{pfc_wd_storm_template}}{%else%}{{pfc_wd_storm_stop_template}}{%endif%}" - name: Deploy pfc packet generater file to fanout switch diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_test.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_test.yml index 26c5bdf7dbe..839e475f448 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_test.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_all_test.yml @@ -1,4 +1,4 @@ -# pfc_frames_number intends to be large enough so that PFC storm keeps happenning until runs pfc_storm_stop command. +# pfc_frames_number intends to be large enough so that PFC storm keeps happenning until runs pfc_storm_stop command. - name: Prepare variables required for PFC test set_fact: pfc_queue_index: 3 @@ -23,8 +23,8 @@ register: peer_ports_result - set_fact: - peer_devices: "{{peer_devices_result.results | map(attribute='ansible_facts.peer_device_item') | list}}" - peer_ports: "{{peer_ports_result.results | map(attribute='ansible_facts.peer_port_item') | list}}" + peer_devices: "{{peer_devices_result.results | map(attribute='ansible_facts.peer_device_item') | list}}" + peer_ports: "{{peer_ports_result.results | map(attribute='ansible_facts.peer_port_item') | list}}" - set_fact: pfc_gen_file: pfc_gen.py @@ -32,7 +32,7 @@ - name: Get the peer device and peer port map combine_list_to_dict: keys={{peer_devices}} values={{peer_ports}} become: no - connection: local + delegate_to: localhost failed_when: False - block: @@ -41,20 +41,20 @@ become: yes - name: Start to copy and send PFC packets from all peers - vars: + vars: test_expect_file: "expect_pfc_wd_detect" test_ignore_file: "ignore_pfc_wd_messages" storm_action: "start" include_tasks: roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml - with_dict: "{{combined_dict}}" + with_dict: "{{combined_dict}}" - name: Stop PFC packets from all peers - vars: + vars: test_expect_file: "expect_pfc_wd_restore" test_ignore_file: "ignore_pfc_wd_messages" storm_action: "stop" include_tasks: roles/test/tasks/pfc_wd/functional_test/storm_all_action.yml - with_dict: "{{combined_dict}}" + with_dict: "{{combined_dict}}" always: - name: Clean up config diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_from_neighbor.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_from_neighbor.yml index 8704e35cfc3..56b26de8fd4 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/storm_from_neighbor.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/storm_from_neighbor.yml @@ -4,7 +4,7 @@ pfc_wd_test_port: "{{item.key}}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost become: no - name: Prepare parameters required for PFC storming diff --git a/ansible/roles/test/tasks/pfc_wd/functional_test/timer_test.yml b/ansible/roles/test/tasks/pfc_wd/functional_test/timer_test.yml index b5c3cbf8e03..7959c85ea57 100644 --- a/ansible/roles/test/tasks/pfc_wd/functional_test/timer_test.yml +++ b/ansible/roles/test/tasks/pfc_wd/functional_test/timer_test.yml @@ -60,8 +60,8 @@ - debug: var: "{{item}}" with_items: - - real_detect_time - - real_restore_time + - "{{ real_detect_time }}" + - "{{ real_restore_time }}" - name: Append detect and restore time to lists set_fact: diff --git a/ansible/roles/test/tasks/pfcwd/config_shape_rate.yml b/ansible/roles/test/tasks/pfcwd/config_shape_rate.yml index b445841a68b..7492b04a027 100644 --- a/ansible/roles/test/tasks/pfcwd/config_shape_rate.yml +++ b/ansible/roles/test/tasks/pfcwd/config_shape_rate.yml @@ -7,19 +7,19 @@ interface: "{{item.interface}}" shape_rate: "{{item.shape_rate}}" set: "{{item.set}}" - + - conn_graph_facts: host={{ device }} - connection: local - + delegate_to: localhost + - set_fact: device_host: "{{device_info['mgmtip']}}" device_hwsku: "{{device_info['HwSku']}}" - + - name: Set shape rate of interface {{interface}} on {{device_host}} action: apswitch template=config_interface_shape_rate.j2 args: host: "{{device_host}}" login: "{{switch_login[hwsku_map[device_hwsku]]}}" connection: switch - + diff --git a/ansible/roles/test/tasks/pytest_runner.yml b/ansible/roles/test/tasks/pytest_runner.yml index 188422bb8cc..110a3d45d1f 100644 --- a/ansible/roles/test/tasks/pytest_runner.yml +++ b/ansible/roles/test/tasks/pytest_runner.yml @@ -35,7 +35,7 @@ - name: append inventory file set_fact: - pytest_cmd: '{{ pytest_cmd }} --inventory=../ansible/{{ inventory_file }}' + pytest_cmd: '{{ pytest_cmd }} --inventory={{ inventory_file }}' - name: append testbed file set_fact: @@ -52,7 +52,7 @@ - debug: var=pytest_cmd - name: run py.test - connection: local + delegate_to: localhost shell: '{{ pytest_cmd }}' args: chdir: ../tests/ diff --git a/ansible/roles/test/tasks/qos_get_ports.yml b/ansible/roles/test/tasks/qos_get_ports.yml index 58d92a4c1f6..a6cad13cbe4 100644 --- a/ansible/roles/test/tasks/qos_get_ports.yml +++ b/ansible/roles/test/tasks/qos_get_ports.yml @@ -80,7 +80,7 @@ dut_switch_ports: "{{dut_switch_ports}}" minigraph_bgp: "{{minigraph_bgp}}" minigraph_neighbors: "{{minigraph_neighbors}}" - connection: local + delegate_to: localhost - debug: var: testing_ports_ip @@ -99,7 +99,7 @@ - name: Generate IPs in VLAN range get_ip_in_range: num="{{dut_switch_ports|length}}" prefix="{{minigraph_vlan_interfaces[0]['addr']}}/{{minigraph_vlan_interfaces[0]['prefixlen']}}" exclude_ips="{{minigraph_vlan_interfaces[0]['addr']}}" become: no - connection: local + delegate_to: localhost failed_when: False when: minigraph_vlans | length > 0 diff --git a/ansible/roles/test/tasks/resume_fanout_ports.yml b/ansible/roles/test/tasks/resume_fanout_ports.yml index 9226c5e7eb0..6ddde62ec47 100644 --- a/ansible/roles/test/tasks/resume_fanout_ports.yml +++ b/ansible/roles/test/tasks/resume_fanout_ports.yml @@ -10,7 +10,7 @@ neighbor_interface: "{{neighbors[interface]['peerport']}}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost - set_fact: peer_host: "{{device_info['mgmtip']}}" diff --git a/ansible/roles/test/tasks/service_acl.yml b/ansible/roles/test/tasks/service_acl.yml index b3b547167f9..ad4aca4dd06 100644 --- a/ansible/roles/test/tasks/service_acl.yml +++ b/ansible/roles/test/tasks/service_acl.yml @@ -4,7 +4,7 @@ host: "{{ ansible_host }}" version: "v2c" community: "{{ snmp_rocommunity }}" - connection: local + delegate_to: localhost - name: Copy config_service_acls.sh to the DuT (this also ensures we can successfully SSH to the DuT) become: true @@ -42,7 +42,7 @@ host: "{{ ansible_host }}" version: "v2c" community: "{{ snmp_rocommunity }}" - connection: local + delegate_to: localhost register: result failed_when: "'No SNMP response received before timeout' not in result.msg" @@ -73,4 +73,4 @@ host: "{{ ansible_host }}" version: "v2c" community: "{{ snmp_rocommunity }}" - connection: local + delegate_to: localhost diff --git a/ansible/roles/test/tasks/single_lag_lacp_rate_test.yml b/ansible/roles/test/tasks/single_lag_lacp_rate_test.yml index b62deed4137..1f5ae29a27f 100644 --- a/ansible/roles/test/tasks/single_lag_lacp_rate_test.yml +++ b/ansible/roles/test/tasks/single_lag_lacp_rate_test.yml @@ -21,7 +21,7 @@ neighbor_interface: "{{ fanout_neighbors[flap_intf]['peerport'] }}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost ### Now figure out remote VM and interface info for the falpping lag member and run minlink test - set_fact: diff --git a/ansible/roles/test/tasks/single_lag_test.yml b/ansible/roles/test/tasks/single_lag_test.yml index ca2788a8d4e..3f3956696e7 100644 --- a/ansible/roles/test/tasks/single_lag_test.yml +++ b/ansible/roles/test/tasks/single_lag_test.yml @@ -1,15 +1,15 @@ ### Part of lag test palybook lag_2.yml (--tag lag_2) -### This playbook test one single port channel minimum link feature of one member interface shutdown +### This playbook test one single port channel minimum link feature of one member interface shutdown ### and portchannel member interfaces sending ACP DU rate # Set maximum value of "smart" timeout to be the same as before, -# user can now set own value outside the test, for example by passing '-e wait_timeout=5' -- set_fact: +# user can now set own value outside the test, for example by passing '-e wait_timeout=5' +- set_fact: wait_timeout: 30 when: "wait_timeout is not defined" # Gather information of port channel ports, minimum links and total interface member numbers -- set_fact: +- set_fact: po: "{{ item }}" po_interfaces: "{{ lag_facts.lags[item]['po_config']['ports'] }}" po_intf_num: "{{ lag_facts.lags[item]['po_config']['ports']|length }}" @@ -28,7 +28,7 @@ neighbor_interface: "{{ fanout_neighbors[flap_intf]['peerport'] }}" - conn_graph_facts: host={{ peer_device }} - connection: local + delegate_to: localhost - set_fact: peer_host: "{{ device_info['mgmtip'] }}" @@ -51,6 +51,6 @@ - name: test vm interface flap (no physical port down, more like remote port lock) that lag interface can change to correct po status follow minimum links requirement include_tasks: lag_minlink.yml - vars: + vars: deselect_time: 95 wait_down_time: "{{ wait_timeout | int }}" diff --git a/ansible/roles/test/tasks/snmp.yml b/ansible/roles/test/tasks/snmp.yml index b02f2a5c0f4..a84a9ddd58f 100644 --- a/ansible/roles/test/tasks/snmp.yml +++ b/ansible/roles/test/tasks/snmp.yml @@ -1,7 +1,7 @@ # Gather facts with SNMP version 2 - name: Gathering basic snmp facts about the device snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - connection: local + delegate_to: localhost # Test SNMP is working with sysdesc - name: Validating SNMP was successful and Hostname is what is expected @@ -15,7 +15,7 @@ include_tasks: roles/test/tasks/snmp/pfc_counters.yml - name: include snmp queues test - include_tasks: roles/test/tasks/snmp/queues.yml + include_tasks: roles/test/tasks/snmp/queues.yml - name: include snmp lldp test include_tasks: roles/test/tasks/snmp/lldp.yml @@ -23,13 +23,13 @@ - block: - name: include snmp cpu test - include_tasks: roles/test/tasks/snmp/cpu.yml + include_tasks: roles/test/tasks/snmp/cpu.yml - name: inlcude snmp physical table test include_tasks: roles/test/tasks/snmp/phys_table.yml - name: include snmp PSU test - include_tasks: roles/test/tasks/snmp/psu.yml + include_tasks: roles/test/tasks/snmp/psu.yml when: - testcase_name is defined - (hostvars[ansible_hostname]['type'] is not defined) or (hostvars[ansible_hostname]['type'] != 'simx') \ No newline at end of file diff --git a/ansible/roles/test/tasks/snmp/cpu.yml b/ansible/roles/test/tasks/snmp/cpu.yml index 7e686b2e684..826ba93a480 100644 --- a/ansible/roles/test/tasks/snmp/cpu.yml +++ b/ansible/roles/test/tasks/snmp/cpu.yml @@ -1,4 +1,59 @@ -- name: run test - include_tasks: roles/test/tasks/pytest_runner.yml - vars: - test_node: snmp/test_snmp_cpu.py +# Test SNMP CPU Utilization +# +# - Pulls CPU usage via shell commans +# - Polls SNMP for CPU usage +# - Difference should be < 2% (allowing float->int rounding on each result) +# +# +# Requires: Ansible v1.x+ +# +# Usage: +# +# sudo ansible-playbook test.yml -i str --limit 10.3.147.142 --sudo --vault-password-file ~/password.txt --tags snmp_cpu +# +# +# TODO: abstract the snmp OID by SKU + +- block: + - name: Start cpu load generation + shell: cpu_load() { yes > /dev/null & }; cpu_load && cpu_load && cpu_load && cpu_load + become: yes + + - name: Wait for load to reflect in SNMP + pause: seconds=20 + + # Gather facts with SNMP version 2 + - name: Gathering basic snmp facts about the device + snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} is_dell=yes + delegate_to: localhost + + - name: Pull CPU utilization via shell + # Explanation: Run top command with 2 iterations, 5sec delay. Discard the first iteration, then grap the CPU line from the second, + # subtract 100% - idle, and round down to integer. + shell: top -bn2 -d5 | awk '/^top -/ { p=!p } { if (!p) print }' | awk '/Cpu/ { cpu = 100 - $8 };END { print cpu }' | awk '{printf "%.0f",$1}' + register: shell_cpu_usage + become: yes + + # If no value exists, fail instead of doing string->int conversion and weird math + - name: 'Validate SNMP CPU Utilization exists and is valid' + assert: + that: '(ansible_ChStackUnitCpuUtil5sec is defined) and ( {{ansible_ChStackUnitCpuUtil5sec|isnan}} == False ) ' + + - name: CPU usage from SNMP + debug: var=ansible_ChStackUnitCpuUtil5sec + + - name: CPU usage from TOP + debug: var=shell_cpu_usage.stdout + + - name: Difference between SNMP and TOP + debug: msg="{{ ((ansible_ChStackUnitCpuUtil5sec) - (shell_cpu_usage.stdout|int)) | abs() }}" + + # Compare results + - name: 'Validating SNMP CPU utilization matches shell "top" result' + assert: + that: "{{ ((ansible_ChStackUnitCpuUtil5sec) - (shell_cpu_usage.stdout|int)) | abs() }} <= 5" + + always: + - name: Stop cpu load generation + shell: killall yes + become: yes diff --git a/ansible/roles/test/tasks/snmp/interfaces.yml b/ansible/roles/test/tasks/snmp/interfaces.yml index 74a738081dc..18f559f6934 100644 --- a/ansible/roles/test/tasks/snmp/interfaces.yml +++ b/ansible/roles/test/tasks/snmp/interfaces.yml @@ -1,4 +1,37 @@ -- name: run test - include_tasks: roles/test/tasks/pytest_runner.yml - vars: - test_node: snmp/test_snmp_interfaces.py +# Gather facts with SNMP version 2 +- name: Gathering basic snmp facts about the device + snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} + delegate_to: localhost + +- set_fact: + snmp_intf: [] + mg_intf: [] + +- name: Create snmp interfaces list + set_fact: + snmp_intf: "{{ snmp_intf + [item.value.name] }}" + with_dict: "{{ snmp_interfaces }}" + when: "{{item.value.name is defined}}" + +- name: Create minigraph interfaces list + set_fact: + mg_intf: "{{ mg_intf + [item.value.alias] }}" + with_dict: "{{ minigraph_ports }}" + +- name: Add port channel interfaces into minigraph interfaces list + set_fact: + mg_intf: "{{ mg_intf + [item.key] }}" + with_dict: "{{ minigraph_portchannels }}" + +- name: Add management port into minigraph interfaces list + set_fact: + mg_intf: "{{ mg_intf + [minigraph_mgmt_interface.alias] }}" + +- debug: var=minigraph_port_name_to_alias_map +- debug: var=snmp_intf +- debug: var=mg_intf + +- name: Check for missing interfaces in SNMP + fail: msg="Minigraph interface {{ minigraph_port_name_to_alias_map[item] if item in minigraph_port_name_to_alias_map else item }} not in SNMP interfaces" + when: "{{ (item in minigraph_port_name_to_alias_map and minigraph_port_name_to_alias_map[item] not in snmp_intf) or (item not in minigraph_port_name_to_alias_map and item not in snmp_intf) }}" + with_items: "{{ mg_intf }}" diff --git a/ansible/roles/test/tasks/snmp/lldp.yml b/ansible/roles/test/tasks/snmp/lldp.yml index 8184e1a99eb..20615fd6b11 100644 --- a/ansible/roles/test/tasks/snmp/lldp.yml +++ b/ansible/roles/test/tasks/snmp/lldp.yml @@ -1,4 +1,114 @@ -- name: run test - include_tasks: roles/test/tasks/pytest_runner.yml - vars: - test_node: snmp/test_snmp_lldp.py +# Test checks for ieee802_1ab MIBs: +# - lldpLocalSystemData 1.0.8802.1.1.2.1.3 +# - lldpLocPortTable 1.0.8802.1.1.2.1.3.7 +# - lldpLocManAddrTable 1.0.8802.1.1.2.1.3.8 +# +# - lldpRemTable 1.0.8802.1.1.2.1.4.1 +# - lldpRemManAddrTable 1.0.8802.1.1.2.1.4.2 +# +# For local data check if every OID has value +# For remote values check for availability for +# at least 80% of minigraph neighbors +# (similar to lldp test) + + +# Gather facts with SNMP version 2 +- name: Gathering basic snmp facts about the device + snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} + delegate_to: localhost + +- name: Print SNMP LLDP information + debug: msg="{{ snmp_lldp }}" + +# Check if lldpLocalSysData is present + +- name: "Verify {{ item }} is defined" + assert: { that: "{{ snmp_lldp[item] is defined }} + and not {{ snmp_lldp[item] | search('No Such Object currently exists') }}" } + with_items: + - lldpLocChassisIdSubtype + - lldpLocChassisId + - lldpLocSysName + - lldpLocSysDesc + +- set_fact: + snmp_ports: "{{ snmp_ports|default({}) | combine({ item.key : item.value}) }}" + when: "{{ item.value.name is defined }} + and ({{ item.value['name'].find('Ethernet') != -1 }} or {{ item.value['name'].find('eth') != -1 }})" + with_dict: "{{ snmp_interfaces }}" + +# Check if lldpLocPortTable is present for all ports +- name: Verify lldpLocPortTable is present on port {{ item.value.name }} + assert: { that: "{{ item.value['lldpLocPortNum'] is defined }} + and {{ item.value['lldpLocPortIdSubtype'] is defined }} + and {{ item.value['lldpLocPortId'] is defined }} + and {{ item.value['lldpLocPortDesc'] is defined }}" } + with_dict: "{{ snmp_ports }}" + +# Check if lldpLocManAddrTable is present +- name: "Verify {{ item }} is defined" + assert: { that: "{{ snmp_lldp[item] is defined }} + and not {{ snmp_lldp[item] | search('No Such Object currently exists') }}" } + with_items: + - lldpLocManAddrSubtype + - lldpLocManAddr + - lldpLocManAddrLen + - lldpLocManAddrIfSubtype + - lldpLocManAddrIfId + - lldpLocManAddrOID + +# Check if lldpRemTable is present +- set_fact: + active_intf: [] + +- name: find minigraph lldp neighbor + set_fact: + minigraph_lldp_nei: "{{ minigraph_lldp_nei|default({}) | combine({ item.key : item.value}) }}" + when: "'server' not in item.value['name'] | lower" + with_dict: "{{ minigraph_neighbors }}" + +- name: Check if lldpRemTable is present on port {{ item.value.name }} + when: "{{ item.value['lldpRemTimeMark'] is defined }} + and {{ item.value['lldpRemLocalPortNum'] is defined }} + and {{ item.value['lldpRemIndex'] is defined }} + and {{ item.value['lldpRemChassisIdSubtype'] is defined }} + and {{ item.value['lldpRemChassisId'] is defined }} + and {{ item.value['lldpRemPortIdSubtype'] is defined }} + and {{ item.value['lldpRemPortId'] is defined }} + and {{ item.value['lldpRemPortDesc'] is defined }} + and {{ item.value['lldpRemSysName'] is defined }} + and {{ item.value['lldpRemSysDesc'] is defined }} + and {{ item.value['lldpRemSysCapSupported'] is defined }} + and {{ item.value['lldpRemSysCapEnabled'] is defined }}" + set_fact: + active_intf: "{{ active_intf + [item] }}" + with_dict: "{{ snmp_interfaces }}" + +- debug: + msg: "Found {{ active_intf | length }} Ifs with lldpRemTable data\n + Minigraph contains {{ minigraph_lldp_nei | length }} neighbors" + +- name: Verify lldpRemTable is available on most interfaces + assert: {that: "{{ minigraph_lldp_nei | length * 0.8 }} <= {{ active_intf | length }}" } + +# Check if lldpRemManAddrTable is present +- set_fact: + active_intf: [] + +- name: Check if lldpRemManAddrTable is present on port {{ item.value.name }} + when: "{{ item.value['lldpRemManAddrSubtype'] is defined }} + and {{ item.value['lldpRemManAddr'] is defined }} + and {{ item.value['lldpRemManAddr'] is defined }} + and {{ item.value['lldpRemManAddrIfSubtype'] is defined }} + and {{ item.value['lldpRemManAddrIfId'] is defined }} + and {{ item.value['lldpRemManAddrOID'] is defined }}" + set_fact: + active_intf: "{{ active_intf + [item] }}" + with_dict: "{{ snmp_interfaces }}" + +- debug: + msg: "Found {{ active_intf | length }} Ifs with lldpRemManAddr data\n + Minigraph contains {{ minigraph_lldp_nei | length }} neighbors" + +- name: Verify lldpRemManAddr is available on most interfaces + assert: {that: "{{ minigraph_lldp_nei | length * 0.8 }} <= {{ active_intf | length }}" } diff --git a/ansible/roles/test/tasks/snmp/pfc_counters.yml b/ansible/roles/test/tasks/snmp/pfc_counters.yml index f1f096d8a09..3438de0913f 100644 --- a/ansible/roles/test/tasks/snmp/pfc_counters.yml +++ b/ansible/roles/test/tasks/snmp/pfc_counters.yml @@ -1,4 +1,15 @@ -- name: run test - include_tasks: roles/test/tasks/pytest_runner.yml - vars: - test_node: snmp/test_snmp_pfc_counters.py +# Gather facts with SNMP version 2 +- name: Gathering basic snmp facts about the device + snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} + delegate_to: localhost + +# Check PFC counters +# Ignore management ports, assuming the names starting with 'eth', eg. eth0 +- fail: + msg: "Port {{ item.key }} does not have PFC counters" + when: "{{ (not item.value.name.startswith('eth')) and + ('cpfcIfRequests' not in item.value.keys() or + 'cpfcIfIndications' not in item.value.keys() or + 'requestsPerPriority' not in item.value.keys() or + 'indicationsPerPriority' not in item.value.keys()) }}" + with_dict: "{{ snmp_interfaces }}" diff --git a/ansible/roles/test/tasks/snmp/phys_table.yml b/ansible/roles/test/tasks/snmp/phys_table.yml index 3e6dff3eefc..467f703d36c 100644 --- a/ansible/roles/test/tasks/snmp/phys_table.yml +++ b/ansible/roles/test/tasks/snmp/phys_table.yml @@ -1,7 +1,7 @@ # Gather facts with SNMP version 2 - name: Gathering basic snmp facts about the device snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - connection: local + delegate_to: localhost - set_fact: chassis_id: "1" diff --git a/ansible/roles/test/tasks/snmp/psu.yml b/ansible/roles/test/tasks/snmp/psu.yml index 13cf10db969..72f52e9d804 100644 --- a/ansible/roles/test/tasks/snmp/psu.yml +++ b/ansible/roles/test/tasks/snmp/psu.yml @@ -1,7 +1,7 @@ # Gather facts with SNMP version 2 - name: Gathering basic snmp facts about the device snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - connection: local + delegate_to: localhost # We assume that all the PSUs tested should be in good status, otherwise, fix the PSU manually - fail: diff --git a/ansible/roles/test/tasks/snmp/queues.yml b/ansible/roles/test/tasks/snmp/queues.yml index 8a012864696..f1c07399e9c 100644 --- a/ansible/roles/test/tasks/snmp/queues.yml +++ b/ansible/roles/test/tasks/snmp/queues.yml @@ -1,4 +1,9 @@ -- name: run test - include_tasks: roles/test/tasks/pytest_runner.yml - vars: - test_node: snmp/test_snmp_queue.py +# Gather facts with SNMP version 2 +- name: Gathering basic snmp facts about the device + snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} + delegate_to: localhost + +- fail: + msg: "Port {{ item.key }} does not have queue counters" + when: "{{ item.value.description | match('^Ethernet') }} and {{ item.value['queues'] is not defined }}" + with_dict: "{{ snmp_interfaces }}" diff --git a/ansible/roles/test/tasks/sonic.yml b/ansible/roles/test/tasks/sonic.yml index bfdda1a202b..91d2e42afc0 100644 --- a/ansible/roles/test/tasks/sonic.yml +++ b/ansible/roles/test/tasks/sonic.yml @@ -27,7 +27,7 @@ set_fact: sonic_asic_type: marvell when: sonic_hwsku in marvell_hwskus - + ########################################################################### ##### run test using ansible tag when no testbedname specified ###### ########################################################################### @@ -59,7 +59,7 @@ - block: - name: Gathering testbed information test_facts: testbed_name="{{ testbed_name }}" testbed_file="{{ testbed_file }}" - connection: local + delegate_to: localhost - fail: msg="The DUT you are trying to run test does not belongs to this testbed" when: testbed_facts['dut'] != inventory_hostname diff --git a/ansible/roles/test/tasks/syslog.yml b/ansible/roles/test/tasks/syslog.yml index fa74c902b7f..c502bb65b16 100644 --- a/ansible/roles/test/tasks/syslog.yml +++ b/ansible/roles/test/tasks/syslog.yml @@ -19,7 +19,7 @@ # Fetch the source IP of the ansible server - name: Get localhost facts setup: - connection: local + delegate_to: localhost register: local_facts #- debug: var=local_facts.ansible_facts.ansible_eth0.ipv4.address @@ -49,7 +49,7 @@ # Start local ryslog Server - name: Load imudp module in local syslog - connection: local + delegate_to: localhost become: true lineinfile: line: "module(load=\"imudp\")" @@ -57,7 +57,7 @@ state: present - name: Remove imudp ports - connection: local + delegate_to: localhost become: true lineinfile: regexp: "input\\(type=\"imudp\" port=\"\\d+\"\\)" @@ -65,7 +65,7 @@ state: absent - name: Add imudp port {{ syslog_port }} - connection: local + delegate_to: localhost become: true lineinfile: line: "input(type=\"imudp\" port=\"{{ syslog_port }}\")" @@ -73,20 +73,20 @@ state: present - name: Stop Syslog Daemon - connection: local + delegate_to: localhost become: true shell: killall rsyslogd ignore_errors: true - name: Remove local /var/log/syslog become: true - connection: local + delegate_to: localhost file: path: /var/log/syslog state: absent - name: Start Syslog Daemon - connection: local + delegate_to: localhost become: true service: name=rsyslog state=started @@ -112,7 +112,7 @@ # Check Messages - name: Check syslog messages for the test message - connection: local + delegate_to: localhost become: true shell: grep {{ inventory_hostname }} /var/log/syslog | grep "{{ test_message }}" | grep -v ansible register: grep_result diff --git a/ansible/roles/test/tasks/vlan_configure.yml b/ansible/roles/test/tasks/vlan_configure.yml index c9ac5506d1f..57083ec229a 100644 --- a/ansible/roles/test/tasks/vlan_configure.yml +++ b/ansible/roles/test/tasks/vlan_configure.yml @@ -14,7 +14,7 @@ - name: Generate VLAN ports information template: src=roles/test/templates/vlan_info.j2 dest=/tmp/vlan_info.yml - connection: local + delegate_to: localhost - name: Load VLAN ports info from file include_vars: '/tmp/vlan_info.yml' diff --git a/ansible/roles/test/tasks/vlantb.yml b/ansible/roles/test/tasks/vlantb.yml index 0648c586261..e1f4e080eec 100644 --- a/ansible/roles/test/tasks/vlantb.yml +++ b/ansible/roles/test/tasks/vlantb.yml @@ -3,18 +3,15 @@ #----------------------------------------- - name: Vlan test setup on testbed include_tasks: vlan_configure.yml - tags: vlan_configure #----------------------------------------- # Run Vlan test #----------------------------------------- - name: Vlan test run on testbed include_tasks: vlan_test.yml - tags: vlan_test #----------------------------------------- # Clean up Vlan configuration #----------------------------------------- - name: Clean up Vlan test configuration on the testbed include_tasks: vlan_cleanup.yml - tags: vlan_cleanup diff --git a/ansible/roles/test/tasks/vnet_vxlan.yml b/ansible/roles/test/tasks/vnet_vxlan.yml index 5375fd4f224..4e41cd99634 100644 --- a/ansible/roles/test/tasks/vnet_vxlan.yml +++ b/ansible/roles/test/tasks/vnet_vxlan.yml @@ -42,7 +42,7 @@ - name: Generate VNet configuration template: src=roles/test/templates/vnet_config.j2 dest=/tmp/vnet_config.yml - connection: local + delegate_to: localhost - name: Load VNet info from file include_vars: '/tmp/vnet_config.yml' diff --git a/ansible/roles/vm_set/library/kickstart.py b/ansible/roles/vm_set/library/kickstart.py index 93b299f6a13..b9a719c2363 100644 --- a/ansible/roles/vm_set/library/kickstart.py +++ b/ansible/roles/vm_set/library/kickstart.py @@ -164,7 +164,7 @@ def session(new_params): ('aaa root secret 0 %s' % str(new_params['new_root_password']), [r'\(config\)#']), ] - curtime = datetime().datetime().now().isoformat() + curtime = datetime.datetime.now().isoformat() debug = MyDebug('/tmp/debug.%s.%s.txt' % (new_params['hostname'], curtime), enabled=True) ss = SerialSession(new_params['telnet_port'], debug) ss.login(new_params['login'], new_params['password']) diff --git a/ansible/roles/vm_set/tasks/docker.yml b/ansible/roles/vm_set/tasks/docker.yml index dd8049b8127..bd281412c09 100644 --- a/ansible/roles/vm_set/tasks/docker.yml +++ b/ansible/roles/vm_set/tasks/docker.yml @@ -29,12 +29,17 @@ become: yes environment: "{{ proxy_env | default({}) }}" +- name: Get default pip_executable + set_fact: + pip_executable: /usr/bin/pip + when: pip_executable is not defined + - name: remove old python packages - pip: name=docker-py state=absent + pip: name=docker-py state=absent executable={{ pip_executable }} become: yes environment: "{{ proxy_env | default({}) }}" - name: Install python packages - pip: name=docker version=4.1.0 state=forcereinstall + pip: name=docker version=4.1.0 state=forcereinstall executable={{ pip_executable }} become: yes environment: "{{ proxy_env | default({}) }}" diff --git a/ansible/roles/vm_set/tasks/start_sid.yml b/ansible/roles/vm_set/tasks/start_sid.yml index 83a58cfceed..ca0970bd4e6 100755 --- a/ansible/roles/vm_set/tasks/start_sid.yml +++ b/ansible/roles/vm_set/tasks/start_sid.yml @@ -1,4 +1,4 @@ -- name: Create directory for SimX in docker(SID) images and disk images +- name: Create directory for SimX in docker(SID) images and disk images file: path={{ item }} state=directory mode=0755 with_items: - "{{ home_path }}/sid/images" @@ -32,8 +32,8 @@ - fail: msg="{{ item }} is not defined" when: "{{ item }} is not defined" with_items: - - mellanox_spc1_hwskus - - mellanox_spc2_hwskus + - "{{ mellanox_spc1_hwskus }}" + - "{{ mellanox_spc2_hwskus }}" - set_fact: chip: "spectrum" diff --git a/ansible/roles/vm_set/tasks/start_sonic_vm.yml b/ansible/roles/vm_set/tasks/start_sonic_vm.yml index 17d3d4fa508..40d95e622eb 100644 --- a/ansible/roles/vm_set/tasks/start_sonic_vm.yml +++ b/ansible/roles/vm_set/tasks/start_sonic_vm.yml @@ -24,7 +24,7 @@ - name: Get DUT port alias port_alias: hwsku={{ hostvars[dut_name].hwsku }} - connection: local + delegate_to: localhost - name: Define vm {{ dut_name }} virt: name={{ dut_name }} diff --git a/ansible/testbed_add_vm_topology.yml b/ansible/testbed_add_vm_topology.yml index 6dcf746e4cf..5e35e0974c0 100644 --- a/ansible/testbed_add_vm_topology.yml +++ b/ansible/testbed_add_vm_topology.yml @@ -6,7 +6,7 @@ # - configuration property # - configuration # -# topology key contains a dictionary of hostnames with 'vm_offset' and 'vlans' keys in it. +# topology key contains a dictionary of hostnames with 'vm_offset' and 'vlans' keys in it. # 'vm_offset' is used to map current hostname vm_set VM to server VM (like ARISTA01T0 -> VM0300). # This offset is used on VM_base # 'vlans' is a list of vlan offsets which helps us to calculate vlan numbers which will be connected to Eth1/1..Eth1/8 interfaces. @@ -69,7 +69,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'start_sonic_vm' } diff --git a/ansible/testbed_connect_vms.yml b/ansible/testbed_connect_vms.yml index 0bd464407d3..b5aae29394d 100644 --- a/ansible/testbed_connect_vms.yml +++ b/ansible/testbed_connect_vms.yml @@ -43,7 +43,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'connect_vms' } diff --git a/ansible/testbed_disconnect_vms.yml b/ansible/testbed_disconnect_vms.yml index 1b32bb17311..a75593a4ea8 100644 --- a/ansible/testbed_disconnect_vms.yml +++ b/ansible/testbed_disconnect_vms.yml @@ -43,7 +43,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'disconnect_vms' } diff --git a/ansible/testbed_refresh_dut.yml b/ansible/testbed_refresh_dut.yml index 2ae764bfb22..2902f8e31a6 100644 --- a/ansible/testbed_refresh_dut.yml +++ b/ansible/testbed_refresh_dut.yml @@ -6,7 +6,7 @@ # - configuration property # - configuration # -# topology key contains a dictionary of hostnames with 'vm_offset' and 'vlans' keys in it. +# topology key contains a dictionary of hostnames with 'vm_offset' and 'vlans' keys in it. # 'vm_offset' is used to map current hostname vm_set VM to server VM (like ARISTA01T0 -> VM0300). # This offset is used on VM_base # 'vlans' is a list of vlan offsets which helps us to calculate vlan numbers which will be connected to Eth1/1..Eth1/8 interfaces. @@ -69,7 +69,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'stop_sonic_vm' } diff --git a/ansible/testbed_remove_vm_topology.yml b/ansible/testbed_remove_vm_topology.yml index 855360f5034..9a83ee1610b 100644 --- a/ansible/testbed_remove_vm_topology.yml +++ b/ansible/testbed_remove_vm_topology.yml @@ -52,7 +52,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'remove_topo' } diff --git a/ansible/testbed_renumber_vm_topology.yml b/ansible/testbed_renumber_vm_topology.yml index 5fe11f05370..2f92ab7256c 100644 --- a/ansible/testbed_renumber_vm_topology.yml +++ b/ansible/testbed_renumber_vm_topology.yml @@ -51,7 +51,7 @@ - name: Read dut minigraph conn_graph_facts: host={{ dut_name }} - connection: local + delegate_to: localhost roles: - { role: vm_set, action: 'renumber_topo' } diff --git a/tests/conftest.py b/tests/conftest.py index 62cfe547ea6..afe31512fcb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -93,7 +93,7 @@ def testbed_devices(ansible_adhoc, testbed): # when no ptf defined in testbed.csv # try to parse it from inventory dut = devices["dut"] - ptf_host = dut.host.options["inventory_manager"].get_vars(dut.hostname)["ptf_host"] + ptf_host = dut.host.options["inventory_manager"].get_host(dut.hostname).get_vars()["ptf_host"] devices["ptf"] = PTFHost(ansible_adhoc, ptf_host) # In the future, we can implement more classes for interacting with other testbed devices in the lib.devices From b9ac2c2e212d6c18b40a5ffa05b866e2aaefbdac Mon Sep 17 00:00:00 2001 From: Xin Wang Date: Tue, 10 Dec 2019 10:59:23 +0800 Subject: [PATCH 2/2] Revert SNMP tests to pytest Change-Id: I31f43b19cf8cf6ec77848238d2ed6df0cae025e8 Signed-off-by: Xin Wang --- ansible/roles/test/tasks/snmp/cpu.yml | 63 +--------- ansible/roles/test/tasks/snmp/interfaces.yml | 41 +----- ansible/roles/test/tasks/snmp/lldp.yml | 118 +----------------- .../roles/test/tasks/snmp/pfc_counters.yml | 19 +-- ansible/roles/test/tasks/snmp/queues.yml | 13 +- 5 files changed, 20 insertions(+), 234 deletions(-) diff --git a/ansible/roles/test/tasks/snmp/cpu.yml b/ansible/roles/test/tasks/snmp/cpu.yml index 826ba93a480..7e686b2e684 100644 --- a/ansible/roles/test/tasks/snmp/cpu.yml +++ b/ansible/roles/test/tasks/snmp/cpu.yml @@ -1,59 +1,4 @@ -# Test SNMP CPU Utilization -# -# - Pulls CPU usage via shell commans -# - Polls SNMP for CPU usage -# - Difference should be < 2% (allowing float->int rounding on each result) -# -# -# Requires: Ansible v1.x+ -# -# Usage: -# -# sudo ansible-playbook test.yml -i str --limit 10.3.147.142 --sudo --vault-password-file ~/password.txt --tags snmp_cpu -# -# -# TODO: abstract the snmp OID by SKU - -- block: - - name: Start cpu load generation - shell: cpu_load() { yes > /dev/null & }; cpu_load && cpu_load && cpu_load && cpu_load - become: yes - - - name: Wait for load to reflect in SNMP - pause: seconds=20 - - # Gather facts with SNMP version 2 - - name: Gathering basic snmp facts about the device - snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} is_dell=yes - delegate_to: localhost - - - name: Pull CPU utilization via shell - # Explanation: Run top command with 2 iterations, 5sec delay. Discard the first iteration, then grap the CPU line from the second, - # subtract 100% - idle, and round down to integer. - shell: top -bn2 -d5 | awk '/^top -/ { p=!p } { if (!p) print }' | awk '/Cpu/ { cpu = 100 - $8 };END { print cpu }' | awk '{printf "%.0f",$1}' - register: shell_cpu_usage - become: yes - - # If no value exists, fail instead of doing string->int conversion and weird math - - name: 'Validate SNMP CPU Utilization exists and is valid' - assert: - that: '(ansible_ChStackUnitCpuUtil5sec is defined) and ( {{ansible_ChStackUnitCpuUtil5sec|isnan}} == False ) ' - - - name: CPU usage from SNMP - debug: var=ansible_ChStackUnitCpuUtil5sec - - - name: CPU usage from TOP - debug: var=shell_cpu_usage.stdout - - - name: Difference between SNMP and TOP - debug: msg="{{ ((ansible_ChStackUnitCpuUtil5sec) - (shell_cpu_usage.stdout|int)) | abs() }}" - - # Compare results - - name: 'Validating SNMP CPU utilization matches shell "top" result' - assert: - that: "{{ ((ansible_ChStackUnitCpuUtil5sec) - (shell_cpu_usage.stdout|int)) | abs() }} <= 5" - - always: - - name: Stop cpu load generation - shell: killall yes - become: yes +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: snmp/test_snmp_cpu.py diff --git a/ansible/roles/test/tasks/snmp/interfaces.yml b/ansible/roles/test/tasks/snmp/interfaces.yml index 18f559f6934..74a738081dc 100644 --- a/ansible/roles/test/tasks/snmp/interfaces.yml +++ b/ansible/roles/test/tasks/snmp/interfaces.yml @@ -1,37 +1,4 @@ -# Gather facts with SNMP version 2 -- name: Gathering basic snmp facts about the device - snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - delegate_to: localhost - -- set_fact: - snmp_intf: [] - mg_intf: [] - -- name: Create snmp interfaces list - set_fact: - snmp_intf: "{{ snmp_intf + [item.value.name] }}" - with_dict: "{{ snmp_interfaces }}" - when: "{{item.value.name is defined}}" - -- name: Create minigraph interfaces list - set_fact: - mg_intf: "{{ mg_intf + [item.value.alias] }}" - with_dict: "{{ minigraph_ports }}" - -- name: Add port channel interfaces into minigraph interfaces list - set_fact: - mg_intf: "{{ mg_intf + [item.key] }}" - with_dict: "{{ minigraph_portchannels }}" - -- name: Add management port into minigraph interfaces list - set_fact: - mg_intf: "{{ mg_intf + [minigraph_mgmt_interface.alias] }}" - -- debug: var=minigraph_port_name_to_alias_map -- debug: var=snmp_intf -- debug: var=mg_intf - -- name: Check for missing interfaces in SNMP - fail: msg="Minigraph interface {{ minigraph_port_name_to_alias_map[item] if item in minigraph_port_name_to_alias_map else item }} not in SNMP interfaces" - when: "{{ (item in minigraph_port_name_to_alias_map and minigraph_port_name_to_alias_map[item] not in snmp_intf) or (item not in minigraph_port_name_to_alias_map and item not in snmp_intf) }}" - with_items: "{{ mg_intf }}" +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: snmp/test_snmp_interfaces.py diff --git a/ansible/roles/test/tasks/snmp/lldp.yml b/ansible/roles/test/tasks/snmp/lldp.yml index 20615fd6b11..8184e1a99eb 100644 --- a/ansible/roles/test/tasks/snmp/lldp.yml +++ b/ansible/roles/test/tasks/snmp/lldp.yml @@ -1,114 +1,4 @@ -# Test checks for ieee802_1ab MIBs: -# - lldpLocalSystemData 1.0.8802.1.1.2.1.3 -# - lldpLocPortTable 1.0.8802.1.1.2.1.3.7 -# - lldpLocManAddrTable 1.0.8802.1.1.2.1.3.8 -# -# - lldpRemTable 1.0.8802.1.1.2.1.4.1 -# - lldpRemManAddrTable 1.0.8802.1.1.2.1.4.2 -# -# For local data check if every OID has value -# For remote values check for availability for -# at least 80% of minigraph neighbors -# (similar to lldp test) - - -# Gather facts with SNMP version 2 -- name: Gathering basic snmp facts about the device - snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - delegate_to: localhost - -- name: Print SNMP LLDP information - debug: msg="{{ snmp_lldp }}" - -# Check if lldpLocalSysData is present - -- name: "Verify {{ item }} is defined" - assert: { that: "{{ snmp_lldp[item] is defined }} - and not {{ snmp_lldp[item] | search('No Such Object currently exists') }}" } - with_items: - - lldpLocChassisIdSubtype - - lldpLocChassisId - - lldpLocSysName - - lldpLocSysDesc - -- set_fact: - snmp_ports: "{{ snmp_ports|default({}) | combine({ item.key : item.value}) }}" - when: "{{ item.value.name is defined }} - and ({{ item.value['name'].find('Ethernet') != -1 }} or {{ item.value['name'].find('eth') != -1 }})" - with_dict: "{{ snmp_interfaces }}" - -# Check if lldpLocPortTable is present for all ports -- name: Verify lldpLocPortTable is present on port {{ item.value.name }} - assert: { that: "{{ item.value['lldpLocPortNum'] is defined }} - and {{ item.value['lldpLocPortIdSubtype'] is defined }} - and {{ item.value['lldpLocPortId'] is defined }} - and {{ item.value['lldpLocPortDesc'] is defined }}" } - with_dict: "{{ snmp_ports }}" - -# Check if lldpLocManAddrTable is present -- name: "Verify {{ item }} is defined" - assert: { that: "{{ snmp_lldp[item] is defined }} - and not {{ snmp_lldp[item] | search('No Such Object currently exists') }}" } - with_items: - - lldpLocManAddrSubtype - - lldpLocManAddr - - lldpLocManAddrLen - - lldpLocManAddrIfSubtype - - lldpLocManAddrIfId - - lldpLocManAddrOID - -# Check if lldpRemTable is present -- set_fact: - active_intf: [] - -- name: find minigraph lldp neighbor - set_fact: - minigraph_lldp_nei: "{{ minigraph_lldp_nei|default({}) | combine({ item.key : item.value}) }}" - when: "'server' not in item.value['name'] | lower" - with_dict: "{{ minigraph_neighbors }}" - -- name: Check if lldpRemTable is present on port {{ item.value.name }} - when: "{{ item.value['lldpRemTimeMark'] is defined }} - and {{ item.value['lldpRemLocalPortNum'] is defined }} - and {{ item.value['lldpRemIndex'] is defined }} - and {{ item.value['lldpRemChassisIdSubtype'] is defined }} - and {{ item.value['lldpRemChassisId'] is defined }} - and {{ item.value['lldpRemPortIdSubtype'] is defined }} - and {{ item.value['lldpRemPortId'] is defined }} - and {{ item.value['lldpRemPortDesc'] is defined }} - and {{ item.value['lldpRemSysName'] is defined }} - and {{ item.value['lldpRemSysDesc'] is defined }} - and {{ item.value['lldpRemSysCapSupported'] is defined }} - and {{ item.value['lldpRemSysCapEnabled'] is defined }}" - set_fact: - active_intf: "{{ active_intf + [item] }}" - with_dict: "{{ snmp_interfaces }}" - -- debug: - msg: "Found {{ active_intf | length }} Ifs with lldpRemTable data\n - Minigraph contains {{ minigraph_lldp_nei | length }} neighbors" - -- name: Verify lldpRemTable is available on most interfaces - assert: {that: "{{ minigraph_lldp_nei | length * 0.8 }} <= {{ active_intf | length }}" } - -# Check if lldpRemManAddrTable is present -- set_fact: - active_intf: [] - -- name: Check if lldpRemManAddrTable is present on port {{ item.value.name }} - when: "{{ item.value['lldpRemManAddrSubtype'] is defined }} - and {{ item.value['lldpRemManAddr'] is defined }} - and {{ item.value['lldpRemManAddr'] is defined }} - and {{ item.value['lldpRemManAddrIfSubtype'] is defined }} - and {{ item.value['lldpRemManAddrIfId'] is defined }} - and {{ item.value['lldpRemManAddrOID'] is defined }}" - set_fact: - active_intf: "{{ active_intf + [item] }}" - with_dict: "{{ snmp_interfaces }}" - -- debug: - msg: "Found {{ active_intf | length }} Ifs with lldpRemManAddr data\n - Minigraph contains {{ minigraph_lldp_nei | length }} neighbors" - -- name: Verify lldpRemManAddr is available on most interfaces - assert: {that: "{{ minigraph_lldp_nei | length * 0.8 }} <= {{ active_intf | length }}" } +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: snmp/test_snmp_lldp.py diff --git a/ansible/roles/test/tasks/snmp/pfc_counters.yml b/ansible/roles/test/tasks/snmp/pfc_counters.yml index 3438de0913f..f1f096d8a09 100644 --- a/ansible/roles/test/tasks/snmp/pfc_counters.yml +++ b/ansible/roles/test/tasks/snmp/pfc_counters.yml @@ -1,15 +1,4 @@ -# Gather facts with SNMP version 2 -- name: Gathering basic snmp facts about the device - snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - delegate_to: localhost - -# Check PFC counters -# Ignore management ports, assuming the names starting with 'eth', eg. eth0 -- fail: - msg: "Port {{ item.key }} does not have PFC counters" - when: "{{ (not item.value.name.startswith('eth')) and - ('cpfcIfRequests' not in item.value.keys() or - 'cpfcIfIndications' not in item.value.keys() or - 'requestsPerPriority' not in item.value.keys() or - 'indicationsPerPriority' not in item.value.keys()) }}" - with_dict: "{{ snmp_interfaces }}" +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: snmp/test_snmp_pfc_counters.py diff --git a/ansible/roles/test/tasks/snmp/queues.yml b/ansible/roles/test/tasks/snmp/queues.yml index f1c07399e9c..8a012864696 100644 --- a/ansible/roles/test/tasks/snmp/queues.yml +++ b/ansible/roles/test/tasks/snmp/queues.yml @@ -1,9 +1,4 @@ -# Gather facts with SNMP version 2 -- name: Gathering basic snmp facts about the device - snmp_facts: host={{ ansible_host }} version=v2c community={{ snmp_rocommunity }} - delegate_to: localhost - -- fail: - msg: "Port {{ item.key }} does not have queue counters" - when: "{{ item.value.description | match('^Ethernet') }} and {{ item.value['queues'] is not defined }}" - with_dict: "{{ snmp_interfaces }}" +- name: run test + include_tasks: roles/test/tasks/pytest_runner.yml + vars: + test_node: snmp/test_snmp_queue.py