-
Notifications
You must be signed in to change notification settings - Fork 902
Add BMC platform api test #20751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
echuawu
wants to merge
1
commit into
sonic-net:master
Choose a base branch
from
echuawu:bmc_api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add BMC platform api test #20751
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import re | ||
|
|
||
|
|
||
| def show_firmware(duthost): | ||
| out = duthost.command("fwutil show status") | ||
| num_spaces = 2 | ||
| curr_chassis = "" | ||
| output_data = {"chassis": {}} | ||
| status_output = out['stdout'] | ||
| separators = re.split(r'\s{2,}', status_output.splitlines()[1]) # get separators | ||
| output_lines = status_output.splitlines()[2:] | ||
|
|
||
| for line in output_lines: | ||
| data = [] | ||
| start = 0 | ||
|
|
||
| for sep in separators: | ||
| curr_len = len(sep) | ||
| data.append(line[start:start+curr_len].strip()) | ||
| start += curr_len + num_spaces | ||
|
|
||
| if data[0].strip() != "": | ||
| curr_chassis = data[0].strip() | ||
| output_data["chassis"][curr_chassis] = {"component": {}} | ||
|
|
||
| output_data["chassis"][curr_chassis]["component"][data[2]] = data[3] | ||
|
|
||
| return output_data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| """ This module provides interface to interact with the BMC of the DUT via platform API remotely """ | ||
| import ast | ||
| import json | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def bmc_pmon_api(conn, name, args=None): | ||
| if args is None: | ||
| args = [] | ||
| conn.request('POST', '/platform/chassis/bmc/{}'.format(name), json.dumps({'args': args})) | ||
| resp = conn.getresponse() | ||
| res = json.loads(resp.read())['res'] | ||
| logger.info('Executing chassis API: "{}", arguments: "{}", result: "{}"'.format(name, args, res)) | ||
| return res | ||
|
|
||
|
|
||
| def bmc_host_api(duthost, api_name, *args): | ||
| bmc_instance = 'sudo python -c "import sonic_platform; \ | ||
| bmc = sonic_platform.platform.Platform().get_chassis().get_bmc(); \ | ||
| print(bmc.{})"' | ||
| res = duthost.shell(bmc_instance.format(api_name + str(args)))['stdout'] | ||
| try: | ||
| return ast.literal_eval(res) | ||
| except (ValueError, SyntaxError): | ||
| return res.strip() | ||
|
|
||
|
|
||
| def get_name(conn): | ||
| return bmc_pmon_api(conn, 'get_name') | ||
|
|
||
|
|
||
| def get_presence(conn): | ||
| return bmc_pmon_api(conn, 'get_presence') | ||
|
|
||
|
|
||
| def get_model(duthost): | ||
| return bmc_host_api(duthost, 'get_model') | ||
|
|
||
|
|
||
| def get_serial(duthost): | ||
| return bmc_host_api(duthost, 'get_serial') | ||
|
|
||
|
|
||
| def get_revision(conn): | ||
| return bmc_pmon_api(conn, 'get_revision') | ||
|
|
||
|
|
||
| def get_status(conn): | ||
| return bmc_pmon_api(conn, 'get_status') | ||
|
|
||
|
|
||
| def is_replaceable(conn): | ||
| return bmc_pmon_api(conn, 'is_replaceable') | ||
|
|
||
|
|
||
| def get_eeprom(duthost): | ||
| return bmc_host_api(duthost, 'get_eeprom') | ||
|
|
||
|
|
||
| def get_version(duthost): | ||
| return bmc_host_api(duthost, 'get_version') | ||
|
|
||
|
|
||
| def reset_root_password(duthost): | ||
| return bmc_host_api(duthost, 'reset_root_password') | ||
|
|
||
|
|
||
| def trigger_bmc_debug_log_dump(duthost): | ||
| return bmc_host_api(duthost, 'trigger_bmc_debug_log_dump') | ||
|
|
||
|
|
||
| def get_bmc_debug_log_dump(duthost, task_id, filename, path): | ||
| return bmc_host_api(duthost, 'get_bmc_debug_log_dump', task_id, filename, path) | ||
|
|
||
|
|
||
| def update_firmware(duthost, fw_image): | ||
| return bmc_host_api(duthost, 'update_firmware', fw_image) | ||
|
|
||
|
|
||
| def request_bmc_reset(duthost): | ||
| return bmc_host_api(duthost, '_request_bmc_reset') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that all products will have to use "0penBmcTempPass!" ? In some cases, the OS could be not OpenBMC, so the password should be something standard.