File tree Expand file tree Collapse file tree 3 files changed +19
-6
lines changed
scenarios-bootc/presubmits Expand file tree Collapse file tree 3 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,17 @@ SSH_PASSWORD_OPTS="-o PubkeyAuthentication=no -o PreferredAuthentications=passwo
21
21
22
22
# Show the IP address of the VM
23
23
function get_ip {
24
- sudo virsh domifaddr " $1 " \
25
- | grep ipv \
26
- | awk ' {print $4}' \
27
- | cut -f1 -d/
24
+ # To avoid stale DHCP leases test each of the IP addresses reported by
25
+ # domifaddr. Include it only if the VM responds to a ping.
26
+ # In order to have a predictable output, list ipv4 first and then ipv6.
27
+ for ipv in ipv4 ipv6; do
28
+ iplist=$( sudo virsh domifaddr " $1 " | grep " ${ipv} " | awk ' {print $4}' | cut -f1 -d/ || true)
29
+ for ip in ${iplist} ; do
30
+ if ping -c 1 -W 1 " ${ip} " & > /dev/null; then
31
+ echo " ${ip} "
32
+ fi
33
+ done
34
+ done
28
35
}
29
36
30
37
# Use the RHEL version and other settings to build a unique VM name
Original file line number Diff line number Diff line change @@ -339,14 +339,19 @@ function get_vm_ip {
339
339
local -r start=$( date +%s)
340
340
local ip
341
341
ip=$( " ${ROOTDIR} /scripts/devenv-builder/manage-vm.sh" ip -n " ${vmname} " | head -1)
342
- while [ " ${ip} " = " " ] ; do
342
+ while true ; do
343
343
now=$( date +%s)
344
344
if [ $(( now - start )) -ge ${VM_BOOT_TIMEOUT} ]; then
345
345
echo " Timed out while waiting for IP retrieval"
346
346
exit 1
347
347
fi
348
348
sleep 1
349
+ # Try pinging the IP address to avoid stale DHCP leases that would falsely
350
+ # return as the current IP for the VM.
349
351
ip=$( " ${ROOTDIR} /scripts/devenv-builder/manage-vm.sh" ip -n " ${vmname} " | head -1)
352
+ if ping -c 1 -W 1 " ${ip} " & > /dev/null; then
353
+ break
354
+ fi
350
355
done
351
356
echo " ${ip} "
352
357
}
Original file line number Diff line number Diff line change @@ -13,8 +13,9 @@ scenario_remove_vms() {
13
13
14
14
scenario_run_tests () {
15
15
local -r vmname=$( full_vm_name host1)
16
+ # Valid IP addresses are the first two entries returned by manage-vm script.
16
17
local -r vm_ip1=$( " ${ROOTDIR} /scripts/devenv-builder/manage-vm.sh" ip -n " ${vmname} " | head -1)
17
- local -r vm_ip2=$( " ${ROOTDIR} /scripts/devenv-builder/manage-vm.sh" ip -n " ${vmname} " | tail -1)
18
+ local -r vm_ip2=$( " ${ROOTDIR} /scripts/devenv-builder/manage-vm.sh" ip -n " ${vmname} " | head -2 | tail -1)
18
19
19
20
run_tests host1 \
20
21
--variable " USHIFT_HOST_IP1:${vm_ip1} " \
You can’t perform that action at this time.
0 commit comments