Skip to content

Commit ffa7c45

Browse files
committed
Fix checkers failures
1 parent d0f5d76 commit ffa7c45

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

scripts/bmc_techsupport.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def extract_debug_dump_file(self, task_id, filepath):
7474
'''
7575
try:
7676
if task_id is None or task_id == BMCDebugDumpExtractor.INVALID_TASK_ID:
77-
raise Exception(f'Invalid Task-ID')
77+
raise Exception('Invalid Task-ID')
7878
log_dump_dir = os.path.dirname(filepath)
7979
log_dump_filename = os.path.basename(filepath)
8080
if not log_dump_dir or not log_dump_filename:
@@ -84,12 +84,20 @@ def extract_debug_dump_file(self, task_id, filepath):
8484

8585
start_time = time.time()
8686
log.log_info("Collecting BMC debug log dump")
87-
ret, err_msg = self.bmc.get_bmc_debug_log_dump(task_id=task_id, filename=log_dump_filename, path=log_dump_dir,
88-
timeout=TIMEOUT_FOR_GET_BMC_DEBUG_LOG_DUMP_IN_SECONDS)
87+
ret, err_msg = self.bmc.get_bmc_debug_log_dump(
88+
task_id=task_id,
89+
filename=log_dump_filename,
90+
path=log_dump_dir,
91+
timeout=TIMEOUT_FOR_GET_BMC_DEBUG_LOG_DUMP_IN_SECONDS
92+
)
8993
end_time = time.time()
9094
duration = end_time - start_time
9195
if ret != 0:
92-
log.log_error(f'BMC debug log dump does not finish within {TIMEOUT_FOR_GET_BMC_DEBUG_LOG_DUMP_IN_SECONDS} seconds: {err_msg}')
96+
timeout_msg = (
97+
f'BMC debug log dump does not finish within '
98+
f'{TIMEOUT_FOR_GET_BMC_DEBUG_LOG_DUMP_IN_SECONDS} seconds: {err_msg}'
99+
)
100+
log.log_error(timeout_msg)
93101
raise Exception(err_msg)
94102
log.log_info(f'Finished successfully collecting BMC debug log dump. Duration: {duration} seconds')
95103
except Exception as e:
@@ -114,8 +122,12 @@ def main(mode, task_id, filepath):
114122

115123
if __name__ == "__main__":
116124
parser = argparse.ArgumentParser(description="BMC tech-support generator script.")
117-
parser.add_argument('-m', '--mode', choices=['collect', 'trigger'], required=True,
118-
help="Mode of operation: 'collect' for collecting debug dump or 'trigger' for triggering debug dump task.")
125+
parser.add_argument(
126+
'-m', '--mode',
127+
choices=['collect', 'trigger'],
128+
required=True,
129+
help="Mode of operation: 'collect' for collecting debug dump or 'trigger' for triggering debug dump task."
130+
)
119131
parser.add_argument('-p', '--path', help="Path to save the BMC debug log dump file.")
120132
parser.add_argument('-t', '--task', help="Task-ID to monitor and collect the debug dump from.")
121133
args = parser.parse_args()

show/platform.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,32 @@ def bmc():
7878

7979

8080
# 'summary' subcommand ("show platform bmc summary")
81-
@bmc.command()
81+
@bmc.command(name='summary')
8282
@click.option('--json', is_flag=True, help="Output in JSON format")
83-
def summary(json):
83+
def bmc_summary(json):
8484
"""Show BMC summary information"""
8585
try:
8686
import sonic_platform
8787
chassis = sonic_platform.platform.Platform().get_chassis()
8888
bmc = chassis.get_bmc()
89-
89+
9090
if bmc is None:
9191
click.echo("BMC is not available on this platform")
9292
return
93-
93+
9494
eeprom_info = bmc.get_eeprom()
9595
if not eeprom_info:
9696
click.echo("Failed to retrieve BMC EEPROM information")
9797
return
98-
98+
9999
# Extract the required fields
100100
manufacturer = eeprom_info.get('Manufacturer', 'N/A')
101101
model = eeprom_info.get('Model', 'N/A')
102102
part_number = eeprom_info.get('PartNumber', 'N/A')
103103
power_state = eeprom_info.get('PowerState', 'N/A')
104104
serial_number = eeprom_info.get('SerialNumber', 'N/A')
105105
bmc_version = bmc.get_version()
106-
106+
107107
if json:
108108
bmc_summary = {
109109
'Manufacturer': manufacturer,
@@ -121,7 +121,7 @@ def summary(json):
121121
click.echo(f"SerialNumber: {serial_number}")
122122
click.echo(f"PowerState: {power_state}")
123123
click.echo(f"FirmwareVersion: {bmc_version}")
124-
124+
125125
except Exception as e:
126126
click.echo(f"Error retrieving BMC information: {str(e)}")
127127

@@ -135,25 +135,25 @@ def eeprom(json):
135135
import sonic_platform
136136
chassis = sonic_platform.platform.Platform().get_chassis()
137137
bmc = chassis.get_bmc()
138-
138+
139139
if bmc is None:
140140
click.echo("BMC is not available on this platform")
141141
return
142-
142+
143143
# Get BMC EEPROM information
144144
eeprom_info = bmc.get_eeprom()
145-
145+
146146
if not eeprom_info:
147147
click.echo("Failed to retrieve BMC EEPROM information")
148148
return
149-
149+
150150
# Extract the required fields
151151
manufacturer = eeprom_info.get('Manufacturer', 'N/A')
152152
model = eeprom_info.get('Model', 'N/A')
153153
part_number = eeprom_info.get('PartNumber', 'N/A')
154154
power_state = eeprom_info.get('PowerState', 'N/A')
155155
serial_number = eeprom_info.get('SerialNumber', 'N/A')
156-
156+
157157
if json:
158158
bmc_eeprom = {
159159
'Manufacturer': manufacturer,
@@ -169,7 +169,7 @@ def eeprom(json):
169169
click.echo(f"PartNumber: {part_number}")
170170
click.echo(f"PowerState: {power_state}")
171171
click.echo(f"SerialNumber: {serial_number}")
172-
172+
173173
except Exception as e:
174174
click.echo(f"Error retrieving BMC EEPROM information: {str(e)}")
175175

tests/show_platform_test.py

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import sys
44
import textwrap
55
from unittest import mock
6-
sys.modules['sonic_platform'] = mock.MagicMock()
6+
7+
mock_sonic_platform = mock.MagicMock()
8+
sys.modules['sonic_platform'] = mock_sonic_platform
9+
sys.modules['sonic_platform.platform'] = mock_sonic_platform.platform
710

811
import pytest
912
from click.testing import CliRunner
@@ -184,17 +187,17 @@ class TestShowPlatformBmc(object):
184187
- show platform bmc summary
185188
- show platform bmc eeprom
186189
"""
187-
190+
188191
TEST_BMC_EEPROM_INFO = {
189192
'Manufacturer': 'NVIDIA',
190193
'Model': 'P3809',
191194
'PartNumber': '692-13809-3404-000',
192195
'PowerState': 'On',
193196
'SerialNumber': '1320725102601'
194197
}
195-
198+
196199
TEST_BMC_VERSION = '88.0002.1252'
197-
200+
198201
def test_bmc_summary_regular_output(self):
199202
"""Test 'show platform bmc summary' with regular output"""
200203
expected_output = """\
@@ -212,22 +215,22 @@ def test_bmc_summary_regular_output(self):
212215
self.TEST_BMC_EEPROM_INFO['PowerState'],
213216
self.TEST_BMC_VERSION
214217
)
215-
218+
216219
mock_platform = mock.MagicMock()
217220
mock_chassis = mock.MagicMock()
218221
mock_bmc = mock.MagicMock()
219-
222+
220223
mock_platform.get_chassis.return_value = mock_chassis
221224
mock_chassis.get_bmc.return_value = mock_bmc
222225
mock_bmc.get_eeprom.return_value = self.TEST_BMC_EEPROM_INFO
223226
mock_bmc.get_version.return_value = self.TEST_BMC_VERSION
224-
227+
225228
sys.modules['sonic_platform'].platform.Platform.return_value = mock_platform
226-
229+
227230
result = CliRunner().invoke(show.cli.commands['platform'].commands['bmc'].commands['summary'], [])
228231
assert result.exit_code == 0, result.output
229232
assert result.output == textwrap.dedent(expected_output)
230-
233+
231234
def test_bmc_summary_json_output(self):
232235
"""Test 'show platform bmc summary' with JSON output"""
233236
expected_json = {
@@ -238,23 +241,23 @@ def test_bmc_summary_json_output(self):
238241
'PowerState': self.TEST_BMC_EEPROM_INFO['PowerState'],
239242
'FirmwareVersion': self.TEST_BMC_VERSION
240243
}
241-
244+
242245
mock_platform = mock.MagicMock()
243246
mock_chassis = mock.MagicMock()
244247
mock_bmc = mock.MagicMock()
245-
248+
246249
mock_platform.get_chassis.return_value = mock_chassis
247250
mock_chassis.get_bmc.return_value = mock_bmc
248251
mock_bmc.get_eeprom.return_value = self.TEST_BMC_EEPROM_INFO
249252
mock_bmc.get_version.return_value = self.TEST_BMC_VERSION
250-
253+
251254
sys.modules['sonic_platform'].platform.Platform.return_value = mock_platform
252-
255+
253256
result = CliRunner().invoke(show.cli.commands['platform'].commands['bmc'].commands['summary'], ['--json'])
254257
assert result.exit_code == 0, result.output
255258
output_json = json.loads(result.output)
256259
assert output_json == expected_json
257-
260+
258261
def test_bmc_eeprom_regular_output(self):
259262
"""Test 'show platform bmc eeprom' with regular output"""
260263
expected_output = """\
@@ -270,21 +273,21 @@ def test_bmc_eeprom_regular_output(self):
270273
self.TEST_BMC_EEPROM_INFO['PowerState'],
271274
self.TEST_BMC_EEPROM_INFO['SerialNumber']
272275
)
273-
276+
274277
mock_platform = mock.MagicMock()
275278
mock_chassis = mock.MagicMock()
276279
mock_bmc = mock.MagicMock()
277-
280+
278281
mock_platform.get_chassis.return_value = mock_chassis
279282
mock_chassis.get_bmc.return_value = mock_bmc
280283
mock_bmc.get_eeprom.return_value = self.TEST_BMC_EEPROM_INFO
281-
284+
282285
sys.modules['sonic_platform'].platform.Platform.return_value = mock_platform
283-
286+
284287
result = CliRunner().invoke(show.cli.commands['platform'].commands['bmc'].commands['eeprom'], [])
285288
assert result.exit_code == 0, result.output
286289
assert result.output == textwrap.dedent(expected_output)
287-
290+
288291
def test_bmc_eeprom_json_output(self):
289292
"""Test 'show platform bmc eeprom' with JSON output"""
290293
expected_json = {
@@ -294,17 +297,17 @@ def test_bmc_eeprom_json_output(self):
294297
'PowerState': self.TEST_BMC_EEPROM_INFO['PowerState'],
295298
'SerialNumber': self.TEST_BMC_EEPROM_INFO['SerialNumber']
296299
}
297-
300+
298301
mock_platform = mock.MagicMock()
299302
mock_chassis = mock.MagicMock()
300303
mock_bmc = mock.MagicMock()
301-
304+
302305
mock_platform.get_chassis.return_value = mock_chassis
303306
mock_chassis.get_bmc.return_value = mock_bmc
304307
mock_bmc.get_eeprom.return_value = self.TEST_BMC_EEPROM_INFO
305-
308+
306309
sys.modules['sonic_platform'].platform.Platform.return_value = mock_platform
307-
310+
308311
result = CliRunner().invoke(show.cli.commands['platform'].commands['bmc'].commands['eeprom'], ['--json'])
309312
assert result.exit_code == 0, result.output
310313
output_json = json.loads(result.output)

0 commit comments

Comments
 (0)