Skip to content

Commit 4750b90

Browse files
authored
Fix missing PSU fans in test_psu_fan.py (sonic-net#17641)
Description of PR Summary: Fixes problem with missing PSU in test_psu_fan.py Approach What is the motivation for this PR? Failing testcases in test_psu_fan.py How did you do it? Used the same approach as in test_psu.py How did you verify/test it? Run testcases in T0-100G Signed-off-by: Eduard Yakubchyk <eyakubch@cisco.com>
1 parent fc799d3 commit 4750b90

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

tests/platform_tests/api/conftest.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
import os
22
import pytest
33

4+
from tests.common.helpers.platform_api import psu
45
from tests.common.plugins.loganalyzer.loganalyzer import LogAnalyzer
56

67
SERVER_FILE = 'platform_api_server.py'
78
SERVER_PORT = 8000
89

910
IPTABLES_DELETE_RULE_CMD = 'iptables -D INPUT -p tcp -m tcp --dport {} -j ACCEPT'.format(SERVER_PORT)
1011

12+
def skip_absent_psu(psu_num, platform_api_conn, psu_skip_list, logger): # noqa F811
13+
name = psu.get_name(platform_api_conn, psu_num)
14+
if name in psu_skip_list:
15+
logger.info("Skipping PSU {} since it is part of psu_skip_list".format(name))
16+
return True
17+
return False
18+
1119

1220
@pytest.fixture(scope='module', autouse=True)
1321
def stop_platform_api_service(duthosts):

tests/platform_tests/api/test_psu.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from tests.platform_tests.cli.util import get_skip_mod_list
88
from .platform_api_test_base import PlatformApiTestBase
99
from tests.common.utilities import skip_release_for_platform, wait_until
10+
from tests.platform_tests.api.conftest import skip_absent_psu
1011
from tests.common.platform.device_utils import platform_api_conn, start_platform_api_service # noqa F401
1112

13+
1214
###################################################
1315
# TODO: Remove this after we transition to Python 3
1416
import sys
@@ -81,13 +83,6 @@ def get_psu_facts(self, duthost, psu_idx, def_value, *keys):
8183

8284
return def_value
8385

84-
def skip_absent_psu(self, psu_num, platform_api_conn): # noqa F811
85-
name = psu.get_name(platform_api_conn, psu_num)
86-
if name in self.psu_skip_list:
87-
logger.info("Skipping PSU {} since it is part of psu_skip_list".format(name))
88-
return True
89-
return False
90-
9186
def get_psu_parameter(self, psu_info, psu_parameter, get_data, message):
9287
data = None
9388
is_supported = self.get_psu_facts(psu_info["duthost"], psu_info["psu_id"], True, psu_parameter)
@@ -105,7 +100,7 @@ def get_psu_parameter(self, psu_info, psu_parameter, get_data, message):
105100
def test_get_name(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
106101
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
107102
for i in range(self.num_psus):
108-
if self.skip_absent_psu(i, platform_api_conn):
103+
if skip_absent_psu(i, platform_api_conn, self.psu_skip_list, logger):
109104
continue
110105
name = psu.get_name(platform_api_conn, i)
111106
if self.expect(name is not None, "Unable to retrieve PSU {} name".format(i)):
@@ -128,7 +123,7 @@ def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
128123

129124
def test_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
130125
for i in range(self.num_psus):
131-
if self.skip_absent_psu(i, platform_api_conn):
126+
if skip_absent_psu(i, platform_api_conn, self.psu_skip_list, logger):
132127
continue
133128
model = psu.get_model(platform_api_conn, i)
134129
if self.expect(model is not None, "Unable to retrieve PSU {} model".format(i)):
@@ -137,7 +132,7 @@ def test_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
137132

138133
def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
139134
for i in range(self.num_psus):
140-
if self.skip_absent_psu(i, platform_api_conn):
135+
if skip_absent_psu(i, platform_api_conn, self.psu_skip_list, logger):
141136
continue
142137
serial = psu.get_serial(platform_api_conn, i)
143138
if self.expect(serial is not None, "Unable to retrieve PSU {} serial number".format(i)):
@@ -148,7 +143,7 @@ def test_get_revision(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
148143
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
149144
skip_release(duthost, ["201811", "201911", "202012"])
150145
for i in range(self.num_psus):
151-
if self.skip_absent_psu(i, platform_api_conn):
146+
if skip_absent_psu(i, platform_api_conn, self.psu_skip_list, logger):
152147
continue
153148
revision = psu.get_revision(platform_api_conn, i)
154149
if self.expect(revision is not None, "Unable to retrieve PSU {} serial number".format(i)):
@@ -157,7 +152,7 @@ def test_get_revision(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
157152

158153
def test_get_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
159154
for i in range(self.num_psus):
160-
if self.skip_absent_psu(i, platform_api_conn):
155+
if skip_absent_psu(i, platform_api_conn, self.psu_skip_list, logger):
161156
continue
162157
status = psu.get_status(platform_api_conn, i)
163158
if self.expect(status is not None, "Unable to retrieve PSU {} status".format(i)):
@@ -166,7 +161,7 @@ def test_get_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
166161

167162
def test_get_position_in_parent(self, platform_api_conn): # noqa F811
168163
for psu_id in range(self.num_psus):
169-
if self.skip_absent_psu(psu_id, platform_api_conn):
164+
if skip_absent_psu(psu_id, platform_api_conn, self.psu_skip_list, logger):
170165
continue
171166
position = psu.get_position_in_parent(platform_api_conn, psu_id)
172167
if self.expect(position is not None,
@@ -177,7 +172,7 @@ def test_get_position_in_parent(self, platform_api_conn): # noqa F811
177172

178173
def test_is_replaceable(self, platform_api_conn): # noqa F811
179174
for psu_id in range(self.num_psus):
180-
if self.skip_absent_psu(psu_id, platform_api_conn):
175+
if skip_absent_psu(psu_id, platform_api_conn, self.psu_skip_list, logger):
181176
continue
182177
replaceable = psu.is_replaceable(platform_api_conn, psu_id)
183178
if self.expect(replaceable is not None,
@@ -337,7 +332,7 @@ def test_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platfo
337332

338333
psus_skipped = 0
339334
for psu_id in range(self.num_psus):
340-
if self.skip_absent_psu(psu_id, platform_api_conn):
335+
if skip_absent_psu(psu_id, platform_api_conn, self.psu_skip_list, logger):
341336
continue
342337
name = psu.get_name(platform_api_conn, psu_id)
343338
led_support = duthost.facts.get("chassis").get("psus")[psu_id].get("led")
@@ -398,7 +393,7 @@ def test_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platfo
398393

399394
def test_thermals(self, platform_api_conn): # noqa F811
400395
for psu_id in range(self.num_psus):
401-
if self.skip_absent_psu(psu_id, platform_api_conn):
396+
if skip_absent_psu(psu_id, platform_api_conn, self.psu_skip_list, logger):
402397
continue
403398
try:
404399
num_thermals = int(psu.get_num_thermals(platform_api_conn, psu_id))

tests/platform_tests/api/test_psu_fans.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import pytest
66

77
from tests.common.helpers.platform_api import chassis, psu, psu_fan
8+
from tests.platform_tests.cli.util import get_skip_mod_list
9+
from tests.platform_tests.api.conftest import skip_absent_psu
810
from tests.common.platform.device_utils import platform_api_conn, start_platform_api_service # noqa F401
911

1012
from .platform_api_test_base import PlatformApiTestBase
@@ -46,7 +48,7 @@ class TestPsuFans(PlatformApiTestBase):
4648
# level, so we must do the same here to prevent a scope mismatch.
4749

4850
@pytest.fixture(scope="function", autouse=True)
49-
def setup(self, platform_api_conn): # noqa F811
51+
def setup(self, platform_api_conn, duthosts, enum_rand_one_per_hwsku_hostname): # noqa F811
5052
if self.num_psus is None:
5153
try:
5254
self.num_psus = chassis.get_num_psus(platform_api_conn)
@@ -56,6 +58,9 @@ def setup(self, platform_api_conn): # noqa F811
5658
if self.num_psus == 0:
5759
pytest.skip("No psus found on device")
5860

61+
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
62+
self.psu_skip_list = get_skip_mod_list(duthost, ['psus'])
63+
5964
#
6065
# Helper functions
6166
#
@@ -99,6 +104,8 @@ def get_fan_facts(self, duthost, psu_idx, fan_idx, def_value, *keys):
99104
def test_get_name(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
100105
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
101106
for j in range(self.num_psus):
107+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
108+
continue
102109
num_fans = psu.get_num_fans(platform_api_conn, j)
103110

104111
for i in range(num_fans):
@@ -135,6 +142,8 @@ def test_get_name(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, p
135142

136143
def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
137144
for j in range(self.num_psus):
145+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
146+
continue
138147
num_fans = psu.get_num_fans(platform_api_conn, j)
139148

140149
for i in range(num_fans):
@@ -151,6 +160,8 @@ def test_get_presence(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
151160

152161
def test_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
153162
for j in range(self.num_psus):
163+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
164+
continue
154165
num_fans = psu.get_num_fans(platform_api_conn, j)
155166

156167
for i in range(num_fans):
@@ -163,6 +174,8 @@ def test_get_model(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
163174

164175
def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
165176
for j in range(self.num_psus):
177+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
178+
continue
166179
num_fans = psu.get_num_fans(platform_api_conn, j)
167180

168181
for i in range(num_fans):
@@ -176,6 +189,8 @@ def test_get_serial(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
176189

177190
def test_get_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
178191
for j in range(self.num_psus):
192+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
193+
continue
179194
num_fans = psu.get_num_fans(platform_api_conn, j)
180195

181196
for i in range(num_fans):
@@ -188,6 +203,8 @@ def test_get_status(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost,
188203

189204
def test_get_position_in_parent(self, platform_api_conn): # noqa F811
190205
for j in range(self.num_psus):
206+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
207+
continue
191208
num_fans = psu.get_num_fans(platform_api_conn, j)
192209
for i in range(num_fans):
193210
position = psu_fan.get_position_in_parent(platform_api_conn, j, i)
@@ -199,6 +216,8 @@ def test_get_position_in_parent(self, platform_api_conn): # noqa F811
199216

200217
def test_is_replaceable(self, platform_api_conn): # noqa F811
201218
for j in range(self.num_psus):
219+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
220+
continue
202221
num_fans = psu.get_num_fans(platform_api_conn, j)
203222
for i in range(num_fans):
204223
replaceable = psu_fan.is_replaceable(platform_api_conn, j, i)
@@ -216,6 +235,8 @@ def test_is_replaceable(self, platform_api_conn): # noqa F811
216235
def test_get_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localhost, platform_api_conn): # noqa F811
217236
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
218237
for j in range(self.num_psus):
238+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
239+
continue
219240
num_fans = psu.get_num_fans(platform_api_conn, j)
220241

221242
for i in range(num_fans):
@@ -241,6 +262,8 @@ def test_get_direction(self, duthosts, enum_rand_one_per_hwsku_hostname, localho
241262
]
242263

243264
for j in range(self.num_psus):
265+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
266+
continue
244267
num_fans = psu.get_num_fans(platform_api_conn, j)
245268

246269
for i in range(num_fans):
@@ -257,6 +280,8 @@ def test_get_fans_target_speed(self, duthosts, enum_rand_one_per_hwsku_hostname,
257280
psus_skipped = 0
258281

259282
for j in range(self.num_psus):
283+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
284+
continue
260285
num_fans = psu.get_num_fans(platform_api_conn, j)
261286
fans_skipped = 0
262287

@@ -297,6 +322,8 @@ def test_set_fans_speed(self, duthosts, enum_rand_one_per_hwsku_hostname, localh
297322
psus_skipped = 0
298323

299324
for j in range(self.num_psus):
325+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
326+
continue
300327
target_speed = random.randint(1, 100)
301328
num_fans = psu.get_num_fans(platform_api_conn, j)
302329
fans_skipped = 0
@@ -344,6 +371,8 @@ def test_set_fans_led(self, duthosts, enum_rand_one_per_hwsku_hostname, localhos
344371
psus_skipped = 0
345372

346373
for j in range(self.num_psus):
374+
if skip_absent_psu(j, platform_api_conn, self.psu_skip_list, logger):
375+
continue
347376
num_fans = psu.get_num_fans(platform_api_conn, j)
348377
fans_skipped = 0
349378

0 commit comments

Comments
 (0)