Skip to content

Commit fb3143c

Browse files
committed
net: fix race condition in get_ip_from_vm_or_virt_handler_pod
The function read vm.vmi.interfaces[0]["ipAddresses"] once without waiting. With Fedora 43 the guest agent reports IPs slower than Fedora 41, so ipAddresses is still None right after AgentConnected becomes True, causing TypeError on iteration. Delegate the VM branch to lookup_iface_status_ip which polls the VMI with a watcher until IPs are reported. Signed-off-by: Sergei Volkov <sevolkov@redhat.com> Assisted-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0e936a9 commit fb3143c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

utilities/network.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import utilities.infra
3030
from libs.net.ip import ICMP_HEADER_SIZE, ip_header_size
31-
from libs.net.vmspec import VMInterfaceStatusNotFoundError
31+
from libs.net.vmspec import IpNotFound, VMInterfaceStatusNotFoundError, lookup_iface_status_ip
3232
from utilities.constants import (
3333
ACTIVE_BACKUP,
3434
FLAT_OVERLAY_STR,
@@ -753,10 +753,15 @@ def get_ip_from_vm_or_virt_handler_pod(family, vm=None, virt_handler_pod=None):
753753
raise ValueError("must send VM or virt-handler pod")
754754

755755
if vm:
756-
addr_list = vm.vmi.interfaces[0]["ipAddresses"]
757-
else:
758-
addr_list = [ip_addr["ip"] for ip_addr in virt_handler_pod.instance.status.podIPs]
756+
iface_name = vm.vmi.interfaces[0]["name"]
757+
ip_family = 4 if family == IPV4_STR else 6
758+
try:
759+
ip = lookup_iface_status_ip(vm=vm, iface_name=iface_name, ip_family=ip_family)
760+
except IpNotFound:
761+
return None
762+
return str(ip) if ip else None
759763

764+
addr_list = [ip_addr["ip"] for ip_addr in virt_handler_pod.instance.status.podIPs]
760765
ip_list = [ip for ip in addr_list if get_valid_ip_address(dst_ip=ip, family=family)]
761766
return ip_list[0] if ip_list else None
762767

0 commit comments

Comments
 (0)