|
|
1064ba |
From 3774ec0a9873b4dfbc647ee57f16fe461706c1b2 Mon Sep 17 00:00:00 2001
|
|
|
5a2e6e |
From: Ryan McCabe <rmccabe@redhat.com>
|
|
|
1064ba |
Date: Tue, 21 Nov 2017 11:50:18 -0500
|
|
|
1064ba |
Subject: [PATCH] Render DNS and DOMAIN lines for sysconfig
|
|
|
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>
|
|
|
1064ba |
Resolves: rhbz#1489270
|
|
|
5a2e6e |
---
|
|
|
5a2e6e |
cloudinit/net/sysconfig.py | 17 +++++++++++++++++
|
|
|
1064ba |
tests/unittests/test_net.py | 11 ++++++++---
|
|
|
1064ba |
2 files changed, 25 insertions(+), 3 deletions(-)
|
|
|
5a2e6e |
|
|
|
5a2e6e |
diff --git a/cloudinit/net/sysconfig.py b/cloudinit/net/sysconfig.py
|
|
|
1064ba |
index ca031691..e34c8491 100644
|
|
|
5a2e6e |
--- a/cloudinit/net/sysconfig.py
|
|
|
5a2e6e |
+++ b/cloudinit/net/sysconfig.py
|
|
|
1064ba |
@@ -350,6 +350,23 @@ class Renderer(renderer.Renderer):
|
|
|
1064ba |
if 'gateway' in subnet:
|
|
|
1064ba |
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:
|
|
|
1064ba |
+ if isinstance(subnet['dns_search'], (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
|
|
|
1064ba |
index 4a32eb88..551370d4 100644
|
|
|
5a2e6e |
--- a/tests/unittests/test_net.py
|
|
|
5a2e6e |
+++ b/tests/unittests/test_net.py
|
|
|
1064ba |
@@ -820,7 +820,9 @@ USERCTL=no
|
|
|
1064ba |
|
|
|
1064ba |
def test_network_config_v1_samples(self):
|
|
|
1064ba |
ns = network_state.parse_net_config_data(CONFIG_V1_SIMPLE_SUBNET)
|
|
|
1064ba |
- render_dir = self.tmp_path("render")
|
|
|
1064ba |
+ tmp_dir = tempfile.mkdtemp()
|
|
|
1064ba |
+ self.addCleanup(shutil.rmtree, tmp_dir)
|
|
|
1064ba |
+ render_dir = os.path.join(tmp_dir, "render")
|
|
|
1064ba |
os.makedirs(render_dir)
|
|
|
1064ba |
renderer = sysconfig.Renderer()
|
|
|
1064ba |
renderer.render_network_state(render_dir, ns)
|
|
|
1064ba |
@@ -844,7 +846,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)
|
|
|
1064ba |
@@ -904,7 +908,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 |
--
|
|
|
1064ba |
2.13.6
|
|
|
5a2e6e |
|