From 126fe656a976b3f46a755e83ea9950f72815a87e Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Fri, 23 Jul 2021 13:18:05 +0200 Subject: [PATCH] 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 --- tempest/common/utils/linux/remote_client.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tempest/common/utils/linux/remote_client.py b/tempest/common/utils/linux/remote_client.py index b68a879a01..5d6e129d87 100644 --- a/tempest/common/utils/linux/remote_client.py +++ b/tempest/common/utils/linux/remote_client.py @@ -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.'