aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Jeanneret <cedric.jeanneret@camptocamp.com>2017-09-15 00:13:39 +0200
committerCédric Jeanneret <cedric.jeanneret@camptocamp.com>2017-09-15 00:14:20 +0200
commit9ce34d529d7faa65cfa6f88aaecf735f92c4c89b (patch)
tree4845d996ab4c6d69d0d31f8669a24e0bf2df02b3
parent77fe5922bd7ca5c2a199d383b03537c08edfcc1c (diff)
Allow to pass more than two DNS while putting 2 DNS
Until now, when we pass more than 2 DNS, only the first one is added in the ifcg-* config files. This patch-set proves the issue, and proves the correction actually works. Change-Id: I70a779782ab87cd4f74f3c50b0e649f503b386e3 Closes-Bug: #1716171 (cherry picked from commit 8ddab87c6ee2e80025e9340d806f93921779198b)
-rw-r--r--os_net_config/impl_ifcfg.py6
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py16
2 files changed, 19 insertions, 3 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 3a82597..4f9e0c3 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -398,10 +398,10 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "DHCLIENTARGS=%s\n" % base_opt.dhclient_args
if base_opt.dns_servers:
data += "DNS1=%s\n" % base_opt.dns_servers[0]
- if len(base_opt.dns_servers) == 2:
+ if len(base_opt.dns_servers) >= 2:
data += "DNS2=%s\n" % base_opt.dns_servers[1]
- elif len(base_opt.dns_servers) > 2:
- logger.warning('ifcfg format supports a max of 2 dns servers.')
+ if len(base_opt.dns_servers) > 2:
+ logger.warning('ifcfg format supports max 2 resolvers.')
return data
def _add_routes(self, interface_name, routes=[]):
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 337eeb3..4b91448 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -876,6 +876,22 @@ DNS2=5.6.7.8
"""
self.assertEqual(em1_config, self.get_interface_config('em1'))
+ def test_interface_more_dns_servers(self):
+ interface1 = objects.Interface('em1', dns_servers=['1.2.3.4',
+ '5.6.7.8',
+ '9.10.11.12'])
+ self.provider.add_interface(interface1)
+ em1_config = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+BOOTPROTO=none
+DNS1=1.2.3.4
+DNS2=5.6.7.8
+"""
+ self.assertEqual(em1_config, self.get_interface_config('em1'))
+
def test_nm_controlled(self):
interface1 = objects.Interface('em1', nm_controlled=True)
interface2 = objects.Interface('em2', nm_controlled=True)