|
|
ef3f20 |
From c4df9de80715ff76c39faea00d27acdb8a75aac7 Mon Sep 17 00:00:00 2001
|
|
|
ef3f20 |
From: Lars Kellogg-Stedman <lars@redhat.com>
|
|
|
ef3f20 |
Date: Sat, 4 Mar 2017 17:07:16 -0500
|
|
|
ef3f20 |
Subject: [PATCH] net: do not raise exception for > 3 nameservers
|
|
|
ef3f20 |
|
|
|
ef3f20 |
log a warning rather than raising ValueError if we see more than three
|
|
|
ef3f20 |
nameserver addresses.
|
|
|
ef3f20 |
|
|
|
ef3f20 |
LP: #1670052
|
|
|
ef3f20 |
(cherry picked from commit 657fd40f9ee692a817ec4614cd0d6cb0539ffabf)
|
|
|
ef3f20 |
---
|
|
|
ef3f20 |
cloudinit/distros/parsers/resolv_conf.py | 11 +++++++----
|
|
|
ef3f20 |
tests/unittests/test_distros/test_resolv.py | 2 +-
|
|
|
ef3f20 |
2 files changed, 8 insertions(+), 5 deletions(-)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
diff --git a/cloudinit/distros/parsers/resolv_conf.py b/cloudinit/distros/parsers/resolv_conf.py
|
|
|
ef3f20 |
index ff6ee30..d1f8a04 100644
|
|
|
ef3f20 |
--- a/cloudinit/distros/parsers/resolv_conf.py
|
|
|
ef3f20 |
+++ b/cloudinit/distros/parsers/resolv_conf.py
|
|
|
ef3f20 |
@@ -6,9 +6,11 @@
|
|
|
ef3f20 |
|
|
|
ef3f20 |
from six import StringIO
|
|
|
ef3f20 |
|
|
|
ef3f20 |
+from cloudinit.distros.parsers import chop_comment
|
|
|
ef3f20 |
+from cloudinit import log as logging
|
|
|
ef3f20 |
from cloudinit import util
|
|
|
ef3f20 |
|
|
|
ef3f20 |
-from cloudinit.distros.parsers import chop_comment
|
|
|
ef3f20 |
+LOG = logging.getLogger(__name__)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
|
|
|
ef3f20 |
# See: man resolv.conf
|
|
|
ef3f20 |
@@ -79,9 +81,10 @@ class ResolvConf(object):
|
|
|
ef3f20 |
if len(new_ns) == len(current_ns):
|
|
|
ef3f20 |
return current_ns
|
|
|
ef3f20 |
if len(current_ns) >= 3:
|
|
|
ef3f20 |
- # Hard restriction on only 3 name servers
|
|
|
ef3f20 |
- raise ValueError(("Adding %r would go beyond the "
|
|
|
ef3f20 |
- "'3' maximum name servers") % (ns))
|
|
|
ef3f20 |
+ LOG.warn("ignoring nameserver %r: adding would "
|
|
|
ef3f20 |
+ "exceed the maximum of "
|
|
|
ef3f20 |
+ "'3' name servers (see resolv.conf(5))" % (ns))
|
|
|
ef3f20 |
+ return current_ns[:3]
|
|
|
ef3f20 |
self._remove_option('nameserver')
|
|
|
ef3f20 |
for n in new_ns:
|
|
|
ef3f20 |
self._contents.append(('option', ['nameserver', n, '']))
|
|
|
ef3f20 |
diff --git a/tests/unittests/test_distros/test_resolv.py b/tests/unittests/test_distros/test_resolv.py
|
|
|
ef3f20 |
index 6b535a9..c9d0347 100644
|
|
|
ef3f20 |
--- a/tests/unittests/test_distros/test_resolv.py
|
|
|
ef3f20 |
+++ b/tests/unittests/test_distros/test_resolv.py
|
|
|
ef3f20 |
@@ -46,7 +46,7 @@ class TestResolvHelper(TestCase):
|
|
|
ef3f20 |
self.assertNotIn('10.3', rp.nameservers)
|
|
|
ef3f20 |
self.assertEqual(len(rp.nameservers), 3)
|
|
|
ef3f20 |
rp.add_nameserver('10.2')
|
|
|
ef3f20 |
- self.assertRaises(ValueError, rp.add_nameserver, '10.3')
|
|
|
ef3f20 |
+ rp.add_nameserver('10.3')
|
|
|
ef3f20 |
self.assertNotIn('10.3', rp.nameservers)
|
|
|
ef3f20 |
|
|
|
ef3f20 |
def test_search_domains(self):
|