Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a fixture to disable thermal policy #2953

Merged
merged 2 commits into from
Feb 16, 2021
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
20 changes: 9 additions & 11 deletions tests/platform_tests/test_platform_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/platform_tests/thermal_control_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion tests/system_health/test_system_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
Expand Down