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