def test_power_override(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): """This function tests both the get_power_override() and set_power_override() APIs""" duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx", "nokia"]) for i in self.sfp_setup["sfp_test_port_indices"]: info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect(info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue if not self.is_xcvr_support_power_override(info_dict): logger.warning("test_power_override: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue # Enable power override in both low-power and high-power modes for state in [True, False]: ret = sfp.set_power_override(platform_api_conn, i, True, state) self.expect(ret is True, "Failed to {} power override for transceiver {}".format("enable" if state is True else "disable", i)) power_override = sfp.get_power_override(platform_api_conn, i) if self.expect(power_override is not None, "Unable to retrieve transceiver {} power override data".format(i)): self.expect(power_override is True, "Transceiver {} power override data is incorrect".format(i)) # Disable power override ret = sfp.set_power_override(platform_api_conn, i, False, None) self.expect(ret is True, "Failed to disable power override for transceiver {}".format(i)) power_override = sfp.get_power_override(platform_api_conn, i) if self.expect(power_override is not None, "Unable to retrieve transceiver {} power override data".format(i)): self.expect(power_override is False, "Transceiver {} power override data is incorrect".format(i)) self.assert_expectations()
def test_tx_disable_channel(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): """This function tests both the get_tx_disable_channel() and tx_disable_channel() APIs""" duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx", "nokia"]) for i in self.sfp_setup["sfp_test_port_indices"]: # First ensure that the transceiver type supports setting TX disable on individual channels info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect(info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue if not self.is_xcvr_optical(info_dict): logger.warning("test_tx_disable_channel: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue # Test all TX disable combinations for a four-channel transceiver (i.e., 0x0 through 0xF) # We iterate in reverse here so that we end with 0x0 (no channels disabled) for expected_mask in range(0xF, 0x0, -1): # Enable TX on all channels ret = sfp.tx_disable_channel(platform_api_conn, i, 0xF, False) self.expect(ret is True, "Failed to enable TX on all channels for transceiver {}".format(i)) ret = sfp.tx_disable_channel(platform_api_conn, i, expected_mask, True) self.expect(ret is True, "Failed to disable TX channels using mask '{}' for transceiver {}".format(expected_mask, i)) tx_disable_chan_mask = sfp.get_tx_disable_channel(platform_api_conn, i) if self.expect(tx_disable_chan_mask is not None, "Unable to retrieve transceiver {} TX disabled channel data".format(i)): self.expect(tx_disable_chan_mask == expected_mask, "Transceiver {} TX disabled channel data is incorrect".format(i)) self.assert_expectations()
def test_get_transceiver_bulk_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: bulk_status_dict = sfp.get_transceiver_bulk_status( platform_api_conn, i) if self.expect( bulk_status_dict is not None, "Unable to retrieve transceiver {} bulk status".format(i)): if self.expect( isinstance(bulk_status_dict, dict), "Transceiver {} bulk status appears incorrect".format( i)): # TODO: This set of keys should be present no matter how many channels are present on the xcvr # If the xcvr has multiple channels, we should adjust the fields here accordingly actual_keys = bulk_status_dict.keys() missing_keys = set( self.EXPECTED_XCVR_BULK_STATUS_KEYS) - set(actual_keys) for key in missing_keys: self.expect( False, "Transceiver {} bulk status does not contain field: '{}'" .format(i, key)) self.assert_expectations()
def test_set_high_threshold(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] thermals_skipped = 0 skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) # Ensure the thermal temperature is sane for i in range(self.num_thermals): threshold_supported = self.get_thermal_facts(duthost, i, True, "high-threshold") threshold_controllable = self.get_thermal_facts(duthost, i, True, "controllable") if not threshold_supported or not threshold_controllable: logger.info("test_set_high_threshold: Skipping thermal {} (threshold not controllable)".format(i)) thermals_skipped += 1 continue high_temperature = 80 result = thermal.set_high_threshold(platform_api_conn, i, high_temperature) if self.expect(result is not None, "Failed to perform set_high_threshold"): self.expect(result is True, "Failed to set set_high_threshold for thermal {} to {}".format(i, high_temperature)) temperature = thermal.get_high_threshold(platform_api_conn, i) if self.expect(temperature is not None, "Unable to retrieve Thermal {} high threshold".format(i)): if self.expect(isinstance(temperature, float), "Thermal {} high threshold appears incorrect".format(i)): self.expect(temperature == 80, "Thermal {} high threshold {} is not matching the set value {}".format(i, temperature, high_temperature)) if thermals_skipped == self.num_thermals: pytest.skip("skipped as all chassis thermals' high-threshold is not controllable") self.assert_expectations()
def test_get_rx_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) # TODO: Do more sanity checking on the data we retrieve # TODO: Should we should expect get_rx_power() to return None or a list of "N/A" strings # if the transceiver is non-optical, e.g., DAC for i in self.sfp_setup["sfp_test_port_indices"]: # Determine whether the transceiver type supports RX power info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect( info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue if not self.is_xcvr_optical(info_dict): logger.warning( "test_get_rx_power: Skipping transceiver {} (not applicable for this transceiver type)" .format(i)) continue rx_power = sfp.get_rx_power(platform_api_conn, i) if self.expect( rx_power is not None, "Unable to retrieve transceiver {} RX power data".format( i)): self.expect( isinstance(rx_power, list) and (all(isinstance(item, float) for item in rx_power)), "Transceiver {} RX power data appears incorrect".format(i)) self.assert_expectations()
def test_set_high_threshold(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) # Ensure the thermal temperature is sane for i in range(self.num_thermals): high_temperature = 80 result = thermal.set_high_threshold(platform_api_conn, i, high_temperature) if self.expect(result is not None, "Failed to perform set_high_threshold"): self.expect( result is True, "Failed to set set_high_threshold for thermal {} to {}". format(i, high_temperature)) temperature = thermal.get_high_threshold(platform_api_conn, i) if self.expect( temperature is not None, "Unable to retrieve Thermal {} high threshold".format(i)): if self.expect( isinstance(temperature, float), "Thermal {} high threshold appears incorrect".format( i)): self.expect( temperature == 80, "Thermal {} high threshold {} is not matching the set value {}" .format(i, temperature, high_temperature)) self.assert_expectations()
def test_get_tx_power(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Do more sanity checking on the data we retrieve duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: tx_power = sfp.get_tx_power(platform_api_conn, i) if self.expect( tx_power is not None, "Unable to retrieve transceiver {} TX power data".format( i)): continue # Determine whether the transceiver type supports RX power # If the transceiver is non-optical, e.g., DAC, we should receive a list of "N/A" strings info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect( info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue if not self.is_xcvr_optical(info_dict): self.expect( isinstance(tx_power, list) and (all(item == "N/A" for item in tx_power)), "Transceiver {} TX power data appears incorrect".format(i)) else: self.expect( isinstance(tx_power, list) and (all(isinstance(item, float) for item in tx_power)), "Transceiver {} TX power data appears incorrect".format(i)) self.assert_expectations()
def test_is_replaceable(self, duthosts, enum_rand_one_per_hwsku_hostname, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for sfp_id in self.sfp_setup["sfp_test_port_indices"]: replaceable = sfp.is_replaceable(platform_api_conn, sfp_id) if self.expect(replaceable is not None, "Failed to perform is_replaceable for sfp {}".format(sfp_id)): self.expect(isinstance(replaceable, bool), "Replaceable value must be a bool value for sfp {}".format(sfp_id)) self.assert_expectations()
def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: serial = sfp.get_serial(platform_api_conn, i) if self.expect(serial is not None, "Unable to retrieve transceiver {} serial number".format(i)): self.expect(isinstance(serial, STRING_TYPE), "Transceiver {} serial number appears incorrect".format(i)) self.assert_expectations()
def test_get_firmware_update_notification(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["nokia"]) for i in range(self.num_components): for image in image_list: notif = component.get_firmware_update_notification(platform_api_conn, i, image) # Can return "None" if no update required. pytest_assert(isinstance(notif, STRING_TYPE), "Component {}: Firmware update notification appears to be incorrect from image {}".format(i, image))
def test_update_firmware(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["nokia"]) for i in range(self.num_components): for image in image_list: update_status = component.update_firmware(platform_api_conn, i, image) if self.expect(update_status is not None, "Component {}: Failed to update firmware from image {}".format(i, image)): self.expect(isinstance(update_status, bool), "Component {}: Return of Firmware update appears to be incorrect from image {}".format(i, image)) self.assert_expectations()
def test_get_available_firmware_version(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["nokia"]) for i in range(self.num_components): for image in image_list: avail_fw_version = component.get_available_firmware_version(platform_api_conn, i, image) if self.expect(avail_fw_version is not None, "Component {}: Failed to retrieve available firmware version from image {}".format(i, image)): self.expect(isinstance(avail_fw_version, STRING_TYPE), "Component {}: Available Firmware version appears to be incorrect from image {}".format(i, image)) self.assert_expectations()
def test_get_reset_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) # TODO: Do more sanity checking on the data we retrieve for i in self.sfp_setup["sfp_test_port_indices"]: reset_status = sfp.get_reset_status(platform_api_conn, i) if self.expect(reset_status is not None, "Unable to retrieve transceiver {} reset status".format(i)): self.expect(isinstance(reset_status, bool), "Transceiver {} reset status appears incorrect".format(i)) self.assert_expectations()
def test_temperature(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): ''' PSU temperature test ''' duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) psus_skipped = 0 for psu_id in range(self.num_psus): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: logger.info("skipping check for {}".format(name)) else: temperature_supported = self.get_psu_facts( duthost, psu_id, True, "temperature") if not temperature_supported: logger.info( "test_set_fans_speed: Skipping chassis fan {} (speed not controllable)" .format(psu_id)) psus_skipped += 1 continue temperature = psu.get_temperature(platform_api_conn, psu_id) if self.expect( temperature is not None, "Failed to retrieve temperature of PSU {}".format( psu_id)): self.expect( isinstance(temperature, float), "PSU {} temperature appears incorrect".format(psu_id)) temp_threshold = psu.get_temperature_high_threshold( platform_api_conn, psu_id) if self.expect( temp_threshold is not None, "Failed to retrieve temperature threshold of PSU {}". format(psu_id)): if self.expect( isinstance(temp_threshold, float), "PSU {} temperature high threshold appears incorrect" .format(psu_id)): self.expect( temperature < temp_threshold, "Temperature {} of PSU {} is over the threshold {}" .format(temperature, psu_id, temp_threshold)) if psus_skipped == self.num_psus: pytest.skip( "skipped as all chassis psus' temperature sensor is not supported" ) self.assert_expectations()
def test_show_platform_firmware_status(duthosts, enum_rand_one_per_hwsku_hostname): """ @summary: Verify output of `show platform firmware status` """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) cmd = " ".join([CMD_SHOW_PLATFORM, "firmware", "status"]) logging.info("Verifying output of '{}' on '{}' ...".format( cmd, duthost.hostname)) firmware_output_lines = duthost.command(cmd)["stdout_lines"] verify_show_platform_firmware_status_output(firmware_output_lines, duthost.hostname)
def test_reset(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Verify that the transceiver was actually reset duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect(info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue ret = sfp.reset(platform_api_conn, i) if self.is_xcvr_resettable(info_dict): self.expect(ret is True, "Failed to reset transceiver {}".format(i)) else: self.expect(ret is False, "Resetting transceiver {} succeeded but should have failed".format(i)) self.assert_expectations()
def test_get_tx_bias(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) # TODO: Do more sanity checking on the data we retrieve for i in self.sfp_setup["sfp_test_port_indices"]: info_dict = sfp.get_transceiver_info(platform_api_conn, i) # Determine whether the transceiver type supports TX Bias if not self.is_xcvr_optical(info_dict): logger.warning("test_get_tx_bias: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue tx_bias = sfp.get_tx_bias(platform_api_conn, i) if self.expect(tx_bias is not None, "Unable to retrieve transceiver {} TX bias data".format(i)): self.expect(isinstance(tx_bias, list) and (all(isinstance(item, float) for item in tx_bias)), "Transceiver {} TX bias data appears incorrect".format(i)) self.assert_expectations()
def test_get_voltage(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Do more sanity checking on the data we retrieve duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.is_xcvr_optical(info_dict): logger.info("test_get_voltage: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue voltage = sfp.get_voltage(platform_api_conn, i) if self.expect(voltage is not None, "Unable to retrieve transceiver {} voltage".format(i)): self.expect(isinstance(voltage, float), "Transceiver {} voltage appears incorrect".format(i)) self.assert_expectations()
def test_get_tx_fault(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Do more sanity checking on the data we retrieve duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: tx_fault = sfp.get_tx_fault(platform_api_conn, i) if self.expect( tx_fault is not None, "Unable to retrieve transceiver {} TX fault data".format( i)): self.expect( isinstance(tx_fault, list) and (all(isinstance(item, bool) for item in tx_fault)), "Transceiver {} TX fault data appears incorrect".format(i)) self.assert_expectations()
def test_get_rx_los(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Do more sanity checking on the data we retrieve duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.is_xcvr_optical(info_dict): logger.info("test_get_rx_los: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue rx_los = sfp.get_rx_los(platform_api_conn, i) if self.expect(rx_los is not None, "Unable to retrieve transceiver {} RX loss-of-signal data".format(i)): self.expect(isinstance(rx_los, list) and (all(isinstance(item, bool) for item in rx_los)), "Transceiver {} RX loss-of-signal data appears incorrect".format(i)) self.assert_expectations()
def test_power(self, duthost, localhost, platform_api_conn): ''' PSU power test ''' duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) for psu_id in range(self.num_psus): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: logger.info("skipping check for {}".format(name)) else: voltage = psu.get_voltage(platform_api_conn, psu_id) if self.expect(voltage is not None, "Failed to retrieve voltage of PSU {}".format(psu_id)): self.expect(isinstance(voltage, float), "PSU {} voltage appears incorrect".format(psu_id)) current = psu.get_current(platform_api_conn, psu_id) if self.expect(current is not None, "Failed to retrieve current of PSU {}".format(psu_id)): self.expect(isinstance(current, float), "PSU {} current appears incorrect".format(psu_id)) power = psu.get_power(platform_api_conn, psu_id) if self.expect(power is not None, "Failed to retrieve power of PSU {}".format(psu_id)): self.expect(isinstance(power, float), "PSU {} power appears incorrect".format(psu_id)) max_supp_power = psu.get_maximum_supplied_power(platform_api_conn, psu_id) if self.expect(max_supp_power is not None, "Failed to retrieve maximum supplied power power of PSU {}".format(psu_id)): self.expect(isinstance(power, float), "PSU {} power appears incorrect".format(psu_id)) if current is not None and voltage is not None and power is not None: self.expect(abs(power - (voltage*current)) < power*0.1, "PSU {} reading does not make sense \ (power:{}, voltage:{}, current:{})".format(psu_id, power, voltage, current)) powergood_status = psu.get_powergood_status(platform_api_conn, psu_id) if self.expect(powergood_status is not None, "Failed to retrieve operational status of PSU {}".format(psu_id)): self.expect(powergood_status is True, "PSU {} is not operational".format(psu_id)) high_threshold = psu.get_voltage_high_threshold(platform_api_conn, psu_id) if self.expect(high_threshold is not None, "Failed to retrieve the high voltage threshold of PSU {}".format(psu_id)): self.expect(isinstance(high_threshold, float), "PSU {} voltage high threshold appears incorrect".format(psu_id)) low_threshold = psu.get_voltage_low_threshold(platform_api_conn, psu_id) if self.expect(low_threshold is not None, "Failed to retrieve the low voltage threshold of PSU {}".format(psu_id)): self.expect(isinstance(low_threshold, float), "PSU {} voltage low threshold appears incorrect".format(psu_id)) if high_threshold is not None and low_threshold is not None: self.expect(voltage < high_threshold and voltage > low_threshold, "Voltage {} of PSU {} is not in between {} and {}".format(voltage, psu_id, low_threshold, high_threshold)) self.assert_expectations()
def test_get_transceiver_threshold_info(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # TODO: Do more sanity checking on transceiver threshold info values duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: thold_info_dict = sfp.get_transceiver_threshold_info(platform_api_conn, i) if self.expect(thold_info_dict is not None, "Unable to retrieve transceiver {} threshold info".format(i)): if self.expect(isinstance(thold_info_dict, dict), "Transceiver {} threshold info appears incorrect".format(i)): actual_keys = thold_info_dict.keys() missing_keys = set(self.EXPECTED_XCVR_THRESHOLD_INFO_KEYS) - set(actual_keys) for key in missing_keys: self.expect(False, "Transceiver {} threshold info does not contain field: '{}'".format(i, key)) unexpected_keys = set(actual_keys) - set(self.EXPECTED_XCVR_THRESHOLD_INFO_KEYS) for key in unexpected_keys: self.expect(False, "Transceiver {} threshold info contains unexpected field '{}'".format(i, key)) self.assert_expectations()
def test_temperature(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): ''' PSU temperature test ''' duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista"]) for psu_id in range(self.num_psus): name = psu.get_name(platform_api_conn, psu_id) if name in self.psu_skip_list: logger.info("skipping check for {}".format(name)) else: temperature = psu.get_temperature(platform_api_conn, psu_id) if self.expect(temperature is not None, "Failed to retrieve temperature of PSU {}".format(psu_id)): self.expect(isinstance(temperature, float), "PSU {} temperature appears incorrect".format(psu_id)) temp_threshold = psu.get_temperature_high_threshold(platform_api_conn, psu_id) if self.expect(temp_threshold is not None, "Failed to retrieve temperature threshold of PSU {}".format(psu_id)): if self.expect(isinstance(temp_threshold, float), "PSU {} temperature high threshold appears incorrect".format(psu_id)): self.expect(temperature < temp_threshold, "Temperature {} of PSU {} is over the threshold {}".format(temperature, psu_id, temp_threshold)) self.assert_expectations()
def test_tx_disable(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): """This function tests both the get_tx_disable() and tx_disable() APIs""" duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012"], ["arista", "mlnx"]) for i in self.sfp_setup["sfp_test_port_indices"]: # First ensure that the transceiver type supports setting TX disable info_dict = sfp.get_transceiver_info(platform_api_conn, i) if not self.expect(info_dict is not None, "Unable to retrieve transceiver {} info".format(i)): continue if not self.is_xcvr_optical(info_dict): logger.warning("test_tx_disable: Skipping transceiver {} (not applicable for this transceiver type)".format(i)) continue for state in [True, False]: ret = sfp.tx_disable(platform_api_conn, i, state) if self.expect(ret is True, "Failed to {} TX disable for transceiver {}".format("set" if state is True else "clear", i)): tx_disable = sfp.get_tx_disable(platform_api_conn, i) if self.expect(tx_disable is not None, "Unable to retrieve transceiver {} TX disable data".format(i)): self.expect(isinstance(tx_disable, list) and (all(item == state) for item in tx_disable), "Transceiver {} TX disable data is incorrect".format(i)) self.assert_expectations()
def test_show_platform_syseeprom(duthosts, enum_rand_one_per_hwsku_hostname, dut_vars): """ @summary: Verify output of `show platform syseeprom` """ duthost = duthosts[enum_rand_one_per_hwsku_hostname] skip_release_for_platform(duthost, ["202012", "201911", "201811"], ["arista_7050"]) cmd = " ".join([CMD_SHOW_PLATFORM, "syseeprom"]) logging.info("Verifying output of '{}' on '{}' ...".format( cmd, duthost.hostname)) syseeprom_cmd = duthost.command(cmd) syseeprom_output = syseeprom_cmd["stdout"] syseeprom_output_lines = syseeprom_cmd["stdout_lines"] """ Gather expected data from a inventory file instead if 'syseeprom_info' is defined in the inventory # Sample inventory with syseeprom: str-msn2700-01: ansible_host: 10.251.0.188 model: MSN2700-CS2FO serial: MT1234X56789 base_mac: 24:8a:07:12:34:56 syseeprom_info: "0x21": "MSN2700" "0x22": "MSN2700-CS2FO" "0x23": "MT1234X56789" "0x24": "24:8a:07:12:34:56" "0x25": "12/07/2016" "0x26": "0" "0x28": "x86_64-mlnx_x86-r0" "0x29": "2016.11-5.1.0008-9600" "0x2A": "128" "0x2B": "Mellanox" "0xFE": "0xFBA1E964" """ if 'syseeprom_info' in dut_vars: expected_syseeprom_info_dict = dut_vars['syseeprom_info'] parsed_syseeprom = {} # Can't use util.get_fields as the values go beyond the last set of '---' in the hearder line. regex_int = re.compile(r'([\S\s]+)(0x[A-F0-9]+)\s+([\d]+)\s+([\S\s]*)') for line in syseeprom_output_lines[6:]: t1 = regex_int.match(line) if t1: tlv_code_lower_case = t1.group(2).strip().lower() parsed_syseeprom[tlv_code_lower_case] = t1.group(4).strip() for field in expected_syseeprom_info_dict: pytest_assert( field.lower() in parsed_syseeprom, "Expected field '{}' not present in syseeprom on '{}'".format( field, duthost.hostname)) pytest_assert( parsed_syseeprom[ field.lower()] == expected_syseeprom_info_dict[field], "System EEPROM info is incorrect - for '{}', rcvd '{}', expected '{}' on '{}'" .format(field, parsed_syseeprom[field.lower()], expected_syseeprom_info_dict[field], duthost.hostname)) if duthost.facts["asic_type"] in ["mellanox"]: expected_fields = [ "Product Name", "Part Number", "Serial Number", "Base MAC Address", "Manufacture Date", "Device Version", "MAC Addresses", "Manufacturer", "Vendor Extension", "ONIE Version", "CRC-32" ] utility_cmd = "sudo python -c \"import imp; \ m = imp.load_source('eeprom', '/usr/share/sonic/device/{}/plugins/eeprom.py'); \ t = m.board('board', '', '', ''); e = t.read_eeprom(); t.decode_eeprom(e)\"".format( duthost.facts["platform"]) utility_cmd_output = duthost.command(utility_cmd) for field in expected_fields: pytest_assert( syseeprom_output.find(field) >= 0, "Expected field '{}' was not found on '{}'".format( field, duthost.hostname)) pytest_assert( utility_cmd_output["stdout"].find(field) >= 0, "Expected field '{}' was not found on '{}'".format( field, duthost.hostname)) for line in utility_cmd_output["stdout_lines"]: if not line.startswith( '-' ): # do not validate line '-------------------- ---- --- -----' line_regexp = re.sub(r'\s+', '\s+', line) pytest_assert( re.search(line_regexp, syseeprom_output), "Line '{}' was not found in output on '{}'".format( line, duthost.hostname))