From 745b2537e79eca59f8e9f2f15230482fcdf140aa Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 11:54:50 +0200 Subject: Refactor module * Use a top dhcp class with a $server boolean param * Refactor the dhcp::class to use packages/config/service classes * Don't use inheritance, put everything in dhcp::params --- manifests/init.pp | 7 +++++ manifests/params.pp | 7 +++++ manifests/server.pp | 6 ++-- manifests/server/base.pp | 65 -------------------------------------------- manifests/server/config.pp | 43 +++++++++++++++++++++++++++++ manifests/server/debian.pp | 21 -------------- manifests/server/packages.pp | 8 ++++++ manifests/server/service.pp | 10 +++++++ 8 files changed, 78 insertions(+), 89 deletions(-) create mode 100644 manifests/init.pp delete mode 100644 manifests/server/base.pp create mode 100644 manifests/server/config.pp delete mode 100644 manifests/server/debian.pp create mode 100644 manifests/server/packages.pp create mode 100644 manifests/server/service.pp (limited to 'manifests') diff --git a/manifests/init.pp b/manifests/init.pp new file mode 100644 index 0000000..8a14b13 --- /dev/null +++ b/manifests/init.pp @@ -0,0 +1,7 @@ +class dhcp ( + $server = true, +) { + if $server { + class { '::dhcp::server': } + } +} diff --git a/manifests/params.pp b/manifests/params.pp index d2ba584..20fbcd2 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -17,6 +17,13 @@ class dhcp::params { lenny => 'dhcp3-server', squeeze => 'isc-dhcp-server', } + + $service_pattern = $::lsbdistcodename? { + lenny => '/usr/sbin/dhcpd3', + squeeze => '/usr/sbin/dhcpd', + } + + $base_template = 'dhcp/dhcpd.conf.debian.erb' } default: { diff --git a/manifests/server.pp b/manifests/server.pp index 6bdf51f..779b305 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -33,7 +33,7 @@ node "dhcp.toto.ltd" { */ class dhcp::server { - case $::operatingsystem { - Debian: { include dhcp::server::debian } - } + class { '::dhcp::server::packages': } -> + class { '::dhcp::server::config': } ~> + class { '::dhcp::server::service': } } diff --git a/manifests/server/base.pp b/manifests/server/base.pp deleted file mode 100644 index 4e7d645..0000000 --- a/manifests/server/base.pp +++ /dev/null @@ -1,65 +0,0 @@ -# = Class dhcp::server::base -# -# Do NOT include this class - it won't work at all. -# Set variables for package name and so on. -# This class should be inherited in dhcp::server::$operatingsystem. -# -class dhcp::server::base { - - include dhcp::params - include concat::setup - - package {'dhcp-server': - ensure => present, - name => $dhcp::params::srv_dhcpd, - } - - service {'dhcpd': - ensure => running, - name => $dhcp::params::srv_dhcpd, - enable => true, - require => Package['dhcp-server'], - } - - concat {"${dhcp::params::config_dir}/dhcpd.conf": - owner => root, - group => root, - mode => '0644', - } - - concat::fragment {'00.dhcp.server.base': - ensure => present, - target => "${dhcp::params::config_dir}/dhcpd.conf", - require => Package['dhcp-server'], - notify => Service['dhcpd'], - } - - file {"${dhcp::params::config_dir}/dhcpd.conf.d": - ensure => directory, - mode => '0700', - recurse => true, - purge => true, - force => true, - source => 'puppet:///modules/dhcp/empty' - } - - file {"${dhcp::params::config_dir}/subnets": - ensure => directory, - recurse => true, - purge => true, - force => true, - source => 'puppet:///modules/dhcp/empty', - require => Package['dhcp-server'], - notify => Service['dhcpd'], - } - - file {"${dhcp::params::config_dir}/hosts.d": - ensure => directory, - recurse => true, - purge => true, - force => true, - source => 'puppet:///modules/dhcp/empty', - require => Package['dhcp-server'], - } - -} diff --git a/manifests/server/config.pp b/manifests/server/config.pp new file mode 100644 index 0000000..c37d044 --- /dev/null +++ b/manifests/server/config.pp @@ -0,0 +1,43 @@ +class dhcp::server::config { + include ::dhcp::params + include ::concat::setup + + concat {"${dhcp::params::config_dir}/dhcpd.conf": + owner => root, + group => root, + mode => '0644', + } + + concat::fragment {'00.dhcp.server.base': + ensure => present, + target => "${dhcp::params::config_dir}/dhcpd.conf", + content => template($dhcp::params::base_template), + } + + file {"${dhcp::params::config_dir}/dhcpd.conf.d": + ensure => directory, + mode => '0700', + recurse => true, + purge => true, + force => true, + source => "puppet:///modules/${module_name}/empty" + } + + file {"${dhcp::params::config_dir}/subnets": + ensure => directory, + recurse => true, + purge => true, + force => true, + source => "puppet:///modules/${module_name}/empty", + require => Package['dhcp-server'], + notify => Service['dhcpd'], + } + + file {"${dhcp::params::config_dir}/hosts.d": + ensure => directory, + recurse => true, + purge => true, + force => true, + source => "puppet:///modules/${module_name}/empty", + } +} diff --git a/manifests/server/debian.pp b/manifests/server/debian.pp deleted file mode 100644 index 5d23bbe..0000000 --- a/manifests/server/debian.pp +++ /dev/null @@ -1,21 +0,0 @@ -# = Class: dhcp::server::debian -# -# Installs a dhcp server on debian system. -# -# This class should not be included as is, -# please include "dhcp::server" instead. -# -class dhcp::server::debian inherits dhcp::server::base { - - Concat::Fragment['00.dhcp.server.base'] { - content => template('dhcp/dhcpd.conf.debian.erb'), - } - - Service['dhcpd'] { - pattern => $::lsbdistcodename ? { - squeeze => '/usr/sbin/dhcpd', - lenny => '/usr/sbin/dhcpd3', - } - } - -} diff --git a/manifests/server/packages.pp b/manifests/server/packages.pp new file mode 100644 index 0000000..34751e8 --- /dev/null +++ b/manifests/server/packages.pp @@ -0,0 +1,8 @@ +class dhcp::server::packages { + include ::dhcp::params + + package {'dhcp-server': + ensure => present, + name => $dhcp::params::srv_dhcpd, + } +} diff --git a/manifests/server/service.pp b/manifests/server/service.pp new file mode 100644 index 0000000..d531a7d --- /dev/null +++ b/manifests/server/service.pp @@ -0,0 +1,10 @@ +class dhcp::server::service { + include ::dhcp::params + + service {'dhcpd': + ensure => running, + name => $dhcp::params::srv_dhcpd, + enable => true, + pattern => $dhcp::params::service_pattern, + } +} -- cgit v1.2.3 From 90aa04648bf2e79890e47b8f84df8903f9958a12 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 11:58:37 +0200 Subject: Use # as comments --- manifests/server.pp | 65 +++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'manifests') diff --git a/manifests/server.pp b/manifests/server.pp index 779b305..63e9f37 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,37 +1,34 @@ -/* - -= Class: dhcp::server -Simple OS wrapper. Include this to install a dhcp server on your host. - -Requires: - 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 - -Example: -node "dhcp.toto.ltd" { - $dhcpd_opts = ['domain-name "toto.ltd"', "domain-name-servers 192.168.21.1"] - include dhcp::server - - dhcp::subnet {"10.27.20.0": - ensure => present, - broadcast => "10.27.20.255", - other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], - } - - dhcp::host {"titi-eth0": - ensure => present, - mac => "0e:18:fa:fe:d9:00", - subnet => "10.27.20.0", - fixed_address => "10.27.10.52", - } -} -*/ - +# = Class: dhcp::server +# Simple OS wrapper. Include this to install a dhcp server on your host. +# +# Requires: +# 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 +# +# Example: +# node "dhcp.toto.ltd" { +# $dhcpd_opts = ['domain-name "toto.ltd"', "domain-name-servers 192.168.21.1"] +# include dhcp::server +# +# dhcp::subnet {"10.27.20.0": +# ensure => present, +# broadcast => "10.27.20.255", +# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], +# } +# +# dhcp::host {"titi-eth0": +# ensure => present, +# mac => "0e:18:fa:fe:d9:00", +# subnet => "10.27.20.0", +# fixed_address => "10.27.10.52", +# } +# } +# class dhcp::server { class { '::dhcp::server::packages': } -> class { '::dhcp::server::config': } ~> -- cgit v1.2.3 From 87096a875d4bee517e0c8c807218394a2024bd46 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 12:21:01 +0200 Subject: Add variable validations --- manifests/params.pp | 4 ++-- manifests/server/config.pp | 13 ++++++++++--- manifests/server/packages.pp | 7 +++++++ manifests/server/service.pp | 9 +++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) (limited to 'manifests') diff --git a/manifests/params.pp b/manifests/params.pp index 20fbcd2..925f3f5 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,4 +1,4 @@ -# = Class: dhcp::params +# Class: dhcp::params # # Do NOT include this class - it won't do anything. # Set variables for names and paths @@ -23,7 +23,7 @@ class dhcp::params { squeeze => '/usr/sbin/dhcpd', } - $base_template = 'dhcp/dhcpd.conf.debian.erb' + $server_template = "${module_name}/dhcpd.conf.debian.erb" } default: { diff --git a/manifests/server/config.pp b/manifests/server/config.pp index c37d044..4898a60 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -1,7 +1,16 @@ +# Class: dhcp::server::config +# +# Configure the DHCP server +# class dhcp::server::config { include ::dhcp::params include ::concat::setup + validate_string($dhcp::params::config_dir) + validate_absolute_path($dhcp::params::config_dir) + validate_string($dhcp::params::server_template) + validate_re($dhcp::params::server_template, '^\S+$') + concat {"${dhcp::params::config_dir}/dhcpd.conf": owner => root, group => root, @@ -11,7 +20,7 @@ class dhcp::server::config { concat::fragment {'00.dhcp.server.base': ensure => present, target => "${dhcp::params::config_dir}/dhcpd.conf", - content => template($dhcp::params::base_template), + content => template($dhcp::params::server_template), } file {"${dhcp::params::config_dir}/dhcpd.conf.d": @@ -29,8 +38,6 @@ class dhcp::server::config { purge => true, force => true, source => "puppet:///modules/${module_name}/empty", - require => Package['dhcp-server'], - notify => Service['dhcpd'], } file {"${dhcp::params::config_dir}/hosts.d": diff --git a/manifests/server/packages.pp b/manifests/server/packages.pp index 34751e8..b89ede3 100644 --- a/manifests/server/packages.pp +++ b/manifests/server/packages.pp @@ -1,6 +1,13 @@ +# Class: dhcp::server::packages +# +# Install the DHCP server +# class dhcp::server::packages { include ::dhcp::params + validate_string($dhcp::params::srv_dhcpd) + validate_re($dhcp::params::srv_dhcpd, '^\S+$') + package {'dhcp-server': ensure => present, name => $dhcp::params::srv_dhcpd, diff --git a/manifests/server/service.pp b/manifests/server/service.pp index d531a7d..ef016c5 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -1,6 +1,15 @@ +# Class: dhcp::server::service +# +# Manage the DHCP server service +# class dhcp::server::service { include ::dhcp::params + validate_string($dhcp::params::srv_dhcpd) + validate_re($dhcp::params::srv_dhcpd, '^\S+$') + validate_string($dhcp::params::service_pattern) + validate_re($dhcp::params::service_pattern, '^\S+$') + service {'dhcpd': ensure => running, name => $dhcp::params::srv_dhcpd, -- cgit v1.2.3 From 4cc54cff2d04eedb672c7cc6b92a5edcccac63c9 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 12:34:23 +0200 Subject: Add spec tests for the dhcp class --- manifests/hosts.pp | 2 +- manifests/params.pp | 2 +- spec/classes/dhcp_spec.rb | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 spec/classes/dhcp_spec.rb (limited to 'manifests') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index b159449..426d661 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -42,7 +42,7 @@ define dhcp::hosts ( $template = 'dhcp/host.conf.erb', ) { - include dhcp::params + include ::dhcp::params concat::fragment {"dhcp.host.${name}": target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", diff --git a/manifests/params.pp b/manifests/params.pp index 925f3f5..0938e4a 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -27,7 +27,7 @@ class dhcp::params { } default: { - fail "${name} is not available for ${::operatingsystem}/${::lsbdistcodename}" + fail "Unsupported OS ${::operatingsystem}/${::lsbdistcodename}" } } diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb new file mode 100644 index 0000000..c833c52 --- /dev/null +++ b/spec/classes/dhcp_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe 'dhcp' do + context 'When on an unsupported OS' do + let (:facts) { { + :operatingsystem => 'RedHat', + :osfamily => 'Redhat', + :lsbdistcodename => 'Santiago' + } } + + it 'should fail' do + expect { + should contain_package('dhcp-server') + }.to raise_error(Puppet::Error, /Unsupported OS RedHat\/Santiago/) + end + end + + context 'When on Debian lenny' do + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'lenny' + } } + + # Package + it { should contain_package('dhcp-server').with( + :name => 'dhcp3-server' + ) } + + # Config + it { should contain_concat('/etc/dhcp3/dhcpd.conf').with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } + + # Service + it { should contain_service('dhcpd').with( + :ensure => 'running', + :name => 'dhcp3-server', + :enable => true, + :pattern => '/usr/sbin/dhcpd3' + ) } + end + + context 'When on Debian squeeze' do + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze' + } } + + # Package + it { should contain_package('dhcp-server').with( + :name => 'isc-dhcp-server' + ) } + + # Config + it { should contain_concat('/etc/dhcp/dhcpd.conf').with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } + + # Service + it { should contain_service('dhcpd').with( + :ensure => 'running', + :name => 'isc-dhcp-server', + :enable => true, + :pattern => '/usr/sbin/dhcpd' + ) } + end +end -- cgit v1.2.3 From a3158aaca4070a4de89b49d687854d72df8741fe Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 12:37:03 +0200 Subject: Fix trailing whitespaces --- manifests/server.pp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'manifests') diff --git a/manifests/server.pp b/manifests/server.pp index 63e9f37..ceffa14 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,26 +1,26 @@ # = Class: dhcp::server # Simple OS wrapper. Include this to install a dhcp server on your host. -# +# # Requires: # 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 -# +# # Example: # node "dhcp.toto.ltd" { # $dhcpd_opts = ['domain-name "toto.ltd"', "domain-name-servers 192.168.21.1"] # include dhcp::server -# +# # dhcp::subnet {"10.27.20.0": # ensure => present, # broadcast => "10.27.20.255", # other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], # } -# +# # dhcp::host {"titi-eth0": # ensure => present, # mac => "0e:18:fa:fe:d9:00", -- cgit v1.2.3 From 65bea20e0d8e61de7519bb1ab0677597500aaac7 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 14:25:15 +0200 Subject: Get rid of unscoped variables in dhcp::server, fix template --- manifests/init.pp | 9 +++++- manifests/server.pp | 20 +++++++----- manifests/server/config.pp | 4 +++ spec/classes/dhcp_spec.rb | 68 +++++++++++++++++++++++++++++++++++++++++ templates/dhcpd.conf.debian.erb | 16 +++------- 5 files changed, 97 insertions(+), 20 deletions(-) (limited to 'manifests') diff --git a/manifests/init.pp b/manifests/init.pp index 8a14b13..e1e05b3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, + } } } diff --git a/manifests/server.pp b/manifests/server.pp index ceffa14..d83c26f 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -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, @@ -29,7 +31,11 @@ # } # } # -class dhcp::server { +class dhcp::server ( + $ddns_update = 'none', + $authoritative = false, + $opts = [], +) { class { '::dhcp::server::packages': } -> class { '::dhcp::server::config': } ~> class { '::dhcp::server::service': } diff --git a/manifests/server/config.pp b/manifests/server/config.pp index 4898a60..0c1a74a 100644 --- a/manifests/server/config.pp +++ b/manifests/server/config.pp @@ -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, diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index c833c52..ce9228e 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -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 diff --git a/templates/dhcpd.conf.debian.erb b/templates/dhcpd.conf.debian.erb index ee95bee..7dfd168 100644 --- a/templates/dhcpd.conf.debian.erb +++ b/templates/dhcpd.conf.debian.erb @@ -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 -- cgit v1.2.3 From 2b4ea8662914c9652cfde1834bbfdc6d25e45209 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Thu, 11 Apr 2013 14:37:04 +0200 Subject: Doc in dhcp::server --- manifests/server.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'manifests') diff --git a/manifests/server.pp b/manifests/server.pp index d83c26f..1c77cf2 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -5,10 +5,10 @@ # module "common": git://github.com/camptocamp/puppet-common.git # # facultative argument: -# *$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 +# *$ddns_update* : ddns-update-style option (defaults to 'none') +# *$authoritative* : a boolean setting whether the DHCP server is +# authoritative (defaults to false) +# *$opts* : an array of DHCPD valid options # # Example: # node "dhcp.toto.ltd" { -- cgit v1.2.3 From f4e7bdf477586e34e47a972172c15809ac92fe3c Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:38:14 +0200 Subject: Improve template host.conf.erb with validations and add spec for dhcp::hosts --- manifests/hosts.pp | 26 ++- spec/defines/dhcp_hosts_spec.rb | 411 ++++++++++++++++++++++++++++++++++++++++ templates/host.conf.erb | 32 ++-- 3 files changed, 451 insertions(+), 18 deletions(-) create mode 100644 spec/defines/dhcp_hosts_spec.rb (limited to 'manifests') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 426d661..f8e5faf 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -1,4 +1,4 @@ -# = Definition: dhcp::hosts +# Definition: dhcp::hosts # # Creates a dhcp configuration for given hosts # @@ -38,15 +38,27 @@ define dhcp::hosts ( $hash_data, $subnet, - $global_options = false, - $template = 'dhcp/host.conf.erb', + $ensure = present, + $global_options = [], + $template = "${module_name}/host.conf.erb", ) { include ::dhcp::params - concat::fragment {"dhcp.host.${name}": - target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", - content => template($template), - notify => Service['dhcpd'], + validate_string($ensure) + validate_re($ensure, ['present', 'absent'], + "\$ensure must be either 'present' or 'absent', got '${ensure}'") + validate_hash($hash_data) + validate_string($subnet) + validate_re($subnet, '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$') + validate_array($global_options) + validate_string($template) + + if ($ensure == 'present') { + concat::fragment {"dhcp.host.${name}": + target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", + content => template($template), + notify => Service['dhcpd'], + } } } diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb new file mode 100644 index 0000000..658be20 --- /dev/null +++ b/spec/defines/dhcp_hosts_spec.rb @@ -0,0 +1,411 @@ +require 'spec_helper' + +describe 'dhcp::hosts' do + let (:title) { 'My hosts' } + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + } } + + context 'when passing wrong value for ensure' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :ensure => 'running' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end + + context 'when hash_data is not passed' do + let (:params) { { + :subnet => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/) + end + end + + context 'when passing wrong type for hash_data' do + let (:params) { { + :hash_data => 'foo', + :subnet => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not a Hash\./) + end + end + + context 'when subnet is not passed' do + let (:params) { { + :hash_data => {}, + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/) + end + end + + context 'when passing wrong type for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for global_options' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :global_options => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not an Array\./) + end + end + + context 'when passing wrong type for template' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :template => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing one entry in hash_data' do + context 'when passing wrong type for an host data' do + let (:params) { { + :hash_data => { + 'host1' => true, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a Hash/) + end + end + + context 'when interfaces is not passed' do + let (:params) { { + :hash_data => { + 'host1' => { + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/) + end + end + + context 'when passing wrong value for an interface' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth 0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"eth 0" does not match/) + end + end + + context 'when passing wrong type for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => true, + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => 'my mac', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my mac" does not match/) + end + end + + context 'when passing wrong type for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => true, + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string/) + end + end + + context 'when passing wrong value for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => 'my wrong value', + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my wrong value" does not match/) + end + end + + context 'when not passing fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /fixed-address host1;/ + ) } + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /foo;\nbar;\n/ + ) } + end + + context 'when overriding options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => ['baz'], + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /baz;\n/ + ) } + end + + context 'when passing wrong type for options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => true, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when passing wrong value for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => 'my wrong value', + }, + }, + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my wrong value" does not match/) + end + end + + context 'when not passing fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /fixed-address host1;/ + ) } + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :content => /foo;\nbar;\n/ + ) } + end + + context 'when passing two hosts' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + 'wlan0' => '00:aa:bb:44:55:ff', + }, + }, + 'host2' => { + 'interfaces' => { + 'eth1' => '00:11:af:33:44:55', + }, + 'fixed_address' => 'foo.example.com', + 'options' => ['opt1'], + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with_content( + /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( + /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( + /host host2-eth1 \{\n hardware ethernet 00:11:af:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) + } + end + end + + context 'when passing two entries in hash_data' do + end + + context 'when passing global_options' do + end + + context 'when overriding template' do + end +end diff --git a/templates/host.conf.erb b/templates/host.conf.erb index e6a7073..398d798 100644 --- a/templates/host.conf.erb +++ b/templates/host.conf.erb @@ -1,16 +1,26 @@ -<%- @hash_data.sort.each do |host, datas| -%> -<%- datas.fetch('interfaces').sort.each do |if_name, if_mac| -%> +<%- @hash_data.sort.each do |host, data| + scope.function_validate_hash([data]) -%> +<%- + raise Puppet::ParseError, "Missing interfaces hash for host '#{host}'" unless data.has_key? 'interfaces' + data.fetch('interfaces').sort.each do |if_name, if_mac| + scope.function_validate_re([if_name, '^\S+$']) + scope.function_validate_string([if_mac]) + scope.function_validate_re([if_mac, '^[a-f0-9:.]+$']) + -%> host <%= host %>-<%= if_name %> { hardware ethernet <%= if_mac %>; -<% if datas.fetch('fixed_address', false) -%> - fixed-address <%= datas.fetch('fixed_address') %>; -<% else -%> - fixed-address <%= host %>; -<% end -%> -<% if datas.fetch('option', false) -%> - <%= datas.fetch('option') %> -<% elsif @global_options -%> - <%= @global_options %> +<% + fixed_address = data.fetch('fixed_address', nil) || host + scope.function_validate_string([fixed_address]) + scope.function_validate_re([fixed_address, '^\S+$']) + -%> + fixed-address <%= fixed_address %>; +<% + options = data.fetch('options', nil) || @global_options + scope.function_validate_array([options]) + unless options.empty? + -%> + <%= options.join(";\n") %>; <% end -%> } <% end -%> -- cgit v1.2.3 From f7025518512c0bf8d63f413f7be78347fedee9f4 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:50:24 +0200 Subject: Test target for concat::fragment in dhcp::hosts --- manifests/hosts.pp | 8 +++----- spec/defines/dhcp_hosts_spec.rb | 7 ++++++- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'manifests') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index f8e5faf..676d507 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -4,15 +4,14 @@ # # Arguments # $template: dhcp host template - default: 'dhcp/host.conf.erb' -# $global_options: global options for the whole bunch of hosts. +# $global_options: an array of global options for the whole bunch of hosts. # you may override it per host, setting the host "options" # directly in the hash. # $subnet: targeted subnet # $hash_data: hash containing data - default form: # { # => { -# options => false, -# fixed_address => false, +# options => ['opt1', 'opt2'], # interfaces => { # eth0 => 'mac-address', # eth1 => 'mac-address', @@ -22,8 +21,7 @@ # } # }, # => { -# options => false, -# fixed_address => false, +# fixed_address => 'foo.example.com', # interfaces => { # eth0 => 'mac-address', # eth1 => 'mac-address', diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb index c8face6..f5f44ca 100644 --- a/spec/defines/dhcp_hosts_spec.rb +++ b/spec/defines/dhcp_hosts_spec.rb @@ -255,6 +255,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /fixed-address host1;/ ) } end @@ -273,6 +274,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /foo;\nbar;\n/ ) } end @@ -292,6 +294,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /baz;\n/ ) } end @@ -331,6 +334,7 @@ describe 'dhcp::hosts' do } } it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', :content => /foo;\nbar;\n/ ) } end @@ -355,7 +359,8 @@ describe 'dhcp::hosts' do :subnet => '1.2.3.4' } } - it { should contain_concat__fragment('dhcp.host.My hosts').with_content( + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content( /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( /host host2-eth1 \{\n hardware ethernet 00:11:af:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) -- cgit v1.2.3 From e1f00ed6c75724251c3e205a3a50c7a3a4bcb077 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:53:21 +0200 Subject: Rename shared-network as shared_network --- manifests/shared-network.pp | 25 ------------------------- manifests/shared_network.pp | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) delete mode 100644 manifests/shared-network.pp create mode 100644 manifests/shared_network.pp (limited to 'manifests') diff --git a/manifests/shared-network.pp b/manifests/shared-network.pp deleted file mode 100644 index 9a02a5b..0000000 --- a/manifests/shared-network.pp +++ /dev/null @@ -1,25 +0,0 @@ -# == Definition: dhcp::shared-network -# Creates a shared-network -# -# Arguments: -# *$subnets* : subnet list to be included in the shared-network -# -# Warnings: -# - subnets must exists -# - subnets must have $is_shared set to true (default is false) -# -define dhcp::shared-network( - $ensure = present, - $subnets = [] -) { - - include dhcp::params - - concat::fragment {"shared-${name}": - ensure => $ensure, - target => "${dhcp::params::config_dir}/dhcpd.conf", - content => template('dhcp/shared-network.erb'), - require => Dhcp::Subnet[$subnets], - } - -} diff --git a/manifests/shared_network.pp b/manifests/shared_network.pp new file mode 100644 index 0000000..9a02a5b --- /dev/null +++ b/manifests/shared_network.pp @@ -0,0 +1,25 @@ +# == Definition: dhcp::shared-network +# Creates a shared-network +# +# Arguments: +# *$subnets* : subnet list to be included in the shared-network +# +# Warnings: +# - subnets must exists +# - subnets must have $is_shared set to true (default is false) +# +define dhcp::shared-network( + $ensure = present, + $subnets = [] +) { + + include dhcp::params + + concat::fragment {"shared-${name}": + ensure => $ensure, + target => "${dhcp::params::config_dir}/dhcpd.conf", + content => template('dhcp/shared-network.erb'), + require => Dhcp::Subnet[$subnets], + } + +} -- cgit v1.2.3 From f28c3616cefa8f2c53fd04cbc2b3a58b0cb4f0be Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 10:56:56 +0200 Subject: Pass $ensure to concat::fragment in dhcp::hosts --- manifests/hosts.pp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'manifests') diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 676d507..9e2b284 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -52,11 +52,10 @@ define dhcp::hosts ( validate_array($global_options) validate_string($template) - if ($ensure == 'present') { - concat::fragment {"dhcp.host.${name}": - target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", - content => template($template), - notify => Service['dhcpd'], - } + concat::fragment {"dhcp.host.${name}": + ensure => $ensure, + target => "${dhcp::params::config_dir}/hosts.d/${subnet}.conf", + content => template($template), + notify => Service['dhcpd'], } } -- cgit v1.2.3 From b35e1322d0a791ab22cb2c385ec913492c75026d Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 11:10:45 +0200 Subject: Rename dhcp::shared-network to dhcp::shared_network, add specs --- manifests/shared_network.pp | 15 ++++--- spec/defines/dhcp_shared_network_spec.rb | 71 ++++++++++++++++++++++++++++++++ templates/shared-network.erb | 9 ++-- 3 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 spec/defines/dhcp_shared_network_spec.rb (limited to 'manifests') diff --git a/manifests/shared_network.pp b/manifests/shared_network.pp index 9a02a5b..38f14fb 100644 --- a/manifests/shared_network.pp +++ b/manifests/shared_network.pp @@ -8,17 +8,22 @@ # - subnets must exists # - subnets must have $is_shared set to true (default is false) # -define dhcp::shared-network( +define dhcp::shared_network( $ensure = present, - $subnets = [] + $subnets = [], ) { - include dhcp::params + include ::dhcp::params - concat::fragment {"shared-${name}": + validate_string($ensure) + validate_re($ensure, ['present', 'absent'], + "\$ensure must be either 'present' or 'absent', got '${ensure}'") + validate_array($subnets) + + concat::fragment {"dhcp-shared-${name}": ensure => $ensure, target => "${dhcp::params::config_dir}/dhcpd.conf", - content => template('dhcp/shared-network.erb'), + content => template("${module_name}/shared-network.erb"), require => Dhcp::Subnet[$subnets], } diff --git a/spec/defines/dhcp_shared_network_spec.rb b/spec/defines/dhcp_shared_network_spec.rb new file mode 100644 index 0000000..ff5a2c5 --- /dev/null +++ b/spec/defines/dhcp_shared_network_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper' + +describe 'dhcp::shared_network' do + let (:title) { 'My network' } + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze' + } } + + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'running', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end + + context 'when passing wrong type for subnets' do + let (:params) { { + :subnets => true, + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when passing no parameters' do + it { should contain_concat__fragment('dhcp-shared-My network').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf' + ).with_content( + /shared-network My network/ + ) + } + end + + context 'when passing wrong type for a subnet' do + let (:params) { { + :subnets => [true], + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for a subnet' do + let (:params) { { + :subnets => ['wrong value'], + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /"wrong value" does not match/) + end + end + + context 'when passing subnets' do + end +end diff --git a/templates/shared-network.erb b/templates/shared-network.erb index 99a7aca..407106a 100644 --- a/templates/shared-network.erb +++ b/templates/shared-network.erb @@ -1,6 +1,9 @@ -#### dhcp::shared-network <%= name %> -shared-network <%= name %> { -<% subnets.each do |subnet| -%> +#### dhcp::shared_network <%= @name %> +shared-network <%= @name %> { +<% @subnets.each do |subnet| + scope.function_validate_string([subnet]) + scope.function_validate_re([subnet, '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$']) +-%> include "<%= scope.lookupvar("dhcp::params::config_dir") %>/subnets/<%= subnet %>.conf"; <% end -%> } -- cgit v1.2.3 From eda301b7ba8f8827d1c9973ffaba0c1c7a029d98 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 12:29:45 +0200 Subject: Add spec for dhcp::subnet and improve template and definition --- manifests/subnet.pp | 57 +++++---- spec/defines/dhcp_subnet_spec.rb | 252 +++++++++++++++++++++++++++++++++++++++ templates/subnet.conf.erb | 49 ++++---- 3 files changed, 307 insertions(+), 51 deletions(-) create mode 100644 spec/defines/dhcp_subnet_spec.rb (limited to 'manifests') diff --git a/manifests/subnet.pp b/manifests/subnet.pp index 18ffdc5..b9826da 100644 --- a/manifests/subnet.pp +++ b/manifests/subnet.pp @@ -27,16 +27,29 @@ # define dhcp::subnet( $broadcast, - $ensure=present, - $netmask=false, - $routers=false, - $subnet_mask=false, - $domain_name=false, - $other_opts=false, - $is_shared=false + $ensure = present, + $netmask = undef, + $routers = [], + $subnet_mask = undef, + $domain_name = undef, + $other_opts = [], + $is_shared = false ) { - include dhcp::params + include ::dhcp::params + + $ip_re = '^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$' + + validate_string($ensure) + validate_re($ensure, ['present', 'absent'], + "\$ensure must be either 'present' or 'absent', got '${ensure}'") + validate_string($broadcast) + validate_re($broadcast, $ip_re) + validate_string($netmask) + validate_array($routers) + validate_string($subnet_mask) + validate_string($domain_name) + validate_bool($is_shared) concat {"${dhcp::params::config_dir}/hosts.d/${name}.conf": owner => root, @@ -48,34 +61,30 @@ define dhcp::subnet( ensure => $ensure, owner => root, group => root, - content => template('dhcp/subnet.conf.erb'), + content => template("${module_name}/subnet.conf.erb"), notify => Service['dhcpd'], } - if ! $is_shared { - concat::fragment {"dhcp.${name}": - ensure => $ensure, - target => "${dhcp::params::config_dir}/dhcpd.conf", - content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n", - } - } else { - concat::fragment {"dhcp.${name}": - ensure => absent, - target => "${dhcp::params::config_dir}/dhcpd.conf", - content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n", - } - + $ensure_shared = $is_shared ? { + true => $ensure, + false => 'absent', + } + concat::fragment {"dhcp.subnet.${name}": + ensure => $ensure_shared, + target => "${dhcp::params::config_dir}/dhcpd.conf", + content => "include \"${dhcp::params::config_dir}/subnets/${name}.conf\";\n", } - concat::fragment {"subnet.${name}.hosts": + concat::fragment {"dhcp.subnet.${name}.hosts": ensure => $ensure, target => "${dhcp::params::config_dir}/dhcpd.conf", content => "include \"${dhcp::params::config_dir}/hosts.d/${name}.conf\";\n", } - concat::fragment {"00.dhcp.${name}.base": + concat::fragment {"dhcp.subnet.${name}.base": ensure => $ensure, target => "${dhcp::params::config_dir}/hosts.d/${name}.conf", content => "# File managed by puppet\n", + order => '00', } } diff --git a/spec/defines/dhcp_subnet_spec.rb b/spec/defines/dhcp_subnet_spec.rb new file mode 100644 index 0000000..48ab71b --- /dev/null +++ b/spec/defines/dhcp_subnet_spec.rb @@ -0,0 +1,252 @@ +require 'spec_helper' + +describe 'dhcp::subnet' do + let (:title) { '1.2.3.4' } + let (:facts) { { + :operatingsystem => 'Debian', + :osfamily => 'Debian', + :lsbdistcodename => 'squeeze', + :netmask_eth0 => '255.255.255.0', + :domain => 'example.com', + } } + + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'running', + :broadcast => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end + + context 'when not passing broadcast' do + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /Must pass broadcast to Dhcp::Subnet/) + end + end + + context 'when passing wrong type for broadcast' do + let (:params) { { + :broadcast => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for broadcast' do + let (:params) { { + :broadcast => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for netmask' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for netmask' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for routers' do + let (:params) { { + :broadcast => '1.2.3.4', + :routers => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when passing wrong type for subnet_mask' do + let (:params) { { + :broadcast => '1.2.3.4', + :subnet_mask => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong type for domain_name' do + let (:params) { { + :broadcast => '1.2.3.4', + :domain_name => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong type for is_shared' do + let (:params) { { + :broadcast => '1.2.3.4', + :is_shared => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" is not a boolean\./) + end + end + + context 'when using defaults' do + let (:params) { { + :broadcast => '1.2.3.4', + } } + + it { should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf').with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + /subnet 1\.2\.3\.4 netmask 255\.255\.255\.0 \{\n/ + ).with_content( + /option routers 255\.255\.255\.0;\n/ + ).with_content( + /option subnet-mask 255\.255\.255\.0;\n/ + ).with_content( + /option broadcast-address 1\.2\.3\.4;\n/ + ).with_content( + /option domain-name "example\.com";\n/ + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( + :ensure => 'absent' + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.hosts').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => "include \"/etc/dhcp/hosts.d/1\.2\.3\.4\.conf\";\n" + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.base').with( + :ensure => 'present', + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => "# File managed by puppet\n", + :order => '00' + ) } + end + + context 'when is_shared is true' do + let (:params) { { + :broadcast => '1.2.3.4', + :is_shared => true, + } } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n" + ) } + end + + context 'when passing other_opts as array' do + let (:params) { { + :broadcast => '1.2.3.4', + :other_opts => ['foo', 'bar'], + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + / foo;\n bar;\n/ + ) } + end + + context 'when passing other_opts as string' do + let (:params) { { + :broadcast => '1.2.3.4', + :other_opts => 'bar', + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + / bar;\n/ + ) } + end + + context 'when overriding all parameters' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => '255.1.2.0', + :routers => ['2.3.4.5', '3.4.5.6'], + :subnet_mask => '255.255.1.0', + :domain_name => 'foo.io', + :other_opts => ['foo', 'bar'], + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + /subnet 1\.2\.3\.4 netmask 255\.1\.2\.0 \{\n/ + ).with_content( + /option routers 2\.3\.4\.5,3\.4\.5\.6;\n/ + ).with_content( + /option subnet-mask 255\.255\.1\.0;\n/ + ).with_content( + /option broadcast-address 1\.2\.3\.4;\n/ + ).with_content( + /option domain-name "foo\.io";\n/ + ).with_content( + / foo;\n bar;\n/ + ) } + end +end diff --git a/templates/subnet.conf.erb b/templates/subnet.conf.erb index 89ca82f..11f9ed4 100644 --- a/templates/subnet.conf.erb +++ b/templates/subnet.conf.erb @@ -1,33 +1,28 @@ # File managed by puppet -<% if netmask -%> -subnet <%=name%> netmask <%=netmask%> { -<% else -%> -subnet <%=name%> netmask <%=netmask_eth0%> { -<% end -%> -<% if routers and not routers.empty? -%> - option routers <%= routers.collect! {|i| "#{i}" }.join(",") %>; -<% else -%> - option routers <%=network_eth0%>; -<% end -%> -<% if subnet_mask -%> - option subnet-mask <%=subnet_mask%>; -<% elsif netmask -%> - option subnet-mask <%=netmask%>; -<% else -%> - option subnet-mask <%=netmask_eth0%>; -<% end -%> - option broadcast-address <%=broadcast%>; -<% if domain_name -%> - option domain-name "<%=domain_name%>"; -<% else -%> - option domain-name "<%=domain%>"; -<% end -%> -<% if other_opts and not other_opts.empty? -%> - <% if other_opts.is_a?(Array) -%> -<%= other_opts.collect! {|i| " #{i};"}.join("\n") %> +<%- + _netmask = @netmask || scope.lookupvar('::netmask_eth0') + scope.function_validate_re([_netmask, @ip_re]) -%> +subnet <%= @name %> netmask <%= _netmask %> { +<%- + _routers = @routers unless @routers.empty? + _routers ||= [scope.lookupvar('::netmask_eth0')] + scope.function_validate_array([_routers]) -%> + option routers <%= _routers.collect! {|i| "#{i}" }.join(',') %>; +<%- + _subnet_mask = @subnet_mask || _netmask + scope.function_validate_re([_subnet_mask, @ip_re]) -%> + option subnet-mask <%= _subnet_mask %>; + option broadcast-address <%= @broadcast %>; +<%- + _domain_name = @domain_name || scope.lookupvar('::domain') + 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 -%> - <%=other_opts%>; + <%= @other_opts %>; <% end -%> <% end -%> } -- cgit v1.2.3 From 928dbaa62bcc37092ddec36b1f715365576eae6d Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 14:11:44 +0200 Subject: doc --- README.md | 8 +++++++ manifests/hosts.pp | 38 +++++++++++++++++++++++++------ manifests/init.pp | 22 ++++++++++++++++++ manifests/server.pp | 54 +++++++++++++++++++++++---------------------- manifests/shared_network.pp | 20 ++++++++++++----- manifests/subnet.pp | 34 ++++++++++++++-------------- 6 files changed, 120 insertions(+), 56 deletions(-) (limited to 'manifests') diff --git a/README.md b/README.md index 7a54b86..eb129db 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,14 @@ This module is provided by [Camptocamp](http://www.camptocamp.com/) * dhcp * dhcp::server +### dhcp + +The `dhcp` class is a wrapper around `dhcp::server`: + + include ::dhcp + +### dhcp::server + ## Definitions * dhcp::hosts diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 9e2b284..1767a90 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -2,13 +2,13 @@ # # Creates a dhcp configuration for given hosts # -# Arguments -# $template: dhcp host template - default: 'dhcp/host.conf.erb' -# $global_options: an array of global options for the whole bunch of hosts. -# you may override it per host, setting the host "options" -# directly in the hash. -# $subnet: targeted subnet -# $hash_data: hash containing data - default form: +# Parameters: +# ['template'] - DHCP host template - default: 'dhcp/host.conf.erb' +# ['global_options'] - An array of global options for the whole bunch of +# hosts. You may override it per host, setting the +# host "options" directly in the hash. +# ['subnet'] - Targeted subnet +# ['hash_data'] - Hash containing data - default form: # { # => { # options => ['opt1', 'opt2'], @@ -33,6 +33,30 @@ # …, # } # +# Sample usage: +# ::dhcp::hosts { 'workstations': +# subnet => '192.168.1.0', +# 'hash_data' => { +# 'host1' => { +# 'interfaces' => { +# 'eth0' => '00:11:22:33:44:55', +# 'wlan0' => '00:aa:bb:44:55:ff', +# }, +# }, +# 'host2' => { +# 'interfaces' => { +# 'eth1' => '00:11:af:33:44:55', +# }, +# 'fixed_address' => 'foo.example.com', +# 'options' => ['opt1'], +# }, +# }, +# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat +# define dhcp::hosts ( $hash_data, $subnet, diff --git a/manifests/init.pp b/manifests/init.pp index e1e05b3..9af496f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,3 +1,25 @@ +# Class: dhcp +# +# This class provides a simple way to install a DHCP server +# It will install and configure the necessary packages. +# +# Parameters: +# ['server'] - Whether to install the DHCP server +# (default: true) +# ['server_ddns_update'] - Set ddns_update on dhcp::server +# ['server_authoritative'] - Set authoritative on dhcp::server +# ['server_opts'] - Set opts for dhcp::server +# +# Actions: +# - Deploys a DHCP server +# +# Sample usage: +# include ::dhcp +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat +# class dhcp ( $server = true, $server_ddns_update = undef, diff --git a/manifests/server.pp b/manifests/server.pp index 1c77cf2..a44cfe1 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,35 +1,37 @@ -# = Class: dhcp::server -# Simple OS wrapper. Include this to install a dhcp server on your host. +# Class: dhcp::server # -# Requires: -# module "common": git://github.com/camptocamp/puppet-common.git +# Installs and configures a DHCP server. # -# facultative argument: -# *$ddns_update* : ddns-update-style option (defaults to 'none') -# *$authoritative* : a boolean setting whether the DHCP server is -# authoritative (defaults to false) -# *$opts* : an array of DHCPD valid options +# Parameters: +# ['ddns_update'] : ddns-update-style option (defaults to 'none') +# ['authoritative'] : a boolean setting whether the DHCP server is +# authoritative (defaults to false) +# ['opts'] : an array of DHCPD valid options # -# Example: -# node "dhcp.toto.ltd" { -# class { 'dhcp::server': -# opts => ['domain-name "toto.ltd"', -# 'domain-name-servers 192.168.21.1'], -# } +# Sample usage: +# node "dhcp.toto.ltd" { +# class { 'dhcp::server': +# opts => ['domain-name "toto.ltd"', +# 'domain-name-servers 192.168.21.1'], +# } # -# dhcp::subnet {"10.27.20.0": -# ensure => present, -# broadcast => "10.27.20.255", -# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], -# } +# dhcp::subnet {"10.27.20.0": +# ensure => present, +# broadcast => "10.27.20.255", +# other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], +# } # -# dhcp::host {"titi-eth0": -# ensure => present, -# mac => "0e:18:fa:fe:d9:00", -# subnet => "10.27.20.0", -# fixed_address => "10.27.10.52", +# dhcp::host {"titi-eth0": +# ensure => present, +# mac => "0e:18:fa:fe:d9:00", +# subnet => "10.27.20.0", +# fixed_address => "10.27.10.52", +# } # } -# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat # class dhcp::server ( $ddns_update = 'none', diff --git a/manifests/shared_network.pp b/manifests/shared_network.pp index 38f14fb..766f432 100644 --- a/manifests/shared_network.pp +++ b/manifests/shared_network.pp @@ -1,12 +1,22 @@ -# == Definition: dhcp::shared-network +# Definition: dhcp::shared-network +# # Creates a shared-network # -# Arguments: -# *$subnets* : subnet list to be included in the shared-network +# Parameters: +# ['subnets'] - An array of subnets to be included in the shared-network. +# +# Sample usage: +# ::dhcp::shared_network { 'office': +# subnets => ['192.168.1.0', '192.168.2.0'], +# } +# +# Requires: +# - puppetlabs/stdlib +# - ripienaar/concat # # Warnings: -# - subnets must exists -# - subnets must have $is_shared set to true (default is false) +# - subnets must exists +# - subnets must have $is_shared set to true (default is false) # define dhcp::shared_network( $ensure = present, diff --git a/manifests/subnet.pp b/manifests/subnet.pp index b9826da..b70a233 100644 --- a/manifests/subnet.pp +++ b/manifests/subnet.pp @@ -1,29 +1,27 @@ -# = Definition: dhcp::subnet -# Creates a subnet -# -# Arguments: -# *$broadcast* : subnet broadcast (mandatory) -# *$netmask* : subnet netmask (if not set, takes eth0 netmask) -# *$routers* : subnet routers (array) (if not set, takes eth0 IP) -# *$subnet_mask* : netmask sent to dhcp guests (if not set, takes -# $netmask, or netmask_eth0) -# *$domain_name* : subnet domain name (if not set, takes server domain) -# *$other_opts* : any other DHCPD option, as an array -# *$is_shared* : whether it's part of a shared network or not. Default: false +# Definition: dhcp::subnet # -# Example: +# Creates a subnet # -# node "dhcp.domain.ltd" { -# $dhcpd_domain_name = 'domain.ltd' -# $dhcpd_dns_servers = '10.27.21.1, 10.26.21.1' -# include dhcp +# Parameters: +# ['broadcast'] : subnet broadcast (mandatory) +# ['netmask'] : subnet netmask +# (default: $::netmask_eth0) +# ['routers'] : An array of subnet routers +# (default: $::netmask) +# ['subnet_mask'] : netmask sent to dhcp guests +# (default: the value of $netmask) +# ['domain_name'] : subnet domain name +# (default: $::domain) +# ['other_opts'] : An array of additional DHCPD options +# ['is_shared'] : whether it's part of a shared network or not +# (default: false) # +# Sample usage: # dhcp::subnet {"10.27.20.0": # ensure => present, # broadcast => "10.27.20.255", # other_opts => ['filename "pxelinux.0";', 'next-server 10.27.10.1;'], # } -# } # define dhcp::subnet( $broadcast, -- cgit v1.2.3 From 6fd559e9c99e85426d41358a5ed95c522c8031bc Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 14:20:38 +0200 Subject: README --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ manifests/hosts.pp | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'manifests') diff --git a/README.md b/README.md index eb129db..eb8ae5b 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,60 @@ The `dhcp` class is a wrapper around `dhcp::server`: ### dhcp::server +Installs a DHCP server: + + class { 'dhcp::server': + opts => ['domain-name "toto.ltd"', + 'domain-name-servers 192.168.21.1'], + } + ## Definitions * dhcp::hosts * dhcp::shared\_network * dhcp::subnet +### dhcp::hosts + +Creates a DHCP configuration for the given hosts: + + dhcp::hosts { 'workstations': + subnet => '192.168.1.0', + 'hash_data' => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + 'wlan0' => '00:aa:bb:44:55:ff', + }, + }, + 'host2' => { + 'interfaces' => { + 'eth1' => '00:11:af:33:44:55', + }, + 'fixed_address' => 'foo.example.com', + 'options' => ['opt1'], + }, + }, + } + +### dhcp::shared\_network + +Creates a shared-network entry: + + dhcp::shared_network { 'office': + subnets => ['192.168.1.0', '192.168.2.0'], + } + +### dhcp::subnet + +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;'], + } + ## Contributing Please report bugs and feature request using [GitHub issue diff --git a/manifests/hosts.pp b/manifests/hosts.pp index 1767a90..9c5d1b3 100644 --- a/manifests/hosts.pp +++ b/manifests/hosts.pp @@ -1,6 +1,6 @@ # Definition: dhcp::hosts # -# Creates a dhcp configuration for given hosts +# Creates a dhcp configuration for the given hosts # # Parameters: # ['template'] - DHCP host template - default: 'dhcp/host.conf.erb' -- cgit v1.2.3 From c0f46562b70777b9a4a39429d94c49e869150c64 Mon Sep 17 00:00:00 2001 From: Raphaël Pinson Date: Fri, 12 Apr 2013 15:14:55 +0200 Subject: Fix inverted logic for $is_shared in dhcp::subnet --- manifests/subnet.pp | 4 ++-- spec/defines/dhcp_subnet_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'manifests') diff --git a/manifests/subnet.pp b/manifests/subnet.pp index b70a233..e7c72dd 100644 --- a/manifests/subnet.pp +++ b/manifests/subnet.pp @@ -64,8 +64,8 @@ define dhcp::subnet( } $ensure_shared = $is_shared ? { - true => $ensure, - false => 'absent', + true => 'absent', + false => $ensure, } concat::fragment {"dhcp.subnet.${name}": ensure => $ensure_shared, diff --git a/spec/defines/dhcp_subnet_spec.rb b/spec/defines/dhcp_subnet_spec.rb index 48ab71b..b679551 100644 --- a/spec/defines/dhcp_subnet_spec.rb +++ b/spec/defines/dhcp_subnet_spec.rb @@ -161,7 +161,9 @@ describe 'dhcp::subnet' do ) } it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( - :ensure => 'absent' + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n" ) } it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.hosts').with( @@ -185,9 +187,7 @@ describe 'dhcp::subnet' do } } it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n" + :ensure => 'absent' ) } end -- cgit v1.2.3