def build_ip_interface(self, duthost, tbinfo): """ builds a list of active IP interfaces and port index for each ASIC Returns: { asic_index: { portIndex: { "ipv4": peer ipv4, "bgp_neighbor": BGP neighbor } . . } . . } """ topo = tbinfo["topo"]["name"] if topo not in self.SUPPORTED_T1_TOPOS: pytest.skip("unsupported topology {}".format(topo)) pytest_require(duthost.is_multi_asic, "Not a multi asic platform") mg_facts = duthost.get_extended_minigraph_facts(tbinfo) ip_ifaces = duthost.get_active_ip_interfaces(tbinfo, asic_index="all") port_ips = dict() for idx in range(len(ip_ifaces)): port_ips.update(self.build_port_ips(idx, ip_ifaces[idx], mg_facts)) return port_ips
def test_memory_checker(duthosts, enum_rand_one_per_hwsku_frontend_hostname): """Checks whether the telemetry container can be restarted or not if the memory usage of it is beyond the threshold. The `stress` utility is leveraged as the memory stressing tool. Args: duthosts: The fixture returns list of DuTs. enum_rand_one_per_hwsku_frontend_hostname: The fixture randomly pick up a frontend DuT from testbed. Returns: None. """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] # TODO: Currently we only test 'telemetry' container which has the memory threshold 400MB # and number of vm_workers is hard coded. We will extend this testing on all containers after # the feature 'memory_checker' is fully implemented. container_name = "telemetry" vm_workers = 4 pytest_require( ("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 20191130.72 and older image versions!") install_stress_utility(duthost, container_name) consume_memory_and_restart_container(duthost, container_name, vm_workers) remove_stress_utility(duthost, container_name) postcheck_critical_processes(duthost, container_name)
def test_arp_garp_enabled(duthosts, enum_rand_one_per_hwsku_frontend_hostname, garp_setup, setup_ptf_arp, intfs_for_test, config_facts, ptfadapter): ''' Send a gratuitous ARP (GARP) packet from the PTF to the DUT The DUT should learn the (previously unseen) ARP info from the packet ''' duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] ptf_intf_ipv4_addr, _, _ = setup_ptf_arp arp_accept_vals = garp_setup pytest_require(all(int(val) == 1 for val in arp_accept_vals), 'Gratuitous ARP not enabled for this device') arp_request_ip = increment_ipv4_addr(ptf_intf_ipv4_addr) arp_src_mac = '00:00:07:08:09:0a' _, _, intf1_index, _, = intfs_for_test pkt = testutils.simple_arp_packet(pktlen=60, eth_dst='ff:ff:ff:ff:ff:ff', eth_src=arp_src_mac, vlan_pcp=0, arp_op=2, ip_snd=arp_request_ip, ip_tgt=arp_request_ip, hw_snd=arp_src_mac, hw_tgt='ff:ff:ff:ff:ff:ff' ) logger.info("Sending GARP for target {} from PTF interface {}".format(arp_request_ip, intf1_index)) testutils.send_packet(ptfadapter, intf1_index, pkt) vlan_intfs = config_facts['VLAN_INTERFACE'].keys() switch_arptable = duthost.switch_arptable()['ansible_facts'] pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['macaddress'].lower() == arp_src_mac.lower()) pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['interface'] in vlan_intfs)
def skip_if_not_supported(is_route_flow_counter_supported): """Skip the test if route flow counter is not supported on this platform Args: rand_selected_dut (object): DUT object """ pytest_require(is_route_flow_counter_supported, 'route flow counter is not supported')
def test_default_route_with_bgp_flap(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_asic_index, tbinfo): """ Check the default route present in app_db has the correct nexthops ip Check the default route is removed when the bgp sessions are shutdown """ pytest_require('t1-backend' not in tbinfo['topo']['name'], \ "Skip this testcase since this topology {} has no default routes"\ .format(tbinfo['topo']['name'])) duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] asichost = duthost.asic_instance(enum_asic_index) config_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] bgp_neighbors = config_facts.get('BGP_NEIGHBOR', {}) af_list = ['ipv4', 'ipv6'] # verify the default route is correct in the app db for af in af_list: verify_default_route_in_app_db(asichost, tbinfo, af) duthost.command("sudo config bgp shutdown all") if not wait_until(120, 2, 0, duthost.is_bgp_state_idle): pytest.fail( 'BGP Shutdown Timeout: BGP sessions not shutdown after 120 seconds') # give some more time for default route to be removed if not wait_until(120, 2, 0, asichost.is_default_route_removed_from_app_db): pytest.fail( 'Default route is not removed from APP_DB') duthost.command("sudo config bgp startup all") if not wait_until(300, 10, 0, duthost.check_bgp_session_state, bgp_neighbors.keys()): pytest.fail("not all bgp sessions are up after config reload")
def test_pfc_pause_single_lossy_prio_reboot( ixia_api, ixia_testbed_config, conn_graph_facts, fanout_graph_facts, localhost, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, rand_lossy_prio, all_prio_list, prio_dscp_map, reboot_type): """ Test if PFC will impact a single lossy priority after various kinds of reboots Args: ixia_api (pytest fixture): IXIA session ixia_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph localhost (pytest fixture): localhost handle duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): port to test, e.g., 's6100-1|Ethernet0' rand_lossy_prio (str): lossy priority to test, e.g., 's6100-1|2' all_prio_list (pytest fixture): list of all the priorities prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority). reboot_type (str): reboot type to be issued on the DUT Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') dut_hostname2, lossy_prio = rand_lossy_prio.split('|') pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2, "Priority and port are not mapped to the expected DUT") testbed_config, port_config_list = ixia_testbed_config duthost = duthosts[rand_one_dut_hostname] lossy_prio = int(lossy_prio) pause_prio_list = [lossy_prio] test_prio_list = [lossy_prio] bg_prio_list = [p for p in all_prio_list] bg_prio_list.remove(lossy_prio) logger.info("Issuing a {} reboot on the dut {}".format( reboot_type, duthost.hostname)) reboot(duthost, localhost, reboot_type=reboot_type) logger.info("Wait until the system is stable") pytest_assert(wait_until(300, 20, duthost.critical_services_fully_started), "Not all critical services are fully started") run_pfc_test(api=ixia_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, global_pause=False, pause_prio_list=pause_prio_list, test_prio_list=test_prio_list, bg_prio_list=bg_prio_list, prio_dscp_map=prio_dscp_map, test_traffic_pause=False)
def test_ssh_limits(duthosts, rand_one_dut_hostname, tacacs_creds, setup_limit): """ This test case will test following 2 scenarios: 1. Following 2 templates can be render by hostcfgd correctly: /usr/share/sonic/templates/pam_limits.j2 /usr/share/sonic/templates/limits.conf.j2 2. SSH login session limit works correctly. """ duthost = duthosts[rand_one_dut_hostname] # if template file not exist on duthost, ignore this UT pytest_require(limit_template_exist(duthost), "Template file {0} not exist, ignore test case.".format(LIMITS_CONF_TEMPLATE_PATH)) dut_ip = duthost.mgmt_ip local_user = tacacs_creds['local_user'] local_user_password = tacacs_creds['local_user_passwd'] # Create multiple login session to test maxlogins limit, first session will success ssh_session_1 = ssh_connect_remote(dut_ip, local_user, local_user_password) login_message_1 = get_login_result(ssh_session_1) logging.debug("Login session 1 result:\n{0}\n".format(login_message_1)) pytest_assert("There were too many logins for" not in login_message_1) # The second session will be disconnect by device ssh_session_2 = ssh_connect_remote(dut_ip, local_user, local_user_password) login_message_2 = get_login_result(ssh_session_2) logging.debug("Login session 2 result:\n{0}\n".format(login_message_2)) pytest_assert("There were too many logins for" in login_message_2) ssh_session_1.close() ssh_session_2.close()
def test_show_platform_fanstatus_mocked(duthosts, enum_rand_one_per_hwsku_hostname, mocker_factory, disable_thermal_policy): """ @summary: Check output of 'show platform fan'. """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] # Mock data and check mocker = mocker_factory(duthost, 'FanStatusMocker') pytest_require( mocker, "No FanStatusMocker for %s, skip rest of the testing in this case" % duthost.facts['asic_type']) logging.info('Mock FAN status data...') mocker.mock_data() logging.info('Wait and check actual data with mocked FAN status data...') retry_call(check_cli_output_with_mocker, fargs=[ duthost, mocker, CMD_PLATFORM_FANSTATUS, THERMAL_CONTROL_TEST_WAIT_TIME, 2 ], tries=3, delay=30)
def test_ipv6_nd(duthost, ptfhost, config_facts, tbinfo, ip_and_intf_info, ptfadapter, get_function_conpleteness_level, proxy_arp_enabled): _, _, ptf_intf_ipv6_addr, _, ptf_intf_index = ip_and_intf_info ptf_intf_ipv6_addr = increment_ipv6_addr(ptf_intf_ipv6_addr) pytest_require(proxy_arp_enabled, 'Proxy ARP not enabled for all VLANs') pytest_require(ptf_intf_ipv6_addr is not None, 'No IPv6 VLAN address configured on device') normalized_level = get_function_conpleteness_level if normalized_level is None: normalized_level = "basic" loop_times = LOOP_TIMES_LEVEL_MAP[normalized_level] ipv6_avaliable = get_crm_resources(duthost, "ipv6_neighbor", "available") - get_crm_resources( duthost, "ipv6_neighbor", "used") nd_avaliable = min(ipv6_avaliable, ENTRIES_NUMBERS) while loop_times > 0: loop_times -= 1 add_nd(duthost, ptfhost, ptfadapter, config_facts, tbinfo, ip_and_intf_info, ptf_intf_index, nd_avaliable) pytest_assert( wait_until( 20, 1, 0, lambda: get_fdb_dynamic_mac_count(duthost) >= nd_avaliable), "Neighbor Table Add failed") clear_dut_arp_cache(duthost) fdb_cleanup(duthost) # Wait for 10 seconds before starting next loop time.sleep(10)
def test_incremental_qos_config_updates(duthost, tbinfo, ensure_dut_readiness, configdb_field, operation): pytest_require('2700' in duthost.facts['hwsku'], "This test only runs on Mellanox 2700 devices") tmpfile = generate_tmpfile(duthost) logger.info( "tmpfile {} created for json patch of field: {} and operation: {}". format(tmpfile, configdb_field, operation)) if operation == "remove": value = "" else: value = calculate_field_value(duthost, tbinfo, configdb_field) logger.info( "value to be added to json patch: {} operation: {} field: {}".format( value, operation, configdb_field)) json_patch = [{ "op": "{}".format(operation), "path": "/BUFFER_POOL/{}".format(configdb_field), "value": "{}".format(value) }] try: output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile) expect_op_success(duthost, output) ensure_application_of_updated_config(duthost, configdb_field, value) finally: delete_tmpfile(duthost, tmpfile)
def test_monit_reporting_message(duthosts, enum_rand_one_per_hwsku_frontend_hostname, disable_lldp): """Checks whether the format of alerting message from Monit is correct or not. 202012 and newer image version will be skipped for testing since Supervisord replaced Monit to do the monitoring critical processes. Args: duthosts: The fixture returns list of DuTs. enum_rand_one_per_hwsku_frontend_hostname: The fixture randomly pick up a frontend DuT from testbed. disable_lldp: The fixture function stops `lldpmgrd` process before testing and restarts `lldpmgrd` process at teardown. Returns: None. """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] pytest_require( "201811" in duthost.os_version or "201911" in duthost.os_version, "Test is not supported for 202012 and newer image versions!") if not wait_until(180, 60, check_monit_last_output, duthost): pytest.fail("Expected Monit reporting message not found")
def test_show_platform_temperature_mocked(duthosts, enum_rand_one_per_hwsku_hostname, mocker_factory, ignore_particular_error_log): """ @summary: Check output of 'show platform temperature' """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] # Mock data and check mocker = mocker_factory(duthost, 'ThermalStatusMocker') pytest_require( mocker, "No ThermalStatusMocker for %s, skip rest of the testing in this case" % duthost.facts['asic_type']) logging.info('Mock Thermal status data...') mocker.mock_data() logging.info( 'Wait and check actual data with mocked Thermal status data...') retry_call(check_cli_output_with_mocker, fargs=[ duthost, mocker, CMD_PLATFORM_TEMPER, THERMAL_CONTROL_TEST_WAIT_TIME ], tries=3, delay=30)
def test_src_ip_is_class_e(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, ports_info): """ @summary: Create a packet with source IP address in class E. """ duthost = duthosts[rand_one_dut_hostname] asic_type = duthost.facts["asic_type"] pytest_require("broadcom" not in asic_type, "BRCM does not drop SIP class E packets") ip_list = ["240.0.0.1", "255.255.255.254"] for ip_class_e in ip_list: log_pkt_params(ports_info["dut_iface"], ports_info["dst_mac"], ports_info["src_mac"], pkt_fields["ipv4_dst"], ip_class_e) pkt = testutils.simple_tcp_packet( eth_dst=ports_info["dst_mac"], # DUT port eth_src=ports_info["src_mac"], # PTF port ip_src=ip_class_e, ip_dst=pkt_fields["ipv4_dst"], # VM source tcp_sport=pkt_fields["tcp_sport"], tcp_dport=pkt_fields["tcp_dport"]) do_test("L3", pkt, ptfadapter, ports_info, setup["neighbor_sniff_ports"], tx_dut_ports)
def test_collect_testbed_prio(duthosts, tbinfo): all_prio = {} lossless_prio = {} lossy_prio = {} tbname = tbinfo['conf-name'] pytest_require(tbname, "skip test due to lack of testbed name.") for dut in duthosts: all_prio[dut.hostname] = collect_dut_all_prio(dut) lossless_prio[dut.hostname] = collect_dut_lossless_prio(dut) lossy_prio[dut.hostname] = collect_dut_lossy_prio(dut) prio_info = [all_prio, lossless_prio, lossy_prio] file_names = [ tbname + '-' + x + '.json' for x in ['all', 'lossless', 'lossy'] ] folder = 'priority' for i in range(len(file_names)): filepath = os.path.join(folder, file_names[i]) try: if not os.path.exists(folder): os.mkdir(folder) with open(filepath, 'w') as yf: json.dump({tbname: prio_info[i]}, yf, indent=4) except IOError as e: logger.warning('Unable to create file {}: {}'.format(filepath, e))
def turn_all_outlets_on(pdu_ctrl): all_outlet_status = pdu_ctrl.get_outlet_status() pytest_require(all_outlet_status and len(all_outlet_status) >= 2, 'Skip the test, cannot to get at least 2 outlet status: {}'.format(all_outlet_status)) for outlet in all_outlet_status: if not outlet["outlet_on"]: pdu_ctrl.turn_on_outlet(outlet) time.sleep(5)
def check_image_version(duthosts): """Skip the test for unsupported images.""" for duthost in duthosts: pytest_require( "201911" not in duthost.os_version, "Test not supported for 201911 images. Skipping the test") yield
def test_show_platform_fanstatus_mocked(duthosts, rand_one_dut_hostname, mocker_factory): """ @summary: Check output of 'show platform fan'. """ duthost = duthosts[rand_one_dut_hostname] # Load an invalid thermal control configuration file here to avoid thermal policy affect the test result with ThermalPolicyFileContext(duthost, THERMAL_POLICY_INVALID_FORMAT_FILE): # Mock data and check mocker = mocker_factory(duthost, 'FanStatusMocker') pytest_require( mocker, "No FanStatusMocker for %s, skip rest of the testing in this case" % duthost.facts['asic_type']) logging.info('Mock FAN status data...') mocker.mock_data() logging.info( 'Wait and check actual data with mocked FAN status data...') result = check_cli_output_with_mocker(duthost, mocker, CMD_PLATFORM_FANSTATUS, THERMAL_CONTROL_TEST_WAIT_TIME, 2) pytest_assert(result, 'FAN mock data mismatch')
def acl(duthosts, enum_rand_one_per_hwsku_frontend_hostname, acl_setup): """ setup/teardown ACL rules based on test class requirements :param duthost: DUT host object :param acl_setup: setup information :return: """ duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname] acl_facts = duthost.acl_facts()["ansible_facts"]["ansible_acl_facts"] pytest_require(ACL_TABLE_NAME in acl_facts, "{} acl table not exists") loganalyzer = LogAnalyzer(ansible_host=duthost, marker_prefix='acl') loganalyzer.load_common_config() try: loganalyzer.expect_regex = [LOG_EXPECT_ACL_RULE_CREATE_RE] with loganalyzer: setup_acl_rules(duthost, acl_setup) except LogAnalyzerError as err: # cleanup config DB in case of log analysis error teardown_acl(duthost, acl_setup) raise err try: yield finally: loganalyzer.expect_regex = [LOG_EXPECT_ACL_RULE_REMOVE_RE] with loganalyzer: teardown_acl(duthost, acl_setup)
def test_arp_garp_enabled(rand_selected_dut, garp_enabled, ip_and_intf_info, intfs_for_test, config_facts, ptfadapter): """ Send a gratuitous ARP (GARP) packet from the PTF to the DUT The DUT should learn the (previously unseen) ARP info from the packet """ pytest_require(garp_enabled, 'Gratuitous ARP not enabled for this device') duthost = rand_selected_dut ptf_intf_ipv4_addr = ip_and_intf_info[0] arp_request_ip = increment_ipv4_addr(ptf_intf_ipv4_addr) arp_src_mac = '00:00:07:08:09:0a' _, _, intf1_index, _, = intfs_for_test pkt = testutils.simple_arp_packet(pktlen=60, eth_dst='ff:ff:ff:ff:ff:ff', eth_src=arp_src_mac, vlan_pcp=0, arp_op=2, ip_snd=arp_request_ip, ip_tgt=arp_request_ip, hw_snd=arp_src_mac, hw_tgt='ff:ff:ff:ff:ff:ff' ) clear_dut_arp_cache(duthost) logger.info("Sending GARP for target {} from PTF interface {}".format(arp_request_ip, intf1_index)) testutils.send_packet(ptfadapter, intf1_index, pkt) vlan_intfs = config_facts['VLAN_INTERFACE'].keys() switch_arptable = duthost.switch_arptable()['ansible_facts'] pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['macaddress'].lower() == arp_src_mac.lower()) pytest_assert(switch_arptable['arptable']['v4'][arp_request_ip]['interface'] in vlan_intfs)
def test_cpu_thermal_control(rand_selected_dut, mocker_factory): duthost = rand_selected_dut dut_platform = duthost.facts["platform"] pytest_require(dut_platform == "x86_64-nvidia_sn4800-r0", 'This test case is only for platform x86_64-nvidia_sn4800-r0, skipping...') mocker = mocker_factory(duthost, 'CpuThermalMocker') temp_step = 1000 # Mock CPU temperature is lower than low threshold mocker.mock_cpu_pack_temperature(mocker.LOW_THRESHOLD - temp_step) wait_result = wait_until(10, 3, 0, check_cpu_cooling_state, mocker, mocker.MIN_COOLING_STATE) pytest_assert(wait_result, 'CPU cooling state is not MIN when temperature is below low threshold') # Mock CPU temperature is raising mocker.mock_cpu_pack_temperature(mocker.LOW_THRESHOLD) wait_result = wait_until(10, 3, 0, check_cpu_cooling_state, mocker, mocker.MIN_COOLING_STATE + 1) pytest_assert(wait_result, 'CPU cooling state is not increasing when temperature is rasing') # Mock CPU temperature is larger than high threshold mocker.mock_cpu_pack_temperature(mocker.HIGH_THRESHOLD + temp_step) wait_result = wait_until(10, 3, 0, check_cpu_cooling_state, mocker, mocker.MAX_COOLING_STATE) pytest_assert(wait_result, 'CPU cooling state is not MAX increasing when temperature is beyond high threshold') # Mock CPU temperature is decreasing mocker.mock_cpu_pack_temperature(mocker.HIGH_THRESHOLD) wait_result = wait_until(10, 3, 0, check_cpu_cooling_state, mocker, mocker.MAX_COOLING_STATE - 1) pytest_assert(wait_result, 'CPU cooling state is not decreasing when temperature is decreasing')
def test_pfc_pause_multi_lossy_prio_reboot(ixia_api, ixia_testbed, conn_graph_facts, fanout_graph_facts, localhost, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, lossless_prio_list, lossy_prio_list, prio_dscp_map, reboot_type): """ Test if PFC will impact multiple lossy priorities after various kinds of reboots Args: ixia_api (pytest fixture): IXIA session ixia_testbed (pytest fixture): L2/L3 config of a T0 testbed conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph localhost (pytest fixture): localhost handle duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): port to test, e.g., 's6100-1|Ethernet0' lossless_prio_list (pytest fixture): list of all the lossless priorities lossy_prio_list (pytest fixture): list of all the lossy priorities prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority). reboot_type (str): reboot type to be issued on the DUT Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') pytest_require(rand_one_dut_hostname == dut_hostname, "Port is not mapped to the expected DUT") duthost = duthosts[rand_one_dut_hostname] pause_prio_list = lossy_prio_list test_prio_list = lossy_prio_list bg_prio_list = lossless_prio_list logger.info("Issuing a {} reboot on the dut {}".format(reboot_type, duthost.hostname)) reboot(duthost, localhost, reboot_type=reboot_type) logger.info("Wait until the system is stable") pytest_assert(wait_until(300, 20, duthost.critical_services_fully_started), "Not all critical services are fully started") run_pfc_test(api=ixia_api, testbed_config=ixia_testbed, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, global_pause=False, pause_prio_list=pause_prio_list, test_prio_list=test_prio_list, bg_prio_list=bg_prio_list, prio_dscp_map=prio_dscp_map, test_traffic_pause=False)
def test_dst_ip_link_local(do_test, ptfadapter, duthosts, rand_one_dut_hostname, setup, tx_dut_ports, pkt_fields, ports_info): """ @summary: Create a packet with link-local address "169.254.0.0/16". """ duthost = duthosts[rand_one_dut_hostname] asic_type = duthost.facts["asic_type"] pytest_require("broadcom" not in asic_type, "BRCM does not drop DIP link local packets") link_local_ip = "169.254.10.125" pkt_params = { "eth_dst": ports_info["dst_mac"], # DUT port "eth_src": ports_info["src_mac"], # PTF port "tcp_sport": pkt_fields["tcp_sport"], "tcp_dport": pkt_fields["tcp_dport"] } pkt_params["ip_src"] = pkt_fields["ipv4_src"] # VM source pkt_params["ip_dst"] = link_local_ip pkt = testutils.simple_tcp_packet(**pkt_params) logger.info(pkt_params) do_test("L3", pkt, ptfadapter, ports_info, setup["neighbor_sniff_ports"], tx_dut_ports)
def test_pfcwd_basic_single_lossless_prio_reboot(snappi_api, snappi_testbed_config, conn_graph_facts, fanout_graph_facts, localhost, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, rand_one_dut_lossless_prio, prio_dscp_map, reboot_type, trigger_pfcwd): """ Verify PFC watchdog basic test works on a single lossless priority after various types of reboot Args: snappi_api (pytest fixture): SNAPPI session snappi_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph localhost (pytest fixture): localhost handle duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0' rand_one_dut_lossless_prio (str): name of lossless priority to test, e.g., 's6100-1|3' prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority) reboot_type (str): reboot type to be issued on the DUT trigger_pfcwd (bool): if PFC watchdog is expected to be triggered Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') dut_hostname2, lossless_prio = rand_one_dut_lossless_prio.split('|') pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2, "Priority and port are not mapped to the expected DUT") duthost = duthosts[rand_one_dut_hostname] skip_pfcwd_test(duthost=duthost, trigger_pfcwd=trigger_pfcwd) testbed_config, port_config_list = snappi_testbed_config lossless_prio = int(lossless_prio) logger.info("Issuing a {} reboot on the dut {}".format(reboot_type, duthost.hostname)) reboot(duthost, localhost, reboot_type=reboot_type) logger.info("Wait until the system is stable") pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") run_pfcwd_basic_test(api=snappi_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, prio_list=[lossless_prio], prio_dscp_map=prio_dscp_map, trigger_pfcwd=trigger_pfcwd)
def skip_if_no_lags(duthosts): def has_lags(dut): lag_facts = dut.lag_facts( host=dut.hostname)['ansible_facts']['lag_facts'] return len(lag_facts['names']) > 0 some_dut_has_lags = any(has_lags(dut) for dut in duthosts) pytest_require(some_dut_has_lags, 'No LAGs found in any DUT')
def check_dut_asic_type(request, duthost): asic_marks = [mark for mark in request.node.iter_markers(name="asic")] if not asic_marks: return supported_asics = [x.lower() for x in asic_marks[0].args] if not supported_asics: return dut_asic_type = duthost.facts["asic_type"].lower() pytest_require((dut_asic_type in supported_asics), "Unsupported platform")
def test_pfc_pause_single_lossless_prio(ixia_api, ixia_testbed_config, conn_graph_facts, fanout_graph_facts, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, enum_dut_lossless_prio, all_prio_list, prio_dscp_map): """ Test if PFC can pause a single lossless priority Args: ixia_api (pytest fixture): IXIA session ixia_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): port to test, e.g., 's6100-1|Ethernet0' enum_dut_lossless_prio (str): lossless priority to test, e.g., 's6100-1|3' all_prio_list (pytest fixture): list of all the priorities prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority). Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') dut_hostname2, lossless_prio = enum_dut_lossless_prio.split('|') pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2, "Priority and port are not mapped to the expected DUT") testbed_config, port_config_list = ixia_testbed_config duthost = duthosts[rand_one_dut_hostname] lossless_prio = int(lossless_prio) pause_prio_list = [lossless_prio] test_prio_list = [lossless_prio] bg_prio_list = [p for p in all_prio_list] bg_prio_list.remove(lossless_prio) run_pfc_test(api=ixia_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, global_pause=False, pause_prio_list=pause_prio_list, test_prio_list=test_prio_list, bg_prio_list=bg_prio_list, prio_dscp_map=prio_dscp_map, test_traffic_pause=True)
def test_pfcwd_basic_single_lossless_prio_service_restart( ixia_api, ixia_testbed_config, conn_graph_facts, fanout_graph_facts, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, rand_one_dut_lossless_prio, prio_dscp_map, restart_service, trigger_pfcwd): """ Verify PFC watchdog basic test works on a single lossless priority after various service restarts Args: ixia_api (pytest fixture): IXIA session ixia_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0' rand_one_dut_lossless_prio (str): name of lossless priority to test, e.g., 's6100-1|3' prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority) restart_service (str): service to restart on the DUT. Only 'swss' affects pfcwd currently trigger_pfcwd (bool): if PFC watchdog is expected to be triggered Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') dut_hostname2, lossless_prio = rand_one_dut_lossless_prio.split('|') pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2, "Priority and port are not mapped to the expected DUT") duthost = duthosts[rand_one_dut_hostname] skip_pfcwd_test(duthost=duthost, trigger_pfcwd=trigger_pfcwd) testbed_config, port_config_list = ixia_testbed_config lossless_prio = int(lossless_prio) logger.info("Issuing a restart of service {} on the dut {}".format( restart_service, duthost.hostname)) services_to_reset = DEPENDENT_SERVICES + [restart_service] for service in services_to_reset: duthost.command("systemctl reset-failed {}".format(service)) duthost.command("systemctl restart {}".format(restart_service)) logger.info("Wait until the system is stable") pytest_assert( wait_until(300, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") run_pfcwd_basic_test(api=ixia_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, prio_list=[lossless_prio], prio_dscp_map=prio_dscp_map, trigger_pfcwd=trigger_pfcwd)
def test_pfcwd_basic_multi_lossless_prio_restart_service(snappi_api, snappi_testbed_config, conn_graph_facts, fanout_graph_facts, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, lossless_prio_list, prio_dscp_map, restart_service, trigger_pfcwd): """ Verify PFC watchdog basic test works on multiple lossless priorities after various service restarts Args: snappi_api (pytest fixture): SNAPPI session snappi_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): name of port to test, e.g., 's6100-1|Ethernet0' lossless_prio_list (pytest fixture): list of all the lossless priorities prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority) restart_service (str): service to restart on the DUT. Only 'swss' affects pfcwd currently trigger_pfcwd (bool): if PFC watchdog is expected to be triggered Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') pytest_require(rand_one_dut_hostname == dut_hostname, "Port is not mapped to the expected DUT") duthost = duthosts[rand_one_dut_hostname] skip_pfcwd_test(duthost=duthost, trigger_pfcwd=trigger_pfcwd) testbed_config, port_config_list = snappi_testbed_config logger.info("Issuing a restart of service {} on the dut {}".format(restart_service, duthost.hostname)) duthost.command("systemctl reset-failed {}".format(restart_service)) duthost.command("systemctl restart {}".format(restart_service)) logger.info("Wait until the system is stable") pytest_assert(wait_until(300, 20, 0, duthost.critical_services_fully_started), "Not all critical services are fully started") run_pfcwd_basic_test(api=snappi_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, prio_list=lossless_prio_list, prio_dscp_map=prio_dscp_map, trigger_pfcwd=trigger_pfcwd)
def turn_all_psu_on(psu_ctrl): all_psu_status = psu_ctrl.get_psu_status() pytest_require( all_psu_status and len(all_psu_status) >= 2, 'Skip the test, cannot to get at least 2 PSU status: {}'.format( all_psu_status)) for psu in all_psu_status: if not psu["psu_on"]: psu_ctrl.turn_on_psu(psu["psu_id"]) time.sleep(5)
def test_pfcwd_all_to_all(ixia_api, ixia_testbed_config, conn_graph_facts, fanout_graph_facts, duthosts, rand_one_dut_hostname, rand_one_dut_portname_oper_up, rand_one_dut_lossless_prio, lossy_prio_list, prio_dscp_map, trigger_pfcwd): """ Run PFC watchdog test under all to all traffic pattern Args: ixia_api (pytest fixture): IXIA session ixia_testbed_config (pytest fixture): testbed configuration information conn_graph_facts (pytest fixture): connection graph fanout_graph_facts (pytest fixture): fanout graph duthosts (pytest fixture): list of DUTs rand_one_dut_hostname (str): hostname of DUT rand_one_dut_portname_oper_up (str): port to test, e.g., 's6100-1|Ethernet0' rand_one_dut_lossless_prio (str): lossless priority to test, e.g., 's6100-1|3' lossy_prio_list (pytest fixture): list of lossy priorities prio_dscp_map (pytest fixture): priority vs. DSCP map (key = priority) trigger_pfcwd (bool): if PFC watchdog is expected to be triggered Returns: N/A """ dut_hostname, dut_port = rand_one_dut_portname_oper_up.split('|') dut_hostname2, lossless_prio = rand_one_dut_lossless_prio.split('|') pytest_require(rand_one_dut_hostname == dut_hostname == dut_hostname2, "Priority and port are not mapped to the expected DUT") duthost = duthosts[rand_one_dut_hostname] skip_pfcwd_test(duthost=duthost, trigger_pfcwd=trigger_pfcwd) testbed_config, port_config_list = ixia_testbed_config lossless_prio = int(lossless_prio) run_pfcwd_multi_node_test(api=ixia_api, testbed_config=testbed_config, port_config_list=port_config_list, conn_data=conn_graph_facts, fanout_data=fanout_graph_facts, duthost=duthost, dut_port=dut_port, pause_prio_list=[lossless_prio], test_prio_list=[lossless_prio], bg_prio_list=lossy_prio_list, prio_dscp_map=prio_dscp_map, trigger_pfcwd=trigger_pfcwd, pattern="all to all")