|
| 1 | +import logging |
| 2 | +import random |
| 3 | +import re |
| 4 | +import time |
| 5 | + |
| 6 | +import pytest |
| 7 | +import yaml |
| 8 | + |
| 9 | +from tests.common.helpers.assertions import pytest_assert |
| 10 | +from tests.common.helpers.platform_api import chassis, thermal |
| 11 | + |
| 12 | +from platform_api_test_base import PlatformApiTestBase |
| 13 | + |
| 14 | +logger = logging.getLogger(__name__) |
| 15 | + |
| 16 | +pytestmark = [ |
| 17 | + pytest.mark.disable_loganalyzer, # disable automatic loganalyzer |
| 18 | + pytest.mark.topology('any') |
| 19 | +] |
| 20 | + |
| 21 | + |
| 22 | +class TestThermalApi(PlatformApiTestBase): |
| 23 | + |
| 24 | + num_thermals = None |
| 25 | + |
| 26 | + # This fixture would probably be better scoped at the class level, but |
| 27 | + # it relies on the platform_api_conn fixture, which is scoped at the function |
| 28 | + # level, so we must do the same here to prevent a scope mismatch. |
| 29 | + |
| 30 | + @pytest.fixture(scope="function", autouse=True) |
| 31 | + def setup(self, platform_api_conn): |
| 32 | + if self.num_thermals is None: |
| 33 | + try: |
| 34 | + self.num_thermals = int(chassis.get_num_thermals(platform_api_conn)) |
| 35 | + except: |
| 36 | + pytest.fail("num_thermals is not an integer") |
| 37 | + |
| 38 | + # |
| 39 | + # Functions to test methods inherited from DeviceBase class |
| 40 | + # |
| 41 | + def test_get_name(self, duthost, localhost, platform_api_conn): |
| 42 | + for i in range(self.num_thermals): |
| 43 | + name = thermal.get_name(platform_api_conn, i) |
| 44 | + |
| 45 | + if self.expect(name is not None, "Unable to retrieve Thermal {} name".format(i)): |
| 46 | + self.expect(isinstance(name, str), "Thermal {} name appears incorrect".format(i)) |
| 47 | + |
| 48 | + self.assert_expectations() |
| 49 | + |
| 50 | + def test_get_presence(self, duthost, localhost, platform_api_conn): |
| 51 | + for i in range(self.num_thermals): |
| 52 | + presence = thermal.get_presence(platform_api_conn, i) |
| 53 | + |
| 54 | + if self.expect(presence is not None, "Unable to retrieve thermal {} presence".format(i)): |
| 55 | + if self.expect(isinstance(presence, bool), "Thermal {} presence appears incorrect".format(i)): |
| 56 | + self.expect(presence is True, "Thermal {} is not present".format(i)) |
| 57 | + |
| 58 | + self.assert_expectations() |
| 59 | + |
| 60 | + def test_get_model(self, duthost, localhost, platform_api_conn): |
| 61 | + for i in range(self.num_thermals): |
| 62 | + model = thermal.get_model(platform_api_conn, i) |
| 63 | + |
| 64 | + if self.expect(model is not None, "Unable to retrieve thermal {} model".format(i)): |
| 65 | + self.expect(isinstance(model, str), "Thermal {} model appears incorrect".format(i)) |
| 66 | + |
| 67 | + self.assert_expectations() |
| 68 | + |
| 69 | + def test_get_serial(self, duthost, localhost, platform_api_conn): |
| 70 | + for i in range(self.num_thermals): |
| 71 | + serial = thermal.get_serial(platform_api_conn, i) |
| 72 | + |
| 73 | + if self.expect(serial is not None, "Unable to retrieve thermal {} serial number".format(i)): |
| 74 | + self.expect(isinstance(serial, str), "Thermal {} serial number appears incorrect".format(i)) |
| 75 | + |
| 76 | + self.assert_expectations() |
| 77 | + |
| 78 | + def test_get_status(self, duthost, localhost, platform_api_conn): |
| 79 | + for i in range(self.num_thermals): |
| 80 | + status = thermal.get_status(platform_api_conn, i) |
| 81 | + |
| 82 | + if self.expect(status is not None, "Unable to retrieve thermal {} status".format(i)): |
| 83 | + self.expect(isinstance(status, bool), "Thermal {} status appears incorrect".format(i)) |
| 84 | + |
| 85 | + self.assert_expectations() |
| 86 | + |
| 87 | + # |
| 88 | + # Functions to test methods defined in ThermalBase class |
| 89 | + # |
| 90 | + |
| 91 | + def test_get_temperature(self, duthost, localhost, platform_api_conn): |
| 92 | + for i in range(self.num_thermals): |
| 93 | + temperature = thermal.get_temperature(platform_api_conn, i) |
| 94 | + |
| 95 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} temperature".format(i)): |
| 96 | + if self.expect(isinstance(temperature, float), "Thermal {} temperature appears incorrect".format(i)): |
| 97 | + self.expect(temperature > 0 and temperature <= 100, |
| 98 | + "Thermal {} temperature {} reading is not within range".format(i, temperature)) |
| 99 | + self.assert_expectations() |
| 100 | + |
| 101 | + def test_get_low_threshold(self, duthost, localhost, platform_api_conn): |
| 102 | + # Ensure the thermal low threshold temperature is sane |
| 103 | + for i in range(self.num_thermals): |
| 104 | + temperature = thermal.get_low_threshold(platform_api_conn, i) |
| 105 | + |
| 106 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} low threshold".format(i)): |
| 107 | + if self.expect(isinstance(temperature, float), "Thermal {} low threshold appears incorrect".format(i)): |
| 108 | + self.expect(temperature > 0 and temperature <= 100, |
| 109 | + "Thermal {} low threshold {} reading is not within range".format(i, temperature)) |
| 110 | + self.assert_expectations() |
| 111 | + |
| 112 | + def test_get_high_threshold(self, duthost, localhost, platform_api_conn): |
| 113 | + # Ensure the thermal high threshold temperature is sane |
| 114 | + for i in range(self.num_thermals): |
| 115 | + temperature = thermal.get_high_threshold(platform_api_conn, i) |
| 116 | + |
| 117 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} high threshold".format(i)): |
| 118 | + if self.expect(isinstance(temperature, float), "Thermal {} high threshold appears incorrect".format(i)): |
| 119 | + self.expect(temperature > 0 and temperature <= 100, |
| 120 | + "Thermal {} high threshold {} reading is not within range".format(i, temperature)) |
| 121 | + self.assert_expectations() |
| 122 | + |
| 123 | + def test_get_low_critical_threshold(self, duthost, localhost, platform_api_conn): |
| 124 | + # Ensure the thermal low critical threshold temperature is sane |
| 125 | + for i in range(self.num_thermals): |
| 126 | + temperature = thermal.get_low_critical_threshold(platform_api_conn, i) |
| 127 | + |
| 128 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} low critical threshold".format(i)): |
| 129 | + if self.expect(isinstance(temperature, float), "Thermal {} low threshold appears incorrect".format(i)): |
| 130 | + self.expect(temperature > 0 and temperature <= 110, |
| 131 | + "Thermal {} low critical threshold {} reading is not within range".format(i, temperature)) |
| 132 | + self.assert_expectations() |
| 133 | + |
| 134 | + def test_get_high_critical_threshold(self, duthost, localhost, platform_api_conn): |
| 135 | + # Ensure the thermal high threshold temperature is sane |
| 136 | + for i in range(self.num_thermals): |
| 137 | + temperature = thermal.get_high_critical_threshold(platform_api_conn, i) |
| 138 | + |
| 139 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} high critical threshold".format(i)): |
| 140 | + if self.expect(isinstance(temperature, float), "Thermal {} high threshold appears incorrect".format(i)): |
| 141 | + self.expect(temperature > 0 and temperature <= 110, |
| 142 | + "Thermal {} high critical threshold {} reading is not within range".format(i, temperature)) |
| 143 | + self.assert_expectations() |
| 144 | + |
| 145 | + def test_set_low_threshold(self, duthost, localhost, platform_api_conn): |
| 146 | + # Ensure the thermal temperature is sane |
| 147 | + for i in range(self.num_thermals): |
| 148 | + low_temperature = 20 |
| 149 | + result = thermal.set_low_threshold(platform_api_conn, i, low_temperature) |
| 150 | + if self.expect(result is not None, "Failed to perform set_low_threshold"): |
| 151 | + self.expect(result is True, "Failed to set set_low_threshold for thermal {} to {}".format(i, low_temperature)) |
| 152 | + |
| 153 | + temperature = thermal.get_low_threshold(platform_api_conn, i) |
| 154 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} low threshold".format(i)): |
| 155 | + if self.expect(isinstance(temperature, float), "Thermal {} low threshold appears incorrect".format(i)): |
| 156 | + self.expect(temperature == 20, |
| 157 | + "Thermal {} low threshold {} is not matching the set value {}".format(i, temperature, low_temperature)) |
| 158 | + |
| 159 | + self.assert_expectations() |
| 160 | + |
| 161 | + def test_set_high_threshold(self, duthost, localhost, platform_api_conn): |
| 162 | + # Ensure the thermal temperature is sane |
| 163 | + for i in range(self.num_thermals): |
| 164 | + high_temperature = 80 |
| 165 | + result = thermal.set_high_threshold(platform_api_conn, i, high_temperature) |
| 166 | + if self.expect(result is not None, "Failed to perform set_high_threshold"): |
| 167 | + self.expect(result is True, "Failed to set set_high_threshold for thermal {} to {}".format(i, high_temperature)) |
| 168 | + |
| 169 | + temperature = thermal.get_high_threshold(platform_api_conn, i) |
| 170 | + if self.expect(temperature is not None, "Unable to retrieve Thermal {} high threshold".format(i)): |
| 171 | + if self.expect(isinstance(temperature, float), "Thermal {} high threshold appears incorrect".format(i)): |
| 172 | + self.expect(temperature == 80, |
| 173 | + "Thermal {} high threshold {} is not matching the set value {}".format(i, temperature, high_temperature)) |
| 174 | + self.assert_expectations() |
0 commit comments