Wait couple of seconds for dns servers to be set in the guest

In test
tempest.scenario.test_network_basic_ops.TestNetworkBasicOps.test_subnet_details
there is renewal of the DHCP lease made to configure dns nameservers.
And sometimes this test is failing due to missing nameservers in the
/etc/resolv.conf file in the guest VM.
After analyzing logs from such failed jobs I think that the reason of
that may be race between getting dns nameservers from guest VM by test
and actually configuring it inside the guest vm.
So this patch proposes to add wait (5 seconds by default) for non empty
list of the dns nameservers returned from the guest VM. That should
avoid such failures of that test.

Closes-bug: #1914229
Change-Id: I093ae5c11f88cc29e91285ff674788de53645b4e
This commit is contained in:
Slawek Kaplonski 2021-07-23 13:18:05 +02:00
parent 3a05fab126
commit 126fe656a9
1 changed files with 14 additions and 1 deletions

View File

@ -108,7 +108,7 @@ class RemoteClient(remote_client.RemoteClient):
LOG.debug('(get_nic_name_by_ip) Command result: %s', nic)
return nic.strip().strip(":").split('@')[0].lower()
def get_dns_servers(self):
def _get_dns_servers(self):
cmd = 'cat /etc/resolv.conf'
resolve_file = self.exec_command(cmd).strip().split('\n')
entries = (l.split() for l in resolve_file)
@ -116,6 +116,19 @@ class RemoteClient(remote_client.RemoteClient):
if len(l) and l[0] == 'nameserver']
return dns_servers
def get_dns_servers(self, timeout=5):
start_time = int(time.time())
dns_servers = []
while True:
dns_servers = self._get_dns_servers()
if dns_servers:
break
LOG.debug("DNS Servers list empty.")
if int(time.time()) - start_time >= timeout:
LOG.debug("DNS Servers list empty after %s.", timeout)
break
return dns_servers
def _renew_lease_udhcpc(self, fixed_ip=None):
"""Renews DHCP lease via udhcpc client. """
file_path = '/var/run/udhcpc.'