From d9b5df272f956b21bde6c5ac64a77a1864122c09 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Tue, 31 Mar 2015 15:34:16 -0500 Subject: [PATCH] Add dnskeyname parameter --- README.md | 5 ++-- manifests/init.pp | 9 ++++++ spec/classes/dhcp_spec.rb | 54 +++++++++++++++++++++++++++++++++++ templates/dhcpd.conf.ddns.erb | 2 +- 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 90c3665d..89248254 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,9 @@ Define the server and the zones it will be responsible for. nameservers => ['10.0.1.20'], ntpservers => ['us.pool.ntp.org'], interfaces => ['eth0'], - dnsupdatekey => "/etc/bind/keys.d/$ddnskeyname", - require => Bind::Key[ $ddnskeyname ], + dnsupdatekey => '/etc/bind/keys.d/rndc.key', + dnskeyname => 'rndc-key', + require => Bind::Key['rndc-key'], pxeserver => '10.0.1.50', pxefilename => 'pxelinux.0', } diff --git a/manifests/init.pp b/manifests/init.pp index a43e9384..4001549a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,6 +13,7 @@ $interfaces = undef, $interface = 'NOTSET', $dnsupdatekey = undef, + $dnskeyname = undef, $pxeserver = undef, $pxefilename = undef, $logfacility = 'daemon', @@ -55,6 +56,14 @@ $dhcp_interfaces = $interfaces } + if $dnsupdatekey { + $_dnsupdatekey_split = split($dnsupdatekey, '[/]') + $_dnsupdatekey_basename = $_dnsupdatekey_split[-1] + $_dnskeyname = pick($dnskeyname, $_dnsupdatekey_basename) + } else { + $_dnskeyname = $dnskeyname + } + # JJM Decide where to pull the fragment content from. Either this module, or # from the end user. This makes the module much more re-usable by 3rd # parties without modifying the module itself. diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index c6caf630..d045f6f5 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -58,6 +58,60 @@ it {should contain_file(files)} end end + context 'ddns' do + let :params do + default_params.merge({ + :interface => 'eth0', + }) + end + + it do + should contain_concat__fragment('dhcp-conf-ddns').with_content(/^ddns-update-style none;$/) + end + + context 'dnsupdatekey defined' do + let :params do + default_params.merge({ + :interface => 'eth0', + :dnsupdatekey => '/etc/rndc.key', + }) + end + + it do + content = subject.resource('concat::fragment', 'dhcp-conf-ddns').send(:parameters)[:content] + expected_lines = [ + 'ddns-updates on;', + 'ddns-update-style interim;', + 'update-static-leases on;', + 'use-host-decl-names on;', + 'include "/etc/rndc.key";', + "zone #{params['dnsdomain'].first}. {", + " primary #{params['nameservers'].first};", + ' key rndc.key;', + '}', + "zone #{params['dnsdomain'].last}. {", + " primary #{params['nameservers'].first};", + ' key rndc.key;', + '}', + ] + expect(content.split("\n").reject {|l| l =~ /^#|^$/ }).to eq(expected_lines) + end + + context 'dnskeyname defined' do + let :params do + default_params.merge({ + :interface => 'eth0', + :dnsupdatekey => '/etc/rndc.key', + :dnskeyname => 'rndc-key', + }) + end + + it do + should contain_concat__fragment('dhcp-conf-ddns').with_content(/^ key rndc-key;$/) + end + end + end + end end context 'on a Dawin OS' do let :facts do diff --git a/templates/dhcpd.conf.ddns.erb b/templates/dhcpd.conf.ddns.erb index d299d3d1..cf35e35e 100644 --- a/templates/dhcpd.conf.ddns.erb +++ b/templates/dhcpd.conf.ddns.erb @@ -13,7 +13,7 @@ include "<%= @dnsupdatekey %>"; <% @dnsdomain_real.each do |dom| -%> zone <%= dom %>. { primary <%= @nameservers.first %>; - key <%= @dnsupdatekey.split('/').last %>; + key <%= @_dnskeyname %>; } <% end -%> <% else -%>