From 24d4dfa1c2256db068b51115828bbc12e247d7f2 Mon Sep 17 00:00:00 2001 From: Cédric Jeanneret Date: Thu, 5 Nov 2015 08:55:56 +0100 Subject: Create missing directory, and take the opportunity to rename it --- manifests/failover.pp | 4 ++-- manifests/server/config.pp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/manifests/failover.pp b/manifests/failover.pp index 6b465f2..cfcccb0 100644 --- a/manifests/failover.pp +++ b/manifests/failover.pp @@ -23,7 +23,7 @@ define dhcp::failover( default => $ensure, } - file {"${dhcp::params::config_dir}/failover/${name}.conf": + file {"${dhcp::params::config_dir}/failover.d/${name}.conf": ensure => $_ensure, content => template("${module_name}/failover.conf.erb"), group => 'root', @@ -34,7 +34,7 @@ define dhcp::failover( concat::fragment {"dhcp.failover.${name}": ensure => $ensure, - content => "include \"${dhcp::params::config_dir}/failover/${name}.conf\";\n", + content => "include \"${dhcp::params::config_dir}/failover.d/${name}.conf\";\n", target => "${dhcp::params::config_dir}/dhcpd.conf", } diff --git a/manifests/server/config.pp b/manifests/server/config.pp index eb2efa1..68e2104 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -52,4 +52,11 @@ class dhcp::server::config { purge => true, force => true, } + + file {"${dhcp::params::config_dir}/failover.d": + ensure => directory, + recurse => true, + purge => true, + force => true, + } } -- cgit v1.2.3 From 8c46b5c955e128e8049ce578d2101327a9c0a37f Mon Sep 17 00:00:00 2001 From: Cédric Jeanneret Date: Thu, 5 Nov 2015 08:56:45 +0100 Subject: Do not add blindy the semi-colon --- templates/subnet.conf.erb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/templates/subnet.conf.erb b/templates/subnet.conf.erb index 11f9ed4..9592a4c 100644 --- a/templates/subnet.conf.erb +++ b/templates/subnet.conf.erb @@ -19,10 +19,18 @@ subnet <%= @name %> netmask <%= _netmask %> { scope.function_validate_re([_domain_name, '^\S+$']) -%> option domain-name "<%= _domain_name %>"; <% unless @other_opts.empty? -%> - <% if @other_opts.is_a?(Array) -%> -<%= @other_opts.collect! {|i| " #{i};"}.join("\n") %> - <% else -%> +<% +if @other_opts.is_a?(Array) + @other_opts.each do |i| + if i =~ /(\{|\})/ +-%> + <%= i %> +<%- else -%> + <%= i %>; +<% end -%> +<% end -%> +<% else -%> <%= @other_opts %>; - <% end -%> +<% end -%> <% end -%> } -- cgit v1.2.3 From 3536e22af749c3877210c3d29125749cc7571bbf Mon Sep 17 00:00:00 2001 From: Cédric Jeanneret Date: Fri, 6 Nov 2015 08:43:52 +0100 Subject: acceptance for failover --- spec/acceptance/dhcp_failover_spec.rb | 38 +++++++++++++++++++++++++++++++++++ spec/defines/dhcp_failover_spec.rb | 24 +++++++++++----------- 2 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 spec/acceptance/dhcp_failover_spec.rb diff --git a/spec/acceptance/dhcp_failover_spec.rb b/spec/acceptance/dhcp_failover_spec.rb new file mode 100644 index 0000000..5e93c67 --- /dev/null +++ b/spec/acceptance/dhcp_failover_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper_acceptance' + +describe 'dhcp::failover' do + describe 'with defaults' do + it 'should work with no error' do + pp = <<-EOS + class { 'dhcp::server': } + dhcp::failover {'my-failover': + peer_address => '1.1.1.1', + options => { + 'max-response-delay' => 30, + 'max-unacked-updates' => 10, + 'load balance max seconds' => 3, + 'mclt' => 1800, + 'split' => 128, + } + } + $ipaddr = split($::networking['interfaces']['eth0']['ip'], '[.]') + $sub = "${ipaddr[0]}.${ipaddr[1]}.${ipaddr[2]}" + dhcp::subnet {$::networking['interfaces']['eth0']['network']: + broadcast => "${sub}.255", + subnet_mask => $::networking['interfaces']['eth0']['netmask'], + domain_name => 'test.com', + other_opts => [ + "option domain-name-servers ${sub}.1, ${sub}.2", + 'option domain-search "test.com", "internal.test.com"', + 'pool {', + 'failover peer "my-failover"', + "range ${sub}.100 ${sub}.250", + '}', + ] + } + EOS + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + end +end diff --git a/spec/defines/dhcp_failover_spec.rb b/spec/defines/dhcp_failover_spec.rb index d8400b0..75b30fb 100644 --- a/spec/defines/dhcp_failover_spec.rb +++ b/spec/defines/dhcp_failover_spec.rb @@ -21,7 +21,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /"foo" does not match \["present", "absent"\]/) end end @@ -34,7 +34,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /true is not a string\./) end end @@ -47,7 +47,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /is not a valid IPv4 address\./) end end @@ -55,7 +55,7 @@ describe 'dhcp::failover' do context 'when not passing peer_address' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /Must pass peer_address to Dhcp::Failover/) end end @@ -67,7 +67,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /true is not a string\./) end end @@ -79,7 +79,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /is not a valid IPv4 address\./) end end @@ -92,7 +92,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /Expected first argument to be an Integer/) end end @@ -105,7 +105,7 @@ describe 'dhcp::failover' do it 'should fail' do expect { - should contain_file('/etc/dhcp/failover/failover-dhcp.conf') + should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf') }.to raise_error(Puppet::Error, /Expected first argument to be an Integer/) end end @@ -117,7 +117,7 @@ describe 'dhcp::failover' do :peer_address => '1.2.3.4', } } - it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with( + it { should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf').with( :ensure => 'file', :owner => 'root', :group => 'root' @@ -135,7 +135,7 @@ describe 'dhcp::failover' do /peer port 647;\n/ ) } it { should contain_concat__fragment('dhcp.failover.failover-dhcp').with({ - :content => "include \"/etc/dhcp/failover/failover-dhcp.conf\";\n", + :content => "include \"/etc/dhcp/failover.d/failover-dhcp.conf\";\n", :target => '/etc/dhcp/dhcpd.conf', })} end @@ -152,7 +152,7 @@ describe 'dhcp::failover' do }, } } - it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with({ + it { should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf').with({ :ensure => 'file', :owner => 'root', :group => 'root' @@ -183,7 +183,7 @@ describe 'dhcp::failover' do :role => 'secondary', } } - it { should contain_file('/etc/dhcp/failover/failover-dhcp.conf').with({ + it { should contain_file('/etc/dhcp/failover.d/failover-dhcp.conf').with({ :ensure => 'file', :owner => 'root', :group => 'root' -- cgit v1.2.3 From 42f495f3525bc740ea3b2451cfedac912167f843 Mon Sep 17 00:00:00 2001 From: Cédric Jeanneret Date: Fri, 6 Nov 2015 08:44:02 +0100 Subject: corrected readme/doc --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e692aa8..4f944d3 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Creates a subnet: dhcp::subnet {"10.27.20.0": ensure => present, broadcast => "10.27.20.255", - other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], + other_opts => ['filename "pxelinux.0"', 'next-server 10.27.10.1'], } ## dhcp::failover @@ -95,9 +95,9 @@ Creates a failover peer: broadcast => "10.27.20.255", other_opts => [ 'pool {', - 'failover peer "my-failover-peer";', - 'max-lease-time 1800;', - 'range 10.27.20.100 10.27.20.250;', + 'failover peer "my-failover-peer"', + 'max-lease-time 1800', + 'range 10.27.20.100 10.27.20.250', '}', ], } -- cgit v1.2.3