diff --git a/tests/common/devices.py b/tests/common/devices.py index d930ab6d516..609676d3604 100644 --- a/tests/common/devices.py +++ b/tests/common/devices.py @@ -158,6 +158,7 @@ def __init__(self, ansible_adhoc, hostname, self._facts = self._gather_facts() self._os_version = self._get_os_version() + self._kernel_version = self._get_kernel_version() self.reset_critical_services_tracking_list() @@ -192,6 +193,16 @@ def os_version(self): return self._os_version + @property + def kernel_version(self): + """ + The kernel version running on this SONiC device. + + Returns: + str: The SONiC kernel version (e.g. "4.9.0") + """ + return self._kernel_version + @property def critical_services(self): """ @@ -326,6 +337,14 @@ def _get_os_version(self): output = self.command("sonic-cfggen -y /etc/sonic/sonic_version.yml -v build_version") return output["stdout_lines"][0].strip() + def _get_kernel_version(self): + """ + Gets the SONiC kernel version + :return: + """ + output = self.command('uname -r') + return output["stdout"].split('-')[0] + def get_service_props(self, service, props=["ActiveState", "SubState"]): """ @summary: Use 'systemctl show' command to get detailed properties of a service. By default, only get diff --git a/tests/platform_tests/cli/test_show_platform.py b/tests/platform_tests/cli/test_show_platform.py index 385358fe597..9f4383d63fa 100644 --- a/tests/platform_tests/cli/test_show_platform.py +++ b/tests/platform_tests/cli/test_show_platform.py @@ -15,6 +15,7 @@ import pytest import util +from pkg_resources import parse_version from tests.common.helpers.assertions import pytest_assert pytestmark = [ @@ -108,12 +109,16 @@ def test_show_platform_psustatus(duthosts, rand_one_dut_hostname): # TODO: Compare against expected platform-specific output -def verify_show_platform_fan_output(raw_output_lines): +def verify_show_platform_fan_output(duthost, raw_output_lines): """ @summary: Verify output of `show platform fan`. Expected output is - "Fan Not detected" or a table of fan status data conaining 8 columns. + "Fan Not detected" or a table of fan status data conaining expect number of columns. """ - NUM_EXPECTED_COLS = 8 + # workaround to make this test compatible with 201911 and master + if parse_version(duthost.kernel_version) > parse_version('4.9.0'): + NUM_EXPECTED_COLS = 8 + else: + NUM_EXPECTED_COLS = 6 pytest_assert(len(raw_output_lines) > 0, "There must be at least one line of output") if len(raw_output_lines) == 1: @@ -134,7 +139,7 @@ def test_show_platform_fan(duthosts, rand_one_dut_hostname): logging.info("Verifying output of '{}' ...".format(cmd)) fan_status_output_lines = duthost.command(cmd)["stdout_lines"] - verify_show_platform_fan_output(fan_status_output_lines) + verify_show_platform_fan_output(duthost, fan_status_output_lines) # TODO: Test values against platform-specific expected data diff --git a/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py b/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py index 683e4fb3dbd..2d9544b31d4 100644 --- a/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py +++ b/tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py @@ -2,10 +2,12 @@ import json import random import logging +from pkg_resources import parse_version from tests.platform_tests.thermal_control_test_helper import * from tests.common.mellanox_data import get_platform_data from minimum_table import get_min_table + NOT_AVAILABLE = 'N/A' THERMAL_NAMING_RULE = { @@ -37,8 +39,10 @@ "temperature": "gearbox{}_temp_input" }, "asic_ambient": { - "name": "Ambient ASIC Temp", - "temperature": "asic" + "name": "ASIC", + "temperature": "asic", + "high_threshold": "mlxsw/temp_trip_hot", + "high_critical_threshold": "mlxsw/temp_trip_crit" }, "port_ambient": { "name": "Ambient Port Side Temp", @@ -54,6 +58,11 @@ } } +ASIC_THERMAL_RULE_201911 = { + "name": "Ambient ASIC Temp", + "temperature": "asic" +} + FAN_NAMING_RULE = { "fan": { "name": "fan{}", @@ -260,6 +269,16 @@ def deinit(self): logging.error(error_message) raise RuntimeError(error_message) + def is_201911(self): + """ + Workaround to make thermal control test cases compatible with 201911 and master + :return: + """ + if parse_version(self.dut.kernel_version) > parse_version('4.9.0'): + return False + else: + return True + class FanDrawerData: """ @@ -384,7 +403,7 @@ class FanData: PWM_MAX = 255 # Speed tolerance - SPEED_TOLERANCE = 0.2 + SPEED_TOLERANCE = 0.5 # Cooling cur state file COOLING_CUR_STATE_FILE = 'cooling_cur_state' @@ -521,6 +540,10 @@ def __init__(self, mock_helper, naming_rule, index): :param index: Thermal index. """ self.helper = mock_helper + if 'ASIC' in naming_rule['name']: + if self.helper.is_201911(): + naming_rule = ASIC_THERMAL_RULE_201911 + self.name = naming_rule['name'] self.temperature_file = naming_rule['temperature'] self.high_threshold_file = naming_rule['high_threshold'] if 'high_threshold' in naming_rule else None @@ -730,15 +753,18 @@ def mock_data(self): platform_data = get_platform_data(self.mock_helper.dut) psu_count = platform_data["psus"]["number"] naming_rule = FAN_NAMING_RULE['psu_fan'] + if self.mock_helper.is_201911(): + led_color = '' + else: + led_color = 'green' for index in range(1, psu_count + 1): try: fan_data = FanData(self.mock_helper, naming_rule, index) - speed = random.randint(60, 100) fan_data.mock_speed(speed) self.expected_data[fan_data.name] = [ 'N/A', - '', + led_color, fan_data.name, '{}%'.format(fan_data.mocked_speed), NOT_AVAILABLE, diff --git a/tests/platform_tests/thermal_control_test_helper.py b/tests/platform_tests/thermal_control_test_helper.py index 61479823dd0..5d948063189 100644 --- a/tests/platform_tests/thermal_control_test_helper.py +++ b/tests/platform_tests/thermal_control_test_helper.py @@ -256,8 +256,8 @@ def restart_thermal_control_daemon(dut): :return: """ logging.info('Restarting thermal control daemon...') - find_thermalctld_pid_cmd = 'docker exec -i pmon bash -c \'pgrep thermalctld | sort\'' - output = dut.command(find_thermalctld_pid_cmd) + find_thermalctld_pid_cmd = 'docker exec -i pmon bash -c \'pgrep -f thermalctld\' | sort' + output = dut.shell(find_thermalctld_pid_cmd) assert output["rc"] == 0, "Run command '%s' failed" % find_thermalctld_pid_cmd assert len(output["stdout_lines"]) == 2, "There should be 2 thermalctld process" pid_0 = int(output["stdout_lines"][0].strip()) @@ -273,7 +273,7 @@ def restart_thermal_control_daemon(dut): max_wait_time = 30 while max_wait_time > 0: max_wait_time -= 1 - output = dut.command(find_thermalctld_pid_cmd) + output = dut.shell(find_thermalctld_pid_cmd) assert output["rc"] == 0, "Run command '%s' failed" % find_thermalctld_pid_cmd if len(output["stdout_lines"]) != 2: time.sleep(1)