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

[release-4.18] USHIFT-5435: Handle DUID for ipv6 CI tests #4594

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions scripts/devenv-builder/manage-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ SSH_PASSWORD_OPTS="-o PubkeyAuthentication=no -o PreferredAuthentications=passwo

# Show the IP address of the VM
function get_ip {
sudo virsh domifaddr "$1" \
| grep ipv \
| awk '{print $4}' \
| cut -f1 -d/
# To avoid stale DHCP leases test each of the IP addresses reported by
# domifaddr. Include it only if the VM responds to a ping.
# In order to have a predictable output, list ipv4 first and then ipv6.
for ipv in ipv4 ipv6; do
iplist=$(sudo virsh domifaddr "$1" | grep "${ipv}" | awk '{print $4}' | cut -f1 -d/ || true)
for ip in ${iplist}; do
if ping -c 1 -W 1 "${ip}" &> /dev/null; then
echo "${ip}"
fi
done
done
}

# Use the RHEL version and other settings to build a unique VM name
Expand Down
7 changes: 6 additions & 1 deletion test/bin/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,19 @@ function get_vm_ip {
local -r start=$(date +%s)
local ip
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
while [ "${ip}" = "" ]; do
while true; do
now=$(date +%s)
if [ $(( now - start )) -ge ${VM_BOOT_TIMEOUT} ]; then
echo "Timed out while waiting for IP retrieval"
exit 1
fi
sleep 1
# Try pinging the IP address to avoid stale DHCP leases that would falsely
# return as the current IP for the VM.
ip=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
if ping -c 1 -W 1 "${ip}" &> /dev/null; then
break
fi
done
echo "${ip}"
}
Expand Down
21 changes: 21 additions & 0 deletions test/kickstart-templates/includes/post-network.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,24 @@ find /etc/NetworkManager -name '*.nmconnection' -print0 | while IFS= read -r -d
sed -i 's/method=.*/method=auto/g' "${file}"
fi
done

# IPv6 only feature. An IPv6 VM will use DHCPv6 to get an IP address. To identify itself to a DHCP
# server it uses something called DHCP Unique Identifier (DUID), and based on that the DHCP server
# will issue a lease for that DUID and MAC address. When the system boots into anaconda to install
# the OS with kickstart files, the DUID is automatically generated. After the system boots into the
# OS a new DUID may be generated, causing DHCP to identify the VM as a new system, thus allocating
# a new IP address. In order to avoid this, the DUID generated during the installation is saved and
# configured in NetworkManager to use it when the system boots into the OS.
# The DUID is unique per host, and is extracted from the DHCP6 options of the active connections
# from NetworkManager.
DUID=$(nmcli con show --active | \
awk '{print $1}' | \
grep -v NAME | \
xargs nmcli --fields DHCP6.OPTION con show | \
grep dhcp6_client_id | \
awk '{print $4}' | \
uniq)
if [ -n "$DUID" ]; then
mkdir -p /etc/NetworkManager/conf.d/
echo -e "[connection]\nipv6.dhcp-duid=$DUID" > /etc/NetworkManager/conf.d/dhcp-client.conf
fi
3 changes: 2 additions & 1 deletion test/scenarios-bootc/presubmits/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ scenario_remove_vms() {

scenario_run_tests() {
local -r vmname=$(full_vm_name host1)
# Valid IP addresses are the first two entries returned by manage-vm script.
local -r vm_ip1=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -1)
local -r vm_ip2=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | tail -1)
local -r vm_ip2=$("${ROOTDIR}/scripts/devenv-builder/manage-vm.sh" ip -n "${vmname}" | head -2 | tail -1)

run_tests host1 \
--variable "USHIFT_HOST_IP1:${vm_ip1}" \
Expand Down