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

[celestica] consutil to support customize tty device name #1155

Merged
merged 4 commits into from
Oct 13, 2020
Merged
Changes from 1 commit
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
21 changes: 20 additions & 1 deletion consutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
import subprocess
import sys
import os
from swsssdk import ConfigDBConnector
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
Expand All @@ -27,6 +28,11 @@
FLOW_KEY = "flow_control"
DEFAULT_BAUD = "9600"

PREV_REBOOT_CAUSE="/host/reboot-cause/"
sandycelestica marked this conversation as resolved.
Show resolved Hide resolved
DEVICE="/usr/share/sonic/device"
PLATFORM='/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform'
FILENAME="udevprefix.conf"

# QUIET == True => picocom will not output any messages, and pexpect will wait for console
# switch login or command line to let user interact with shell
# Downside: if console switch output ever does not match DEV_READY_MSG, program will think connection failed
Expand All @@ -37,6 +43,19 @@
DEV_READY_MSG = r"([Ll]ogin:|[Pp]assword:|[$>#])" # login prompt or command line prompt
TIMEOUT_SEC = 0.2


proc = subprocess.Popen(PLATFORM,stdout=subprocess.PIPE,shell=True,stderr=subprocess.STDOUT)
sandycelestica marked this conversation as resolved.
Show resolved Hide resolved
stdout = proc.communicate()[0]
proc.wait()
platform = stdout.rstrip('\n')
PLUGIN_PATH="/".join([DEVICE,platform,"plugins","udevprefix.conf"])
Blueve marked this conversation as resolved.
Show resolved Hide resolved

if os.path.exists(PLUGIN_PATH):
fp = open(PLUGIN_PATH,'r')
sandycelestica marked this conversation as resolved.
Show resolved Hide resolved
line=fp.readlines()
DEVICE_PREFIX="/dev/"+line[0]


# runs command, exit if stderr is written to, returns stdout otherwise
# input: cmd (str), output: output of cmd (str)
def run_command(cmd):
Expand Down Expand Up @@ -119,4 +138,4 @@ def getLine(target, deviceBool=False):
lineNumber = line[LINE_KEY]
targetLine = line

return targetLine if lineNumber else None
return targetLine if lineNumber else None