Skip to content

Commit

Permalink
Obtaing the ip address of the guest and update address cache
Browse files Browse the repository at this point in the history
Few of the times it is seen that the ip address is not being fetch and the avocado runs were failed with error "ERROR: Failures occurred while postprocess:\n\n: Guest virt-tests-vm1 dmesg verification failed: Login timeout expired (output: 'exceeded 240 s timeout, last failure: No ipv4 DHCP lease for MAC aa:bb:cc:dd:ee:ff') "

To handle this error the patch has been sent. The patch helps in obtaining ip address of the guest using "virsh-net-dhcp-leases default" command. If the guest mac address is found in the command output, the mac ipv4 address is obatined and updated in the address.cache

Signed-off-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com>
  • Loading branch information
TasmiyaNalatwad committed Sep 18, 2024
1 parent 71b094f commit f04a5f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions virttest/libvirt_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
test_setup,
utils_logfile,
utils_misc,
utils_net,
utils_package,
utils_selinux,
virsh,
Expand Down Expand Up @@ -378,6 +379,15 @@ def backup_xml(self, active=False):
LOG.error("Failed to backup xml file:\n%s", detail)
return ""

def _get_address(self, index=0, ip_version="ipv4", session=None, timeout=60.0):
try:
return super()._get_address(index, ip_version, session, timeout)
except virt_vm.VMIPAddressMissingError:
mac = self.get_mac_address(index).lower()
ipaddr = utils_net.obtain_guest_ip_from_dhcp_leases(mac)
self.address_cache[mac] = ipaddr
return ipaddr

def clone(
self,
name=None,
Expand Down
19 changes: 19 additions & 0 deletions virttest/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
utils_misc,
utils_package,
utils_selinux,
virsh,
)
from virttest.remote import RemoteRunner
from virttest.staging import service, utils_memory
Expand Down Expand Up @@ -4889,3 +4890,21 @@ def check_class_rules(ifname, rule_id, bandwidth, expect_none=False):
stacktrace.log_exc_info(sys.exc_info())
return False
return True


def obtain_guest_ip_from_dhcp_leases(mac):
"""
Obtaining the guest ip address from virsh-net-dhcp-leases command
:param: Mac address of the guest
:return: return ip-address if found for given mac in the
virsh-net-dhcp-leases default table, else return None
"""
output = virsh.net_dhcp_leases("default")
lines = output.stdout.splitlines()
for line in lines:
if mac in line:
parts = line.split()
for part in parts:
if "/" in part:
return part.split("/")[0]
return None

0 comments on commit f04a5f8

Please sign in to comment.