sailesh1993 / rpms / cloud-init

Forked from rpms/cloud-init a year ago
Clone
5a2e6e
From 6f54ccf28a327174df663ea2e07f32d7e632fddd Mon Sep 17 00:00:00 2001
5a2e6e
From: Ryan McCabe <rmccabe@redhat.com>
5a2e6e
Date: Thu, 15 Feb 2018 10:30:40 -0500
5a2e6e
Subject: [PATCH] sysconfig: Render DNS and DOMAIN
5a2e6e
5a2e6e
Currently when dns and dns search info is provided, it is not
5a2e6e
rendered when outputting to sysconfig format.
5a2e6e
5a2e6e
This patch causes the DNS and DOMAIN lines to be written out rendering
5a2e6e
sysconfig.
5a2e6e
5a2e6e
This is a backport of upstream commit
5a2e6e
bbe91cdc6917adb503b455e6860c21ea7b3f567f which will not apply to the
5a2e6e
0.7.9 tree.
5a2e6e
5a2e6e
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
5a2e6e
Resolves: rhbz#1545525
5a2e6e
---
5a2e6e
 cloudinit/net/sysconfig.py  | 17 +++++++++++++++++
5a2e6e
 tests/unittests/test_net.py |  8 +++++---
5a2e6e
 2 files changed, 22 insertions(+), 3 deletions(-)
5a2e6e
5a2e6e
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
5a2e6e
index 9975fe2c..ec412512 100644
5a2e6e
--- a/cloudinit/net/sysconfig.py
5a2e6e
+++ b/cloudinit/net/sysconfig.py
5a2e6e
@@ -354,6 +354,23 @@ class Renderer(renderer.Renderer):
5a2e6e
                     else:
5a2e6e
                         iface_cfg['GATEWAY'] = subnet['gateway']
5a2e6e
 
5a2e6e
+                if 'dns_search' in subnet:
5a2e6e
+                    if isinstance(subnet['dns_search'], (list, tuple)):
5a2e6e
+                        # Currently limited to 6 entries per resolv.conf(5)
5a2e6e
+                        search_list = subnet['dns_search'][:6]
5a2e6e
+                        iface_cfg['DOMAIN'] = ' '.join(search_list)
5a2e6e
+                    else:
5a2e6e
+                        iface_cfg['DOMAIN'] = subnet['dns_search']
5a2e6e
+
5a2e6e
+                if 'dns_nameservers' in subnet:
5a2e6e
+                    if isinstance(subnet['dns_nameservers'], (list, tuple)):
5a2e6e
+                        # Currently limited to 3 entries per resolv.conf(5)
5a2e6e
+                        dns_list = subnet['dns_nameservers'][:3]
5a2e6e
+                        for i, k in enumerate(dns_list, 1):
5a2e6e
+                            iface_cfg['DNS' + str(i)] = k
5a2e6e
+                    else:
5a2e6e
+                        iface_cfg['DNS1'] = subnet['dns_nameservers']
5a2e6e
+
5a2e6e
     @classmethod
5a2e6e
     def _render_subnet_routes(cls, iface_cfg, route_cfg, subnets):
5a2e6e
         for i, subnet in enumerate(subnets, start=len(iface_cfg.children)):
5a2e6e
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
5a2e6e
index d75742be..f2a1998a 100644
5a2e6e
--- a/tests/unittests/test_net.py
5a2e6e
+++ b/tests/unittests/test_net.py
5a2e6e
@@ -780,7 +780,9 @@ USERCTL=no
5a2e6e
 
5a2e6e
     def test_config_with_explicit_loopback(self):
5a2e6e
         ns = network_state.parse_net_config_data(CONFIG_V1_EXPLICIT_LOOPBACK)
5a2e6e
-        render_dir = self.tmp_path("render")
5a2e6e
+        tmp_dir = tempfile.mkdtemp()
5a2e6e
+        self.addCleanup(shutil.rmtree, tmp_dir)
5a2e6e
+        render_dir = os.path.join(tmp_dir, "render")
5a2e6e
         os.makedirs(render_dir)
5a2e6e
         renderer = sysconfig.Renderer()
5a2e6e
         renderer.render_network_state(render_dir, ns)
5a2e6e
@@ -792,7 +794,6 @@ USERCTL=no
5a2e6e
 #
5a2e6e
 BOOTPROTO=dhcp
5a2e6e
 DEVICE=eth0
5a2e6e
-NM_CONTROLLED=no
5a2e6e
 ONBOOT=yes
5a2e6e
 TYPE=Ethernet
5a2e6e
 USERCTL=no
5a2e6e
@@ -841,7 +842,8 @@ iface eth1000 inet dhcp
5a2e6e
         self.assertEqual(expected.lstrip(), contents.lstrip())
5a2e6e
 
5a2e6e
     def test_config_with_explicit_loopback(self):
5a2e6e
-        tmp_dir = self.tmp_dir()
5a2e6e
+        tmp_dir = tempfile.mkdtemp()
5a2e6e
+        self.addCleanup(shutil.rmtree, tmp_dir)
5a2e6e
         ns = network_state.parse_net_config_data(CONFIG_V1_EXPLICIT_LOOPBACK)
5a2e6e
         renderer = eni.Renderer()
5a2e6e
         renderer.render_network_state(tmp_dir, ns)
5a2e6e
-- 
5a2e6e
2.14.3
5a2e6e