Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/common/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions tests/platform_tests/cli/test_show_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pytest

import util
from pkg_resources import parse_version
from tests.common.helpers.assertions import pytest_assert

pytestmark = [
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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",
Expand All @@ -54,6 +58,11 @@
}
}

ASIC_THERMAL_RULE_201911 = {
"name": "Ambient ASIC Temp",
"temperature": "asic"
}

FAN_NAMING_RULE = {
"fan": {
"name": "fan{}",
Expand Down Expand Up @@ -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:
"""
Expand Down Expand Up @@ -384,7 +403,7 @@ class FanData:
PWM_MAX = 255

# Speed tolerance
SPEED_TOLERANCE = 0.2
SPEED_TOLERANCE = 0.5
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why increase speed tolerance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The speed tolerance in production code is 50%, here is to align the test case with it.


# Cooling cur state file
COOLING_CUR_STATE_FILE = 'cooling_cur_state'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/platform_tests/thermal_control_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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)
Expand Down