Skip to content

Commit f5d9eaa

Browse files
authored
[Platform API][pytest]Api tests for thermal class (#2019)
* [Platform API][pytest]Api tests for thermal class Add a basic test suite for the THERMAL class of the new platform API, utilizing the platform API HTTP server, including the following functions: ``` test_get_name test_get_presence test_get_model test_get_serial test_get_status test_get_temperature test_get_low_threshold test_get_high_threshold test_get_low_critical_threshold test_get_high_critical_threshold test_set_low_threshold test_set_high_threshold ``` Signed-off-by: vaibhav-dahiya <vdahiya@microsoft.com>
1 parent 0805536 commit f5d9eaa

3 files changed

Lines changed: 247 additions & 2 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
""" This module provides interface to interact with the thermal of the DUT
2+
via platform API remotely """
3+
4+
import json
5+
import logging
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
def thermal_api(conn, index, name, args=None):
11+
if args is None:
12+
args = []
13+
conn.request('POST', '/platform/chassis/thermal/{}/{}'.format(index, name), json.dumps({'args': args}))
14+
resp = conn.getresponse()
15+
res = json.loads(resp.read())['res']
16+
logger.info('Executing thermal API: "{}", index: {}, arguments: "{}", result: "{}"'.format(name, index, args, res))
17+
return res
18+
19+
#
20+
# Methods inherited from DeviceBase class
21+
#
22+
23+
24+
def get_name(conn, index):
25+
return thermal_api(conn, index, 'get_name')
26+
27+
28+
def get_presence(conn, index):
29+
return thermal_api(conn, index, 'get_presence')
30+
31+
32+
def get_model(conn, index):
33+
return thermal_api(conn, index, 'get_model')
34+
35+
36+
def get_serial(conn, index):
37+
return thermal_api(conn, index, 'get_serial')
38+
39+
40+
def get_status(conn, index):
41+
return thermal_api(conn, index, 'get_status')
42+
43+
#
44+
# Methods defined in thermalBase class
45+
#
46+
47+
48+
def get_temperature(conn, index):
49+
return thermal_api(conn, index, 'get_temperature')
50+
51+
52+
def get_high_threshold(conn, index):
53+
return thermal_api(conn, index, 'get_high_threshold')
54+
55+
56+
def get_low_threshold(conn, index):
57+
return thermal_api(conn, index, 'get_low_threshold')
58+
59+
60+
def set_high_threshold(conn, index, temperature):
61+
return thermal_api(conn, index, 'set_high_threshold', [temperature])
62+
63+
64+
def set_low_threshold(conn, index, temperature):
65+
return thermal_api(conn, index, 'set_low_threshold', [temperature])
66+
67+
68+
def get_high_critical_threshold(conn, index):
69+
return thermal_api(conn, index, 'get_high_critical_threshold')
70+
71+
72+
def get_low_critical_threshold(conn, index):
73+
return thermal_api(conn, index, 'get_low_critical_threshold')

tests/platform_tests/api/test_fan.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
logger = logging.getLogger(__name__)
1515

1616
pytestmark = [
17-
pytest.mark.sanity_check(skip_sanity=True),
1817
pytest.mark.disable_loganalyzer, # disable automatic loganalyzer
1918
pytest.mark.topology('any')
2019
]
@@ -42,7 +41,6 @@ def setup(self, platform_api_conn):
4241
if self.num_fans is None:
4342
try:
4443
self.num_fans = int(chassis.get_num_fans(platform_api_conn))
45-
logger.error("vaibhav got num_fans {}".format(self.num_fans))
4644
except:
4745
pytest.fail("num_fans is not an integer")
4846

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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

Comments
 (0)