Change in vdsm[master]: netinfo: dns: more robust parsing of resolv.conf
fromani at redhat.com
fromani at redhat.com
Wed Mar 9 16:15:20 UTC 2016
Francesco Romani has uploaded a new change for review.
Change subject: netinfo: dns: more robust parsing of resolv.conf
......................................................................
netinfo: dns: more robust parsing of resolv.conf
The current code which parses /etc/resolv.conf is not
very robust. This code should handle manual edit
of such file (discouraged, but possible).
In particular, it should skip silently empty lines;
current code breaks in this case.
I noticed this issue randomly while running Vdsm
on some host of mine, where I routinely edit
/etc/resolv.conf (et. al.)
Change-Id: Iff7cafb643c9191d9a2f6abbcfec0407e6860e07
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M lib/vdsm/netinfo/dns.py
M tests/network/netinfo_test.py
2 files changed, 21 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/58/54558/1
diff --git a/lib/vdsm/netinfo/dns.py b/lib/vdsm/netinfo/dns.py
index 5ab1f57..e22714e 100644
--- a/lib/vdsm/netinfo/dns.py
+++ b/lib/vdsm/netinfo/dns.py
@@ -32,6 +32,8 @@
dnss = []
for line in file_text.splitlines():
words = line.strip().split()
+ if len(words) < 2:
+ continue
if words[0] == 'nameserver':
dnss.append(words[1])
return dnss
diff --git a/tests/network/netinfo_test.py b/tests/network/netinfo_test.py
index 8da77a2..e9e3301 100644
--- a/tests/network/netinfo_test.py
+++ b/tests/network/netinfo_test.py
@@ -34,6 +34,7 @@
from modprobe import RequireBondingMod
from monkeypatch import MonkeyPatch, MonkeyPatchScope
from .nettestlib import dummy_device, veth_pair
+from testlib import permutations, expandPermutations
from testlib import VdsmTestCase as TestCaseBase, namedTemporaryDir
from testValidation import ValidateRunningAsRoot
from testValidation import brokentest
@@ -42,24 +43,31 @@
ETHTOOL_SPEEDS = set([10, 100, 1000, 2500, 10000])
+RESOLV_CONF = (
+ '# Generated by NetworkManager\n'
+ 'search example.com company.net\n'
+ 'domain example.com\n'
+ 'nameserver 192.168.0.100\n'
+ 'nameserver 8.8.8.8\n'
+ 'nameserver 8.8.4.4\n'
+)
+
+ at expandPermutations
class TestNetinfo(TestCaseBase):
- def testGetHostNameservers(self):
- RESOLV_CONF = (
- '# Generated by NetworkManager\n'
- 'search example.com company.net\n'
- 'domain example.com\n'
- 'nameserver 192.168.0.100\n'
- 'nameserver 8.8.8.8\n'
- 'nameserver 8.8.4.4\n'
- )
- dnss = ['192.168.0.100', '8.8.8.8', '8.8.4.4']
+ @permutations([
+ # content, dnss
+ # FIXME: this works, but the output is ugly
+ [RESOLV_CONF, ['192.168.0.100', '8.8.8.8', '8.8.4.4']],
+ [RESOLV_CONF + '\n', ['192.168.0.100', '8.8.8.8', '8.8.4.4']],
+ ])
+ def testGetHostNameservers(self, content, dnss):
with namedTemporaryDir() as temp_dir:
file_path = os.path.join(temp_dir, 'resolv.conf')
with MonkeyPatchScope([(dns, 'DNS_CONF_FILE', file_path)]):
with open(file_path, 'w') as file_object:
- file_object.write(RESOLV_CONF)
+ file_object.write(content)
self.assertEqual(
dns.get_host_nameservers(), dnss)
--
To view, visit https://gerrit.ovirt.org/54558
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iff7cafb643c9191d9a2f6abbcfec0407e6860e07
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>
More information about the vdsm-patches
mailing list