Skip to content
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
merged 8 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions scripts/dpu_tty.py
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)
Copy link
Collaborator

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.

    parser.add_argument('-n', '--name', type=str, required=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

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())
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
'scripts/decode-syseeprom',
'scripts/dropcheck',
'scripts/disk_check.py',
'scripts/dpu_tty.py',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rename the application to dpu-tty? To make the user experience more convenient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

'scripts/dropconfig',
'scripts/dropstat',
'scripts/dualtor_neighbor_check.py',
Expand Down
Loading