sonic-buildimage/check_install.py
Joe LeVeque 905a5127bb
[Python] Align files in root dir, dockers/ and files/ with PEP8 standards (#6109)
**- Why I did it**

Align style with slightly modified PEP8 standards (extend maximum line length to 120 chars). This will also help in the transition to Python 3, where it is more strict about whitespace, plus it helps unify style among the SONiC codebase. Will tackle other directories in separate PRs.

**- How I did it**

Using `autopep8 --in-place --max-line-length 120` and some manual tweaks.
2020-12-03 15:57:50 -08:00

71 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
import argparse
import pexpect
import sys
import time
def main():
parser = argparse.ArgumentParser(description='test_login cmdline parser')
parser.add_argument('-u', default="admin", help='login user name')
parser.add_argument('-P', default="YourPaSsWoRd", help='login password')
parser.add_argument('-p', type=int, default=9000, help='local port')
args = parser.parse_args()
KEY_UP = '\x1b[A'
KEY_DOWN = '\x1b[B'
KEY_RIGHT = '\x1b[C'
KEY_LEFT = '\x1b[D'
login_prompt = 'sonic login:'
passwd_prompt = 'Password:'
cmd_prompt = "{}@sonic:~\$ $".format(args.u)
grub_selection = "The highlighted entry will be executed"
i = 0
while True:
try:
p = pexpect.spawn("telnet 127.0.0.1 {}".format(args.p), timeout=600, logfile=sys.stdout, encoding='utf-8')
break
except Exception as e:
print(str(e))
i += 1
if i == 10:
raise
time.sleep(1)
# select ONIE embed
p.expect(grub_selection)
p.sendline(KEY_DOWN)
# install sonic image
while True:
i = p.expect([login_prompt, passwd_prompt, grub_selection, cmd_prompt])
if i == 0:
# send user name
p.sendline(args.u)
elif i == 1:
# send password
p.sendline(args.P)
elif i == 2:
# select onie install
p.sendline()
else:
break
# check version
time.sleep(5)
p.sendline('show version')
p.expect([cmd_prompt])
p.sendline('show ip bgp sum')
p.expect([cmd_prompt])
p.sendline('sync')
p.expect([cmd_prompt])
if __name__ == '__main__':
main()