Skip to content

Commit 73cd0ea

Browse files
committed
Add BMC platform api test
Including cases: test_get_name() test_get_presence() test_get_model() test_get_serial() test_get_revision() test_get_status() test_is_replaceable() test_get_eeprom() test_get_version() test_reset_root_password() test_bmc_dump() test_bmc_firmware_update() Change-Id: I3491eb538cc6a504200f12614fce24cafec33355
1 parent dac1816 commit 73cd0ea

File tree

7 files changed

+471
-76
lines changed

7 files changed

+471
-76
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import re
2+
3+
4+
def show_firmware(duthost):
5+
out = duthost.command("fwutil show status")
6+
num_spaces = 2
7+
curr_chassis = ""
8+
output_data = {"chassis": {}}
9+
status_output = out['stdout']
10+
separators = re.split(r'\s{2,}', status_output.splitlines()[1]) # get separators
11+
output_lines = status_output.splitlines()[2:]
12+
13+
for line in output_lines:
14+
data = []
15+
start = 0
16+
17+
for sep in separators:
18+
curr_len = len(sep)
19+
data.append(line[start:start+curr_len].strip())
20+
start += curr_len + num_spaces
21+
22+
if data[0].strip() != "":
23+
curr_chassis = data[0].strip()
24+
output_data["chassis"][curr_chassis] = {"component": {}}
25+
26+
output_data["chassis"][curr_chassis]["component"][data[2]] = data[3]
27+
28+
return output_data
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
""" This module provides interface to interact with the BMC of the DUT via platform API remotely """
2+
import ast
3+
import json
4+
import logging
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def bmc_pmon_api(conn, name, args=None):
10+
if args is None:
11+
args = []
12+
conn.request('POST', '/platform/chassis/bmc/{}'.format(name), json.dumps({'args': args}))
13+
resp = conn.getresponse()
14+
res = json.loads(resp.read())['res']
15+
logger.info('Executing chassis API: "{}", arguments: "{}", result: "{}"'.format(name, args, res))
16+
return res
17+
18+
19+
def bmc_host_api(duthost, api_name, *args):
20+
bmc_instance = 'sudo python -c "import sonic_platform; \
21+
bmc = sonic_platform.platform.Platform().get_chassis().get_bmc(); \
22+
print(bmc.{})"'
23+
res = duthost.shell(bmc_instance.format(api_name + str(args)))['stdout']
24+
try:
25+
return ast.literal_eval(res)
26+
except (ValueError, SyntaxError):
27+
return res.strip()
28+
29+
30+
def get_name(conn):
31+
return bmc_pmon_api(conn, 'get_name')
32+
33+
34+
def get_presence(conn):
35+
return bmc_pmon_api(conn, 'get_presence')
36+
37+
38+
def get_model(duthost):
39+
return bmc_host_api(duthost, 'get_model')
40+
41+
42+
def get_serial(duthost):
43+
return bmc_host_api(duthost, 'get_serial')
44+
45+
46+
def get_revision(conn):
47+
return bmc_pmon_api(conn, 'get_revision')
48+
49+
50+
def get_status(conn):
51+
return bmc_pmon_api(conn, 'get_status')
52+
53+
54+
def is_replaceable(conn):
55+
return bmc_pmon_api(conn, 'is_replaceable')
56+
57+
58+
def get_eeprom(duthost):
59+
return bmc_host_api(duthost, 'get_eeprom')
60+
61+
62+
def get_version(duthost):
63+
return bmc_host_api(duthost, 'get_version')
64+
65+
66+
def reset_root_password(duthost):
67+
return bmc_host_api(duthost, 'reset_root_password')
68+
69+
70+
def trigger_bmc_debug_log_dump(duthost):
71+
return bmc_host_api(duthost, 'trigger_bmc_debug_log_dump')
72+
73+
74+
def get_bmc_debug_log_dump(duthost, task_id, filename, path):
75+
return bmc_host_api(duthost, 'get_bmc_debug_log_dump', task_id, filename, path)
76+
77+
78+
def update_firmware(duthost, fw_image):
79+
return bmc_host_api(duthost, 'update_firmware', fw_image)
80+
81+
82+
def request_bmc_reset(duthost):
83+
return bmc_host_api(duthost, '_request_bmc_reset')

0 commit comments

Comments
 (0)