Skip to content

Commit b31f4a8

Browse files
Merge pull request #4571 from pacevedom/USHIFT-5402
USHIFT-5402: Test harness VM IP address robustness
2 parents 4df75d3 + 6c42350 commit b31f4a8

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

scripts/devenv-builder/manage-vm.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ SSH_PASSWORD_OPTS="-o PubkeyAuthentication=no -o PreferredAuthentications=passwo
2121

2222
# Show the IP address of the VM
2323
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
2835
}
2936

3037
# Use the RHEL version and other settings to build a unique VM name

test/bin/scenario.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,19 @@ function get_vm_ip {
339339
local -r start=$(date +%s)
340340
local ip
341341
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
342-
while [ "${ip}" = "" ]; do
342+
while true; do
343343
now=$(date +%s)
344344
if [ $(( now - start )) -ge ${VM_BOOT_TIMEOUT} ]; then
345345
echo "Timed out while waiting for IP retrieval"
346346
exit 1
347347
fi
348348
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.
349351
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
350355
done
351356
echo "${ip}"
352357
}

test/scenarios-bootc/presubmits/[email protected]

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ scenario_remove_vms() {
1313

1414
scenario_run_tests() {
1515
local -r vmname=$(full_vm_name host1)
16+
# Valid IP addresses are the first two entries returned by manage-vm script.
1617
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)
1819

1920
run_tests host1 \
2021
--variable "USHIFT_HOST_IP1:${vm_ip1}" \

0 commit comments

Comments
 (0)