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

tests/serial-console-connection: add timeout (default to 3min) #283

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Changes from all 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
64 changes: 41 additions & 23 deletions tests/serial-console-connection
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
#!/usr/bin/env python
import argparse
import pexpect
import serial
import sys
import time
from pexpect import fdpexpect, TIMEOUT

parser = argparse.ArgumentParser(description='Connect to serial console ' +
'to execute stuff')
parser.add_argument('--port', required=True,
help='serial console device to connect ' +
'to (e.g. /dev/pts/X)')
parser.add_argument('--hostname', default="buster",
help='hostname of the system for login process ' +
'(default: buster)')
parser.add_argument('--user', default="root",
help='user name to use for login (default: root)')
parser.add_argument('--password', default="grml",
help='password for login (default: grml)')
parser.add_argument('--tries', default="12", type=int,
help='Number of retries for finding the login prompt')
parser.add_argument('--poweroff', action="store_true", default=False,
help='send "poweroff" command after all other commands')
parser.add_argument('command', nargs='+',
help='command to execute after logging in')

from pexpect import fdpexpect

parser = argparse.ArgumentParser(
description="Connect to serial console to execute stuff",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
"--port",
required=True,
help="serial console device to connect " + "to (e.g. /dev/pts/X)",
)
parser.add_argument(
"--hostname", default="buster", help="hostname of the system for login process"
)
parser.add_argument("--user", default="root", help="user name to use for login")
parser.add_argument("--password", default="grml", help="password for login")
parser.add_argument(
"--timeout",
default="180",
type=int,
help="Maximum time for finding the login prompt, in seconds",
)
parser.add_argument(
"--tries",
default="12",
type=int,
help="Number of retries for finding the login prompt",
)
parser.add_argument(
"--poweroff",
action="store_true",
default=False,
help='send "poweroff" command after all other commands',
)
parser.add_argument("command", nargs="+", help="command to execute after logging in")


def print_ser_lines(ser):
Expand Down Expand Up @@ -74,15 +87,19 @@ def main():
ser.flushOutput()

success = False
ts_start = time.time()
for i in range(args.tries):
try:
print("Logging into %s via serial console [try %s]" % (port, i))
login(ser, hostname, user, password)
success = True
break
except Exception as except_inst:
print("Login failure (try %s):" % (i, ), except_inst, file=sys.stderr)
print("Login failure (try %s):" % (i,), except_inst, file=sys.stderr)
time.sleep(5)
if time.time() - ts_start > args.timeout:
print("Timeout reached waiting for login prompt", file=sys.stderr)
break

if success:
write_ser_line(ser, "")
Expand All @@ -101,5 +118,6 @@ def main():
if not success:
sys.exit(1)


if __name__ == "__main__":
main()
Loading