2020-11-11 12:18:48 -06:00
|
|
|
#!/usr/bin/env python3
|
2018-11-21 00:32:40 -06:00
|
|
|
|
|
|
|
import argparse
|
2020-11-11 12:18:48 -06:00
|
|
|
import pexpect
|
2018-11-21 00:32:40 -06:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2020-11-11 12:18:48 -06:00
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
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()
|
|
|
|
|
|
|
|
login_prompt = 'sonic login:'
|
|
|
|
passwd_prompt = 'Password:'
|
2020-11-11 12:18:48 -06:00
|
|
|
cmd_prompt = "{}@sonic:~\$ $".format(args.u)
|
2018-11-21 00:32:40 -06:00
|
|
|
grub_selection = "The highlighted entry will be executed"
|
2022-08-29 20:19:58 -05:00
|
|
|
firsttime_prompt = 'firsttime_exit'
|
2018-11-21 00:32:40 -06:00
|
|
|
|
2019-12-03 15:54:57 -06:00
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
try:
|
2020-11-11 12:18:48 -06:00
|
|
|
p = pexpect.spawn("telnet 127.0.0.1 {}".format(args.p), timeout=600, logfile=sys.stdout, encoding='utf-8')
|
2019-12-03 15:54:57 -06:00
|
|
|
break
|
|
|
|
except Exception as e:
|
2020-11-11 12:18:48 -06:00
|
|
|
print(str(e))
|
2019-12-03 15:54:57 -06:00
|
|
|
i += 1
|
|
|
|
if i == 10:
|
|
|
|
raise
|
|
|
|
time.sleep(1)
|
2018-11-21 00:32:40 -06:00
|
|
|
|
Remove the rw folder from the image after installing in KVM (#8746)
* Remove the rw folder from the image after installing in KVM
When the image is installed from within KVM and then loaded, some files
(such as timer stamp files) are created as part of that bootup that then
get into the final image. This can cause some side effects, such as
systemd thinking that some persistent timers need to run because the
last trigger time got missed.
Therefore, at the end of the check_install.py script, remove the rw
folder so that it doesn't exist in the image, and that when this image
is started up in a KVM setup for the first time, it starts with a truly
clean slate.
Without this change, the issue seen was that for fstrim.timer, a stamp
file would be present in /var/lib/systemd/timers (and for other timers
that are marked as persistent). This would then cause fstrim.service to
get started immediately when starting a QEMU setup if the timer for that
service missed a trigger, and not wait 10 minutes after bootup. In the
case of fstrim.timer, that means if the image was started in QEMU after
next Monday, since that timer is scheduled to be triggered weekly.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
* Split installation of SONiC and test bootup into two separate scripts
Just removing the rw directory causes other issues, since the first boot
tasks no longer run since that file isn't present. Also, just recreating
that file doesn't completely help, because there are some files that are
moved from the /host folder into the base filesystem layer, and so are
no longer available.
Instead, split the installation of SONiC and doing the test bootup into
two separate scripts and two separate KVM instances. The first KVM
instance is the one currently being run, while the second one has the
`-snapshot` flag added in, which means any changes to the disk image
don't take effect.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
2021-12-10 15:13:35 -06:00
|
|
|
# select default SONiC Image
|
2018-11-21 00:32:40 -06:00
|
|
|
p.expect(grub_selection)
|
Remove the rw folder from the image after installing in KVM (#8746)
* Remove the rw folder from the image after installing in KVM
When the image is installed from within KVM and then loaded, some files
(such as timer stamp files) are created as part of that bootup that then
get into the final image. This can cause some side effects, such as
systemd thinking that some persistent timers need to run because the
last trigger time got missed.
Therefore, at the end of the check_install.py script, remove the rw
folder so that it doesn't exist in the image, and that when this image
is started up in a KVM setup for the first time, it starts with a truly
clean slate.
Without this change, the issue seen was that for fstrim.timer, a stamp
file would be present in /var/lib/systemd/timers (and for other timers
that are marked as persistent). This would then cause fstrim.service to
get started immediately when starting a QEMU setup if the timer for that
service missed a trigger, and not wait 10 minutes after bootup. In the
case of fstrim.timer, that means if the image was started in QEMU after
next Monday, since that timer is scheduled to be triggered weekly.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
* Split installation of SONiC and test bootup into two separate scripts
Just removing the rw directory causes other issues, since the first boot
tasks no longer run since that file isn't present. Also, just recreating
that file doesn't completely help, because there are some files that are
moved from the /host folder into the base filesystem layer, and so are
no longer available.
Instead, split the installation of SONiC and doing the test bootup into
two separate scripts and two separate KVM instances. The first KVM
instance is the one currently being run, while the second one has the
`-snapshot` flag added in, which means any changes to the disk image
don't take effect.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
2021-12-10 15:13:35 -06:00
|
|
|
p.sendline()
|
2018-11-21 00:32:40 -06:00
|
|
|
|
Remove the rw folder from the image after installing in KVM (#8746)
* Remove the rw folder from the image after installing in KVM
When the image is installed from within KVM and then loaded, some files
(such as timer stamp files) are created as part of that bootup that then
get into the final image. This can cause some side effects, such as
systemd thinking that some persistent timers need to run because the
last trigger time got missed.
Therefore, at the end of the check_install.py script, remove the rw
folder so that it doesn't exist in the image, and that when this image
is started up in a KVM setup for the first time, it starts with a truly
clean slate.
Without this change, the issue seen was that for fstrim.timer, a stamp
file would be present in /var/lib/systemd/timers (and for other timers
that are marked as persistent). This would then cause fstrim.service to
get started immediately when starting a QEMU setup if the timer for that
service missed a trigger, and not wait 10 minutes after bootup. In the
case of fstrim.timer, that means if the image was started in QEMU after
next Monday, since that timer is scheduled to be triggered weekly.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
* Split installation of SONiC and test bootup into two separate scripts
Just removing the rw directory causes other issues, since the first boot
tasks no longer run since that file isn't present. Also, just recreating
that file doesn't completely help, because there are some files that are
moved from the /host folder into the base filesystem layer, and so are
no longer available.
Instead, split the installation of SONiC and doing the test bootup into
two separate scripts and two separate KVM instances. The first KVM
instance is the one currently being run, while the second one has the
`-snapshot` flag added in, which means any changes to the disk image
don't take effect.
Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
2021-12-10 15:13:35 -06:00
|
|
|
# bootup sonic image
|
2018-11-21 00:32:40 -06:00
|
|
|
while True:
|
2022-08-29 20:19:58 -05:00
|
|
|
i = p.expect([login_prompt, passwd_prompt, firsttime_prompt, cmd_prompt])
|
2018-11-21 00:32:40 -06:00
|
|
|
if i == 0:
|
|
|
|
# send user name
|
|
|
|
p.sendline(args.u)
|
|
|
|
elif i == 1:
|
|
|
|
# send password
|
|
|
|
p.sendline(args.P)
|
2022-08-29 20:19:58 -05:00
|
|
|
elif i == 2:
|
|
|
|
# fix a login timeout issue, caused by the login_prompt message mixed with the output message of the rc.local
|
|
|
|
time.sleep(1)
|
|
|
|
p.sendline()
|
2018-11-21 00:32:40 -06:00
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
|
|
|
# check version
|
|
|
|
time.sleep(5)
|
2021-01-30 08:50:35 -06:00
|
|
|
p.sendline('uptime')
|
|
|
|
p.expect([cmd_prompt])
|
2018-11-21 00:32:40 -06:00
|
|
|
p.sendline('show version')
|
|
|
|
p.expect([cmd_prompt])
|
2018-11-22 14:09:21 -06:00
|
|
|
p.sendline('show ip bgp sum')
|
|
|
|
p.expect([cmd_prompt])
|
|
|
|
p.sendline('sync')
|
|
|
|
p.expect([cmd_prompt])
|
2018-11-21 00:32:40 -06:00
|
|
|
|
2020-12-03 17:57:50 -06:00
|
|
|
|
2018-11-21 00:32:40 -06:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|