From dcee1965a231bc64cc621b27082b12b5477e5528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Charlier?= Date: Thu, 24 Apr 2014 16:25:35 +0200 Subject: [PATCH] network/dhcp: allow setting & unsetting dnsmasq_dns_server Also rename dnsmasq_dns_servers to dnsmasq_dns_server as the former is only supported in Icehouse. Add unit tests for the feature. --- examples/params.pp | 2 +- manifests/network/dhcp.pp | 16 ++++++--- spec/classes/cloud_network_dhcp_spec.rb | 44 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 5 deletions(-) diff --git a/examples/params.pp b/examples/params.pp index bd6521f3..69524006 100644 --- a/examples/params.pp +++ b/examples/params.pp @@ -426,7 +426,7 @@ class os_params { $tunnel_eth = $internal_netif_ip $provider_vlan_ranges = ['physnet1:1000:2999'] $provider_bridge_mappings = ['physnet1:br-eth1'] - $dnsmasq_dns_servers = '8.8.8.8,8.8.4.4' + $dnsmasq_dns_server = '8.8.8.8' # Nova $ks_nova_password = 'secrete' diff --git a/manifests/network/dhcp.pp b/manifests/network/dhcp.pp index c136e982..db402130 100644 --- a/manifests/network/dhcp.pp +++ b/manifests/network/dhcp.pp @@ -17,9 +17,9 @@ # class cloud::network::dhcp( - $veth_mtu = 1500, - $debug = true - $dnsmasq_dns_servers = false + $veth_mtu = 1500, + $debug = true, + $dnsmasq_dns_server = false ) { include 'cloud::network' @@ -31,7 +31,15 @@ class cloud::network::dhcp( neutron_dhcp_agent_config { 'DEFAULT/dnsmasq_config_file': value => '/etc/neutron/dnsmasq-neutron.conf'; 'DEFAULT/enable_isolated_metadata': value => true; - 'DEFAULT/dnsmasq_dns_servers': value => $dnsmasq_dns_servers; + } + if $dnsmasq_dns_server { + neutron_dhcp_agent_config { 'DEFAULT/dnsmasq_dns_server': + value => $dnsmasq_dns_server + } + } else { + neutron_dhcp_agent_config { 'DEFAULT/dnsmasq_dns_server': + ensure => absent + } } file { '/etc/neutron/dnsmasq-neutron.conf': diff --git a/spec/classes/cloud_network_dhcp_spec.rb b/spec/classes/cloud_network_dhcp_spec.rb index 5f863045..da7ff382 100644 --- a/spec/classes/cloud_network_dhcp_spec.rb +++ b/spec/classes/cloud_network_dhcp_spec.rb @@ -82,6 +82,48 @@ describe 'cloud::network::dhcp' do should contain_neutron_dhcp_agent_config('DEFAULT/dnsmasq_config_file').with_value('/etc/neutron/dnsmasq-neutron.conf') should contain_neutron_dhcp_agent_config('DEFAULT/enable_isolated_metadata').with_value(true) + should contain_neutron_dhcp_agent_config('DEFAULT/dnsmasq_dns_server').with_ensure('absent') + + should contain_file('/etc/neutron/dnsmasq-neutron.conf').with( + :mode => '0755', + :owner => 'root', + :group => 'root' + ) + should contain_file('/etc/neutron/dnsmasq-neutron.conf').with_content(/^dhcp-option-force=26,1400$/) + end + end + + shared_examples_for 'openstack network dhcp with custom nameserver' do + + let :pre_condition do + "class { 'cloud::network': + rabbit_hosts => ['10.0.0.1'], + rabbit_password => 'secrete', + tunnel_eth => '10.0.1.1', + api_eth => '10.0.0.1', + provider_vlan_ranges => ['physnet1:1000:2999'], + provider_bridge_mappings => ['physnet1:br-eth1'], + verbose => true, + debug => true, + use_syslog => true, + dhcp_lease_duration => '10', + log_facility => 'LOG_LOCAL0' }" + end + + let :params do + { :veth_mtu => '1400', + :debug => true, + :dnsmasq_dns_server => '1.2.3.4' } + end + + it 'configure neutron dhcp' do + should contain_class('neutron::agents::dhcp').with( + :debug => true + ) + + should contain_neutron_dhcp_agent_config('DEFAULT/dnsmasq_config_file').with_value('/etc/neutron/dnsmasq-neutron.conf') + should contain_neutron_dhcp_agent_config('DEFAULT/enable_isolated_metadata').with_value(true) + should contain_neutron_dhcp_agent_config('DEFAULT/dnsmasq_dns_server').with_value('1.2.3.4') should contain_file('/etc/neutron/dnsmasq-neutron.conf').with( :mode => '0755', @@ -102,6 +144,7 @@ describe 'cloud::network::dhcp' do end it_configures 'openstack network dhcp' + it_configures 'openstack network dhcp with custom nameserver' end context 'on RedHat platforms' do @@ -114,6 +157,7 @@ describe 'cloud::network::dhcp' do end it_configures 'openstack network dhcp' + it_configures 'openstack network dhcp with custom nameserver' end end