4975347
From 0dfe06ba4642fbf64c04b6a4e11400a94eb27a9f Mon Sep 17 00:00:00 2001
4975347
From: Major Hayden <major@mhtx.net>
4975347
Date: Tue, 9 May 2023 16:27:36 -0500
4975347
Subject: [PATCH] resolv_conf: Allow > 3 nameservers (#2152)
4975347
4975347
Systems running systemd-resolved or dnsmasq can utlize more than three
4975347
namervers. Older systems will just use the first three and ignore the
4975347
rest.
4975347
4975347
Signed-off-by: Major Hayden <major@redhat.com>
4975347
---
4975347
 cloudinit/distros/parsers/resolv_conf.py |  8 --------
4975347
 tests/unittests/distros/test_resolv.py   | 12 +++++++++---
4975347
 tools/.github-cla-signers                |  1 +
4975347
 3 files changed, 10 insertions(+), 11 deletions(-)
4975347
4975347
diff --git a/cloudinit/distros/parsers/resolv_conf.py b/cloudinit/distros/parsers/resolv_conf.py
4975347
index d31ffeb114..0d8dc83f5f 100644
4975347
--- a/cloudinit/distros/parsers/resolv_conf.py
4975347
+++ b/cloudinit/distros/parsers/resolv_conf.py
4975347
@@ -87,14 +87,6 @@ def add_nameserver(self, ns):
4975347
         new_ns = util.uniq_list(new_ns)
4975347
         if len(new_ns) == len(current_ns):
4975347
             return current_ns
4975347
-        if len(current_ns) >= 3:
4975347
-            LOG.warning(
4975347
-                "ignoring nameserver %r: adding would "
4975347
-                "exceed the maximum of "
4975347
-                "'3' name servers (see resolv.conf(5))",
4975347
-                ns,
4975347
-            )
4975347
-            return current_ns[:3]
4975347
         self._remove_option("nameserver")
4975347
         for n in new_ns:
4975347
             self._contents.append(("option", ["nameserver", n, ""]))
4975347
diff --git a/tests/unittests/distros/test_resolv.py b/tests/unittests/distros/test_resolv.py
4975347
index 65e7810116..363fd31db3 100644
4975347
--- a/tests/unittests/distros/test_resolv.py
4975347
+++ b/tests/unittests/distros/test_resolv.py
4975347
@@ -30,16 +30,22 @@ def test_local_domain(self):
4975347
 
4975347
     def test_nameservers(self):
4975347
         rp = resolv_conf.ResolvConf(BASE_RESOLVE)
4975347
+
4975347
+        # Start with two nameservers that already appear in the configuration.
4975347
         self.assertIn("10.15.44.14", rp.nameservers)
4975347
         self.assertIn("10.15.30.92", rp.nameservers)
4975347
+
4975347
+        # Add a third nameserver and verify it appears in the resolv.conf.
4975347
         rp.add_nameserver("10.2")
4975347
         self.assertIn("10.2", rp.nameservers)
4975347
         self.assertIn("nameserver 10.2", str(rp))
4975347
-        self.assertNotIn("10.3", rp.nameservers)
4975347
         self.assertEqual(len(rp.nameservers), 3)
4975347
-        rp.add_nameserver("10.2")
4975347
+
4975347
+        # Add a fourth nameserver and verify it appears in the resolv.conf.
4975347
         rp.add_nameserver("10.3")
4975347
-        self.assertNotIn("10.3", rp.nameservers)
4975347
+        self.assertIn("10.3", rp.nameservers)
4975347
+        self.assertIn("nameserver 10.3", str(rp))
4975347
+        self.assertEqual(len(rp.nameservers), 4)
4975347
 
4975347
     def test_search_domains(self):
4975347
         rp = resolv_conf.ResolvConf(BASE_RESOLVE)
4975347
diff --git a/tools/.github-cla-signers b/tools/.github-cla-signers
4975347
index 7615f0fbf4..a3d692b634 100644
4975347
--- a/tools/.github-cla-signers
4975347
+++ b/tools/.github-cla-signers
4975347
@@ -82,6 +82,7 @@ lucasmoura
4975347
 lucendio
4975347
 lungj
4975347
 magnetikonline
4975347
+major
4975347
 mal
4975347
 mamercad
4975347
 ManassehZhou