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
3 changes: 2 additions & 1 deletion tests/platform_tests/api/test_fan_drawer_fans.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def test_get_direction(self, duthosts, enum_rand_one_per_hwsku_hostname, localho

self.assert_expectations()

def test_get_fans_target_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn):
def test_get_fans_target_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn,
suspend_and_resume_hw_tc_on_mellanox_device):

duthost = duthosts[enum_rand_one_per_hwsku_hostname]
fan_drawers_skipped = 0
Expand Down
17 changes: 17 additions & 0 deletions tests/platform_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer
from tests.common.plugins.sanity_check.recover import neighbor_vm_restore
from .args.counterpoll_cpu_usage_args import add_counterpoll_cpu_usage_args
from .mellanox.mellanox_thermal_control_test_helper import suspend_hw_tc_service, resume_hw_tc_service


TEMPLATES_DIR = os.path.join(os.path.dirname(
Expand Down Expand Up @@ -712,3 +713,19 @@ def pytest_generate_tests(metafunc):

def pytest_addoption(parser):
add_counterpoll_cpu_usage_args(parser)


@pytest.fixture(scope="function", autouse=False)
def suspend_and_resume_hw_tc_on_mellanox_device(duthosts, enum_rand_one_per_hwsku_hostname):
"""
suspend and resume hw thermal control service on mellanox device
"""

duthost = duthosts[enum_rand_one_per_hwsku_hostname]
if is_mellanox_device(duthost) and duthost.is_host_service_running("hw-management-tc"):
suspend_hw_tc_service(duthost)

yield

if is_mellanox_device(duthost) and duthost.is_host_service_running("hw-management-tc"):
resume_hw_tc_service(duthost)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
SingleFanMocker
from tests.common.mellanox_data import get_platform_data
from .minimum_table import get_min_table
from tests.common.utilities import wait_until
from tests.common.helpers.assertions import pytest_assert


NOT_AVAILABLE = 'N/A'
Expand Down Expand Up @@ -107,6 +109,8 @@
}
}

SUSPEND_FILE_PATH = "/var/run/hw-management/config/suspend"


class SysfsNotExistError(Exception):
"""
Expand Down Expand Up @@ -178,11 +182,6 @@ def _extract_num_of_fans_and_fan_drawers(self):
return

MockerHelper.FAN_NUM = int(content)
platform_data = get_platform_data(self.dut)
if not platform_data['fans']['hot_swappable']:
# For non swappable fan, there is no drawer. We put them in a "virtual" drawer.
MockerHelper.FAN_NUM_PER_DRAWER = MockerHelper.FAN_NUM
return

if MockerHelper.FAN_NUM > fan_drawer_num:
MockerHelper.FAN_NUM_PER_DRAWER = 2
Expand Down Expand Up @@ -844,7 +843,9 @@ def mock_data(self):
# All system fan is controlled to have the same speed, so only
# get a random value once here
speed = random.randint(60, 100)
FanData.mock_cooling_cur_state(self.mock_helper, speed / 10)
if not self.mock_helper.dut.is_host_service_running("hw-management-tc"):
# When image doesn't support new tc, we still use cooling level to control thermal
FanData.mock_cooling_cur_state(self.mock_helper, speed / 10)
while fan_index <= MockerHelper.FAN_NUM:
try:
if (fan_index - 1) % MockerHelper.FAN_NUM_PER_DRAWER == 0:
Expand Down Expand Up @@ -895,6 +896,19 @@ def mock_data(self):
expected_data = self.expected_data[fan_data.name]
expected_data[1] = drawer_data.get_expect_led_color()

platform_data = get_platform_data(self.dut)
if not platform_data['fans']['hot_swappable']:
# For non swappable fan, all fans share one led
is_one_red_led_at_least = False
for _, expected_data in self.expected_data.items():
if expected_data[1] == "red":
is_one_red_led_at_least = True
break
if is_one_red_led_at_least:
logging.info("update all expected led to red")
for fan_name, expected_data in self.expected_data.items():
self.expected_data[fan_name][1] = "red"

platform_data = get_platform_data(self.mock_helper.dut)
psu_count = platform_data["psus"]["number"]
naming_rule = FAN_NAMING_RULE['psu_fan']
Expand Down Expand Up @@ -1382,3 +1396,28 @@ def mock_reset_from_comex(self):

def mock_reset_from_asic(self):
self.mock_helper.mock_value(self.RESET_FROM_ASIC, 1)


def suspend_hw_tc_service(dut):
"""
Suspend thermal control service
"""
logging.info("suspend hw tc service ")

dut.shell(f"sudo touch {SUSPEND_FILE_PATH}")
dut.shell(f"sudo chown admin {SUSPEND_FILE_PATH}")
dut.shell(f"sudo echo 1 > {SUSPEND_FILE_PATH}")

def check_pwm_is_max():
pwm = int(dut.shell("cat /var/run/hw-management/thermal/pwm1")["stdout"])
return pwm == 255

pytest_assert(wait_until(10, 0, 1, check_pwm_is_max), "TC is not suspended")


def resume_hw_tc_service(dut):
"""
Resume hw thermal control service
"""
logging.info("resume hw tc service ")
dut.shell(f"sudo rm -f {SUSPEND_FILE_PATH}")
Loading