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