diff --git a/ansible/roles/vm_set/tasks/main.yml b/ansible/roles/vm_set/tasks/main.yml index 62c975188a9..869c5f38491 100644 --- a/ansible/roles/vm_set/tasks/main.yml +++ b/ansible/roles/vm_set/tasks/main.yml @@ -15,6 +15,11 @@ # Need latest ubuntu 4.10 kernel to fix a openvswitch bug # https://bugs.launchpad.net/ubuntu/+source/kernel-package/+bug/1685742 +- name: Set the default variable package_installation + set_fact: + package_installation: true + when: package_installation is not defined + - name: get host distribution shell: grep ^NAME /etc/os-release | awk -F '=' '{print $2}' | tr -d '"' register: host_distribution @@ -52,45 +57,49 @@ - name: Prompt for rebooting fail: msg: "Kernel upgraded, need to reboot!" - when: kernel_upgrade_needed is defined + when: + - kernel_upgrade_needed is defined + - package_installation|bool -- name: Install necessary packages - apt: pkg={{ item }} update_cache=yes cache_valid_time=86400 - become: yes - with_items: - - ifupdown - - qemu - - openvswitch-switch - - net-tools - - bridge-utils - - util-linux - - iproute2 - - vlan - - apt-transport-https - - ca-certificates - - curl - - software-properties-common - - libvirt-clients - -- name: - apt: - pkg: - - python - - libvirt-bin - - python-libvirt - - python-pip - become: yes - when: host_distribution_version.stdout == "18.04" - -- name: - apt: - pkg: - - python3-libvirt - - python3-pip - - libvirt-daemon-system - - qemu-system-x86 - become: yes - when: host_distribution_version.stdout == "20.04" +- block: + - name: Install necessary packages + apt: pkg={{ item }} update_cache=yes cache_valid_time=86400 + become: yes + with_items: + - ifupdown + - qemu + - openvswitch-switch + - net-tools + - bridge-utils + - util-linux + - iproute2 + - vlan + - apt-transport-https + - ca-certificates + - curl + - software-properties-common + - libvirt-clients + + - name: + apt: + pkg: + - python + - libvirt-bin + - python-libvirt + - python-pip + become: yes + when: host_distribution_version.stdout == "18.04" + + - name: + apt: + pkg: + - python3-libvirt + - python3-pip + - libvirt-daemon-system + - qemu-system-x86 + become: yes + when: host_distribution_version.stdout == "20.04" + when: package_installation|bool - name: Get default pip_executable set_fact: @@ -103,6 +112,7 @@ when: pip_executable is not defined and host_distribution_version.stdout == "20.04" - include_tasks: docker.yml + when: package_installation|bool - name: Ensure {{ ansible_user }} in docker,sudo group user: diff --git a/ansible/testbed_renumber_vm_topology.yml b/ansible/testbed_renumber_vm_topology.yml index 91343ecd9e9..e11aad8049c 100644 --- a/ansible/testbed_renumber_vm_topology.yml +++ b/ansible/testbed_renumber_vm_topology.yml @@ -57,6 +57,10 @@ fail: msg="Define ptf_imagename variable with -e ptf_imagename=something" when: ptf_imagename is not defined + - name: Disable package installation + set_fact: + package_installation: false + - name: Load topo variables include_vars: "vars/topo_{{ topo }}.yml" diff --git a/tests/acl/null_route/test_null_route_helper.py b/tests/acl/null_route/test_null_route_helper.py index 657d405a187..5c694a7f8a5 100644 --- a/tests/acl/null_route/test_null_route_helper.py +++ b/tests/acl/null_route/test_null_route_helper.py @@ -54,6 +54,12 @@ ] +@pytest.fixture(scope="module", autouse=True) +def skip_on_dualtor_testbed(tbinfo): + if 'dualtor' in tbinfo['topo']['name']: + pytest.skip("Skip running on dualtor testbed") + + @pytest.fixture(scope="module") def create_acl_table(rand_selected_dut, tbinfo): """ diff --git a/tests/bgp/test_bgpmon.py b/tests/bgp/test_bgpmon.py index ba37aed2470..52f80bfda08 100644 --- a/tests/bgp/test_bgpmon.py +++ b/tests/bgp/test_bgpmon.py @@ -23,6 +23,13 @@ logger = logging.getLogger(__name__) +@pytest.fixture(scope="module", autouse=True) +def skip_test_bgpmon_on_backend(tbinfo): + """Skip test_bgpmon over storage backend topologies.""" + if "backend" in tbinfo["topo"]["name"]: + pytest.skip("Skipping test_bgpmon. Unsupported topology %s." % tbinfo["topo"]["name"]) + + def get_default_route_ports(host, tbinfo): mg_facts = host.get_extended_minigraph_facts(tbinfo) route_info = json.loads(host.shell("show ip route {} json".format(ZERO_ADDR))['stdout']) diff --git a/tests/common/plugins/sanity_check/recover.py b/tests/common/plugins/sanity_check/recover.py index 100caeef30c..6f5c522fbde 100644 --- a/tests/common/plugins/sanity_check/recover.py +++ b/tests/common/plugins/sanity_check/recover.py @@ -111,7 +111,6 @@ def neighbor_vm_restore(duthost, nbrhosts, tbinfo): vm_neighbors = mg_facts['minigraph_neighbors'] if vm_neighbors: lag_facts = duthost.lag_facts(host = duthost.hostname)['ansible_facts']['lag_facts'] - for lag_name in lag_facts['names']: nbr_intf = lag_facts['lags'][lag_name]['po_config']['ports'].keys()[0] peer_device = vm_neighbors[nbr_intf]['name'] @@ -121,5 +120,7 @@ def neighbor_vm_restore(duthost, nbrhosts, tbinfo): for intf in intf_list: nbr_host.no_shutdown(intf) asn = nbrhosts[peer_device]['conf']['bgp']['asn'] + # start BGPd + nbr_host.start_bgpd() # restore BGP session nbr_host.no_shutdown_bgp(asn) diff --git a/tests/conftest.py b/tests/conftest.py index 48c7ca1f43e..7b38fd05fb9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,8 +36,6 @@ from tests.common.connections.console_host import ConsoleHost -WAIT_FOR_COUNTERS_TIMEOUT = 190 -WAIT_FOR_COUNTERS_INTERVAL = 10 logger = logging.getLogger(__name__) cache = FactsCache() @@ -1145,25 +1143,3 @@ def duts_minigraph_facts(duthosts, tbinfo): } """ return duthosts.get_extended_minigraph_facts(tbinfo) - -@pytest.fixture(scope='function') -def wait_for_counters(duthosts, rand_one_dut_hostname): - duthost = duthosts[rand_one_dut_hostname] - logger.info('Wait until all counters are enabled on the DUT') - counters = ['PORT_STAT', 'PORT_BUFFER_DROP', 'QUEUE_STAT', 'PG_WATERMARK_STAT', 'RIF_STAT'] - current_attempt = 0 - while current_attempt < WAIT_FOR_COUNTERS_TIMEOUT / WAIT_FOR_COUNTERS_INTERVAL: - output = duthost.shell("counterpoll show | sed '1,2d'", module_ignore_errors=True) - assert output.has_key('rc') and output['rc'] == 0, "Failed to get counters status" - counters_lines = output['stdout'].splitlines() - enabled_counters = 0 - for line in counters_lines: - if any(counter in line for counter in counters) and 'enable' in line: - enabled_counters += 1 - continue - if enabled_counters == len(counters): - return - else: - current_attempt += 1 - time.sleep(WAIT_FOR_COUNTERS_INTERVAL) - assert False, "Not all counters are enabled after {} seconds".format(WAIT_FOR_COUNTERS_TIMEOUT) diff --git a/tests/platform_tests/test_auto_negotiation.py b/tests/platform_tests/test_auto_negotiation.py index d50784bdde0..ae2629bba0a 100644 --- a/tests/platform_tests/test_auto_negotiation.py +++ b/tests/platform_tests/test_auto_negotiation.py @@ -16,6 +16,7 @@ from tests.common.helpers.dut_ports import decode_dut_port_name from tests.common.utilities import wait_until from tests.platform_tests.link_flap.link_flap_utils import build_test_candidates +from tests.common.utilities import skip_version pytestmark = [ pytest.mark.topology('any'), @@ -37,6 +38,17 @@ # Key: dut host object, value: a list of candidate ports tuple cadidate_test_ports = {} +@pytest.fixture(autouse=True, scope="module") +def check_image_version(duthost): + """Skips this test if the SONiC image installed on DUT is older than 202106 + + Args: + duthost: Hostname of DUT. + + Returns: + None. + """ + skip_version(duthost, ["201811", "201911", "202012"]) @pytest.fixture(scope='module', autouse=True) def recover_ports(duthosts, enum_dut_portname_module_fixture, fanouthosts): diff --git a/tests/portstat/test_portstat.py b/tests/portstat/test_portstat.py index 3607205de15..b156396abed 100644 --- a/tests/portstat/test_portstat.py +++ b/tests/portstat/test_portstat.py @@ -98,7 +98,7 @@ def reset_portstat(duthosts, enum_rand_one_per_hwsku_frontend_hostname): @pytest.mark.parametrize('command', ['portstat -c', 'portstat --clear']) -def test_portstat_clear(duthosts, enum_rand_one_per_hwsku_frontend_hostname, command, wait_for_counters): +def test_portstat_clear(duthosts, enum_rand_one_per_hwsku_frontend_hostname, command): duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] wait(30, 'Wait for DUT to receive/send some packets') before_portstat = parse_portstat(duthost.command('portstat')['stdout_lines']) diff --git a/tests/snmp/conftest.py b/tests/snmp/conftest.py index caa13f01a4a..f9dd3229638 100644 --- a/tests/snmp/conftest.py +++ b/tests/snmp/conftest.py @@ -7,10 +7,6 @@ def setup_check_snmp_ready(duthosts): for duthost in duthosts: assert wait_until(300, 20, duthost.is_service_fully_started, "snmp"), "SNMP service is not running" -@pytest.fixture(scope="function", autouse=True) -def snmp_wait_for_counters(wait_for_counters): - return - def pytest_addoption(parser): """ Adds options to pytest that are used by the snmp tests. diff --git a/tests/snmp/test_snmp_interfaces.py b/tests/snmp/test_snmp_interfaces.py index 7623ebf141b..8588f9c342e 100644 --- a/tests/snmp/test_snmp_interfaces.py +++ b/tests/snmp/test_snmp_interfaces.py @@ -41,7 +41,7 @@ def collect_all_facts(duthost, ports_list, namespace=None): result[portname].update({'adminstatus': admin}) oper = duthost.shell('{} APPL_DB HGET "PORT_TABLE:{}" "oper_status"'.format(sonic_db_cmd, name), module_ignore_errors=False)['stdout'] result[portname].update({'operstatus': oper}) - result[portname].update({'description': config_facts.get('PORT', {})[name]['description']}) + result[portname].update({'description': config_facts.get('PORT', {})[name].get('description', '')}) elif name.startswith("PortChannel"): result.setdefault(name, {}) key_word = "PORTCHANNEL" @@ -52,7 +52,7 @@ def collect_all_facts(duthost, ports_list, namespace=None): result[name].update({'operstatus': oper['stdout']}) result[name].update({'description': config_facts.get(key_word, {})[name].get('description', '')}) else: - key_word = "MGMT_PORT" + key_word = "MGMT_PORT" result.setdefault(name, {}) result[name].update({'mtu': str(setup[key]['mtu'])}) result[name].update({'type': if_type}) diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index 8670803aa43..46d802553f1 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -177,8 +177,7 @@ def test_telemetry_enabledbydefault(duthosts, rand_one_dut_hostname): pytest_assert(str(v) == status_expected, "Telemetry feature is not enabled") -def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, setup_streaming_telemetry, localhost, wait_for_counters, skip_if_no_data_port): - +def test_telemetry_ouput(duthosts, rand_one_dut_hostname, ptfhost, setup_streaming_telemetry, localhost, skip_if_no_data_port): """Run pyclient from ptfdocker and show gnmi server outputself. """ duthost = duthosts[rand_one_dut_hostname]