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

Remove the rw folder from the image after installing in KVM #8746

Merged
merged 4 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 6 additions & 7 deletions check_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@ def main():
raise
time.sleep(1)

# select ONIE embed
# select default SONiC Image
p.expect(grub_selection)
p.sendline(KEY_DOWN)
p.sendline()

# install sonic image
# bootup sonic image
while True:
i = p.expect([login_prompt, passwd_prompt, grub_selection, cmd_prompt])
i = p.expect([login_prompt, passwd_prompt, 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

Expand All @@ -64,6 +61,8 @@ def main():
p.expect([cmd_prompt])
p.sendline('show ip bgp sum')
p.expect([cmd_prompt])
p.sendline('sudo rm -r /host/image-*/rw/')
saiarcot895 marked this conversation as resolved.
Show resolved Hide resolved
p.expect([cmd_prompt])
p.sendline('sync')
p.expect([cmd_prompt])

Expand Down
49 changes: 49 additions & 0 deletions install_sonic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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('-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'

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)

# select ONIE install
p.expect(['ONIE: Install OS'])
p.expect([grub_selection])
p.sendline()

# wait for grub, and exit
p.expect([grub_selection])


if __name__ == '__main__':
main()
30 changes: 30 additions & 0 deletions scripts/build_kvm_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ kvm_log=$(mktemp)
trap on_exit EXIT
trap on_error ERR

echo "Installing SONiC"

/usr/bin/kvm -m $MEM \
-name "onie" \
-boot "order=cd,once=d" -cdrom "$ONIE_RECOVERY_ISO" \
Expand All @@ -90,6 +92,34 @@ sleep 2.0

echo "to kill kvm: sudo kill $kvm_pid"

./install_sonic.py

kill $kvm_pid

echo "Booting up SONiC"

/usr/bin/kvm -m $MEM \
-name "onie" \
-device e1000,netdev=onienet \
-netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 \
-vnc 0.0.0.0:0 \
-vga std \
-snapshot \
-drive file=$DISK,media=disk,if=virtio,index=0 \
-serial telnet:127.0.0.1:$KVM_PORT,server > $kvm_log 2>&1 &

kvm_pid=$!

sleep 2.0

[ -d "/proc/$kvm_pid" ] || {
echo "ERROR: kvm died."
cat $kvm_log
exit 1
}

echo "to kill kvm: sudo kill $kvm_pid"

./check_install.py -u $SONIC_USERNAME -P $PASSWD -p $KVM_PORT

kill $kvm_pid
Expand Down