-
Notifications
You must be signed in to change notification settings - Fork 658
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
[dpu_tty]: Add a DPU TTY console utility #3535
Merged
+159
−1
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
daec93f
[dpu_tty]: Add a DPU TTY console utility
wenchungw c993bfb
Correct SA errors
wenchungw a40adfc
Correct SA errors
wenchungw a724849
Correct SA error
wenchungw bfec7a9
Fix a SA error
wenchungw d2398bc
Merge branch 'sonic-net:master' into dpu_tty
wenchungw 9e3b184
Update Command-Reference.md
wenchungw 31840f3
Address review comments
wenchungw 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 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,75 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright (c) 2024 Cisco Systems, Inc. | ||
# | ||
|
||
import argparse | ||
import json | ||
import os | ||
import subprocess | ||
from sonic_py_common import device_info | ||
|
||
UART_CON = '/usr/bin/picocom' | ||
|
||
|
||
def get_dpu_tty(dpu_id, tty, baud): | ||
|
||
platform = device_info.get_platform() | ||
if not platform: | ||
print("No platform") | ||
return None | ||
|
||
# Get platform path. | ||
platform_path = device_info.get_path_to_platform_dir() | ||
|
||
if os.path.isfile(os.path.join(platform_path, device_info.PLATFORM_JSON_FILE)): | ||
json_file = os.path.join(platform_path, device_info.PLATFORM_JSON_FILE) | ||
|
||
try: | ||
with open(json_file, 'r') as file: | ||
platform_data = json.load(file) | ||
except (json.JSONDecodeError, IOError, TypeError, ValueError): | ||
print("No platform.json") | ||
return None | ||
|
||
dpus = platform_data.get('DPUS', None) | ||
if dpus is None: | ||
print("No DPUs in platform.json") | ||
return None | ||
|
||
dpu = 'dpu' + str(dpu_id) | ||
|
||
if tty is None: | ||
dev = dpus[dpu]["serial-console"]["device"] | ||
else: | ||
# overwrite tty device in platform.json | ||
dev = tty | ||
|
||
if baud is None: | ||
baud = dpus[dpu]["serial-console"]["baud-rate"] | ||
return dev, baud | ||
|
||
|
||
def main(): | ||
|
||
parser = argparse.ArgumentParser(description='DPU TTY Console Utility') | ||
parser.add_argument('-s', '--slot', type=int, required=True) | ||
parser.add_argument('-t', '--tty') | ||
parser.add_argument('-b', '--baud', type=int) | ||
args = parser.parse_args() | ||
|
||
dpu_tty, dpu_baud = get_dpu_tty(args.slot, args.tty, args.baud) | ||
# Use UART console utility for error checking of dpu_tty and dpu_baud. | ||
|
||
p = subprocess.run([UART_CON, '-b', dpu_baud, '/dev/%s' % dpu_tty]) | ||
if p.returncode: | ||
print('{} failed'.format(p.args)) | ||
if p.stdout: | ||
print(p.stdout) | ||
if p.stderr: | ||
print(p.stderr) | ||
return p.returncode | ||
|
||
|
||
if __name__ == "__main__": | ||
exit(main()) |
This file contains 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 |
---|---|---|
|
@@ -120,6 +120,7 @@ | |
'scripts/decode-syseeprom', | ||
'scripts/dropcheck', | ||
'scripts/disk_check.py', | ||
'scripts/dpu_tty.py', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please rename the application to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
'scripts/dropconfig', | ||
'scripts/dropstat', | ||
'scripts/dualtor_neighbor_check.py', | ||
|
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.
Why is the slot used instead of the DPU name?
I suggest using the DPU name (dpu0, dpu1, dpuX) in all places to refer to the DPU. This will remove any future confusion.
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.
Changed.