From 460602489dbc980776d116f3cc81716a88567ca0 Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Thu, 31 Aug 2017 09:06:53 -0700 Subject: [PATCH] Add dns-nameservers config option for upstream dns servers Adds a dns-servers config option for specifying the forwarding dns servers to be used by the dnsmasq services on the neutron dhcp agent. This enables services using internal dns to also specify the forwarding dns servers in order to resolve hosts outside of the neutron network space. Note: this option only takes effect when the enable-local-dhcp-and-metadata flag is set to True. Change-Id: I510d163dd9738477b15497b25266e73a50368539 Implements: blueprint internal-dns Closes-Bug: #1713721 --- config.yaml | 7 +++++++ hooks/neutron_ovs_context.py | 1 + templates/mitaka/dhcp_agent.ini | 4 ++++ unit_tests/test_neutron_ovs_context.py | 14 ++++++++++---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.yaml b/config.yaml index dac3cee2..2ef2a5a6 100644 --- a/config.yaml +++ b/config.yaml @@ -133,6 +133,13 @@ options: Comma-separated list of key=value config flags with the additional dhcp options for neutron dnsmasq. Note, this option is only valid when enable-local-dhcp-and-metadata option is set to True. + dns-servers: + type: string + default: + description: | + A comma-separated list of DNS servers which will be used by dnsmasq as + forwarders. This option only applies when the enable-local-dhcp-and-metadata + options is set to True. prevent-arp-spoofing: type: boolean default: true diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 0c90fb6b..14dc4a70 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -213,6 +213,7 @@ class DHCPAgentContext(OSContextGenerator): dnsmasq_flags = config('dnsmasq-flags') if dnsmasq_flags: ctxt['dnsmasq_flags'] = config_flags_parser(dnsmasq_flags) + ctxt['dns_servers'] = config('dns-servers') neutron_api_settings = NeutronAPIContext()() if neutron_api_settings.get('dns_domain'): diff --git a/templates/mitaka/dhcp_agent.ini b/templates/mitaka/dhcp_agent.ini index b9517915..01d3c44d 100644 --- a/templates/mitaka/dhcp_agent.ini +++ b/templates/mitaka/dhcp_agent.ini @@ -15,6 +15,10 @@ root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf dnsmasq_config_file = /etc/neutron/dnsmasq.conf {% endif -%} +{% if dns_servers -%} +dnsmasq_dns_servers = {{ dns_servers }} +{% endif -%} + {% if dns_domain -%} dns_domain = {{ dns_domain }} # Per LP#1583769, dhcp_domain needs to be configured in mitaka as well. Additional diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index db88d268..12f3f5d2 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -291,7 +291,8 @@ class DHCPAgentContextTest(CharmTestCase): self.relation_get.return_value = None self.assertEqual( context.DHCPAgentContext()(), - {'dns_domain': 'openstack.example.'} + {'dns_domain': 'openstack.example.', + 'dns_servers': None} ) self.relation_ids.assert_called_with('neutron-plugin') self.relation_get.assert_called_once_with( @@ -314,13 +315,15 @@ class DHCPAgentContextTest(CharmTestCase): 'dns-domain': 'openstack.example.' } _rget.side_effect = lambda *args, **kwargs: rdata + self.test_config.set('dns-servers', '8.8.8.8,4.4.4.4') self.relation_ids.return_value = ['rid1'] self.related_units.return_value = ['nova-compute/0'] self.relation_get.return_value = 'nova' self.assertEqual( context.DHCPAgentContext()(), {'availability_zone': 'nova', - 'dns_domain': 'openstack.example.'} + 'dns_domain': 'openstack.example.', + 'dns_servers': '8.8.8.8,4.4.4.4'} ) self.relation_ids.assert_called_with('neutron-plugin') self.relation_get.assert_called_once_with( @@ -342,12 +345,14 @@ class DHCPAgentContextTest(CharmTestCase): 'network-device-mtu': 1500, } _rget.side_effect = lambda *args, **kwargs: rdata + self.test_config.set('dns-servers', '8.8.8.8') self.relation_ids.return_value = ['rid1'] self.related_units.return_value = ['nova-compute/0'] self.relation_get.return_value = 'nova' self.assertEqual( context.DHCPAgentContext()(), - {'availability_zone': 'nova'} + {'availability_zone': 'nova', + 'dns_servers': '8.8.8.8'} ) self.relation_ids.assert_called_with('neutron-plugin') self.relation_get.assert_called_once_with( @@ -382,7 +387,8 @@ class DHCPAgentContextTest(CharmTestCase): 'dhcp-userclass': 'set:ipxe,iPXE', 'dhcp-match': 'set:ipxe,175', 'server': '1.2.3.4', - } + }, + 'dns_servers': None, } )