Skip to content

Commit

Permalink
passt:Update code of checking nameserver to fix error
Browse files Browse the repository at this point in the history
Remove irrelevant info such as "search" from output of resolv.conf
to avoid inconsistency of nameserver between host and vm.

Signed-off-by: Haijiao Zhao <[email protected]>
  • Loading branch information
chloerh committed Mar 3, 2025
1 parent 0145baa commit 596cfde
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions provider/virtual_network/passt.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,18 @@ def check_nameserver(session):
:param session: vm shell session instance
"""
get_cmd = 'cat /etc/resolv.conf|grep -vE "#|;"'
on_host = process.run(get_cmd, shell=True).stdout_text.strip().split()
on_vm = session.cmd_output(get_cmd).strip().split()
on_host = process.run(get_cmd, shell=True).stdout_text.strip()
on_vm = session.cmd_output(get_cmd).strip()
LOG.debug(f'Output on host:\n{on_host}\nOutput on vm:\n{on_vm}')
# remove zone index
on_host = [re.sub(r'%.*', '', x) for x in on_host]
on_vm = [re.sub(r'%.*', '', x) for x in on_vm]
on_host = [re.sub(r'%.*', '', x) for x in on_host.split()]
on_vm = [re.sub(r'%.*', '', x) for x in on_vm.split()]
# Remove irrelevant items such as "search"
on_host = set([(on_host[i], on_host[i + 1]) for i in range(len(on_host))
if on_host[i].lower() == 'nameserver'])
on_vm = set([(on_vm[i], on_vm[i + 1]) for i in range(len(on_vm))
if on_vm[i].lower() == 'nameserver'])
LOG.debug(f'On host:\n{on_host}\nOn vm:\n{on_vm}')
if on_host == on_vm:
LOG.debug(f'Nameserver on vm is consistent with host:\n{on_host}')
else:
Expand Down

0 comments on commit 596cfde

Please sign in to comment.