aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--manifests/shared_network.pp15
-rw-r--r--spec/defines/dhcp_shared_network_spec.rb71
-rw-r--r--templates/shared-network.erb9
3 files changed, 87 insertions, 8 deletions
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 -%>
}