]> gitweb.fluxo.info Git - puppet-dhcp.git/commitdiff
Get rid of unscoped variables in dhcp::server, fix template
authorRaphaël Pinson <raphael.pinson@camptocamp.com>
Thu, 11 Apr 2013 12:25:15 +0000 (14:25 +0200)
committerRaphaël Pinson <raphael.pinson@camptocamp.com>
Thu, 11 Apr 2013 12:25:15 +0000 (14:25 +0200)
manifests/init.pp
manifests/server.pp
manifests/server/config.pp
spec/classes/dhcp_spec.rb
templates/dhcpd.conf.debian.erb

index 8a14b13547ab3e0955f6d1694479bdc94d6d84a8..e1e05b300844851a5e1bf773ba3071723a49939a 100644 (file)
@@ -1,7 +1,14 @@
 class dhcp (
   $server = true,
+  $server_ddns_update = undef,
+  $server_authoritative = undef,
+  $server_opts = undef,
 ) {
   if $server {
-    class { '::dhcp::server': }
+    class { '::dhcp::server':
+      ddns_update   => $server_ddns_update,
+      authoritative => $server_authoritative,
+      opts          => $server_opts,
+    }
   }
 }
index ceffa1471029d04c116a02c9b1e1c1b6252ef4e8..d83c26f1f4af600105407249c5057cb33be6bb47 100644 (file)
@@ -5,15 +5,17 @@
 #   module "common": git://github.com/camptocamp/puppet-common.git
 #
 # facultative argument:
-#   *$dhcpd_ddns_update*   : ddns-update-style option (default to none)
-#   *$dhcpd_authoritative* : set it if you want that your DHCP server is
-#                             authoritative (default to no)
-#   *$dhcpd_opts*          : any other DHCPD valid options
+#   *$ddns_update*   : ddns-update-style option (default to none)
+#   *$authoritative* : set it if you want that your DHCP server is
+#                      authoritative (default to no)
+#   *$opts*          : any other DHCPD valid options
 #
 # Example:
 # node "dhcp.toto.ltd" {
-#   $dhcpd_opts = ['domain-name "toto.ltd"', "domain-name-servers 192.168.21.1"]
-#   include dhcp::server
+#   class { 'dhcp::server':
+#     opts => ['domain-name "toto.ltd"',
+#              'domain-name-servers 192.168.21.1'],
+#   }
 #
 #   dhcp::subnet {"10.27.20.0":
 #     ensure     => present,
 #   }
 # }
 #
-class dhcp::server {
+class dhcp::server (
+  $ddns_update = 'none',
+  $authoritative = false,
+  $opts = [],
+) {
   class { '::dhcp::server::packages': } ->
   class { '::dhcp::server::config': } ~>
   class { '::dhcp::server::service': }
index 4898a60af85ac91af7f680a37e4f0f57d079f4de..0c1a74a75cae9390499745d98a0b9d7345846c42 100644 (file)
@@ -11,6 +11,10 @@ class dhcp::server::config {
   validate_string($dhcp::params::server_template)
   validate_re($dhcp::params::server_template, '^\S+$')
 
+  validate_string($dhcp::server::ddns_update)
+  validate_bool($dhcp::server::authoritative)
+  validate_array($dhcp::server::opts)
+
   concat {"${dhcp::params::config_dir}/dhcpd.conf":
     owner => root,
     group => root,
index c833c52bcb8e463e55557cd0578f5cf46eddfac9..ce9228ed306525795da83e9ee1104a943bd65859 100644 (file)
@@ -34,6 +34,13 @@ describe 'dhcp' do
       :mode  => '0644'
     ) }
 
+    it { should contain_concat__fragment('00.dhcp.server.base').with(
+      :ensure  => 'present',
+      :target  => '/etc/dhcp3/dhcpd.conf',
+      :content => /log-facility/
+      ).with_content(/ddns-update-style none;/).with_content(/#authoritative/)
+    }
+
     # Service
     it { should contain_service('dhcpd').with(
       :ensure  => 'running',
@@ -62,6 +69,13 @@ describe 'dhcp' do
       :mode  => '0644'
     ) }
 
+    it { should contain_concat__fragment('00.dhcp.server.base').with(
+        :ensure  => 'present',
+        :target  => '/etc/dhcp/dhcpd.conf',
+        :content => /log-facility/
+      ).with_content(/ddns-update-style none;/).with_content(/#authoritative/)
+    }
+
     # Service
     it { should contain_service('dhcpd').with(
       :ensure  => 'running',
@@ -70,4 +84,58 @@ describe 'dhcp' do
       :pattern => '/usr/sbin/dhcpd'
     ) }
   end
+
+  context 'When passing ddns_update' do
+    let (:facts) { {
+      :operatingsystem => 'Debian',
+      :osfamily        => 'Debian',
+      :lsbdistcodename => 'squeeze'
+    } }
+    let (:params) { {
+      :server_ddns_update => 'foo'
+    } }
+
+    it { should contain_concat__fragment('00.dhcp.server.base').with(
+        :ensure  => 'present',
+        :target  => '/etc/dhcp/dhcpd.conf',
+        :content => /log-facility/
+      ).with_content(/ddns-update-style foo;/).with_content(/#authoritative/)
+    }
+  end
+
+  context 'When passing authoritative' do
+    let (:facts) { {
+      :operatingsystem => 'Debian',
+      :osfamily        => 'Debian',
+      :lsbdistcodename => 'squeeze'
+    } }
+    let (:params) { {
+      :server_authoritative => true
+    } }
+
+    it { should contain_concat__fragment('00.dhcp.server.base').with(
+        :ensure  => 'present',
+        :target  => '/etc/dhcp/dhcpd.conf',
+        :content => /log-facility/
+      ).with_content(/ddns-update-style none;/).with_content(/[^#]authoritative/)
+    }
+  end
+
+  context 'When passing opts' do
+    let (:facts) { {
+      :operatingsystem => 'Debian',
+      :osfamily        => 'Debian',
+      :lsbdistcodename => 'squeeze'
+    } }
+    let (:params) { {
+      :server_opts => ['foo', 'bar', 'baz']
+    } }
+
+    it { should contain_concat__fragment('00.dhcp.server.base').with(
+        :ensure  => 'present',
+        :target  => '/etc/dhcp/dhcpd.conf',
+        :content => /log-facility/
+      ).with_content(/ddns-update-style none;/).with_content(/#authoritative/).with_content(/foo;\nbar;\nbaz;\n/)
+    }
+  end
 end
index ee95bee4fd1b65509660eb96515e9888776aa48f..7dfd168a69094131fc7ff40f4f1aac52691a9747 100644 (file)
@@ -4,22 +4,14 @@
 # attempt to do a DNS update when a lease is confirmed. We default to the
 # behavior of the version 2 packages ('none', since DHCP v2 didn't
 # have support for DDNS.)
-<% if has_variable?('dhcpd_ddns_update') -%>
-ddns-update-style <%=dhcpd_ddns_update%>;
-<% else -%>
-ddns-update-style none;
-<% end -%>
+ddns-update-style <%= @ddns_update %>;
 
 # If this DHCP server is the official DHCP server for the local
 # network, the authoritative directive should be uncommented.
-<% if has_variable?('dhcpd_authoritative') -%>
-authoritative;
-<% else -%>
-#authoritative;
-<% end -%>
+<% unless @authoritative -%>#<%- end -%>authoritative;
 
-<% if has_variable?('dhcpd_opts') and not dhcpd_opts.empty? -%>
-<%= dhcpd_opts.join(";\n") %>
+<% unless @opts.empty? -%>
+<%= @opts.join(";\n") %>;
 <% end -%>
 
 # Use this to send dhcp log messages to a different log file (you also