Skip to content

Commit

Permalink
Merge pull request #110 from jearls/add-also_notify-zone-configuration
Browse files Browse the repository at this point in the history
Add notify to server options & also_notify to server and zone options.
  • Loading branch information
solarkennedy committed May 6, 2015
2 parents bfead97 + bdb7ddc commit 94e1841
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 1 deletion.
21 changes: 21 additions & 0 deletions manifests/server/options.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
# both statistic_channel_port and statistic_channel_ip must be defined
# for the statistic api to be enabled
#
# [*zone_notify*]
# Controls notifications when a zone for which this server is
# authoritative changes. String of yes (send notifications to zone's
# NS records and to also-notify list), no (no notifications are sent),
# master-only (only send notifications for master zones), or explicit
# (send notifications only to also-notify list).
# Default: undef, meaning the BIND default of "yes"
#
# [*also_notify*]
# The list of servers to which additional zone-change notifications
# should be sent.
# Default: empty, meaning no additional servers
#
# === Examples
#
# dns::server::options { '/etc/bind/named.conf.options':
Expand All @@ -67,6 +80,8 @@
$allow_query = [],
$statistic_channel_ip = undef,
$statistic_channel_port = undef,
$zone_notify = undef,
$also_notify = [],
) {
$valid_check_names = ['fail', 'warn', 'ignore']
$cfg_dir = $::dns::server::params::cfg_dir
Expand Down Expand Up @@ -98,6 +113,12 @@
fail('The statistic_channel_ip is not an ip string')
}

validate_array($also_notify)
$valid_zone_notify = ['yes', 'no', 'explicit', 'master-only']
if $zone_notify != undef and !member($valid_zone_notify, $zone_notify) {
fail("The zone_notify must be ${valid_zone_notify}")
}

file { $title:
ensure => present,
owner => $::dns::server::params::owner,
Expand Down
9 changes: 8 additions & 1 deletion manifests/zone.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
$allow_forwarder = [],
$forward_policy = 'first',
$slave_masters = undef,
$zone_notify = false,
$zone_notify = undef,
$also_notify = [],
$ensure = present
) {

Expand All @@ -31,6 +32,12 @@
error('The forward policy can only be set to either first or only')
}

validate_array($also_notify)
$valid_zone_notify = ['yes', 'no', 'explicit', 'master-only']
if $zone_notify != undef and !member($valid_zone_notify, $zone_notify) {
fail("The zone_notify must be ${valid_zone_notify}")
}

$zone = $reverse ? {
true => "${name}.in-addr.arpa",
default => $name
Expand Down
64 changes: 64 additions & 0 deletions spec/defines/dns__server__options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,69 @@
it { should contain_file('/etc/bind/named.conf.options').with_content(/inet 127\.0\.0\.1 port 12455;/) }
end

context 'passing no zone_notify setting' do
let :params do
{}
end
it { should contain_file('/etc/bind/named.conf.options').without_content(/^notify /) }
end

context 'passing a wrong zone_notify setting' do
let :params do
{ :zone_notify => 'maybe' }
end
it { should raise_error(Puppet::Error, /The zone_notify/) }
end

context 'passing yes to zone_notify' do
let :params do
{ :zone_notify => 'yes' }
end
it { should contain_file('/etc/bind/named.conf.options').with_content(/^notify yes;/) }
end

context 'passing no to zone_notify' do
let :params do
{ :zone_notify => 'no' }
end
it { should contain_file('/etc/bind/named.conf.options').with_content(/^notify no;/) }
end

context 'passing master-only to zone_notify' do
let :params do
{ :zone_notify => 'master-only' }
end
it { should contain_file('/etc/bind/named.conf.options').with_content(/^notify master-only;/) }
end

context 'passing explicit to zone_notify' do
let :params do
{ :zone_notify => 'explicit' }
end
it { should contain_file('/etc/bind/named.conf.options').with_content(/^notify explicit;/) }
end

context 'passing no also_notify setting' do
let :params do
{}
end
it { should contain_file('/etc/bind/named.conf.options').without_content(/^also-notify /) }
end

context 'passing a string to also_notify' do
let :params do
{ :also_notify => '8.8.8.8' }
end
it { should raise_error(Puppet::Error, /is not an Array/) }
end

context 'passing a valid array to also_notify' do
let :params do
{ :also_notify => [ '8.8.8.8' ] }
end
it { should contain_file('/etc/bind/named.conf.options').with_content(/^also-notify \{/) }
it { should contain_file('/etc/bind/named.conf.options').with_content(/8\.8\.8\.8;/) }
end

end

65 changes: 65 additions & 0 deletions spec/defines/dns__zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,69 @@
end
end

context 'passing no zone_notify setting' do
let :params do
{}
end
it { should contain_concat__fragment('named.conf.local.test.com.include').without_content(/ notify /) }
end

context 'passing a wrong zone_notify setting' do
let :params do
{ :zone_notify => 'maybe' }
end
it { should raise_error(Puppet::Error, /The zone_notify/) }
end

context 'passing yes to zone_notify' do
let :params do
{ :zone_notify => 'yes' }
end
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/ notify yes;/) }
end

context 'passing no to zone_notify' do
let :params do
{ :zone_notify => 'no' }
end
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/ notify no;/) }
end

context 'passing master-only to zone_notify' do
let :params do
{ :zone_notify => 'master-only' }
end
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/ notify master-only;/) }
end

context 'passing explicit to zone_notify' do
let :params do
{ :zone_notify => 'explicit' }
end
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/ notify explicit;/) }
end

context 'passing no also_notify setting' do
let :params do
{}
end
it { should contain_concat__fragment('named.conf.local.test.com.include').without_content(/ also-notify /) }
end

context 'passing a string to also_notify' do
let :params do
{ :also_notify => '8.8.8.8' }
end
it { should raise_error(Puppet::Error, /is not an Array/) }
end

context 'passing a valid array to also_notify' do
let :params do
{ :also_notify => [ '8.8.8.8' ] }
end
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/ also-notify \{/) }
it { should contain_concat__fragment('named.conf.local.test.com.include').with_content(/8\.8\.8\.8;/) }
end

end

11 changes: 11 additions & 0 deletions templates/named.conf.options.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ check-names response <%= @check_names_response %>;
statistics-channels {
inet <%= @statistic_channel_ip %> port <%= @statistic_channel_port %>;
};
<% end -%>
<% if @zone_notify -%>
notify <%= @zone_notify %>;
<% end -%>
<% if @also_notify.size != 0 then -%>
also-notify {
<%- @also_notify.each do |ip| -%>
<%= ip -%>;
<%- end -%>
};
<% end -%>

//========================================================================
Expand Down
7 changes: 7 additions & 0 deletions templates/zone.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ type <%= @zone_type %>;
<% if @zone_notify -%>
notify <%= @zone_notify %>;
<% end -%>
<% if @also_notify.size != 0 -%>
also-notify {
<%- @also_notify.each do |ip| -%>
<%= ip %>;
<%- end -%>
};
<% end -%>
<% if @zone_type != 'forward' -%>
file "<%= @zone_file %>";
<% end -%>
Expand Down

0 comments on commit 94e1841

Please sign in to comment.