From e22642d0c3959fab99a97caf0669e9c7cd3f73a9 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Sun, 7 Feb 2021 09:43:02 +0800 Subject: [PATCH 1/2] Add a fixture to disable thermal policy --- tests/platform_tests/test_platform_info.py | 20 +++++++++---------- .../thermal_control_test_helper.py | 17 ++++++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/platform_tests/test_platform_info.py b/tests/platform_tests/test_platform_info.py index a462d0b2350..23474d6d0e7 100644 --- a/tests/platform_tests/test_platform_info.py +++ b/tests/platform_tests/test_platform_info.py @@ -242,24 +242,22 @@ def test_turn_on_off_psu_and_check_psustatus(duthosts, rand_one_dut_hostname, ps @pytest.mark.disable_loganalyzer -def test_show_platform_fanstatus_mocked(duthosts, rand_one_dut_hostname, mocker_factory): +def test_show_platform_fanstatus_mocked(duthosts, rand_one_dut_hostname, mocker_factory, disable_thermal_policy): """ @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']) + # 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) + 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') + pytest_assert(result, 'FAN mock data mismatch') @pytest.mark.disable_loganalyzer diff --git a/tests/platform_tests/thermal_control_test_helper.py b/tests/platform_tests/thermal_control_test_helper.py index 9dd62f7fd8d..6b4457853e9 100644 --- a/tests/platform_tests/thermal_control_test_helper.py +++ b/tests/platform_tests/thermal_control_test_helper.py @@ -337,3 +337,20 @@ def __exit__(self, exc_type, exc_val, exc_tb): """ self.dut.command('mv -f {} {}'.format(self.thermal_policy_file_backup_path, self.thermal_policy_file_path)) restart_thermal_control_daemon(self.dut) + + +@pytest.fixture +def disable_thermal_policy(duthosts, rand_one_dut_hostname): + """Fixture to help disable thermal policy during the test. After test, it will + automatically re-enable thermal policy. The idea here is to make thermalctld + load a invalid policy file. To use this fixture, the test case will probably + marked as @pytest.mark.disable_loganalyzer. + + Args: + duthosts DUT object representing a SONiC switch under test + rand_one_dut_hostname random DUT hostname + """ + duthost = duthosts[rand_one_dut_hostname] + invalid_policy_file = os.path.join(FILES_DIR, 'invalid_format_policy.json') + with ThermalPolicyFileContext(duthost, invalid_policy_file): + yield \ No newline at end of file From 9e517a43cc4c17f72a76bf3e897ab54b37c600f6 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Sun, 7 Feb 2021 10:08:13 +0800 Subject: [PATCH 2/2] Fix issues --- tests/platform_tests/thermal_control_test_helper.py | 2 +- tests/system_health/test_system_health.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/platform_tests/thermal_control_test_helper.py b/tests/platform_tests/thermal_control_test_helper.py index 6b4457853e9..a05d0f875fb 100644 --- a/tests/platform_tests/thermal_control_test_helper.py +++ b/tests/platform_tests/thermal_control_test_helper.py @@ -353,4 +353,4 @@ def disable_thermal_policy(duthosts, rand_one_dut_hostname): duthost = duthosts[rand_one_dut_hostname] invalid_policy_file = os.path.join(FILES_DIR, 'invalid_format_policy.json') with ThermalPolicyFileContext(duthost, invalid_policy_file): - yield \ No newline at end of file + yield diff --git a/tests/system_health/test_system_health.py b/tests/system_health/test_system_health.py index 588a17e05e8..df900d3788f 100644 --- a/tests/system_health/test_system_health.py +++ b/tests/system_health/test_system_health.py @@ -6,6 +6,7 @@ from pkg_resources import parse_version from tests.common.utilities import wait_until from tests.common.helpers.assertions import pytest_require +from tests.platform_tests.thermal_control_test_helper import disable_thermal_policy from device_mocker import device_mocker_factory pytestmark = [ @@ -97,7 +98,8 @@ def test_service_checker(duthosts, rand_one_dut_hostname): assert summary == expect_summary, 'Expect summary {}, got {}'.format(expect_summary, summary) -def test_device_checker(duthosts, rand_one_dut_hostname, device_mocker_factory): +@pytest.mark.disable_loganalyzer +def test_device_checker(duthosts, rand_one_dut_hostname, device_mocker_factory, disable_thermal_policy): duthost = duthosts[rand_one_dut_hostname] device_mocker = device_mocker_factory(duthost) wait_system_health_boot_up(duthost)