diff --git a/tests/lldp/test_lldp.py b/tests/lldp/test_lldp.py index 9f661109f1a..c77c906bdc9 100644 --- a/tests/lldp/test_lldp.py +++ b/tests/lldp/test_lldp.py @@ -17,12 +17,16 @@ def lldp_setup(duthosts, enum_rand_one_per_hwsku_frontend_hostname, patch_lldpct unpatch_lldpctl(localhost, duthost) -def test_lldp(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost, collect_techsupport_all_duts, enum_frontend_asic_index): +def test_lldp(duthosts, enum_rand_one_per_hwsku_frontend_hostname, localhost, + collect_techsupport_all_duts, enum_frontend_asic_index): """ verify the LLDP message on DUT """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] - config_facts = duthost.asic_instance(enum_frontend_asic_index).config_facts(host=duthost.hostname, source="running")['ansible_facts'] - lldpctl_facts = duthost.lldpctl_facts(asic_instance_id=enum_frontend_asic_index, skip_interface_pattern_list=["eth0", "Ethernet-BP", "Ethernet-IB"])['ansible_facts'] + config_facts = duthost.asic_instance( + enum_frontend_asic_index).config_facts(host=duthost.hostname, source="running")['ansible_facts'] + lldpctl_facts = duthost.lldpctl_facts( + asic_instance_id=enum_frontend_asic_index, + skip_interface_pattern_list=["eth0", "Ethernet-BP", "Ethernet-IB"])['ansible_facts'] if not list(lldpctl_facts['lldpctl'].items()): pytest.fail("No LLDP neighbors received (lldpctl_facts are empty)") for k, v in list(lldpctl_facts['lldpctl'].items()): @@ -46,13 +50,17 @@ def test_lldp_neighbor(duthosts, enum_rand_one_per_hwsku_frontend_hostname, loca not sent since it contain invalid OIDs, bug.*", ]) - res = duthost.shell("docker exec -i lldp lldpcli show chassis | grep \"SysDescr:\" | sed -e 's/^\\s*SysDescr:\\s*//g'") + res = duthost.shell( + "docker exec -i lldp lldpcli show chassis | grep \"SysDescr:\" | sed -e 's/^\\s*SysDescr:\\s*//g'") dut_system_description = res['stdout'] - lldpctl_facts = duthost.lldpctl_facts(asic_instance_id=enum_frontend_asic_index, skip_interface_pattern_list=["eth0", "Ethernet-BP", "Ethernet-IB"])['ansible_facts'] - config_facts = duthost.asic_instance(enum_frontend_asic_index).config_facts(host=duthost.hostname, source="running")['ansible_facts'] + lldpctl_facts = duthost.lldpctl_facts( + asic_instance_id=enum_frontend_asic_index, + skip_interface_pattern_list=["eth0", "Ethernet-BP", "Ethernet-IB"])['ansible_facts'] + config_facts = duthost.asic_instance(enum_frontend_asic_index).config_facts(host=duthost.hostname, + source="running")['ansible_facts'] if not list(lldpctl_facts['lldpctl'].items()): pytest.fail("No LLDP neighbors received (lldpctl_facts are empty)") - # We use the MAC of mgmt port to generate chassis ID as LLDPD dose. + # We use the MAC of mgmt port to generate chassis ID as LLDPD dose. # To be compatible with PR #3331, we keep using router MAC on T2 devices switch_mac = "" if tbinfo["topo"]["type"] != "t2": @@ -68,20 +76,23 @@ def test_lldp_neighbor(duthosts, enum_rand_one_per_hwsku_frontend_hostname, loca for k, v in list(lldpctl_facts['lldpctl'].items()): try: hostip = v['chassis']['mgmt-ip'] - except: + except Exception: logger.info("Neighbor device {} does not sent management IP via lldp".format(v['chassis']['name'])) hostip = nei_meta[v['chassis']['name']]['mgmt_addr'] - nei_lldp_facts = localhost.lldp_facts(host=hostip, version='v2c', community=eos['snmp_rocommunity'])['ansible_facts'] + nei_lldp_facts = localhost.lldp_facts( + host=hostip, version='v2c', community=eos['snmp_rocommunity'])['ansible_facts'] neighbor_interface = v['port']['ifname'] # Verify the published DUT system name field is correct assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_sys_name'] == duthost.hostname # Verify the published DUT chassis id field is not empty assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_chassis_id'] == \ - "0x%s" % (switch_mac.replace(':', '')) + "0x%s" % (switch_mac.replace(':', '')) # Verify the published DUT system description field is correct assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_sys_desc'] == dut_system_description # Verify the published DUT port id field is correct - assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_port_id'] == config_facts['PORT'][k]['alias'] + assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_port_id'] == \ + config_facts['PORT'][k]['alias'] # Verify the published DUT port description field is correct - assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_port_desc'] == config_facts['PORT'][k]['description'] + assert nei_lldp_facts['ansible_lldp_facts'][neighbor_interface]['neighbor_port_desc'] == \ + config_facts['PORT'][k]['description'] diff --git a/tests/log_fidelity/test_bgp_shutdown.py b/tests/log_fidelity/test_bgp_shutdown.py index 4b8d79dd1ff..55c4e7a7d40 100644 --- a/tests/log_fidelity/test_bgp_shutdown.py +++ b/tests/log_fidelity/test_bgp_shutdown.py @@ -3,18 +3,19 @@ from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer, LogAnalyzerError -logger=logging.getLogger(__name__) +logger = logging.getLogger(__name__) pytestmark = [ pytest.mark.topology('any') ] + def check_syslog(duthost, prefix, trigger_action, expected_log, restore_action): loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix=prefix) - loganalyzer.expect_regex=[expected_log] + loganalyzer.expect_regex = [expected_log] try: - marker=loganalyzer.init() + marker = loganalyzer.init() duthost.command(trigger_action) logger.info("Check for expected log {} in syslog".format(expected_log)) loganalyzer.analyze(marker) @@ -26,12 +27,12 @@ def check_syslog(duthost, prefix, trigger_action, expected_log, restore_action): finally: duthost.command(restore_action) + def test_bgp_shutdown(duthosts, enum_rand_one_per_hwsku_frontend_hostname): - duthost=duthosts[enum_rand_one_per_hwsku_frontend_hostname] + duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] BGP_DOWN_EXPECTED_LOG_MESSAGE = "admin state is set to 'down'" BGP_DOWN_COMMAND = "config bgp shutdown all" BGP_UP_COMMAND = "config bgp startup all" check_syslog(duthost, "bgp_shutdown", BGP_DOWN_COMMAND, BGP_DOWN_EXPECTED_LOG_MESSAGE, BGP_UP_COMMAND) - diff --git a/tests/macsec/macsec_config_helper.py b/tests/macsec/macsec_config_helper.py index 855652ef6b3..80fc4313d22 100644 --- a/tests/macsec/macsec_config_helper.py +++ b/tests/macsec/macsec_config_helper.py @@ -17,10 +17,11 @@ 'disable_macsec_port' ] - logger = logging.getLogger(__name__) -def set_macsec_profile(host, port, profile_name, priority, cipher_suite, primary_cak, primary_ckn, policy, send_sci, rekey_period = 0): + +def set_macsec_profile(host, port, profile_name, priority, cipher_suite, + primary_cak, primary_ckn, policy, send_sci, rekey_period=0): if isinstance(host, EosHost): eos_cipher_suite = { "GCM-AES-128": "aes128-gcm", @@ -36,7 +37,7 @@ def set_macsec_profile(host, port, profile_name, priority, cipher_suite, primary if send_sci == 'true': lines.append('sci') host.eos_config( - lines = lines, + lines=lines, parents=['mac security', 'profile {}'.format(profile_name)]) return @@ -56,9 +57,12 @@ def set_macsec_profile(host, port, profile_name, priority, cipher_suite, primary host.command(cmd) if send_sci == "false": # The MAC address of SONiC host is locally administrated - # So, LLDPd will use an arbitrary fixed value (00:60:08:69:97:ef) as the source MAC address of LLDP packet (https://lldpd.github.io/usage.html) - # But the MACsec driver in Linux used by SONiC VM has a bug that cannot handle the packet with different source MAC address to SCI if the send_sci = false - # So, if send_sci = false and the neighbor device is SONiC VM, LLDPd need to use the real MAC address as the source MAC address + # So, LLDPd will use an arbitrary fixed value (00:60:08:69:97:ef) + # as the source MAC address of LLDP packet (https://lldpd.github.io/usage.html) + # But the MACsec driver in Linux used by SONiC VM has a bug that + # cannot handle the packet with different source MAC address to SCI if the send_sci = false + # So, if send_sci = false and the neighbor device is SONiC VM, + # LLDPd need to use the real MAC address as the source MAC address host.command("lldpcli configure system bond-slave-src-mac-type real") @@ -69,14 +73,15 @@ def delete_macsec_profile(host, port, profile_name): parents=['mac security']) return - #if port is None, the macsec profile is deleted from all namespaces if multi-asic + # if port is None, the macsec profile is deleted from all namespaces if multi-asic if host.is_multi_asic and port is None: for ns in host.get_asic_namespace_list(): CMD_PREFIX = "-n {}".format(ns) if ns is not None else " " cmd = "sonic-db-cli {} CONFIG_DB DEL 'MACSEC_PROFILE|{}'".format(CMD_PREFIX, profile_name) host.command(cmd) else: - cmd = "sonic-db-cli {} CONFIG_DB DEL 'MACSEC_PROFILE|{}'".format(getns_prefix(host, port), profile_name) + cmd = ("sonic-db-cli {} CONFIG_DB DEL 'MACSEC_PROFILE|{}'" + .format(getns_prefix(host, port), profile_name)) host.command(cmd) @@ -99,9 +104,10 @@ def enable_macsec_port(host, port, profile_name): time.sleep(2) host.command("sudo config portchannel {} member add {} {}".format(getns_prefix(host, port), pc["name"], port)) - # wait after macsec enable + # wait after macsec enable time.sleep(2) + def disable_macsec_port(host, port): if isinstance(host, EosHost): host.eos_config( @@ -121,9 +127,10 @@ def disable_macsec_port(host, port): time.sleep(2) host.command("sudo config portchannel {} member add {} {}".format(getns_prefix(host, port), pc["name"], port)) - # wait after macsec disable + # wait after macsec disable time.sleep(2) + def enable_macsec_feature(duthost, macsec_nbrhosts): nbrhosts = macsec_nbrhosts num_asics = duthost.num_asics() @@ -162,7 +169,7 @@ def cleanup_macsec_configuration(duthost, ctrl_links, profile_name): wait_all_complete(timeout=300) logger.info("Cleanup macsec configuration step2: delete macsec profile") - # Delete the macsec profile once after it is removed from all interfaces. if we pass port as None, + # Delete the macsec profile once after it is removed from all interfaces. if we pass port as None, # the profile is removed from the DB in all namespaces. submit_async_task(delete_macsec_profile, (duthost, None, profile_name)) @@ -186,13 +193,15 @@ def setup_macsec_configuration(duthost, ctrl_links, profile_name, default_priori # 1. Set macsec profile i = 0 for dut_port, nbr in list(ctrl_links.items()): - submit_async_task(set_macsec_profile, (duthost, dut_port, profile_name, default_priority, - cipher_suite, primary_cak, primary_ckn, policy, send_sci, rekey_period)) + submit_async_task(set_macsec_profile, + (duthost, dut_port, profile_name, default_priority, + cipher_suite, primary_cak, primary_ckn, policy, send_sci, rekey_period)) if i % 2 == 0: priority = default_priority - 1 else: priority = default_priority + 1 - submit_async_task(set_macsec_profile, (nbr["host"], nbr["port"], profile_name, priority, + submit_async_task(set_macsec_profile, + (nbr["host"], nbr["port"], profile_name, priority, cipher_suite, primary_cak, primary_ckn, policy, send_sci, rekey_period)) i += 1 wait_all_complete(timeout=180) @@ -208,7 +217,7 @@ def setup_macsec_configuration(duthost, ctrl_links, profile_name, default_priori for dut_port, nbr in list(ctrl_links.items()): wait_until(20, 3, 0, lambda: duthost.iface_macsec_ok(dut_port) and - nbr["host"].iface_macsec_ok(nbr["port"])) + nbr["host"].iface_macsec_ok(nbr["port"])) # Enabling macsec may cause link flap, which impacts LACP, BGP, etc # protocols. To hold some time for protocol recovery. diff --git a/tests/macsec/macsec_platform_helper.py b/tests/macsec/macsec_platform_helper.py index 965f7e21cab..69e96f69efd 100644 --- a/tests/macsec/macsec_platform_helper.py +++ b/tests/macsec/macsec_platform_helper.py @@ -35,7 +35,7 @@ def sonic_db_cli(host, cmd): return ast.literal_eval(host.shell(cmd)["stdout_lines"][0]) -def get_all_ifnames(host, asic = None): +def get_all_ifnames(host, asic=None): cmd_prefix = " " if host.is_multi_asic and asic is not None: ns = host.get_namespace_from_asic_id(asic.asic_index) diff --git a/tests/macsec/test_controlplane.py b/tests/macsec/test_controlplane.py index ebb07fb25dc..25e4b3752f4 100644 --- a/tests/macsec/test_controlplane.py +++ b/tests/macsec/test_controlplane.py @@ -2,16 +2,12 @@ import pytest import logging import re -import scapy.all as scapy -import ptf.testutils as testutils -from collections import Counter from tests.common.utilities import wait_until from tests.common.devices.eos import EosHost -from tests.common import config_reload -from .macsec_helper import * -from .macsec_config_helper import * -from .macsec_platform_helper import * +from .macsec_helper import check_wpa_supplicant_process, check_appl_db, check_mka_session,\ + get_mka_session, get_sci, get_appl_db, get_ipnetns_prefix +from .macsec_platform_helper import get_platform, get_macsec_ifname logger = logging.getLogger(__name__) diff --git a/tests/macsec/test_dataplane.py b/tests/macsec/test_dataplane.py index 2adbac0a7bd..98d4fbbeafa 100644 --- a/tests/macsec/test_dataplane.py +++ b/tests/macsec/test_dataplane.py @@ -6,12 +6,10 @@ import ptf.testutils as testutils from collections import Counter -from tests.common.utilities import wait_until from tests.common.devices.eos import EosHost -from tests.common import config_reload -from .macsec_helper import * -from .macsec_config_helper import * -from .macsec_platform_helper import * +from .macsec_helper import create_pkt, create_exp_pkt, check_macsec_pkt,\ + get_ipnetns_prefix, get_macsec_sa_name, get_macsec_counters +from .macsec_platform_helper import get_portchannel, find_portchannel_from_member logger = logging.getLogger(__name__) @@ -24,7 +22,8 @@ class TestDataPlane(): BATCH_COUNT = 10 - def test_server_to_neighbor(self, duthost, ctrl_links, downstream_links, upstream_links, ptfadapter, wait_mka_establish): + def test_server_to_neighbor(self, duthost, ctrl_links, downstream_links, + upstream_links, ptfadapter, wait_mka_establish): ptfadapter.dataplane.set_qlen(TestDataPlane.BATCH_COUNT * 100) down_link = list(downstream_links.values())[0] @@ -60,7 +59,7 @@ def test_server_to_neighbor(self, duthost, ctrl_links, downstream_links, upstrea logging.info(payload) # Source mac address is not useful in this test case and we use an arbitrary mac address as the source pkt = create_pkt( - "00:01:02:03:04:05", dut_macaddress, "1.2.3.4", up_host_ip, bytes(payload,encoding='utf8')) + "00:01:02:03:04:05", dut_macaddress, "1.2.3.4", up_host_ip, bytes(payload, encoding='utf8')) exp_pkt = create_exp_pkt(pkt, pkt[scapy.IP].ttl - 1) fail_message = "" @@ -164,7 +163,7 @@ def test_counters(self, duthost, ctrl_links, upstream_links, rekey_period, wait_ ret = duthost.command( "{} ping -c {} -s {} {}".format(get_ipnetns_prefix(duthost, port_name), PKT_NUM, PKT_OCTET, nbr_ip_addr)) assert not ret['failed'] - sleep(10) # wait 10s for polling counters + sleep(10) # wait 10s for polling counters # Sum up end counter egress_end_counters = Counter() diff --git a/tests/macsec/test_deployment.py b/tests/macsec/test_deployment.py index 3ca8ddad561..6c4c0cb37d0 100644 --- a/tests/macsec/test_deployment.py +++ b/tests/macsec/test_deployment.py @@ -1,18 +1,9 @@ -from time import sleep import pytest import logging -import re -import scapy.all as scapy -import ptf.testutils as testutils -from collections import Counter from tests.common.utilities import wait_until -from tests.common.devices.eos import EosHost from tests.common import config_reload -from .macsec_helper import * -from .macsec_config_helper import * -from .macsec_platform_helper import * - +from .macsec_helper import check_appl_db logger = logging.getLogger(__name__) pytestmark = [ diff --git a/tests/macsec/test_fault_handling.py b/tests/macsec/test_fault_handling.py index 9b1a485e1c7..62deedef614 100644 --- a/tests/macsec/test_fault_handling.py +++ b/tests/macsec/test_fault_handling.py @@ -1,17 +1,12 @@ from time import sleep import pytest import logging -import re -import scapy.all as scapy -import ptf.testutils as testutils -from collections import Counter from tests.common.utilities import wait_until from tests.common.devices.eos import EosHost -from tests.common import config_reload -from .macsec_helper import * -from .macsec_config_helper import * -from .macsec_platform_helper import * +from .macsec_helper import get_appl_db +from .macsec_config_helper import disable_macsec_port, enable_macsec_port, delete_macsec_profile, set_macsec_profile +from .macsec_platform_helper import get_eth_ifname, find_portchannel_from_member, get_portchannel logger = logging.getLogger(__name__) @@ -107,8 +102,8 @@ def test_mismatch_macsec_configuration(self, duthost, unctrl_links, # Wait till macsec session has gone down. wait_until(20, 3, 0, - lambda: not duthost.iface_macsec_ok(port_name) and - not nbr["host"].iface_macsec_ok(nbr["port"])) + lambda: not duthost.iface_macsec_ok(port_name) and + not nbr["host"].iface_macsec_ok(nbr["port"])) # Set a wrong cak to the profile primary_cak = "0" * len(primary_cak) diff --git a/tests/macsec/test_interop_protocol.py b/tests/macsec/test_interop_protocol.py index 804050dc7b0..0c70a313acd 100644 --- a/tests/macsec/test_interop_protocol.py +++ b/tests/macsec/test_interop_protocol.py @@ -1,17 +1,12 @@ -from time import sleep import pytest import logging import re -import scapy.all as scapy -import ptf.testutils as testutils -from collections import Counter from tests.common.utilities import wait_until from tests.common.devices.eos import EosHost -from tests.common import config_reload -from .macsec_helper import * -from .macsec_config_helper import * -from .macsec_platform_helper import * +from .macsec_helper import getns_prefix +from .macsec_config_helper import disable_macsec_port, enable_macsec_port +from .macsec_platform_helper import find_portchannel_from_member, get_portchannel, get_lldp_list, sonic_db_cli logger = logging.getLogger(__name__) @@ -36,13 +31,15 @@ def test_port_channel(self, duthost, profile_name, ctrl_links, wait_mka_establis disable_macsec_port(duthost, ctrl_port) # Remove ethernet interface from PortChannel interface - duthost.command("sudo config portchannel {} member del {} {}".format(getns_prefix(duthost, ctrl_port), pc["name"], ctrl_port)) + duthost.command("sudo config portchannel {} member del {} {}" + .format(getns_prefix(duthost, ctrl_port), pc["name"], ctrl_port)) assert wait_until(90, 1, 0, lambda: get_portchannel( duthost)[pc["name"]]["status"] == "Dw") enable_macsec_port(duthost, ctrl_port, profile_name) # Add ethernet interface back to PortChannel interface - duthost.command("sudo config portchannel {} member add {} {}".format(getns_prefix(duthost, ctrl_port), pc["name"], ctrl_port)) + duthost.command("sudo config portchannel {} member add {} {}" + .format(getns_prefix(duthost, ctrl_port), pc["name"], ctrl_port)) assert wait_until(90, 1, 0, lambda: find_portchannel_from_member( ctrl_port, get_portchannel(duthost))["status"] == "Up") @@ -57,23 +54,23 @@ def test_lldp(self, duthost, ctrl_links, profile_name, wait_mka_establish): # select one macsec link for ctrl_port, nbr in list(ctrl_links.items()): assert wait_until(LLDP_TIMEOUT, LLDP_ADVERTISEMENT_INTERVAL, 0, - lambda: nbr["name"] in get_lldp_list(duthost)) + lambda: nbr["name"] in get_lldp_list(duthost)) disable_macsec_port(duthost, ctrl_port) disable_macsec_port(nbr["host"], nbr["port"]) wait_until(20, 3, 0, - lambda: not duthost.iface_macsec_ok(ctrl_port) and - not nbr["host"].iface_macsec_ok(nbr["port"])) + lambda: not duthost.iface_macsec_ok(ctrl_port) and + not nbr["host"].iface_macsec_ok(nbr["port"])) assert wait_until(LLDP_TIMEOUT, LLDP_ADVERTISEMENT_INTERVAL, 0, - lambda: nbr["name"] in get_lldp_list(duthost)) + lambda: nbr["name"] in get_lldp_list(duthost)) enable_macsec_port(duthost, ctrl_port, profile_name) enable_macsec_port(nbr["host"], nbr["port"], profile_name) wait_until(20, 3, 0, - lambda: duthost.iface_macsec_ok(ctrl_port) and - nbr["host"].iface_macsec_ok(nbr["port"])) + lambda: duthost.iface_macsec_ok(ctrl_port) and + nbr["host"].iface_macsec_ok(nbr["port"])) assert wait_until(LLDP_TIMEOUT, LLDP_ADVERTISEMENT_INTERVAL, 0, - lambda: nbr["name"] in get_lldp_list(duthost)) + lambda: nbr["name"] in get_lldp_list(duthost)) @pytest.mark.disable_loganalyzer def test_bgp(self, duthost, ctrl_links, upstream_links, profile_name, wait_mka_establish): @@ -86,7 +83,8 @@ def test_bgp(self, duthost, ctrl_links, upstream_links, profile_name, wait_mka_e BGP_TIMEOUT = 90 def check_bgp_established(ctrl_port, up_link): - command = "sonic-db-cli {} STATE_DB HGETALL 'NEIGH_STATE_TABLE|{}'".format(getns_prefix(duthost, ctrl_port), up_link["local_ipv4_addr"]) + command = ("sonic-db-cli {} STATE_DB HGETALL 'NEIGH_STATE_TABLE|{}'" + .format(getns_prefix(duthost, ctrl_port), up_link["local_ipv4_addr"])) fact = sonic_db_cli(duthost, command) logger.info("bgp state {}".format(fact)) return fact["state"] == "Established" @@ -101,8 +99,8 @@ def check_bgp_established(ctrl_port, up_link): disable_macsec_port(duthost, ctrl_port) disable_macsec_port(nbr["host"], nbr["port"]) wait_until(BGP_TIMEOUT, 3, 0, - lambda: not duthost.iface_macsec_ok(ctrl_port) and - not nbr["host"].iface_macsec_ok(nbr["port"])) + lambda: not duthost.iface_macsec_ok(ctrl_port) and + not nbr["host"].iface_macsec_ok(nbr["port"])) # BGP session should keep established even after holdtime assert wait_until(BGP_TIMEOUT, BGP_KEEPALIVE, BGP_HOLDTIME, check_bgp_established, ctrl_port, upstream_links[ctrl_port]) @@ -112,8 +110,8 @@ def check_bgp_established(ctrl_port, up_link): enable_macsec_port(duthost, ctrl_port, profile_name) enable_macsec_port(nbr["host"], nbr["port"], profile_name) wait_until(BGP_TIMEOUT, 3, 0, - lambda: duthost.iface_macsec_ok(ctrl_port) and - nbr["host"].iface_macsec_ok(nbr["port"])) + lambda: duthost.iface_macsec_ok(ctrl_port) and + nbr["host"].iface_macsec_ok(nbr["port"])) # Wait PortChannel up, which might flap if having one port member wait_until(BGP_TIMEOUT, 5, 5, lambda: find_portchannel_from_member( ctrl_port, get_portchannel(duthost))["status"] == "Up") diff --git a/tests/mclag/conftest.py b/tests/mclag/conftest.py index 5069eb713d2..c9687ac2b1b 100644 --- a/tests/mclag/conftest.py +++ b/tests/mclag/conftest.py @@ -16,6 +16,7 @@ from mclag_helpers import MCLAG_DOMAINE_ID from tests.common.ptf_agent_updater import PtfAgentUpdater + def pytest_addoption(parser): """ Adds options to pytest that are used by the mclag test. @@ -48,7 +49,7 @@ def duthost2(duthosts): @pytest.fixture(scope='module') def mg_facts(duthosts, tbinfo): - return {dut.hostname:dut.get_extended_minigraph_facts(tbinfo) for dut in duthosts} + return {dut.hostname: dut.get_extended_minigraph_facts(tbinfo) for dut in duthosts} @pytest.fixture(scope='module') @@ -97,8 +98,10 @@ def get_routes(duthost1, duthost2, collect, mg_facts): dut2_routes_all = get_dut_routes(duthost2, collect, mg_facts) dut_1_diff_routes = list(set(dut1_routes_all).difference(set(dut2_routes_all))) dut_2_diff_routes = list(set(dut2_routes_all).difference(set(dut1_routes_all))) - res1 = natsorted([route for route in dut_1_diff_routes if ipaddress.ip_network(route).subnet_of(ipaddress.ip_network(SUBNET_CHECK))]) - res2 = natsorted([route for route in dut_2_diff_routes if ipaddress.ip_network(route).subnet_of(ipaddress.ip_network(SUBNET_CHECK))]) + res1 = natsorted([route for route in dut_1_diff_routes if + ipaddress.ip_network(route).subnet_of(ipaddress.ip_network(SUBNET_CHECK))]) + res2 = natsorted([route for route in dut_2_diff_routes if + ipaddress.ip_network(route).subnet_of(ipaddress.ip_network(SUBNET_CHECK))]) return {duthost1.hostname: res1, duthost2.hostname: res2} @@ -122,8 +125,12 @@ def collect(duthosts, tbinfo): _ = [host_interfaces.pop(vm) for vm in res[dut_hostname]['vm_links'] if vm in list(host_interfaces.keys())] res[dut_hostname]['host_interfaces'] = natsorted(host_interfaces) res[dut_hostname]['ptf_map'] = host_interfaces - res[dut_hostname]['all_links'] = natsorted(res[dut_hostname]['host_interfaces'] + res[dut_hostname]['devices_interconnect_interfaces'] + res[dut_hostname]['vm_links']) - res[dut_hostname]['mclag_interfaces'] = natsorted([PC_NAME_TEMPLATE.format(indx + 1) for indx, _ in enumerate(res[dut_hostname]['host_interfaces'][:-2])]) + res[dut_hostname]['all_links'] = natsorted(res[dut_hostname]['host_interfaces'] + + res[dut_hostname]['devices_interconnect_interfaces'] + + res[dut_hostname]['vm_links']) + res[dut_hostname]['mclag_interfaces'] = natsorted( + [PC_NAME_TEMPLATE.format(indx + 1) + for indx, _ in enumerate(res[dut_hostname]['host_interfaces'][:-2])]) return res @@ -182,7 +189,9 @@ def keep_and_peer_link_member(duthosts, collect, mg_facts): """ res = defaultdict(dict) for dut in duthosts: - port_indices = {mg_facts[dut.hostname]['minigraph_port_indices'][k]:k for k in mg_facts[dut.hostname]['minigraph_port_indices']} + port_indices = { + mg_facts[dut.hostname]['minigraph_port_indices'][k]: k + for k in mg_facts[dut.hostname]['minigraph_port_indices']} keep_alive_interface = port_indices[int(collect[dut.hostname]['devices_interconnect_interfaces'][0])] peer_link_member = port_indices[int(collect[dut.hostname]['devices_interconnect_interfaces'][-1])] res[dut.hostname]['keepalive'] = keep_alive_interface @@ -198,4 +207,4 @@ def check_topo(tbinfo): tbinfo: Testbed object """ if tbinfo['topo']['name'] != 't0-mclag': - pytest.skip("test requires t0-mclag topo to run, current topo - {}".format(tbinfo['topo']['name'])) + pytest.skip("test requires t0-mclag topo to run, current topo - {}".format(tbinfo['topo']['name'])) diff --git a/tests/mclag/mclag_helpers.py b/tests/mclag/mclag_helpers.py index 6bca01d8861..913f275c2d0 100644 --- a/tests/mclag/mclag_helpers.py +++ b/tests/mclag/mclag_helpers.py @@ -25,7 +25,9 @@ MCLAG_LOCAL_IP = ipaddress.IPv4Interface(u"10.100.1.1/30") MCLAG_PEER_IP = ipaddress.IPv4Interface(u"{}/{}".format(MCLAG_LOCAL_IP.ip + 1, MCLAG_LOCAL_IP._prefixlen)) MCLAG_PEER_LINK_IP_ACTIVE = ipaddress.IPv4Interface(u"13.1.1.1/30") -MCLAG_PEER_LINK_IP_STANDBY = ipaddress.IPv4Interface(u"{}/{}".format(MCLAG_PEER_LINK_IP_ACTIVE.ip + 1, MCLAG_PEER_LINK_IP_ACTIVE._prefixlen)) +MCLAG_PEER_LINK_IP_STANDBY = ipaddress.IPv4Interface(u"{}/{}" + .format(MCLAG_PEER_LINK_IP_ACTIVE.ip + 1, + MCLAG_PEER_LINK_IP_ACTIVE._prefixlen)) PEER_LINK_NAME = PC_NAME_TEMPLATE.format(100) SUBNET_CHECK = u'192.168.0.0/16' ACTION_FORWARD = 'FORWARD' @@ -47,7 +49,7 @@ def parse_vm_vlan_port(vlan): vlan_index = vlan ptf_index = vlan else: - m = re.match("(\d+)\.(\d+)@(\d+)", vlan) + m = re.match(r"(\d+)\.(\d+)@(\d+)", vlan) (dut_index, vlan_index, ptf_index) = (int(m.group(1)), int(m.group(2)), int(m.group(3))) return (dut_index, vlan_index, ptf_index) @@ -88,6 +90,7 @@ def check_lags_on_ptf(ptfhost, mclag_interfaces): res = re.findall(r'PortChannel\d+', out) pytest_assert(len(res) == len(mclag_interfaces), "Not all PortChannels are up on PTF, {}".format(','.join(res))) + def get_vm_links(tbinfo, dut_index): """ Collect info about links that lead to VMs on each DUT from Testbed info @@ -105,6 +108,7 @@ def get_vm_links(tbinfo, dut_index): result.append(str(vlan_indx)) return result + def check_partner_lag_member(ptfhost, mclag_info, state='UP'): """ Check partner oper state of memeber's on PTF @@ -119,7 +123,9 @@ def check_partner_lag_member(ptfhost, mclag_info, state='UP'): for pc in mclag_info: member = mclag_info[pc].get('member_on_ptf', '') if str(member).isdigit(): - res = ptfhost.shell("cat /sys/class/net/{}/lower_eth{}/bonding_slave/ad_partner_oper_port_state".format(pc, member))['stdout'] + res = ptfhost.shell( + "cat /sys/class/net/{}/lower_eth{}/bonding_slave/ad_partner_oper_port_state" + .format(pc, member))['stdout'] result.add(res) if id_to_check in result and len(result) == 1: logger.info("Partner lag member status = {}, expected {}".format(result, id_to_check)) @@ -153,7 +159,7 @@ def get_port_number(ptfhost, src_port): src_port: Port name """ map = ptfhost.host.options['variable_manager'].extra_vars.get("ifaces_map") - reversed_map = {map[k]:k for k in map} + reversed_map = {map[k]: k for k in map} if not str(src_port).isdigit(): return int(reversed_map[src_port]) return int(src_port) @@ -178,6 +184,7 @@ def get_dst_port(duthost1, duthost2, get_routes, dst_ip, collect): dst_port = collect[duthost2.hostname]['vm_link_on_ptf'] return dst_port + def generate_and_verify_traffic(duthost1, duthost2, ptfadapter, ptfhost, src_port, dst_ip, router_mac, get_routes, collect, down_link_on_dut=None, pkt_action=ACTION_FORWARD): """ @@ -264,7 +271,7 @@ def predict_exp_ttl(duthost1, duthost2, dst_ip, link_down_on_dut): """ dut = duthost2 if link_down_on_dut == duthost1.hostname else duthost1 nexthop = dut.get_ip_route_info(ipaddress.ip_address(str(dst_ip)))['nexthops'] - ttl = TTL - 2 if PEER_LINK_NAME in nexthop[0] else TTL - 1 + ttl = TTL - 2 if PEER_LINK_NAME in nexthop[0] else TTL - 1 return ttl @@ -276,7 +283,8 @@ def get_dut_routes(duthost, collect, mg_facts): collect: Fixture which collects main info about link connection mg_facts: Dict with minigraph facts for each DUT """ - port_indices = {mg_facts[duthost.hostname]['minigraph_port_indices'][k]:k for k in mg_facts[duthost.hostname]['minigraph_port_indices']} + port_indices = {mg_facts[duthost.hostname]['minigraph_port_indices'][k]: k + for k in mg_facts[duthost.hostname]['minigraph_port_indices']} vm_link = collect[duthost.hostname]['vm_links'][0] vm_interface_name = port_indices[int(vm_link)] ip = duthost.show_ip_interface()['ansible_facts']['ip_interfaces'][vm_interface_name]['peer_ipv4'] @@ -293,7 +301,8 @@ def add_mclag_and_orphan_ports(duthost, collect, mg_facts, ip_base=0): mg_facts: Dict with minigraph facts for each DUT ip_base: ip base index to be used """ - port_indices = {mg_facts[duthost.hostname]['minigraph_port_indices'][k]:k for k in mg_facts[duthost.hostname]['minigraph_port_indices']} + port_indices = {mg_facts[duthost.hostname]['minigraph_port_indices'][k]: k + for k in mg_facts[duthost.hostname]['minigraph_port_indices']} cmds = [] for indx, link in enumerate(collect[duthost.hostname]['host_interfaces']): index = indx + 1 @@ -348,7 +357,8 @@ def apply_mclag(duthost, collect, mclag_id, mclag_local_ip, mclag_peer_ip): cmds.append('config feature state iccpd enabled') cmds.append('sleep 60') cmds.append("config mclag add {} {} {}".format(mclag_id, mclag_local_ip, mclag_peer_ip)) - cmds.append("config mclag member add {} {}".format(mclag_id, ','.join(collect[duthost.hostname]['mclag_interfaces']))) + cmds.append("config mclag member add {} {}" + .format(mclag_id, ','.join(collect[duthost.hostname]['mclag_interfaces']))) duthost.shell_cmds(cmds=cmds) @@ -364,7 +374,8 @@ def remove_vlan_members(duthost, mg_facts): for i in mg_facts[duthost.hostname]['minigraph_vlans'][vlan]['members']: cmd.append("config interface shutdown {}".format(i)) cmd.append("sleep 1") - cmd.append("config vlan member del {} {}".format(mg_facts[duthost.hostname]['minigraph_vlans'][vlan]['vlanid'], i)) + cmd.append("config vlan member del {} {}" + .format(mg_facts[duthost.hostname]['minigraph_vlans'][vlan]['vlanid'], i)) duthost.shell_cmds(cmds=cmd) @@ -403,7 +414,8 @@ def check_keepalive_link(duthost1, duthost2, status): dut1_keepalive_status = duthost1.shell("mclagdctl dump state|grep keepalive")['stdout'].split(":")[-1].strip() dut2_keepalive_status = duthost2.shell("mclagdctl dump state|grep keepalive")['stdout'].split(":")[-1].strip() pytest_assert(dut1_keepalive_status == dut2_keepalive_status == status, - "Keepalive status should be {} not {}, {}".format(status, dut1_keepalive_status, dut2_keepalive_status)) + "Keepalive status should be {} not {}, {}" + .format(status, dut1_keepalive_status, dut2_keepalive_status)) def gen_list_pcs_to_check(duthost, mg_facts, collect): diff --git a/tests/mclag/test_mclag_l3.py b/tests/mclag/test_mclag_l3.py index 102d3e7e4d7..101a9595837 100644 --- a/tests/mclag/test_mclag_l3.py +++ b/tests/mclag/test_mclag_l3.py @@ -5,7 +5,7 @@ from tests.common.utilities import wait_until from tests.common.helpers.assertions import pytest_assert -from mclag_helpers import CONFIG_DB_BACKUP, check_partner_lag_member +from mclag_helpers import check_partner_lag_member from mclag_helpers import check_lags_on_ptf from mclag_helpers import remove_vlan_members from mclag_helpers import add_mclag_and_orphan_ports @@ -79,7 +79,7 @@ def setup_mclag(duthost1, duthost2, ptfhost, mg_facts, collect, get_routes, keep apply_mclag(duthost1, collect, MCLAG_DOMAINE_ID, MCLAG_LOCAL_IP.ip, MCLAG_PEER_IP.ip) apply_mclag(duthost2, collect, MCLAG_DOMAINE_ID, MCLAG_PEER_IP.ip, MCLAG_LOCAL_IP.ip) - #Save config to be persistent + # Save config to be persistent duthost1.shell('config save -y') duthost2.shell('config save -y') @@ -99,17 +99,23 @@ def test_check_teamd_system_id(self, duthost1, duthost2, collect): Verify that mclag inetrfaces MAC on standby device is changed to active device MAC """ for lag in collect[duthost1.hostname]['mclag_interfaces']: - dut1_sys_id = duthost1.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] - dut2_sys_id = duthost2.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] - pytest_assert(dut1_sys_id == dut2_sys_id, "Mclag standby device {} system ID shoule be same as active device, but is {}".format(lag, dut2_sys_id)) + dut1_sys_id = duthost1.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + dut2_sys_id = duthost2.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + pytest_assert(dut1_sys_id == dut2_sys_id, + "Mclag standby device {} system ID shoule be same as active device, but is {}" + .format(lag, dut2_sys_id)) class TestMclagMemberPortStatusChange(object): @pytest.fixture() def pre_setup(self, duthost1, duthost2, ptfhost, collect, mg_facts, mclag_intf_num): mclag_info = mclag_intf_to_shutdown(duthost1, duthost2, mg_facts, collect, num_intf=mclag_intf_num) - dut1_to_shut = [mclag_info[i]['member_to_shut'] for i in mclag_info if mclag_info[i]['link_down_on_dut'] == duthost1.hostname] - dut2_to_shut = [mclag_info[i]['member_to_shut'] for i in mclag_info if mclag_info[i]['link_down_on_dut'] == duthost2.hostname] + dut1_to_shut = [mclag_info[i]['member_to_shut'] for i in mclag_info + if mclag_info[i]['link_down_on_dut'] == duthost1.hostname] + dut2_to_shut = [mclag_info[i]['member_to_shut'] for i in mclag_info + if mclag_info[i]['link_down_on_dut'] == duthost2.hostname] duthost1.shutdown_multiple(dut1_to_shut) duthost2.shutdown_multiple(dut2_to_shut) pytest_assert(wait_until(140, 5, 0, check_partner_lag_member, ptfhost, mclag_info, "DOWN"), @@ -122,22 +128,23 @@ def pre_setup(self, duthost1, duthost2, ptfhost, collect, mg_facts, mclag_intf_n pytest_assert(wait_until(120, 5, 0, check_partner_lag_member, ptfhost, mclag_info, "UP"), "Expected Lag partner members isn't up") - def test_mclag_intf_status_down(self, duthost1, duthost2, ptfhost, ptfadapter, get_routes, collect, pre_setup, update_and_clean_ptf_agent): """ - Change mclag inetrfaces status on both peers, by shutting down PortChannel members, send packets to destinaion ip so that traffic would go trough PeerLink + Change mclag inetrfaces status on both peers, by shutting down PortChannel members, + send packets to destinaion ip so that traffic would go trough PeerLink Verify that packets will be received """ dut1_route = get_routes[duthost1.hostname][2] dut2_route = get_routes[duthost2.hostname][2] for indx, mclag_intf in enumerate(pre_setup): down_link_on_dut = pre_setup[mclag_intf]['link_down_on_dut'] - dst_route = ipaddress.IPv4Interface(dut1_route) if down_link_on_dut == duthost1.hostname else ipaddress.IPv4Interface(dut2_route) + dst_route = ipaddress.IPv4Interface(dut1_route) if down_link_on_dut == duthost1.hostname \ + else ipaddress.IPv4Interface(dut2_route) dst_ip = str(str(dst_route.ip + (indx + 1))) generate_and_verify_traffic(duthost1, duthost2, ptfadapter, ptfhost, mclag_intf, dst_ip, - duthost1.facts["router_mac"], get_routes, collect, down_link_on_dut=down_link_on_dut) - + duthost1.facts["router_mac"], get_routes, collect, + down_link_on_dut=down_link_on_dut) def test_mclag_intf_status_up(self, duthost1, duthost2, ptfhost, ptfadapter, get_routes, collect, mclag_intf_num, update_and_clean_ptf_agent): @@ -169,7 +176,6 @@ def shutdown_keepalive_and_restore(self, duthost1, keep_and_peer_link_member): time.sleep(DEFAULT_SESSION_TIMEOUT) duthost1.no_shutdown(keep_and_peer_link_member[duthost1.hostname]['keepalive']) - def test_keepalive_link_down(self, duthost1, duthost2, collect, ptfhost, ptfadapter, get_routes, mclag_intf_num, shutdown_keepalive_and_restore, update_and_clean_ptf_agent): """ @@ -180,9 +186,11 @@ def test_keepalive_link_down(self, duthost1, duthost2, collect, ptfhost, ptfadap # Verify that standby device changed its MAC to default MAC on MCLAG inetrfaces for lag in collect[duthost1.hostname]['mclag_interfaces']: - dut2_sys_id = duthost2.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + dut2_sys_id = duthost2.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] pytest_assert(duthost2.facts["router_mac"] == dut2_sys_id, - "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}".format(duthost2.facts["router_mac"], lag, dut2_sys_id)) + "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}" + .format(duthost2.facts["router_mac"], lag, dut2_sys_id)) # Verify that keepalive link status will be ERROR after keepalive link is set down check_keepalive_link(duthost1, duthost2, 'ERROR') @@ -195,7 +203,6 @@ def test_keepalive_link_down(self, duthost1, duthost2, collect, ptfhost, ptfadap generate_and_verify_traffic(duthost1, duthost2, ptfadapter, ptfhost, mclag_intf, dst_ip, duthost1.facts["router_mac"], get_routes, collect) - def test_session_timeout(self, duthost1, duthost2, collect, change_session_timeout): """ Verify that MCLAG session_timeout can be changed @@ -211,9 +218,11 @@ def test_session_timeout(self, duthost1, duthost2, collect, change_session_timeo check_keepalive_link(duthost1, duthost2, 'ERROR') for lag in collect[duthost1.hostname]['mclag_interfaces']: - dut2_sys_id = duthost2.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + dut2_sys_id = duthost2.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] pytest_assert(duthost2_router_mac == dut2_sys_id, - "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}".format(duthost2_router_mac, lag, dut2_sys_id)) + "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}" + .format(duthost2_router_mac, lag, dut2_sys_id)) class TestActiveDeviceStatusChange(): @@ -223,8 +232,9 @@ def pre_active_setup(self, duthost1, collect, mg_facts, ptfhost, keep_and_peer_l Shutdown mclag interfaces and reboot active device, to simulate loss of active device """ check_portchannels = gen_list_pcs_to_check(duthost1, mg_facts, collect) - ports_to_shut = list(check_portchannels.keys()) + [keep_and_peer_link_member[duthost1.hostname]['keepalive']] + \ - [keep_and_peer_link_member[duthost1.hostname]['peerlink']] + ports_to_shut = list(check_portchannels.keys()) + \ + [keep_and_peer_link_member[duthost1.hostname]['keepalive']] + \ + [keep_and_peer_link_member[duthost1.hostname]['peerlink']] duthost1.shutdown_multiple(ports_to_shut) duthost1.shell("config save -y") duthost1.shell("sudo /sbin/reboot", module_ignore_errors=True) @@ -236,11 +246,10 @@ def pre_active_setup(self, duthost1, collect, mg_facts, ptfhost, keep_and_peer_l duthost1.no_shutdown_multiple(ports_to_shut) duthost1.shell("config save -y") pytest_assert(wait_until(120, 5, 0, check_partner_lag_member, ptfhost, check_portchannels, "UP"), - "Expected partner Lag members isnt up") + "Expected partner Lag members isnt up") pytest_assert(wait_until(300, 20, 0, duthost1.critical_services_fully_started), "All critical services should fully started!{}".format(duthost1.critical_services)) - def test_active_down(self, duthost1, duthost2, ptfadapter, ptfhost, collect, get_routes, mclag_intf_num, update_and_clean_ptf_agent, pre_active_setup): """ @@ -253,9 +262,11 @@ def test_active_down(self, duthost1, duthost2, ptfadapter, ptfhost, collect, get pytest_assert(status == 'ERROR', "Keepalive status should be ERROR, not {}".format(status)) for lag in collect[duthost2.hostname]['mclag_interfaces']: - dut2_sys_id = duthost2.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + dut2_sys_id = duthost2.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] pytest_assert(duthost2.facts["router_mac"] == dut2_sys_id, - "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}".format(duthost2.facts["router_mac"], lag, dut2_sys_id)) + "MCLAG interface MAC on standby device shoudl be it's default MAC {}; lag = {}, mac = {}" + .format(duthost2.facts["router_mac"], lag, dut2_sys_id)) for indx, mclag_intf in enumerate(collect[duthost1.hostname]['mclag_interfaces'][:mclag_intf_num]): dst_ip1 = str(str(dst_route1.ip + (indx + 1))) @@ -273,7 +284,8 @@ def pre_standby_setup(self, duthost2, collect, mg_facts, ptfhost, keep_and_peer_ Shutdown mclag interfaces and reboot standby device, to simulate loss of standby device """ check_portchannels = gen_list_pcs_to_check(duthost2, mg_facts, collect) - ports_to_shut = list(check_portchannels.keys()) + [keep_and_peer_link_member[duthost2.hostname]['keepalive']] + [keep_and_peer_link_member[duthost2.hostname]['peerlink']] + ports_to_shut = list(check_portchannels.keys()) + [keep_and_peer_link_member[duthost2.hostname]['keepalive']] \ + + [keep_and_peer_link_member[duthost2.hostname]['peerlink']] duthost2.shutdown_multiple(ports_to_shut) duthost2.shell("config save -y") duthost2.shell("sudo /sbin/reboot", module_ignore_errors=True) @@ -289,9 +301,8 @@ def pre_standby_setup(self, duthost2, collect, mg_facts, ptfhost, keep_and_peer_ pytest_assert(wait_until(300, 20, 0, duthost2.critical_services_fully_started), "All critical services should fully started!{}".format(duthost2.critical_services)) - def test_standby_down(self, duthost1, duthost2, ptfadapter, ptfhost, collect, get_routes, mclag_intf_num, - update_and_clean_ptf_agent, pre_standby_setup): + update_and_clean_ptf_agent, pre_standby_setup): """ Verify behavior when standby device is lost, traffic should reach only direct uplink of active """ @@ -329,7 +340,6 @@ def pre_setup_peerlink(self, duthost2, keep_and_peer_link_member): pytest_assert(out[peerlink]['admin_state'] == 'up', "PeerLink is expected to be in up state != {}".format(out[peerlink]['admin_state'])) - def test_peer_link_status_change(self, duthost1, duthost2, ptfadapter, ptfhost, collect, get_routes, mclag_intf_num, pre_setup_peerlink): """ @@ -345,9 +355,13 @@ def test_peer_link_status_change(self, duthost1, duthost2, ptfadapter, ptfhost, check_keepalive_link(duthost1, duthost2, 'OK') # Check mclag interfaces on standby have same MAC as active device for lag in collect[duthost1.hostname]['mclag_interfaces']: - dut1_sys_id = duthost1.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] - dut2_sys_id = duthost2.shell("teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] - pytest_assert(dut1_sys_id == dut2_sys_id, "Mclag standby device {} system ID shoule be same as active device, but is {}".format(lag, dut2_sys_id)) + dut1_sys_id = duthost1.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + dut2_sys_id = duthost2.shell( + "teamdctl {} state item get team_device.ifinfo.dev_addr".format(lag))['stdout'] + pytest_assert(dut1_sys_id == dut2_sys_id, + "Mclag standby device {} system ID shoule be same as active device, but is {}" + .format(lag, dut2_sys_id)) # To be able to predict trough which DUT traffic will traverse, # use PortChannel member as source port, not PortChannel diff --git a/tests/memory_checker/test_memory_checker.py b/tests/memory_checker/test_memory_checker.py index 2819f4a37e4..5f756a20788 100644 --- a/tests/memory_checker/test_memory_checker.py +++ b/tests/memory_checker/test_memory_checker.py @@ -239,7 +239,8 @@ def test_setup_and_cleanup(duthosts, creds, enum_dut_feature_container, .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -280,7 +281,8 @@ def remove_and_restart_container(duthosts, creds, enum_dut_feature_container, .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -400,7 +402,7 @@ def get_container_mem_usage(duthost, container_name): Returns: mem_usage: A string represents memory usage. """ - get_mem_usage_cmd = "docker stats --no-stream --format \{{\{{.MemUsage\}}\}} {}".format(container_name) + get_mem_usage_cmd = r"docker stats --no-stream --format \{{\{{.MemUsage\}}\}} {}".format(container_name) cmd_result = duthost.shell(get_mem_usage_cmd) exit_code = cmd_result["rc"] @@ -486,7 +488,8 @@ def consumes_memory_and_checks_monit(duthost, container_name, vm_workers, new_sy @pytest.mark.parametrize("test_setup_and_cleanup", - [' if status == 3 for 1 times within 2 cycles then exec "/usr/bin/restart_service telemetry"'], + [' if status == 3 for 1 times within 2 cycles ' + 'then exec "/usr/bin/restart_service telemetry"'], indirect=["test_setup_and_cleanup"]) def test_memory_checker(duthosts, enum_dut_feature_container, test_setup_and_cleanup, enum_rand_one_per_hwsku_frontend_hostname): @@ -508,7 +511,8 @@ def test_memory_checker(duthosts, enum_dut_feature_container, test_setup_and_cle .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -520,7 +524,8 @@ def test_memory_checker(duthosts, enum_dut_feature_container, test_setup_and_cle vm_workers = 6 pytest_require("Celestica-E1031" not in duthost.facts["hwsku"] - and (("20191130" in duthost.os_version and parse_version(duthost.os_version) > parse_version("20191130.72")) + and (("20191130" in duthost.os_version and + parse_version(duthost.os_version) > parse_version("20191130.72")) or parse_version(duthost.kernel_version) > parse_version("4.9.0")), "Test is not supported for platform Celestica E1031, 20191130.72 and older image versions!") @@ -531,7 +536,8 @@ def test_memory_checker(duthosts, enum_dut_feature_container, test_setup_and_cle @pytest.mark.parametrize("test_setup_and_cleanup", - [' if status == 3 for 1 times within 2 cycles then exec "/usr/bin/restart_service telemetry"'], + [' if status == 3 for 1 times within 2 cycles ' + 'then exec "/usr/bin/restart_service telemetry"'], indirect=["test_setup_and_cleanup"]) def test_monit_reset_counter_failure(duthosts, enum_dut_feature_container, test_setup_and_cleanup, enum_rand_one_per_hwsku_frontend_hostname): @@ -556,7 +562,8 @@ def test_monit_reset_counter_failure(duthosts, enum_dut_feature_container, test_ .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -568,7 +575,8 @@ def test_monit_reset_counter_failure(duthosts, enum_dut_feature_container, test_ vm_workers = 6 pytest_require("Celestica-E1031" not in duthost.facts["hwsku"] - and ("20201231" in duthost.os_version or parse_version(duthost.kernel_version) > parse_version("4.9.0")), + and ("20201231" in duthost.os_version or + parse_version(duthost.kernel_version) > parse_version("4.9.0")), "Test is not supported for platform Celestica E1031, 20191130 and older image versions!") logger.info("Checks whether '{}' is running ...".format(container_name)) @@ -583,7 +591,8 @@ def test_monit_reset_counter_failure(duthosts, enum_dut_feature_container, test_ @pytest.mark.parametrize("test_setup_and_cleanup", - [' if status == 3 for 1 times within 2 cycles then exec "/usr/bin/restart_service telemetry" repeat every 2 cycles'], + [' if status == 3 for 1 times within 2 cycles then exec ' + '"/usr/bin/restart_service telemetry" repeat every 2 cycles'], indirect=["test_setup_and_cleanup"]) def test_monit_new_syntax(duthosts, enum_dut_feature_container, test_setup_and_cleanup, enum_rand_one_per_hwsku_frontend_hostname): @@ -607,7 +616,8 @@ def test_monit_new_syntax(duthosts, enum_dut_feature_container, test_setup_and_c .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -619,7 +629,8 @@ def test_monit_new_syntax(duthosts, enum_dut_feature_container, test_setup_and_c vm_workers = 6 pytest_require("Celestica-E1031" not in duthost.facts["hwsku"] - and (("20191130" in duthost.os_version and parse_version(duthost.os_version) > parse_version("20191130.72")) + and (("20191130" in duthost.os_version and + parse_version(duthost.os_version) > parse_version("20191130.72")) or parse_version(duthost.kernel_version) > parse_version("4.9.0")), "Test is not supported for platform Celestica E1031, 20191130.72 and older image versions!") @@ -646,7 +657,7 @@ def check_log_message(duthost, container_name): None. """ expected_alerting_messages = [] - expected_alerting_messages.append(".*\[memory_checker\] Exits without checking memory usage.*'telemetry'.*") + expected_alerting_messages.append(r".*\[memory_checker\] Exits without checking memory usage.*'telemetry'.*") loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix="memory_checker_skip_removed_container") loganalyzer.expect_regex = [] @@ -682,7 +693,8 @@ def test_memory_checker_without_container_created(duthosts, enum_dut_feature_con .format(container_name, dut_name, enum_rand_one_per_hwsku_frontend_hostname)) pytest_require(container_name == "telemetry", - "Skips testing memory_checker of container '{}' since memory monitoring is only enabled for 'telemetry'." + "Skips testing memory_checker of container '{}' " + "since memory monitoring is only enabled for 'telemetry'." .format(container_name)) duthost = duthosts[dut_name] @@ -693,7 +705,8 @@ def test_memory_checker_without_container_created(duthosts, enum_dut_feature_con container_name = "telemetry" pytest_require("Celestica-E1031" not in duthost.facts["hwsku"] - and (("20191130" in duthost.os_version and parse_version(duthost.os_version) > parse_version("20191130.72")) + and (("20191130" in duthost.os_version and + parse_version(duthost.os_version) > parse_version("20191130.72")) or parse_version(duthost.kernel_version) > parse_version("4.9.0")), "Test is not supported for platform Celestica E1031, 20191130.72 and older image versions!") diff --git a/tests/metadata/sample-testbed.json b/tests/metadata/sample-testbed.json index 5ed669c80f1..0da3b7f7255 100644 --- a/tests/metadata/sample-testbed.json +++ b/tests/metadata/sample-testbed.json @@ -3,363 +3,363 @@ "sample-dut": { "intf_status": { "Ethernet8": { - "alias": "etp3", - "oper_state": "up", - "name": "Ethernet8", - "admin_state": "up", - "vlan": "PortChannel0005", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp3", + "oper_state": "up", + "name": "Ethernet8", + "admin_state": "up", + "vlan": "PortChannel0005", + "speed": "100G", + "fec": "rs" + }, "PortChannel0005": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0005", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0005", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet0": { - "alias": "etp1", - "oper_state": "up", - "name": "Ethernet0", - "admin_state": "up", - "vlan": "PortChannel0002", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp1", + "oper_state": "up", + "name": "Ethernet0", + "admin_state": "up", + "vlan": "PortChannel0002", + "speed": "100G", + "fec": "rs" + }, "Ethernet4": { - "alias": "etp2", - "oper_state": "up", - "name": "Ethernet4", - "admin_state": "up", - "vlan": "PortChannel0002", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp2", + "oper_state": "up", + "name": "Ethernet4", + "admin_state": "up", + "vlan": "PortChannel0002", + "speed": "100G", + "fec": "rs" + }, "Ethernet108": { - "alias": "etp28", - "oper_state": "up", - "name": "Ethernet108", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp28", + "oper_state": "up", + "name": "Ethernet108", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet100": { - "alias": "etp26", - "oper_state": "up", - "name": "Ethernet100", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp26", + "oper_state": "up", + "name": "Ethernet100", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet104": { - "alias": "etp27", - "oper_state": "up", - "name": "Ethernet104", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp27", + "oper_state": "up", + "name": "Ethernet104", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "PortChannel0008": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0008", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0008", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet96": { - "alias": "etp25", - "oper_state": "up", - "name": "Ethernet96", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp25", + "oper_state": "up", + "name": "Ethernet96", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet124": { - "alias": "etp32", - "oper_state": "up", - "name": "Ethernet124", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp32", + "oper_state": "up", + "name": "Ethernet124", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet92": { - "alias": "etp24", - "oper_state": "up", - "name": "Ethernet92", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp24", + "oper_state": "up", + "name": "Ethernet92", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet120": { - "alias": "etp31", - "oper_state": "up", - "name": "Ethernet120", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp31", + "oper_state": "up", + "name": "Ethernet120", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet52": { - "alias": "etp14", - "oper_state": "up", - "name": "Ethernet52", - "admin_state": "up", - "vlan": "PortChannel0020", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp14", + "oper_state": "up", + "name": "Ethernet52", + "admin_state": "up", + "vlan": "PortChannel0020", + "speed": "100G", + "fec": "rs" + }, "PortChannel0002": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0002", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0002", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "PortChannel0023": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0023", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0023", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet56": { - "alias": "etp15", - "oper_state": "up", - "name": "Ethernet56", - "admin_state": "up", - "vlan": "PortChannel0023", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp15", + "oper_state": "up", + "name": "Ethernet56", + "admin_state": "up", + "vlan": "PortChannel0023", + "speed": "100G", + "fec": "rs" + }, "PortChannel0020": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0020", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0020", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet76": { - "alias": "etp20", - "oper_state": "up", - "name": "Ethernet76", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp20", + "oper_state": "up", + "name": "Ethernet76", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet72": { - "alias": "etp19", - "oper_state": "up", - "name": "Ethernet72", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp19", + "oper_state": "up", + "name": "Ethernet72", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet32": { - "alias": "etp9", - "oper_state": "up", - "name": "Ethernet32", - "admin_state": "up", - "vlan": "PortChannel0014", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp9", + "oper_state": "up", + "name": "Ethernet32", + "admin_state": "up", + "vlan": "PortChannel0014", + "speed": "100G", + "fec": "rs" + }, "Ethernet16": { - "alias": "etp5", - "oper_state": "up", - "name": "Ethernet16", - "admin_state": "up", - "vlan": "PortChannel0008", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp5", + "oper_state": "up", + "name": "Ethernet16", + "admin_state": "up", + "vlan": "PortChannel0008", + "speed": "100G", + "fec": "rs" + }, "Ethernet36": { - "alias": "etp10", - "oper_state": "up", - "name": "Ethernet36", - "admin_state": "up", - "vlan": "PortChannel0014", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp10", + "oper_state": "up", + "name": "Ethernet36", + "admin_state": "up", + "vlan": "PortChannel0014", + "speed": "100G", + "fec": "rs" + }, "Ethernet12": { - "alias": "etp4", - "oper_state": "up", - "name": "Ethernet12", - "admin_state": "up", - "vlan": "PortChannel0005", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp4", + "oper_state": "up", + "name": "Ethernet12", + "admin_state": "up", + "vlan": "PortChannel0005", + "speed": "100G", + "fec": "rs" + }, "Ethernet28": { - "alias": "etp8", - "oper_state": "up", - "name": "Ethernet28", - "admin_state": "up", - "vlan": "PortChannel0011", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp8", + "oper_state": "up", + "name": "Ethernet28", + "admin_state": "up", + "vlan": "PortChannel0011", + "speed": "100G", + "fec": "rs" + }, "Ethernet88": { - "alias": "etp23", - "oper_state": "up", - "name": "Ethernet88", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp23", + "oper_state": "up", + "name": "Ethernet88", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet24": { - "alias": "etp7", - "oper_state": "up", - "name": "Ethernet24", - "admin_state": "up", - "vlan": "PortChannel0011", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp7", + "oper_state": "up", + "name": "Ethernet24", + "admin_state": "up", + "vlan": "PortChannel0011", + "speed": "100G", + "fec": "rs" + }, "Ethernet116": { - "alias": "etp30", - "oper_state": "up", - "name": "Ethernet116", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp30", + "oper_state": "up", + "name": "Ethernet116", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet80": { - "alias": "etp21", - "oper_state": "up", - "name": "Ethernet80", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp21", + "oper_state": "up", + "name": "Ethernet80", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet112": { - "alias": "etp29", - "oper_state": "up", - "name": "Ethernet112", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp29", + "oper_state": "up", + "name": "Ethernet112", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "Ethernet84": { - "alias": "etp22", - "oper_state": "up", - "name": "Ethernet84", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp22", + "oper_state": "up", + "name": "Ethernet84", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "PortChannel0017": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0017", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0017", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "PortChannel0014": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0014", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0014", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet48": { - "alias": "etp13", - "oper_state": "up", - "name": "Ethernet48", - "admin_state": "up", - "vlan": "PortChannel0020", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp13", + "oper_state": "up", + "name": "Ethernet48", + "admin_state": "up", + "vlan": "PortChannel0020", + "speed": "100G", + "fec": "rs" + }, "Ethernet44": { - "alias": "etp12", - "oper_state": "up", - "name": "Ethernet44", - "admin_state": "up", - "vlan": "PortChannel0017", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp12", + "oper_state": "up", + "name": "Ethernet44", + "admin_state": "up", + "vlan": "PortChannel0017", + "speed": "100G", + "fec": "rs" + }, "Ethernet40": { - "alias": "etp11", - "oper_state": "up", - "name": "Ethernet40", - "admin_state": "up", - "vlan": "PortChannel0017", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp11", + "oper_state": "up", + "name": "Ethernet40", + "admin_state": "up", + "vlan": "PortChannel0017", + "speed": "100G", + "fec": "rs" + }, "Ethernet64": { - "alias": "etp17", - "oper_state": "up", - "name": "Ethernet64", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp17", + "oper_state": "up", + "name": "Ethernet64", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", + "fec": "rs" + }, "PortChannel0011": { - "alias": "N/A", - "oper_state": "up", - "name": "PortChannel0011", - "admin_state": "up", - "vlan": "routed", - "speed": "200G", + "alias": "N/A", + "oper_state": "up", + "name": "PortChannel0011", + "admin_state": "up", + "vlan": "routed", + "speed": "200G", "fec": "N/A" - }, + }, "Ethernet60": { - "alias": "etp16", - "oper_state": "up", - "name": "Ethernet60", - "admin_state": "up", - "vlan": "PortChannel0023", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp16", + "oper_state": "up", + "name": "Ethernet60", + "admin_state": "up", + "vlan": "PortChannel0023", + "speed": "100G", + "fec": "rs" + }, "Ethernet20": { - "alias": "etp6", - "oper_state": "up", - "name": "Ethernet20", - "admin_state": "up", - "vlan": "PortChannel0008", - "speed": "100G", - "fec": "rs" - }, + "alias": "etp6", + "oper_state": "up", + "name": "Ethernet20", + "admin_state": "up", + "vlan": "PortChannel0008", + "speed": "100G", + "fec": "rs" + }, "Ethernet68": { - "alias": "etp18", - "oper_state": "up", - "name": "Ethernet68", - "admin_state": "up", - "vlan": "routed", - "speed": "100G", + "alias": "etp18", + "oper_state": "up", + "name": "Ethernet68", + "admin_state": "up", + "vlan": "routed", + "speed": "100G", "fec": "rs" } } diff --git a/tests/monit/test_monit_status.py b/tests/monit/test_monit_status.py index 50a3e16ff39..06b6553cdbd 100644 --- a/tests/monit/test_monit_status.py +++ b/tests/monit/test_monit_status.py @@ -5,7 +5,6 @@ import pytest -from pkg_resources import parse_version from tests.common.utilities import wait_until from tests.common.helpers.assertions import pytest_assert from tests.common.helpers.assertions import pytest_require diff --git a/tests/mpls/conftest.py b/tests/mpls/conftest.py index 2d4d0eeab54..ce32578262b 100644 --- a/tests/mpls/conftest.py +++ b/tests/mpls/conftest.py @@ -1,15 +1,18 @@ import logging import pytest import pprint +import random +import os logger = logging.getLogger(__name__) -DUT_TMP_DIR='/tmp' +DUT_TMP_DIR = '/tmp' + +LABEL_POP_ROUTES = 'label_pop_routes' +LABEL_PUSH_ROUTES = 'label_push_routes' +LABEL_SWAP_ROUTES = 'label_swap_routes' +LABEL_DEL_ROUTES = 'label_del_routes' -LABEL_POP_ROUTES='label_pop_routes' -LABEL_PUSH_ROUTES='label_push_routes' -LABEL_SWAP_ROUTES='label_swap_routes' -LABEL_DEL_ROUTES='label_del_routes' @pytest.fixture(scope='module') def setup(duthost, tbinfo, ptfadapter): @@ -23,71 +26,71 @@ def setup(duthost, tbinfo, ptfadapter): pytest.skip('Unsupported topology') # gather ansible facts - mg_facts=duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] - host_facts=duthost.setup()['ansible_facts'] + mg_facts = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts'] + host_facts = duthost.setup()['ansible_facts'] - tor_ports_ids={} - tor_ports=[] - spine_ports_ids={} - spine_ports=[] - tor_addr={} - tor_peer_addr={} - spine_addr={} - spine_peer_addr={} - tor_mac={} - spine_mac={} + tor_ports_ids = {} + tor_ports = [] + spine_ports_ids = {} + spine_ports = [] + tor_addr = {} + tor_peer_addr = {} + spine_addr = {} + spine_peer_addr = {} + tor_mac = {} + spine_mac = {} - all_ifs=[] + all_ifs = [] - ip_ifaces=duthost.get_active_ip_interfaces(tbinfo, asic_index="all") + ip_ifaces = duthost.get_active_ip_interfaces(tbinfo, asic_index="all") - for k,v in list(ip_ifaces[0].items()): + for k, v in list(ip_ifaces[0].items()): all_ifs.append(k) logger.info(ip_ifaces[0][k]) if 'T0' in v['bgp_neighbor']: tor_ports.append(k) - tor_addr[k]=v['ipv4'] - tor_peer_addr[k]=v['peer_ipv4'] + tor_addr[k] = v['ipv4'] + tor_peer_addr[k] = v['peer_ipv4'] elif 'T2' in v['bgp_neighbor']: - spine_ports.append(k) - spine_addr[k]=v['ipv4'] - spine_peer_addr[k]=v['peer_ipv4'] - + spine_ports.append(k) + spine_addr[k] = v['ipv4'] + spine_peer_addr[k] = v['peer_ipv4'] + logger.info('tor_ports: {}'.format(tor_ports)) - logger.info('spine_ports: {}'.format(spine_ports)) - logger.info('tor_addr: {}'.format(tor_addr)) - + logger.info('spine_ports: {}'.format(spine_ports)) + logger.info('tor_addr: {}'.format(tor_addr)) + for dut_port in tor_ports: - port_id=mg_facts['minigraph_port_indices'][dut_port] - tor_ports_ids[dut_port]=port_id - ansible_port='ansible_'+dut_port - tor_mac[dut_port]=host_facts[ansible_port]['macaddress'] - + port_id = mg_facts['minigraph_port_indices'][dut_port] + tor_ports_ids[dut_port] = port_id + ansible_port = 'ansible_'+dut_port + tor_mac[dut_port] = host_facts[ansible_port]['macaddress'] + for dut_port in spine_ports: - port_id=mg_facts['minigraph_port_indices'][dut_port] - spine_ports_ids[dut_port]=port_id - ansible_port='ansible_'+dut_port - spine_mac[dut_port]=host_facts[ansible_port]['macaddress'] + port_id = mg_facts['minigraph_port_indices'][dut_port] + spine_ports_ids[dut_port] = port_id + ansible_port = 'ansible_'+dut_port + spine_mac[dut_port] = host_facts[ansible_port]['macaddress'] logger.info('spine_mac: {}'.format(spine_mac)) logger.info('spine_ports_ids: {}'.format(spine_ports_ids)) - src_port=random.choice(spine_ports) - dst_port=random.choice(tor_ports) + src_port = random.choice(spine_ports) + dst_port = random.choice(tor_ports) - dst_pid=tor_ports_ids[dst_port] - src_pid=spine_ports_ids[src_port] + dst_pid = tor_ports_ids[dst_port] + src_pid = spine_ports_ids[src_port] - dst_mac=tor_mac[dst_port] - src_mac=spine_mac[src_port] + dst_mac = tor_mac[dst_port] + src_mac = spine_mac[src_port] - dst_addr=tor_addr[dst_port] - src_addr=spine_addr[src_port] + dst_addr = tor_addr[dst_port] + src_addr = spine_addr[src_port] - dst_peer_addr=tor_peer_addr[dst_port] - src_peer_addr=spine_peer_addr[src_port] + dst_peer_addr = tor_peer_addr[dst_port] + src_peer_addr = spine_peer_addr[src_port] - setup_information={ + setup_information = { 'duthost': duthost, 'dut_tmp_dir': DUT_TMP_DIR, 'dst_ip_spine_blocked': '192.168.144.1', diff --git a/tests/mpls/test_mpls.py b/tests/mpls/test_mpls.py index 0091ebbc780..05255560ccb 100644 --- a/tests/mpls/test_mpls.py +++ b/tests/mpls/test_mpls.py @@ -7,18 +7,19 @@ import pytest import time -logger=logging.getLogger(__name__) +logger = logging.getLogger(__name__) -pytestmark=[ +pytestmark = [ pytest.mark.topology('t1'), ] -CONFIGS_DIR=os.path.dirname(os.path.realpath(__file__)) -ADD_DIR=os.path.join(CONFIGS_DIR, 'configs') +CONFIGS_DIR = os.path.dirname(os.path.realpath(__file__)) +ADD_DIR = os.path.join(CONFIGS_DIR, 'configs') + +LABEL_POP_ROUTES = 'label_pop_routes' +LABEL_PUSH_ROUTES = 'label_push_routes' +LABEL_SWAP_ROUTES = 'label_swap_routes' +LABEL_DEL_ROUTES = 'label_del_routes' -LABEL_POP_ROUTES='label_pop_routes' -LABEL_PUSH_ROUTES='label_push_routes' -LABEL_SWAP_ROUTES='label_swap_routes' -LABEL_DEL_ROUTES='label_del_routes' class TestBasicMpls: """ @@ -36,7 +37,7 @@ def teardown_labels(self, setup): """ logger.info("Remove mpls comfigs") self.config_interface_mpls(setup, LABEL_DEL_ROUTES, False) - + def icmp_packet(self, setup, ptfadapter): """ create ICMP packet for testing """ return testutils.simple_icmp_packet( @@ -48,6 +49,7 @@ def icmp_packet(self, setup, ptfadapter): icmp_code=0, ip_ttl=64, ) + def mpls_packet(self, setup, ptfadapter): """ create MPLS packet for testing """ return testutils.simple_mpls_packet( @@ -55,9 +57,9 @@ def mpls_packet(self, setup, ptfadapter): eth_src=ptfadapter.dataplane.get_mac(0, setup['src_pid']), mpls_tags=[ { - 'label':1000001, + 'label': 1000001, 'ttl': 63, - 's':1 + 's': 1 } ], inner_frame=testutils.simple_ip_only_packet( @@ -72,21 +74,21 @@ def mpls_stack_packet(self, setup, ptfadapter): eth_dst=setup['src_mac'], eth_src=ptfadapter.dataplane.get_mac(0, setup['src_pid']), mpls_tags=[ - { - 'label':1000001, - 'ttl': 255, - 's':0 - }, - { - 'label':1000010, - 'ttl': 255, - 's':0 - }, - { - 'label':1000011, - 'ttl': 255, - 's':1 - } + { + 'label': 1000001, + 'ttl': 255, + 's': 0 + }, + { + 'label': 1000010, + 'ttl': 255, + 's': 0 + }, + { + 'label': 1000011, + 'ttl': 255, + 's': 1 + } ], inner_frame=testutils.simple_ip_only_packet( ip_dst='192.168.0.1', @@ -96,59 +98,58 @@ def mpls_stack_packet(self, setup, ptfadapter): def expected_mask_ip_packet(self, pkt): """ return mask for ip packet """ - - epkt=pkt.copy() - exp_pkt=pkt.copy() - exp_pkt['IP'].ttl=62 - pkt1=exp_pkt['IP'] - exp_pkt['Ethernet'].type=0x0800 + + exp_pkt = pkt.copy() + exp_pkt['IP'].ttl = 62 + pkt1 = exp_pkt['IP'] + exp_pkt['Ethernet'].type = 0x0800 exp_pkt['Ethernet'].remove_payload() exp_pkt /= pkt1 - exp_pkt=mask.Mask(exp_pkt) - exp_pkt=mask.Mask(exp_pkt) + exp_pkt = mask.Mask(exp_pkt) + exp_pkt = mask.Mask(exp_pkt) exp_pkt.set_do_not_care_scapy(packet.Ether, 'dst') exp_pkt.set_do_not_care_scapy(packet.Ether, 'src') exp_pkt.set_do_not_care_scapy(packet.IP, 'chksum') return exp_pkt - + def expected_mask_mpls_swap_packet(self, pkt, exp_label): """ return mask for mpls packet """ - exp_pkt=pkt.copy() + exp_pkt = pkt.copy() exp_pkt['MPLS'].ttl -= 1 - exp_pkt['MPLS'].label=exp_label - exp_pkt=mask.Mask(exp_pkt) + exp_pkt['MPLS'].label = exp_label + exp_pkt = mask.Mask(exp_pkt) exp_pkt.set_do_not_care_scapy(packet.Ether, 'dst') exp_pkt.set_do_not_care_scapy(packet.Ether, 'src') exp_pkt.set_do_not_care_scapy(packet.IP, 'chksum') return exp_pkt - + def expected_mask_mpls_push_packet(self, pkt, exp_label): """ return mask for mpls packet """ - - exp_pkt=pkt.copy() - exp_pkt['MPLS'].ttl=exp_pkt['IP'].ttl - 1 + + exp_pkt = pkt.copy() + exp_pkt['MPLS'].ttl = exp_pkt['IP'].ttl - 1 exp_pkt['IP'].ttl -= 1 - exp_pkt['MPLS'].label=exp_label - exp_pkt=mask.Mask(exp_pkt) + exp_pkt['MPLS'].label = exp_label + exp_pkt = mask.Mask(exp_pkt) exp_pkt.set_do_not_care_scapy(packet.Ether, 'dst') exp_pkt.set_do_not_care_scapy(packet.Ether, 'src') exp_pkt.set_do_not_care_scapy(packet.IP, 'chksum') - + return exp_pkt - + def config_interface_mpls(self, setup, config_file, enable=True): """ enable/disable mpls on interface """ - duthost=setup['duthost'] + duthost = setup['duthost'] - dst_port=setup['dst_port'] - src_port=setup['src_port'] + dst_port = setup['dst_port'] + src_port = setup['src_port'] - dst_peer_addr=setup['dst_peer_addr'] - src_peer_addr=setup['src_peer_addr'] + dst_peer_addr = setup['dst_peer_addr'] + src_peer_addr = setup['src_peer_addr'] - config_variables={ + config_variables = { 'dst_port': dst_port, 'src_port': src_port, 'dst_peer_addr': dst_peer_addr, @@ -159,103 +160,102 @@ def config_interface_mpls(self, setup, config_file, enable=True): duthost.host.options['variable_manager'].extra_vars.update(config_variables) logger.info('generate config for MPLS') - mpls_config='{}.json'.format(config_file) - mpls_config_path=os.path.join(setup['dut_tmp_dir'], mpls_config) - template_file='{}.j2'.format(config_file) + mpls_config = '{}.json'.format(config_file) + mpls_config_path = os.path.join(setup['dut_tmp_dir'], mpls_config) + template_file = '{}.j2'.format(config_file) duthost.template(src=os.path.join(ADD_DIR, template_file), dest=mpls_config_path) - for intf in [dst_port, src_port]: if enable: - result=duthost.shell('config interface mpls add {}'.format(intf), - module_ignore_errors=True) + result = duthost.shell('config interface mpls add {}'.format(intf), + module_ignore_errors=True) if result['rc'] != 0: - pytest.fail('Failed to enable mplson interface {} : {}'.format(intf, result['stderr'])) + pytest.fail('Failed to enable mplson interface {} : {}'.format(intf, result['stderr'])) else: - result=duthost.shell('config interface mpls remove {}'.format(intf), - module_ignore_errors=True) - if result['rc'] != 0: + result = duthost.shell('config interface mpls remove {}'.format(intf), + module_ignore_errors=True) + if result['rc'] != 0: pytest.fail('Failed to disable mpls on interface {} : {}'.format(intf, result['stderr'])) # Apply config with swssconfig - result=duthost.shell('docker exec -i swss swssconfig /dev/stdin < {}'.format(mpls_config_path), - module_ignore_errors=True) + result = duthost.shell('docker exec -i swss swssconfig /dev/stdin < {}'.format(mpls_config_path), + module_ignore_errors=True) if result['rc'] != 0: - pytest.fail('Failed to apply labelroute configuration file: {}'.format(result['stderr'])) - + pytest.fail('Failed to apply labelroute configuration file: {}'.format(result['stderr'])) + def test_pop_label(self, setup, ptfadapter): """ test pop label """ - dst_pid=setup['dst_pid'] - src_pid=setup['src_pid'] + dst_pid = setup['dst_pid'] + src_pid = setup['src_pid'] self.config_interface_mpls(setup, LABEL_POP_ROUTES) - + time.sleep(2) - - pkt=self.mpls_packet(setup, ptfadapter) - exp_pkt=self.expected_mask_ip_packet(pkt) - + + pkt = self.mpls_packet(setup, ptfadapter) + exp_pkt = self.expected_mask_ip_packet(pkt) + ptfadapter.dataplane.flush() testutils.send(ptfadapter, src_pid, pkt) try: - res=testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) + res = testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) logger.info(res) except Exception as e: - self.teardown_labels(setup) - pytest.fail('MPLS pop test failed \n'+ str(e)) - + self.teardown_labels(setup) + pytest.fail('MPLS pop test failed \n' + str(e)) + self.teardown_labels(setup) def test_swap_label(self, setup, ptfadapter): """ test swap label """ - dst_pid=setup['dst_pid'] - src_pid=setup['src_pid'] + dst_pid = setup['dst_pid'] + src_pid = setup['src_pid'] + + self.config_interface_mpls(setup, LABEL_SWAP_ROUTES) - self.config_interface_mpls(setup, LABEL_SWAP_ROUTES) - time.sleep(2) - - pkt=self.mpls_packet(setup, ptfadapter) - exp_pkt=self.expected_mask_mpls_swap_packet(pkt, 1000002) - + + pkt = self.mpls_packet(setup, ptfadapter) + exp_pkt = self.expected_mask_mpls_swap_packet(pkt, 1000002) + ptfadapter.dataplane.flush() testutils.send(ptfadapter, src_pid, pkt) try: - res=testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) + res = testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) logger.info(res) except Exception as e: self.teardown_labels(setup) - pytest.fail('MPLS swap test failed \n' + str(e)) - + pytest.fail('MPLS swap test failed \n' + str(e)) + self.teardown_labels(setup) - + def test_push_label(self, setup, ptfadapter): """ test push label """ - - dst_pid=setup['dst_pid'] - src_pid=setup['src_pid'] + + dst_pid = setup['dst_pid'] + src_pid = setup['src_pid'] self.config_interface_mpls(setup, LABEL_PUSH_ROUTES) time.sleep(2) - pkt=self.icmp_packet(setup, ptfadapter) - epkt=pkt.copy() - pkt1=epkt['IP'] - epkt['Ethernet'].type=0x8847 + pkt = self.icmp_packet(setup, ptfadapter) + epkt = pkt.copy() + pkt1 = epkt['IP'] + epkt['Ethernet'].type = 0x8847 epkt['Ethernet'].remove_payload() - mp=MPLS(label=1000002, s=1, ttl=255) + mp = MPLS(label=1000002, s=1, ttl=255) # noqa F821 mp.remove_payload() epkt /= mp epkt /= pkt1 - exp_pkt=self.expected_mask_mpls_push_packet(epkt, 1000001) + exp_pkt = self.expected_mask_mpls_push_packet(epkt, 1000001) ptfadapter.dataplane.flush() testutils.send(ptfadapter, src_pid, pkt) try: - res=testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) + res = testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) logger.info(res) except Exception as e: self.teardown_labels(setup) @@ -266,21 +266,21 @@ def test_push_label(self, setup, ptfadapter): def test_swap_labelstack(self, setup, ptfadapter): """ test swap labelstack """ - dst_pid=setup['dst_pid'] - src_pid=setup['src_pid'] + dst_pid = setup['dst_pid'] + src_pid = setup['src_pid'] self.config_interface_mpls(setup, LABEL_SWAP_ROUTES) - + time.sleep(2) - pkt=self.mpls_stack_packet(setup, ptfadapter) - exp_pkt=self.expected_mask_mpls_swap_packet(pkt, 1000002) + pkt = self.mpls_stack_packet(setup, ptfadapter) + exp_pkt = self.expected_mask_mpls_swap_packet(pkt, 1000002) ptfadapter.dataplane.flush() testutils.send(ptfadapter, src_pid, pkt) try: - res=testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) + res = testutils.verify_packet_any_port(ptfadapter, exp_pkt, ports=[dst_pid]) logger.info(res) except Exception as e: self.teardown_labels(setup) diff --git a/tests/mvrf/test_mgmtvrf.py b/tests/mvrf/test_mgmtvrf.py index 3064f6d58b9..e9794347152 100644 --- a/tests/mvrf/test_mgmtvrf.py +++ b/tests/mvrf/test_mgmtvrf.py @@ -28,12 +28,14 @@ def restore_config_db(duthost): # Reload to restore configuration config_reload(duthost, safe_reload=True, check_intf_up_ports=True) + @pytest.fixture(scope="module") def check_ntp_sync(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] ntp_stat = duthost.command('ntpstat', module_ignore_errors=True)['rc'] return ntp_stat + @pytest.fixture(scope="module", autouse=True) def setup_mvrf(duthosts, rand_one_dut_hostname, localhost, check_ntp_sync): """ @@ -51,7 +53,8 @@ def setup_mvrf(duthosts, rand_one_dut_hostname, localhost, check_ntp_sync): except Exception as e: logger.error("Exception raised in setup, exception: {}".format(repr(e))) restore_config_db(duthost) - pytest.fail("Configure mgmt vrf failed, no test case will be executed. Code after 'yield' will not be executed either.") + pytest.fail("Configure mgmt vrf failed, no test case will be executed. " + "Code after 'yield' will not be executed either.") yield @@ -61,23 +64,25 @@ def setup_mvrf(duthosts, rand_one_dut_hostname, localhost, check_ntp_sync): time.sleep(5) localhost.wait_for(host=duthost.mgmt_ip, - port=SONIC_SSH_PORT, - state="started", - search_regex=SONIC_SSH_REGEX, - timeout=90) + port=SONIC_SSH_PORT, + state="started", + search_regex=SONIC_SSH_REGEX, + timeout=90) verify_show_command(duthost, mvrf=False) finally: # Always restore and reload the original config_db. restore_config_db(duthost) + @pytest.fixture(scope='module') def ntp_servers(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] - config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] + config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] ntp_servers = config_facts.get('NTP_SERVER', {}) return ntp_servers + @pytest.fixture() def ntp_teardown(ptfhost, duthosts, rand_one_dut_hostname, ntp_servers): yield @@ -90,6 +95,7 @@ def ntp_teardown(ptfhost, duthosts, rand_one_dut_hostname, ntp_servers): for ntp_server in ntp_servers: duthost.command("config ntp add %s" % ntp_server, module_ignore_errors=True) + @pytest.fixture() def change_critical_services(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] @@ -99,6 +105,7 @@ def change_critical_services(duthosts, rand_one_dut_hostname): yield duthost.reset_critical_services_tracking_list(backup) + def check_ntp_status(host): ntpstat_cmd = 'ntpstat' if isinstance(host, PTFHost): @@ -107,21 +114,22 @@ def check_ntp_status(host): res = execute_dut_command(host, ntpstat_cmd, mvrf=True, ignore_errors=True) return res['rc'] == 0 + def verify_show_command(duthost, mvrf=True): show_mgmt_vrf = duthost.shell("show mgmt-vrf")["stdout"] mvrf_interfaces = {} if mvrf: - mvrf_interfaces["mgmt"] = "\d+:\s+mgmt:\s+ mtu\s+\d+\s+qdisc\s+noqueue\s+state\s+UP" + mvrf_interfaces["mgmt"] = r"\d+:\s+mgmt:\s+ mtu\s+\d+\s+qdisc\s+noqueue\s+state\s+UP" mvrf_interfaces["vrf_table"] = "vrf table 5000" - mvrf_interfaces["eth0"] = "\d+:\s+eth0+:\s+.*master mgmt\s+state\s+UP " - mvrf_interfaces["lo"] = "\d+:\s+lo-m:\s+.*master mgmt" - if not "ManagementVRF : Enabled" in show_mgmt_vrf: + mvrf_interfaces["eth0"] = r"\d+:\s+eth0+:\s+.*master mgmt\s+state\s+UP " + mvrf_interfaces["lo"] = r"\d+:\s+lo-m:\s+.*master mgmt" + if "ManagementVRF : Enabled" not in show_mgmt_vrf: raise Exception("'ManagementVRF : Enabled' not in output of 'show mgmt vrf'") for _, pattern in list(mvrf_interfaces.items()): if not re.search(pattern, show_mgmt_vrf): raise Exception("Unexpected output for MgmtVRF=enabled") else: - if not "ManagementVRF : Disabled" in show_mgmt_vrf: + if "ManagementVRF : Disabled" not in show_mgmt_vrf: raise Exception("'ManagementVRF : Disabled' not in output of 'show mgmt vrf'") @@ -143,13 +151,15 @@ def setup_ntp(ptfhost, duthost, ntp_servers): ptfhost.lineinfile(path="/etc/ntp.conf", line="server 127.127.1.0 prefer") # restart ntp server ntp_en_res = ptfhost.service(name="ntp", state="restarted") - pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost), \ - "NTP server was not started in PTF container {}; NTP service start result {}".format(ptfhost.hostname, ntp_en_res)) + pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost), + "NTP server was not started in PTF container {}; NTP service start result {}" + .format(ptfhost.hostname, ntp_en_res)) # setup ntp on dut to sync with ntp server for ntp_server in ntp_servers: duthost.command("config ntp del %s" % ntp_server) duthost.command("config ntp add %s" % ptfhost.mgmt_ip) + class TestMvrfInbound(): def test_ping(self, duthost): duthost.ping() @@ -253,7 +263,8 @@ def test_warmboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, cre duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost, reboot_type="warm") - pytest_assert(wait_until(120, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") + pytest_assert(wait_until(120, 20, 0, duthost.critical_services_fully_started), + "Not all critical services are fully started") # Change default critical services to check services that starts with bootOn timer duthost.reset_critical_services_tracking_list(['snmp', 'telemetry', 'mgmt-framework']) pytest_assert(wait_until(180, 20, 0, duthost.critical_services_fully_started), @@ -265,7 +276,8 @@ def test_reboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, creds duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost) - pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") + pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), + "Not all critical services are fully started") self.basic_check_after_reboot(duthost, localhost, ptfhost, creds) @pytest.mark.disable_loganalyzer @@ -273,5 +285,6 @@ def test_fastboot(self, duthosts, rand_one_dut_hostname, localhost, ptfhost, cre duthost = duthosts[rand_one_dut_hostname] duthost.command("sudo config save -y") # This will override config_db.json with mgmt vrf config reboot(duthost, localhost, reboot_type="fast") - pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") + pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), + "Not all critical services are fully started") self.basic_check_after_reboot(duthost, localhost, ptfhost, creds) diff --git a/tests/nat/templates/create_nat_binding.j2 b/tests/nat/templates/create_nat_binding.j2 index 1cb06dacd45..460f8914f68 100644 --- a/tests/nat/templates/create_nat_binding.j2 +++ b/tests/nat/templates/create_nat_binding.j2 @@ -26,4 +26,4 @@ "nat_pool": "pool_1" } } -} \ No newline at end of file +} diff --git a/tests/ntp/test_ntp.py b/tests/ntp/test_ntp.py index 9cc229f1ca1..e4a9bf372d1 100644 --- a/tests/ntp/test_ntp.py +++ b/tests/ntp/test_ntp.py @@ -2,10 +2,10 @@ from tests.common.helpers.assertions import pytest_assert import logging import time -logger = logging.getLogger(__name__) - import pytest +logger = logging.getLogger(__name__) + pytestmark = [ pytest.mark.disable_loganalyzer, pytest.mark.topology('any'), @@ -14,6 +14,7 @@ TIME_FORWARD = 3600 + def config_long_jump(duthost, enable=False): """change ntpd option to enable or disable long jump""" if enable: @@ -26,6 +27,7 @@ def config_long_jump(duthost, enable=False): duthost.command("sed -i %s /etc/default/ntp" % regex) duthost.service(name='ntp', state='restarted') + @pytest.fixture(scope="module") def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname): """setup ntp client and server""" @@ -36,11 +38,12 @@ def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname): # restart ntp server ntp_en_res = ptfhost.service(name="ntp", state="restarted") - pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost), \ - "NTP server was not started in PTF container {}; NTP service start result {}".format(ptfhost.hostname, ntp_en_res)) + pytest_assert(wait_until(120, 5, 0, check_ntp_status, ptfhost), + "NTP server was not started in PTF container {}; NTP service start result {}" + .format(ptfhost.hostname, ntp_en_res)) # setup ntp on dut to sync with ntp server - config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] + config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] ntp_servers = config_facts.get('NTP_SERVER', {}) for ntp_server in ntp_servers: duthost.command("config ntp del %s" % ntp_server) @@ -56,6 +59,7 @@ def setup_ntp(ptfhost, duthosts, rand_one_dut_hostname): for ntp_server in ntp_servers: duthost.command("config ntp add %s" % ntp_server) + @pytest.fixture def setup_long_jump_config(duthosts, rand_one_dut_hostname): """set long jump config and set DUT's time forward""" @@ -84,12 +88,14 @@ def setup_long_jump_config(duthosts, rand_one_dut_hostname): duthost.command("date -s '@{}'".format(dut_end_time)) config_long_jump(duthost, long_jump_enable) + def check_ntp_status(host): res = host.command("ntpstat", module_ignore_errors=True) if res['rc'] != 0: - return False + return False return True + def test_ntp_long_jump_enabled(duthosts, rand_one_dut_hostname, setup_ntp, setup_long_jump_config): duthost = duthosts[rand_one_dut_hostname] @@ -98,6 +104,7 @@ def test_ntp_long_jump_enabled(duthosts, rand_one_dut_hostname, setup_ntp, setup pytest_assert(wait_until(720, 10, 0, check_ntp_status, duthost), "NTP long jump enable failed") + def test_ntp_long_jump_disabled(duthosts, rand_one_dut_hostname, setup_ntp, setup_long_jump_config): duthost = duthosts[rand_one_dut_hostname] @@ -106,6 +113,7 @@ def test_ntp_long_jump_disabled(duthosts, rand_one_dut_hostname, setup_ntp, setu if wait_until(720, 10, 0, check_ntp_status, duthost): pytest.fail("NTP long jump disable failed") + def test_ntp(duthosts, rand_one_dut_hostname, setup_ntp): """ Verify that DUT is synchronized with configured NTP server """ duthost = duthosts[rand_one_dut_hostname]