Skip to content

Commit 7b848ab

Browse files
[Build] Fix the build unstalbe issue caused by the kvm not ready (#12180) (#12354)
Why I did it Fix the build unstable issue caused by the kvm 9000 port is not ready to use in 2 seconds. 2022-09-02T10:57:30.8122304Z + /usr/bin/kvm -m 8192 -name onie -boot order=cd,once=d -cdrom target/files/bullseye/onie-recovery-x86_64-kvm_x86_64_4_asic-r0.iso -device e1000,netdev=onienet -netdev user,id=onienet,hostfwd=:0.0.0.0:3041-:22 -vnc 0.0.0.0:0 -vga std -drive file=target/sonic-6asic-vs.img,media=disk,if=virtio,index=0 -drive file=./sonic-installer.img,if=virtio,index=1 -serial telnet:127.0.0.1:9000,server 2022-09-02T10:57:30.8123378Z + sleep 2.0 2022-09-02T10:57:30.8123889Z + '[' -d /proc/284923 ']' 2022-09-02T10:57:30.8124528Z + echo 'to kill kvm: sudo kill 284923' 2022-09-02T10:57:30.8124994Z to kill kvm: sudo kill 284923 2022-09-02T10:57:30.8125362Z + ./install_sonic.py 2022-09-02T10:57:30.8125720Z Trying 127.0.0.1... 2022-09-02T10:57:30.8126041Z telnet: Unable to connect to remote host: Connection refused How I did it Waiting more time until the tcp port 9000 is ready, waiting for 60 seconds in maximum. Co-authored-by: xumia <[email protected]>
1 parent 54b0b8b commit 7b848ab

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

scripts/build_kvm_image.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ prepare_installer_disk()
4848
umount $tmpdir
4949
}
5050

51+
wait_kvm_ready()
52+
{
53+
local count=30
54+
local waiting_in_seconds=2.0
55+
for ((i=1; i<=$count; i++)); do
56+
sleep $waiting_in_seconds
57+
echo "$(date) [$i/$count] waiting for the port $KVM_PORT ready"
58+
if netstat -l | grep -q ":$KVM_PORT"; then
59+
break
60+
fi
61+
done
62+
}
63+
5164
create_disk
5265
prepare_installer_disk
5366

@@ -78,7 +91,7 @@ trap on_error ERR
7891

7992
kvm_pid=$!
8093

81-
sleep 2.0
94+
wait_kvm_ready
8295

8396
[ -d "/proc/$kvm_pid" ] || {
8497
echo "ERROR: kvm died."

0 commit comments

Comments
 (0)