From 742671ee4fa1171b0a0c2988a10e97e0023bff57 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Mon, 16 Jan 2017 14:08:59 +0100 Subject: [PATCH 01/22] fix for define resource zone --- manifests/object/zone.pp | 3 +-- spec/defines/zone_spec.rb | 12 +++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/manifests/object/zone.pp b/manifests/object/zone.pp index 8da98c647..2a274092f 100644 --- a/manifests/object/zone.pp +++ b/manifests/object/zone.pp @@ -48,7 +48,6 @@ validate_string($zone_name) validate_integer($order) - if $endpoints { validate_array($endpoints) } if $parent { validate_string($parent) } if $global { validate_bool($global) } @@ -68,7 +67,7 @@ } } else { $attrs = { - endpoints => $endpoints, + endpoints => any2array($endpoints), parent => $parent, } } diff --git a/spec/defines/zone_spec.rb b/spec/defines/zone_spec.rb index 2f9b1decf..432702a05 100644 --- a/spec/defines/zone_spec.rb +++ b/spec/defines/zone_spec.rb @@ -54,10 +54,11 @@ end - context "#{os} with endpoints => foo (not a valid array)" do + context "#{os} with endpoints => foo" do let(:params) { {:endpoints => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Zone::bar') + .with_content(/endpoints = \[ "foo", \]/) } end @@ -150,10 +151,11 @@ end - context "Windows 2012 R2 with endpoints => foo (not a valid array)" do + context "Windows 2012 R2 with endpoints => foo" do let(:params) { {:endpoints => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Zone::bar') + .with_content(/endpoints = \[ "foo", \]/) } end @@ -178,4 +180,4 @@ it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end -end \ No newline at end of file +end From 41f4aebf9c9b0d22fd2d2685cbf980b2434d600b Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 18:07:53 +0100 Subject: [PATCH 02/22] fix resource object --- manifests/object.pp | 10 ++++------ spec/defines/object_spec.rb | 40 +++++++++++++++++++++---------------- templates/object.conf.erb | 4 ++-- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/manifests/object.pp b/manifests/object.pp index 635b32334..2533c05a2 100644 --- a/manifests/object.pp +++ b/manifests/object.pp @@ -91,9 +91,6 @@ unless is_bool($apply) { validate_re($apply, '^.+\s+(=>\s+.+\s+)?in\s+.+$') } if $apply_target { validate_re($apply_target, ['^Host$', '^Service$'], "${apply_target} isn't supported. Valid values are 'Host' and 'Service'.") } - validate_array($import) - validate_array($assign) - validate_array($ignore) validate_hash($attrs) validate_string($object_type) validate_absolute_path($target) @@ -103,9 +100,10 @@ fail('The object type must be different from the apply target') } - $_attrs = merge($attrs, { - 'assign where' => $assign, - 'ignore where' => $ignore, + $_import = any2array($import) + $_attrs = merge($attrs, { + 'assign where' => any2array($assign), + 'ignore where' => any2array($ignore), }) if !defined(Concat[$target]) { diff --git a/spec/defines/object_spec.rb b/spec/defines/object_spec.rb index 7b9102cc2..652a716fa 100644 --- a/spec/defines/object_spec.rb +++ b/spec/defines/object_spec.rb @@ -142,10 +142,11 @@ end - context "#{os} with import => foo (not a valid array)" do + context "#{os} with import => foo" do let(:params) { {:import => 'foo', :object_type => 'foo', :target => '/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/import "foo"/) } end @@ -158,14 +159,15 @@ end - context "#{os} with assign => foo (not a valid array)" do - let(:params) { {:assign => 'foo', :object_type => 'foo', :target => '/bar/baz', :order => '10'} } + context "#{os} with assign => host.vars.os == bar && host.address" do + let(:params) { {:assign => 'host.vars.os == bar && host.address', :object_type => 'foo', :target => '/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/assign where host.vars.os == "bar" && host.address/) } end - context "#{os} with ignore => [ NodeName != baz || !host.display_name]" do + context "#{os} with ignore => [ NodeName != baz || !host.display_name ]" do let(:params) { {:ignore => ['NodeName != baz || !host.display_name'], :object_type => 'foo', :target => '/bar/baz', :order => '10'} } it { is_expected.to contain_concat__fragment('bar') @@ -173,10 +175,11 @@ end - context "#{os} with ignore => foo (not a valid array)" do - let(:params) { {:ignore => 'foo', :object_type => 'foo', :target => '/bar/baz', :order => '10'} } + context "#{os} with ignore => NodeName != baz || !host.display_name" do + let(:params) { {:ignore => 'NodeName != baz || !host.display_name', :object_type => 'foo', :target => '/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/ignore where NodeName != "baz" \|{2} !host.display_name/) } end @@ -367,10 +370,11 @@ end - context "Windows 2012 R2 with import => foo (not a valid array)" do + context "Windows 2012 R2 with import => foo" do let(:params) { {:import => 'foo', :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/import "foo"/) } end @@ -383,10 +387,11 @@ end - context "Windows 2012 R2 with assign => foo (not a valid array)" do - let(:params) { {:assign => 'foo', :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } + context "Windows 2012 R2 with assign => host.vars.os == bar && host.address" do + let(:params) { {:assign => 'host.vars.os == bar && host.address', :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/assign where host.vars.os == "bar" && host.address/) } end @@ -398,10 +403,11 @@ end - context "Windows 2012 R2 with ignore => foo (not a valid array)" do - let(:params) { {:ignore => 'foo', :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } + context "Windows 2012 R2 with ignore => NodeName != baz || !host.display_name" do + let(:params) { {:ignore => 'NodeName != baz || !host.display_name', :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('bar') + .with_content(/ignore where NodeName != "baz" \|{2} !host.display_name/) } end diff --git a/templates/object.conf.erb b/templates/object.conf.erb index 24f8ad3fa..19f590ce6 100644 --- a/templates/object.conf.erb +++ b/templates/object.conf.erb @@ -10,10 +10,10 @@ "<%= @object_name %>" <% end -%> <% if @apply && @apply_target %>to <%= @apply_target -%><% end -%> { <% end -%> -<% @import.each do |i| -%> +<% @_import.each do |i| -%> import "<%= i %>" <% end -%> -<% unless @import.empty? %><%= "\n" %><% end -%> +<% unless @_import.empty? %><%= "\n" %><% end -%> <% if @apply.is_a?(String) and @apply =~ /^([A-Za-z_]+)\s+in\s+.+$/ -%> <%= scope.function_icinga2_attributes([@_attrs.merge({$1 => :undef}),2]) -%> <% elsif @apply.is_a?(String) and @apply =~ /^([A-Za-z_]+)\s+=>\s+([A-Za-z_]+)\s+in\s+.+$/ %> From 43853429d3c46d1fca39e85f5c7312fef82c19f8 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 18:17:59 +0100 Subject: [PATCH 03/22] fix resource apiuser --- manifests/object/apiuser.pp | 3 +-- spec/defines/apiuser_spec.rb | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/manifests/object/apiuser.pp b/manifests/object/apiuser.pp index 1006cc1f9..53bcc2420 100644 --- a/manifests/object/apiuser.pp +++ b/manifests/object/apiuser.pp @@ -63,7 +63,6 @@ validate_string($apiuser_name) validate_string($order) validate_absolute_path($target) - validate_array($permissions) if $password { validate_string($password) } if $client_cn { validate_string($client_cn) } @@ -72,7 +71,7 @@ $attrs = { password => $password, client_cn => $client_cn, - permissions => $permissions, + permissions => any2array($permissions), } # create object diff --git a/spec/defines/apiuser_spec.rb b/spec/defines/apiuser_spec.rb index b4a55e4f4..54e87d8d8 100644 --- a/spec/defines/apiuser_spec.rb +++ b/spec/defines/apiuser_spec.rb @@ -61,10 +61,12 @@ end - context "#{os} with permissions => foo (not a valid array)" do + context "#{os} with permissions => foo" do let(:params) { {:permissions => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::ApiUser::bar') + .with({'target' => '/bar/baz'}) + .with_content(/permissions = \[ "foo", \]/) } end end end @@ -141,9 +143,11 @@ end - context "Windows 2012 R2 with permissions => foo (not a valid array)" do + context "Windows 2012 R2 with permissions => foo" do let(:params) { {:permissions => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::ApiUser::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/permissions = \[ "foo", \]/) } end -end \ No newline at end of file +end From ec582fe95ab43bad30c5214b94cbe3a60935d84c Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 18:23:22 +0100 Subject: [PATCH 04/22] fix resource checkcommand --- manifests/object/checkcommand.pp | 5 +---- spec/defines/checkcommand_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/manifests/object/checkcommand.pp b/manifests/object/checkcommand.pp index c221b24ec..ea280a230 100644 --- a/manifests/object/checkcommand.pp +++ b/manifests/object/checkcommand.pp @@ -60,20 +60,17 @@ # validation validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") - validate_array($import) validate_absolute_path($target) validate_integer($order) if $checkcommand_name { validate_string($checkcommand_name) } - if !is_array($command) { validate_string($command) } - if !is_string($command) { validate_array($command) } if $env { validate_hash($env) } if $timeout { validate_integer($timeout) } if $arguments { validate_hash($arguments) } # compose the attributes $attrs = { - command => $command, + command => any2array($command), env => $env, vars => $vars, timeout => $timeout, diff --git a/spec/defines/checkcommand_spec.rb b/spec/defines/checkcommand_spec.rb index 24994c741..25fe59d16 100644 --- a/spec/defines/checkcommand_spec.rb +++ b/spec/defines/checkcommand_spec.rb @@ -32,12 +32,12 @@ end - context "#{os} with command => foo" do - let(:params) { {:command => 'foo', :target => '/bar/baz'} } + context "#{os} with command => PluginDir + /bar" do + let(:params) { {:command => 'PluginDir + /bar', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::CheckCommand::bar') .with({'target' => '/bar/baz'}) - .with_content(/command = "foo"/) } + .with_content(/command = \[ PluginDir \+ "\/bar", \]/) } end @@ -125,12 +125,12 @@ end - context "Windows 2012 R2 with command => foo" do - let(:params) { {:command => 'foo', :target => 'C:/bar/baz'} } + context "Windows 2012 R2 with command => PluginDir + /bar" do + let(:params) { {:command => 'PluginDir + /bar', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::CheckCommand::bar') .with({'target' => 'C:/bar/baz'}) - .with_content(/command = "foo"/) } + .with_content(/command = \[ PluginDir \+ "\/bar", \]/) } end From 2d5cbfd71e2a9c00015328567d327bb2c245afd2 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 18:39:46 +0100 Subject: [PATCH 05/22] fix object dependency --- manifests/object/dependency.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/object/dependency.pp b/manifests/object/dependency.pp index c6f7f9d3c..166d11f11 100644 --- a/manifests/object/dependency.pp +++ b/manifests/object/dependency.pp @@ -102,7 +102,6 @@ unless is_bool($apply) { validate_string($apply) } validate_re($apply_target, ['^Host$', '^Service$'], "${apply_target} isn't supported. Valid values are 'Host' and 'Service'.") - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) From 121fe2df524337bc17d1095435eb955ee3248d4c Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 18:42:28 +0100 Subject: [PATCH 06/22] fix object eventcommand --- manifests/object/eventcommand.pp | 1 - 1 file changed, 1 deletion(-) diff --git a/manifests/object/eventcommand.pp b/manifests/object/eventcommand.pp index 03055a10e..b0c4c520d 100644 --- a/manifests/object/eventcommand.pp +++ b/manifests/object/eventcommand.pp @@ -65,7 +65,6 @@ validate_string($eventcommand_name) validate_absolute_path($target) validate_string($order) - validate_array($import) if !is_array($command) { validate_string($command) } if !is_string($command) { validate_array($command) } From d3f8886cca797f4d30e61695813d061f635fff1a Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:04:26 +0100 Subject: [PATCH 07/22] fix object host --- manifests/object/host.pp | 6 ++--- spec/defines/host_spec.rb | 50 ++++++++++----------------------------- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/manifests/object/host.pp b/manifests/object/host.pp index 485dd4a76..497a79512 100644 --- a/manifests/object/host.pp +++ b/manifests/object/host.pp @@ -150,7 +150,6 @@ # validation validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_integer($order) @@ -158,8 +157,9 @@ if $host_name { validate_string($host_name) } if $address { validate_string($address) } if $address6 { validate_string($address6) } - if $groups { validate_array($groups) } if $display_name { validate_string($display_name) } + if $vars { validate_hash($vars) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } validate_string($check_command) if $max_check_attempts { validate_integer($max_check_attempts) } if $check_period { validate_string($check_period) } @@ -188,7 +188,7 @@ address => $address, address6 => $address6, vars => $vars, - groups => $groups, + groups => $_groups, display_name => $display_name, check_command => $check_command, max_check_attempts => $max_check_attempts, diff --git a/spec/defines/host_spec.rb b/spec/defines/host_spec.rb index 77137fad3..d87aaa663 100644 --- a/spec/defines/host_spec.rb +++ b/spec/defines/host_spec.rb @@ -20,7 +20,8 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') .with({'target' => '/bar/baz'}) .with_content(/object Host "bar"/) - .with_content(/check_command = "foocommand"/)} + .with_content(/check_command = "foocommand"/) + .without_content(/groups =/)} end @@ -31,22 +32,6 @@ end - context "#{os} with import => [foo, bar]" do - let(:params) { {:import => ['foo','bar'], :target => '/bar/baz', :check_command => 'foocommand'} } - - it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') - .with({'target' => '/bar/baz'}) - .with_content(/import "foo"\n\s*import "bar"/) } - end - - - context "#{os} with import => foo (not a valid array)" do - let(:params) { {:import => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } - - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } - end - - context "#{os} with display_name => foo" do let(:params) { {:display_name => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } @@ -83,10 +68,12 @@ end - context "#{os} with groups => foo (not a valid array)" do + context "#{os} with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end @@ -482,7 +469,8 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') .with({'target' => '/bar/baz'}) .with_content(/object Host "bar"/) - .with_content(/check_command = "foocommand"/)} + .with_content(/check_command = "foocommand"/) + .without_content(/groups =/)} end @@ -493,22 +481,6 @@ end - context "Windows 2012 R2 with import => [foo, bar]" do - let(:params) { {:import => ['foo','bar'], :target => '/bar/baz', :check_command => 'foocommand'} } - - it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') - .with({'target' => '/bar/baz'}) - .with_content(/import "foo"\r\n\s*import "bar"/) } - end - - - context "Windows 2012 R2 with import => foo (not a valid array)" do - let(:params) { {:import => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } - - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } - end - - context "Windows 2012 R2 with display_name => foo" do let(:params) { {:display_name => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } @@ -545,10 +517,12 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do + context "Windows 2012 R2 with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Host::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end From 5cf2813fad664717c1a2fb31e5309979903974da Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:12:19 +0100 Subject: [PATCH 08/22] fix object zone --- manifests/object/zone.pp | 5 +++-- spec/defines/zone_spec.rb | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/manifests/object/zone.pp b/manifests/object/zone.pp index 2a274092f..b04952b36 100644 --- a/manifests/object/zone.pp +++ b/manifests/object/zone.pp @@ -31,7 +31,7 @@ define icinga2::object::zone( $ensure = present, $zone_name = $title, - $endpoints = [], + $endpoints = undef, $parent = undef, $global = false, $target = undef, @@ -48,6 +48,7 @@ validate_string($zone_name) validate_integer($order) + if $endpoints { $_endpoints = any2array($endpoints) } else { $_endpoints = undef } if $parent { validate_string($parent) } if $global { validate_bool($global) } @@ -67,7 +68,7 @@ } } else { $attrs = { - endpoints => any2array($endpoints), + endpoints => $_endpoints, parent => $parent, } } diff --git a/spec/defines/zone_spec.rb b/spec/defines/zone_spec.rb index 432702a05..c41fed677 100644 --- a/spec/defines/zone_spec.rb +++ b/spec/defines/zone_spec.rb @@ -19,6 +19,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Zone::bar') .with({'target' => '/bar/baz'}) + .without_content(/endpoints =/) .with_content(/object Zone "bar"/) } end @@ -116,6 +117,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Zone::bar') .with({'target' => 'C:/bar/baz'}) + .without_content(/endpoints =/) .with_content(/object Zone "bar"/) } end From 08c83ade0b1869930de90d38fe5021ffcd632442 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:20:59 +0100 Subject: [PATCH 09/22] fix object dependency spec default test --- manifests/object/dependency.pp | 4 ++-- spec/defines/dependency_spec.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/manifests/object/dependency.pp b/manifests/object/dependency.pp index 166d11f11..d740eee2f 100644 --- a/manifests/object/dependency.pp +++ b/manifests/object/dependency.pp @@ -114,7 +114,7 @@ if $disable_notifications { validate_bool ( $disable_notifications ) } if $ignore_soft_states { validate_bool ( $ignore_soft_states ) } if $period { validate_string ( $period ) } - if $states { validate_array ( $states ) } + if $states { $_states = any2array($states) } else { $_states = undef } # compose attributes $attrs = { @@ -126,7 +126,7 @@ 'disable_notifications' => $disable_notifications, 'ignore_soft_states' => $ignore_soft_states, 'period' => $period, - 'states' => $states, + 'states' => $_states, } # create object diff --git a/spec/defines/dependency_spec.rb b/spec/defines/dependency_spec.rb index 2ea3033bc..e601e07d1 100644 --- a/spec/defines/dependency_spec.rb +++ b/spec/defines/dependency_spec.rb @@ -22,6 +22,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Dependency::bar') .with({'target' => '/bar/baz'}) .with_content(/object Dependency "bar"/) + .without_content(/states =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -187,14 +188,16 @@ end - context "#{os} with states => foo (not a valid array)" do + context "#{os} with states => foo" do let(:params) { { :states => 'foo', :target => '/bar/baz', :parent_host_name => 'parentfoo', :child_host_name => 'childfoo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Dependency::bar') + .with({'target' => '/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end end end @@ -234,6 +237,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Dependency::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object Dependency "bar"/) + .without_content(/states =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -399,13 +403,15 @@ end - context "Windows 2012 R2 with states => foo (not a valid array)" do + context "Windows 2012 R2 with states => foo" do let(:params) { { :states => 'foo', :target => 'C:/bar/baz', :parent_host_name => 'parentfoo', :child_host_name => 'childfoo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Dependency::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end end From ce9122fbbecd146c7978d91369c689f056e9ab36 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:26:33 +0100 Subject: [PATCH 10/22] fix object checkcommand spec default test --- manifests/object/checkcommand.pp | 3 ++- spec/defines/checkcommand_spec.rb | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/manifests/object/checkcommand.pp b/manifests/object/checkcommand.pp index ea280a230..2bbf4043b 100644 --- a/manifests/object/checkcommand.pp +++ b/manifests/object/checkcommand.pp @@ -64,13 +64,14 @@ validate_integer($order) if $checkcommand_name { validate_string($checkcommand_name) } + if $command { $_command = any2array($command) } else { $_command = undef } if $env { validate_hash($env) } if $timeout { validate_integer($timeout) } if $arguments { validate_hash($arguments) } # compose the attributes $attrs = { - command => any2array($command), + command => $_command, env => $env, vars => $vars, timeout => $timeout, diff --git a/spec/defines/checkcommand_spec.rb b/spec/defines/checkcommand_spec.rb index 25fe59d16..75a8fb114 100644 --- a/spec/defines/checkcommand_spec.rb +++ b/spec/defines/checkcommand_spec.rb @@ -19,6 +19,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::CheckCommand::bar') .with({'target' => '/bar/baz'}) + .without_content(/command =/) .with_content(/object CheckCommand "bar"/) } end @@ -106,12 +107,13 @@ ] } context "Windows 2012 R2 with all defaults and target => C:/bar/baz" do - let(:params) { {:target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:target => 'C:/bar/baz'} } it { is_expected.to contain_concat('C:/bar/baz') } it { is_expected.to contain_concat__fragment('icinga2::object::CheckCommand::bar') .with({'target' => 'C:/bar/baz'}) + .without_content(/command =/) .with_content(/object CheckCommand "bar"/) } end From d8ef1b8e1cc457802d5e5d08fd07f83df845d546 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:34:34 +0100 Subject: [PATCH 11/22] fix object hostgroup --- manifests/object/hostgroup.pp | 6 ++---- spec/defines/hostgroup_spec.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/manifests/object/hostgroup.pp b/manifests/object/hostgroup.pp index 0a8d3b5ce..3122ed9ea 100644 --- a/manifests/object/hostgroup.pp +++ b/manifests/object/hostgroup.pp @@ -48,13 +48,11 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($hostgroup_name) - validate_array($assign) - validate_array($ignore) validate_string($order) validate_absolute_path($target) if $display_name { validate_string($display_name) } - if $groups { validate_array($groups) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } if $ignore != [] and $assign == [] { fail('When attribute ignore is used, assign must be set.') @@ -63,7 +61,7 @@ # compose the attributes $attrs = { display_name => $display_name, - groups => $groups, + groups => $_groups, } # create object diff --git a/spec/defines/hostgroup_spec.rb b/spec/defines/hostgroup_spec.rb index 95d9c6cc5..33fed251d 100644 --- a/spec/defines/hostgroup_spec.rb +++ b/spec/defines/hostgroup_spec.rb @@ -20,6 +20,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::HostGroup::bar') .with({'target' => '/bar/baz'}) .with_content(/object HostGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -46,10 +47,12 @@ end - context "#{os} with groups => foo (not a valid array)" do + context "#{os} with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::HostGroup::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end @@ -92,6 +95,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::HostGroup::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object HostGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -118,10 +122,12 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do + context "Windows 2012 R2 with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::HostGroup::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end From 5a21d3a5b4e37ca3b251f63ce65b7481e118fe8b Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 19:50:49 +0100 Subject: [PATCH 12/22] fix object notification --- manifests/object/notification.pp | 33 +++++++++--------- spec/defines/notification_spec.rb | 56 ++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/manifests/object/notification.pp b/manifests/object/notification.pp index d98942f55..8a52f5478 100644 --- a/manifests/object/notification.pp +++ b/manifests/object/notification.pp @@ -110,24 +110,21 @@ unless is_bool($apply) { validate_string($apply) } validate_re($apply_target, ['^Host$', '^Service$'], "${apply_target} isn't supported. Valid values are 'Host' and 'Service'.") - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - validate_string ($host_name) - if $service_name { validate_string ($service_name)} - if $users { validate_array ($users )} - if $user_groups { validate_array ($user_groups )} - if $times { validate_hash ($times )} - if $command { validate_string ($command )} - if $interval { validate_integer ($interval )} - if $period { validate_string ($period )} - if $zone { validate_string ($zone) } - if $types { validate_array ($types) } - if $states { validate_array ($states) } - if $assign { validate_array ($assign) } - if $ignore { validate_array ($ignore) } + validate_string($host_name) + if $service_name { validate_string($service_name) } + if $users { $_users = any2array($users) } else { $_users = undef } + if $user_groups { $_user_groups = any2array($user_groups) } else { $_user_groups = undef } + if $times { validate_hash($times) } + if $command { validate_string($command) } + if $interval { validate_integer($interval) } + if $period { validate_string($period) } + if $zone { validate_string($zone) } + if $types { $_types = any2array($types) } else { $_types = undef } + if $states { $_states = any2array($states) } else { $_states = undef } if $ignore != [] and $assign == [] { fail('When attribute ignore is used, assign must be set.') @@ -138,15 +135,15 @@ 'host_name' => $host_name, 'service_name' => $service_name, 'vars' => $vars, - 'users' => $users, - 'user_groups' => $user_groups, + 'users' => $_users, + 'user_groups' => $_user_groups, 'times' => $times, 'command' => $command, 'interval' => $interval, 'period' => $period, 'zone' => $zone, - 'types' => $types, - 'states' => $states, + 'types' => $_types, + 'states' => $_states, } # create object diff --git a/spec/defines/notification_spec.rb b/spec/defines/notification_spec.rb index 8218641c7..5eb4668f2 100644 --- a/spec/defines/notification_spec.rb +++ b/spec/defines/notification_spec.rb @@ -18,6 +18,10 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') .with({'target' => '/bar/baz'}) + .without_content(/users =/) + .without_content(/user_groups =/) + .without_content(/types =/) + .without_content(/states =/) .with_content(/object Notification "bar"/) .with_content(/host_name = "foohost"/)} @@ -72,10 +76,12 @@ end - context "#{os} with users => foo (not a valid array)" do + context "#{os} with users => foo" do let(:params) { {:users => 'foo', :target => '/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => '/bar/baz'}) + .with_content(/users = \[ "foo", \]/) } end @@ -88,10 +94,12 @@ end - context "#{os} with user_groups => foo (not a valid array)" do + context "#{os} with user_groups => foo" do let(:params) { {:user_groups => 'foo', :target => '/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => '/bar/baz'}) + .with_content(/user_groups = \[ "foo", \]/) } end @@ -163,10 +171,12 @@ end - context "#{os} with types => foo (not a valid array)" do + context "#{os} with types => foo" do let(:params) { {:types => 'foo', :target => '/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => '/bar/baz'}) + .with_content(/types = \[ "foo", \]/) } end @@ -179,10 +189,12 @@ end - context "#{os} with states => foo (not a valid array)" do + context "#{os} with states => foo" do let(:params) { {:states => 'foo', :target => '/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => '/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end context "#{os} with assign => [] and ignore => [ foo ]" do @@ -224,6 +236,10 @@ it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') .with({'target' => 'C:/bar/baz'}) + .without_content(/users =/) + .without_content(/user_groups =/) + .without_content(/types =/) + .without_content(/states =/) .with_content(/object Notification "bar"/) .with_content(/host_name = "foohost"/)} @@ -278,10 +294,12 @@ end - context "Windows 2012 R2 with users => foo (not a valid array)" do + context "Windows 2012 R2 with users => foo" do let(:params) { {:users => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/users = \[ "foo", \]/) } end @@ -294,10 +312,12 @@ end - context "Windows 2012 R2 with user_groups => foo (not a valid array)" do + context "Windows 2012 R2 with user_groups => foo" do let(:params) { {:user_groups => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/user_groups = \[ "foo", \]/) } end @@ -369,10 +389,12 @@ end - context "Windows 2012 R2 with types => foo (not a valid array)" do + context "Windows 2012 R2 with types => foo" do let(:params) { {:types => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/types = \[ "foo", \]/) } end @@ -385,10 +407,12 @@ end - context "Windows 2012 R2 with states => foo (not a valid array)" do + context "Windows 2012 R2 with states => foo" do let(:params) { {:states => 'foo', :target => 'C:/bar/baz', :host_name => 'foohost'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Notification::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end context "Windows 2012 R2 with assign => [] and ignore => [ foo ]" do From 8b26cd6b8a3e26be33729b8999029a6895a74cc9 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 20:00:14 +0100 Subject: [PATCH 13/22] fix object notificationcommand --- manifests/object/notificationcommand.pp | 6 ++-- spec/defines/notificationcommand_spec.rb | 36 ++++++++++++------------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/manifests/object/notificationcommand.pp b/manifests/object/notificationcommand.pp index 9965a2362..d9bc9bfd5 100644 --- a/manifests/object/notificationcommand.pp +++ b/manifests/object/notificationcommand.pp @@ -69,20 +69,18 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($notificationcommand_name) - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - if !is_array($command) { validate_string($command) } - if !is_string($command) { validate_array($command) } + if $command { $_command = any2array($command) } else { $_command = undef } if $env { validate_hash ($env) } if $timeout { validate_integer ($timeout) } if $arguments { validate_hash ($arguments) } # compose attributes $attrs = { - 'command' => $command, + 'command' => $_command, 'env' => $env, 'vars' => $vars, 'timeout' => $timeout, diff --git a/spec/defines/notificationcommand_spec.rb b/spec/defines/notificationcommand_spec.rb index 7733383a3..1338cce2d 100644 --- a/spec/defines/notificationcommand_spec.rb +++ b/spec/defines/notificationcommand_spec.rb @@ -12,14 +12,14 @@ end context "#{os} with all defaults and target => /bar/baz" do - let(:params) { {:target => '/bar/baz', :command => ['foocommand']} } + let(:params) { {:target => '/bar/baz'} } it { is_expected.to contain_concat('/bar/baz') } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => '/bar/baz'}) .with_content(/object NotificationCommand "bar"/) - .with_content(/command = \[ "foocommand", \]/)} + .without_content(/command =/)} it { is_expected.to contain_icinga2__object('icinga2::object::NotificationCommand::bar') .that_notifies('Class[icinga2::service]') } @@ -49,12 +49,12 @@ it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => '/bar/baz'}) - .with_content(/command = "foo"/) } + .with_content(/command = \[ "foo", \]/) } end context "#{os} with env => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:env => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz', :command => ['foocommand'] } } + let(:params) { {:env => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({ 'target' => '/bar/baz' }) @@ -63,14 +63,14 @@ context "#{os} with env => 'foo' (not a valid hash)" do - let(:params) { {:env => 'foo', :target => '/bar/baz', :command => ['foocommand']} } + let(:params) { {:env => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) } end context "#{os} with vars => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz', :command => ['foocommand'] } } + let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({ 'target' => '/bar/baz' }) @@ -80,7 +80,7 @@ context "#{os} with timeout => 30" do - let(:params) { {:timeout => '30', :target => '/bar/baz', :command => ['foocommand']} } + let(:params) { {:timeout => '30', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => '/bar/baz'}) @@ -89,7 +89,7 @@ context "#{os} with timeout => foo (not a valid integer)" do - let(:params) { {:timeout => 'foo', :target => '/bar/baz', :command => ['foocommand']} } + let(:params) { {:timeout => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end @@ -108,7 +108,7 @@ context "#{os} with arguments => foo (not a valid hash)" do - let(:params) { {:arguments => 'foo', :target => '/bar/baz', :command => ['foocommand']} } + let(:params) { {:arguments => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) } end @@ -141,14 +141,14 @@ context "Windows 2012 R2 with all defaults and target => C:/bar/baz" do - let(:params) { {:target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:target => 'C:/bar/baz'} } it { is_expected.to contain_concat('C:/bar/baz') } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object NotificationCommand "bar"/) - .with_content(/command = \[ "foocommand", \]/)} + .without_content(/command =/)} it { is_expected.to contain_icinga2__object('icinga2::object::NotificationCommand::bar') .that_notifies('Class[icinga2::service]') } @@ -178,12 +178,12 @@ it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => 'C:/bar/baz'}) - .with_content(/command = "foo"/) } + .with_content(/command = \[ "foo", \]/) } end context "Windows 2012 R2 with env => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:env => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz', :command => ['foocommand'] } } + let(:params) { {:env => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({ 'target' => 'C:/bar/baz' }) @@ -192,14 +192,14 @@ context "Windows 2012 R2 with env => 'foo' (not a valid hash)" do - let(:params) { {:env => 'foo', :target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:env => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) } end context "Windows 2012 R2 with vars => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz', :command => ['foocommand'] } } + let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({ 'target' => 'C:/bar/baz' }) @@ -209,7 +209,7 @@ context "Windows 2012 R2 with timeout => 30" do - let(:params) { {:timeout => '30', :target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:timeout => '30', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::NotificationCommand::bar') .with({'target' => 'C:/bar/baz'}) @@ -218,7 +218,7 @@ context "Windows 2012 R2 with timeout => foo (not a valid integer)" do - let(:params) { {:timeout => 'foo', :target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:timeout => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end @@ -237,7 +237,7 @@ context "Windows 2012 R2 with arguments => foo (not a valid hash)" do - let(:params) { {:arguments => 'foo', :target => 'C:/bar/baz', :command => ['foocommand']} } + let(:params) { {:arguments => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a Hash/) } end From 5866a84386528bc3e18044c3a199c99f3de7c51a Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 20:03:38 +0100 Subject: [PATCH 14/22] fix object scheduleddowntime docs --- manifests/object/scheduleddowntime.pp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/manifests/object/scheduleddowntime.pp b/manifests/object/scheduleddowntime.pp index 506c68861..6259f515f 100644 --- a/manifests/object/scheduleddowntime.pp +++ b/manifests/object/scheduleddowntime.pp @@ -8,13 +8,15 @@ # Set to present enables the object, absent disables it. Defaults to present. # # [*scheduleddowntime_name*] -# Set the Icinga 2 name of the scheduleddowntime object. Defaults to title of the define resource. +# Set the Icinga 2 name of the scheduleddowntime object. +# Defaults to title of the define resource. # # [*host_name*] # The name of the host this comment belongs to. # # [*service_name*] -# The short name of the service this comment belongs to. If omitted, this comment object is treated as host comment. +# The short name of the service this comment belongs to. If omitted, +# this comment object is treated as host comment. # # [*author*] # The author's name. @@ -29,14 +31,16 @@ # The duration as number. # # [*ranges*] -# A dictionary containing information which days and durations apply to this timeperiod. +# A dictionary containing information which days and durations +# apply to this timeperiod. # # [*apply*] -# Dispose an apply instead an object if set to 'true'. Value is taken as statement, -# i.e. 'vhost => config in host.vars.vhosts'. Defaults to false. +# Dispose an apply instead an object if set to 'true'. Value is taken as +# statement, i.e. 'vhost => config in host.vars.vhosts'. Defaults to false. # # [*apply_target*] -# An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`. +# An object type on which to target the apply rule. Valid values +# are `Host` and `Service`. Defaults to `Host`. # # [*assign*] # Assign user group members using the group assign rules. From 3e02930b31dc96e0dd0a5c9e74bde116ae89baad Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:01:34 +0100 Subject: [PATCH 15/22] fix object service --- manifests/object/service.pp | 47 +++--- spec/defines/service_spec.rb | 318 ++++++++++------------------------- 2 files changed, 111 insertions(+), 254 deletions(-) diff --git a/manifests/object/service.pp b/manifests/object/service.pp index d4d774d6b..067878818 100644 --- a/manifests/object/service.pp +++ b/manifests/object/service.pp @@ -201,43 +201,42 @@ "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($service_name) unless is_bool($apply) { validate_string($apply) } - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - if $display_name { validate_string ($display_name) } - validate_string($host_name) - if $groups { validate_array ($groups) } - validate_string($check_command) - if $max_check_attempts { validate_integer ($max_check_attempts) } - if $check_period { validate_string ($check_period) } + if $display_name { validate_string($display_name) } + if $host_name { validate_string($host_name) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } + if $check_command { validate_string($check_command) } + if $max_check_attempts { validate_integer($max_check_attempts) } + if $check_period { validate_string($check_period) } if $check_timeout { validate_re($check_timeout, '^\d+\.?\d*[d|h|m|s]?$') } if $check_interval { validate_re($check_interval, '^\d+\.?\d*[d|h|m|s]?$') } if $retry_interval { validate_re($retry_interval, '^\d+\.?\d*[d|h|m|s]?$') } - if $enable_notifications { validate_bool ($enable_notifications) } - if $enable_active_checks { validate_bool ($enable_active_checks) } - if $enable_passive_checks { validate_bool ($enable_passive_checks) } - if $enable_event_handler { validate_bool ($enable_event_handler) } - if $enable_flapping { validate_bool ($enable_flapping) } - if $enable_perfdata { validate_bool ($enable_perfdata) } - if $event_command { validate_string ($event_command) } - if $flapping_threshold { validate_integer ($flapping_threshold) } - if $volatile { validate_bool ($volatile) } - if $zone { validate_string ($zone) } - if $command_endpoint { validate_string ($command_endpoint) } - if $notes { validate_string ($notes) } - if $notes_url { validate_string ($notes_url) } - if $action_url { validate_string ($action_url) } - if $icon_image { validate_absolute_path ($icon_image) } - if $icon_image_alt { validate_string ($icon_image_alt) } + if $enable_notifications { validate_bool($enable_notifications) } + if $enable_active_checks { validate_bool($enable_active_checks) } + if $enable_passive_checks { validate_bool($enable_passive_checks) } + if $enable_event_handler { validate_bool($enable_event_handler) } + if $enable_flapping { validate_bool($enable_flapping) } + if $enable_perfdata { validate_bool($enable_perfdata) } + if $event_command { validate_string($event_command) } + if $flapping_threshold { validate_integer($flapping_threshold) } + if $volatile { validate_bool($volatile) } + if $zone { validate_string($zone) } + if $command_endpoint { validate_string($command_endpoint) } + if $notes { validate_string($notes) } + if $notes_url { validate_string($notes_url) } + if $action_url { validate_string($action_url) } + if $icon_image { validate_absolute_path($icon_image) } + if $icon_image_alt { validate_string($icon_image_alt) } # compose the attributes $attrs = { 'display_name' => $display_name , 'host_name' => $host_name , - 'groups' => $groups , + 'groups' => $_groups , 'vars' => $vars , 'check_command' => $check_command , 'max_check_attempts' => $max_check_attempts , diff --git a/spec/defines/service_spec.rb b/spec/defines/service_spec.rb index 31e43e5b2..2e4d4fb06 100644 --- a/spec/defines/service_spec.rb +++ b/spec/defines/service_spec.rb @@ -13,15 +13,13 @@ context "#{os} with all defaults and target => /bar/baz" do - let(:params) { { - :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:target => '/bar/baz'} } it { is_expected.to contain_concat('/bar/baz') } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) + .without_content(/groups =/) .with_content(/object Service "bar"/) } it { is_expected.to contain_icinga2__object('icinga2::object::Service::bar') @@ -30,9 +28,7 @@ context "#{os} with service_name => foo" do - let(:params) { {:service_name => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:service_name => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -41,9 +37,7 @@ context "#{os} with display_name => foo" do - let(:params) { {:display_name => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:display_name => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -52,8 +46,7 @@ context "#{os} with host_name => foo" do - let(:params) { {:host_name => 'foo', :target => '/bar/baz', - :check_command => 'commandfoo'} } + let(:params) { {:host_name => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -62,9 +55,7 @@ context "#{os} with groups => [foo, bar]" do - let(:params) { {:groups => ['foo','bar'], :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:groups => ['foo','bar'], :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -72,18 +63,16 @@ end - context "#{os} with groups => foo (not a valid array)" do - let(:params) { {:groups => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + context "#{os} with groups => foo" do + let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end context "#{os} with vars => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo' } } + let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({ 'target' => '/bar/baz' }) @@ -93,8 +82,7 @@ context "#{os} with check_command => foo" do - let(:params) { {:check_command => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo'} } + let(:params) { {:check_command => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -103,9 +91,7 @@ context "#{os} with max_check_attempts => 30" do - let(:params) { {:max_check_attempts => '30', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:max_check_attempts => '30', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -114,9 +100,7 @@ context "#{os} with max_check_attempts => foo (not a valid integer)" do - let(:params) { {:max_check_attempts => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:max_check_attempts => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end @@ -124,8 +108,7 @@ context "#{os} with check_period => foo" do - let(:params) { {:check_period => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo'} } + let(:params) { {:check_period => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -143,16 +126,14 @@ context "#{os} with check_interval => foo (not a valid value)" do - let(:params) { {:check_interval => 'foo', :target => '/bar/baz', :check_command => 'foocommand'} } + let(:params) { {:check_interval => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } end context "#{os} with retry_interval => 30s" do - let(:params) { {:retry_interval => '30s', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:retry_interval => '30s', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -161,18 +142,14 @@ context "#{os} with retry_interval => foo (not a valid value)" do - let(:params) { {:retry_interval => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:retry_interval => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } end context "#{os} with enable_notifications => false" do - let(:params) { {:enable_notifications => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_notifications => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -181,18 +158,14 @@ context "#{os} with enable_notifications => foo (not a valid boolean)" do - let(:params) { {:enable_notifications => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_notifications => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with enable_active_checks => false" do - let(:params) { {:enable_active_checks => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_active_checks => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -201,18 +174,14 @@ context "#{os} with enable_active_checks => foo (not a valid boolean)" do - let(:params) { {:enable_active_checks => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_active_checks => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with enable_passive_checks => false" do - let(:params) { {:enable_passive_checks => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_passive_checks => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -221,18 +190,14 @@ context "#{os} with enable_passive_checks => foo (not a valid boolean)" do - let(:params) { {:enable_passive_checks => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_passive_checks => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with enable_event_handler => false" do - let(:params) { {:enable_event_handler => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_event_handler => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -241,18 +206,14 @@ context "#{os} with enable_event_handler => foo (not a valid boolean)" do - let(:params) { {:enable_event_handler => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_event_handler => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with enable_flapping => false" do - let(:params) { {:enable_flapping => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_flapping => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -261,18 +222,14 @@ context "#{os} with enable_flapping => foo (not a valid boolean)" do - let(:params) { {:enable_flapping => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_flapping => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with enable_perfdata => false" do - let(:params) { {:enable_perfdata => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_perfdata => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -281,18 +238,14 @@ context "#{os} with enable_perfdata => foo (not a valid boolean)" do - let(:params) { {:enable_perfdata => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_perfdata => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with event_command => foo" do - let(:params) { {:event_command => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:event_command => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -301,9 +254,7 @@ context "#{os} with flapping_threshold => 30" do - let(:params) { {:flapping_threshold => '30', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:flapping_threshold => '30', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -312,18 +263,14 @@ context "#{os} with flapping_threshold => foo (not a valid integer)" do - let(:params) { {:flapping_threshold => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:flapping_threshold => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end context "#{os} with volatile => false" do - let(:params) { {:volatile => false, :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:volatile => false, :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -332,18 +279,14 @@ context "#{os} with volatile => foo (not a valid boolean)" do - let(:params) { {:volatile => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:volatile => 'foo', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "#{os} with zone => foo" do - let(:params) { {:zone => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:zone => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -352,9 +295,7 @@ context "#{os} with command_endpoint => foo" do - let(:params) { {:command_endpoint => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:command_endpoint => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -363,9 +304,7 @@ context "#{os} with notes => foo" do - let(:params) { {:notes => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:notes => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -374,9 +313,7 @@ context "#{os} with notes_url => foo" do - let(:params) { {:notes_url => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:notes_url => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -385,9 +322,7 @@ context "#{os} with action_url => foo" do - let(:params) { {:action_url => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:action_url => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -396,9 +331,7 @@ context "#{os} with icon_image = /foo/bar" do - let(:params) { {:icon_image => '/foo/bar', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image => '/foo/bar', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({ 'target' => '/bar/baz' }) @@ -407,18 +340,14 @@ context "#{os} with icon_image = foo/bar (not a valid absolute path)" do - let(:params) { {:icon_image => 'foo/bar', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image => 'foo/bar', :target => '/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } end context "#{os} with icon_image_alt => foo" do - let(:params) { {:icon_image_alt => 'foo', :target => '/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image_alt => 'foo', :target => '/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => '/bar/baz'}) @@ -452,15 +381,13 @@ context "Windows 2012 R2 with all defaults and target => C:/bar/baz" do - let(:params) { { - :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:target => 'C:/bar/baz'} } it { is_expected.to contain_concat('C:/bar/baz') } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) + .without_content(/groups =/) .with_content(/object Service "bar"/) } it { is_expected.to contain_icinga2__object('icinga2::object::Service::bar') @@ -469,9 +396,7 @@ context "Windows 2012 R2 with service_name => foo" do - let(:params) { {:service_name => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:service_name => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -480,9 +405,7 @@ context "Windows 2012 R2 with display_name => foo" do - let(:params) { {:display_name => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:display_name => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -491,8 +414,7 @@ context "Windows 2012 R2 with host_name => foo" do - let(:params) { {:host_name => 'foo', :target => 'C:/bar/baz', - :check_command => 'commandfoo'} } + let(:params) { {:host_name => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -501,9 +423,7 @@ context "Windows 2012 R2 with groups => [foo, bar]" do - let(:params) { {:groups => ['foo','bar'], :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:groups => ['foo','bar'], :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -511,18 +431,16 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do - let(:params) { {:groups => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + context "Windows 2012 R2 with groups => foo" do + let(:params) { {:groups => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end context "Windows 2012 R2 with vars => { foo => 'bar', bar => 'foo' }" do - let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo' } } + let(:params) { {:vars => { 'foo' => "bar", 'bar' => "foo"}, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({ 'target' => 'C:/bar/baz' }) @@ -532,8 +450,7 @@ context "Windows 2012 R2 with check_command => foo" do - let(:params) { {:check_command => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo'} } + let(:params) { {:check_command => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -542,9 +459,7 @@ context "Windows 2012 R2 with max_check_attempts => 30" do - let(:params) { {:max_check_attempts => '30', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:max_check_attempts => '30', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -553,17 +468,14 @@ context "Windows 2012 R2 with max_check_attempts => foo (not a valid integer)" do - let(:params) { {:max_check_attempts => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:max_check_attempts => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end context "Windows 2012 R2 with check_period => foo" do - let(:params) { {:check_period => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo'} } + let(:params) { {:check_period => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -581,16 +493,14 @@ context "Windows 2012 R2 with check_interval => foo (not a valid value)" do - let(:params) { {:check_interval => 'foo', :target => 'C:/bar/baz', :check_command => 'foocommand'} } + let(:params) { {:check_interval => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } end context "Windows 2012 R2 with retry_interval => 30s" do - let(:params) { {:retry_interval => '30s', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:retry_interval => '30s', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -599,18 +509,14 @@ context "Windows 2012 R2 with retry_interval => foo (not a valid value)" do - let(:params) { {:retry_interval => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:retry_interval => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" does not match/) } end context "Windows 2012 R2 with enable_notifications => false" do - let(:params) { {:enable_notifications => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_notifications => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -619,18 +525,14 @@ context "Windows 2012 R2 with enable_notifications => foo (not a valid boolean)" do - let(:params) { {:enable_notifications => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_notifications => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with enable_active_checks => false" do - let(:params) { {:enable_active_checks => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_active_checks => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -639,18 +541,14 @@ context "Windows 2012 R2 with enable_active_checks => foo (not a valid boolean)" do - let(:params) { {:enable_active_checks => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_active_checks => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with enable_passive_checks => false" do - let(:params) { {:enable_passive_checks => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_passive_checks => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -659,18 +557,14 @@ context "Windows 2012 R2 with enable_passive_checks => foo (not a valid boolean)" do - let(:params) { {:enable_passive_checks => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_passive_checks => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with enable_event_handler => false" do - let(:params) { {:enable_event_handler => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_event_handler => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -679,18 +573,14 @@ context "Windows 2012 R2 with enable_event_handler => foo (not a valid boolean)" do - let(:params) { {:enable_event_handler => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_event_handler => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with enable_flapping => false" do - let(:params) { {:enable_flapping => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_flapping => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -699,18 +589,14 @@ context "Windows 2012 R2 with enable_flapping => foo (not a valid boolean)" do - let(:params) { {:enable_flapping => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_flapping => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with enable_perfdata => false" do - let(:params) { {:enable_perfdata => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_perfdata => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -719,18 +605,14 @@ context "Windows 2012 R2 with enable_perfdata => foo (not a valid boolean)" do - let(:params) { {:enable_perfdata => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:enable_perfdata => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with event_command => foo" do - let(:params) { {:event_command => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:event_command => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -739,9 +621,7 @@ context "Windows 2012 R2 with flapping_threshold => 30" do - let(:params) { {:flapping_threshold => '30', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:flapping_threshold => '30', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -750,18 +630,14 @@ context "Windows 2012 R2 with flapping_threshold => foo (not a valid integer)" do - let(:params) { {:flapping_threshold => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:flapping_threshold => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /first argument to be an Integer/) } end context "Windows 2012 R2 with volatile => false" do - let(:params) { {:volatile => false, :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:volatile => false, :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -770,18 +646,14 @@ context "Windows 2012 R2 with volatile => foo (not a valid boolean)" do - let(:params) { {:volatile => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:volatile => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo" is not a boolean/) } end context "Windows 2012 R2 with zone => foo" do - let(:params) { {:zone => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:zone => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -790,9 +662,7 @@ context "Windows 2012 R2 with command_endpoint => foo" do - let(:params) { {:command_endpoint => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:command_endpoint => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -801,9 +671,7 @@ context "Windows 2012 R2 with notes => foo" do - let(:params) { {:notes => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:notes => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -812,9 +680,7 @@ context "Windows 2012 R2 with notes_url => foo" do - let(:params) { {:notes_url => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:notes_url => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -823,9 +689,7 @@ context "Windows 2012 R2 with action_url => foo" do - let(:params) { {:action_url => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:action_url => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) @@ -833,9 +697,7 @@ end context "Windows 2012 R2 with icon_image = /foo/bar" do - let(:params) { {:icon_image => '/foo/bar', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image => '/foo/bar', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({ 'target' => 'C:/bar/baz' }) @@ -844,18 +706,14 @@ context "Windows 2012 R2 with icon_image = foo/bar (not a valid absolute path)" do - let(:params) { {:icon_image => 'foo/bar', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image => 'foo/bar', :target => 'C:/bar/baz'} } it { is_expected.to raise_error(Puppet::Error, /"foo\/bar" is not an absolute path/) } end context "Windows 2012 R2 with icon_image_alt => foo" do - let(:params) { {:icon_image_alt => 'foo', :target => 'C:/bar/baz', - :host_name => 'hostfoo', - :check_command => 'commandfoo'} } + let(:params) { {:icon_image_alt => 'foo', :target => 'C:/bar/baz'} } it { is_expected.to contain_concat__fragment('icinga2::object::Service::bar') .with({'target' => 'C:/bar/baz'}) From dd976716f8a3b373e7d4e4f95005a64bcb313039 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:06:05 +0100 Subject: [PATCH 16/22] fix object servicegroup --- manifests/object/servicegroup.pp | 15 +++++++-------- spec/defines/servicegroup_spec.rb | 14 ++++++++++---- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/manifests/object/servicegroup.pp b/manifests/object/servicegroup.pp index e45152c9f..c31a5b056 100644 --- a/manifests/object/servicegroup.pp +++ b/manifests/object/servicegroup.pp @@ -22,12 +22,12 @@ # [*ignore*] # Exclude users using the group ignore rules. # -# [*template*] -# Set to true creates a template instead of an object. Defaults to false. -# # [*import*] # Sorted List of templates to include. Defaults to an empty list. # +# [*template*] +# Set to true creates a template instead of an object. Defaults to false. +# # [*target*] # Destination config file to store in this object. File will be declared the # first time. @@ -41,11 +41,11 @@ $ensure = present, $servicegroup_name = $title, $display_name = undef, - $groups = [], + $groups = undef, $assign = [], $ignore = [], - $template = false, $import = [], + $template = false, $order = '65', ){ include ::icinga2::params @@ -56,19 +56,18 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($servicegroup_name) - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - validate_array ( $groups ) if $display_name { validate_string ( $display_name ) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } # compose attributes $attrs = { 'display_name' => $display_name, - 'groups' => $groups, + 'groups' => $_groups, } # create object diff --git a/spec/defines/servicegroup_spec.rb b/spec/defines/servicegroup_spec.rb index 63d75da77..4c591a4c8 100644 --- a/spec/defines/servicegroup_spec.rb +++ b/spec/defines/servicegroup_spec.rb @@ -19,6 +19,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::ServiceGroup::bar') .with({'target' => '/bar/baz'}) .with_content(/object ServiceGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -54,10 +55,12 @@ end - context "#{os} with groups => foo (not a valid array)" do + context "#{os} with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::ServiceGroup::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end end end @@ -94,6 +97,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::ServiceGroup::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object ServiceGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -129,9 +133,11 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do + context "Windows 2012 R2 with groups => foo" do let(:params) { {:groups => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::ServiceGroup::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end end From 9deb10e8b755b4ea36b8a61015cca104f9ba03dc Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:12:05 +0100 Subject: [PATCH 17/22] fix object timeperiod --- manifests/object/timeperiod.pp | 15 +++++++-------- spec/defines/timeperiod_spec.rb | 28 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/manifests/object/timeperiod.pp b/manifests/object/timeperiod.pp index 71738d79d..290ba0a4d 100644 --- a/manifests/object/timeperiod.pp +++ b/manifests/object/timeperiod.pp @@ -60,25 +60,24 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($timeperiod_name) - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - if $display_name { validate_string ($display_name) } - if $ranges { validate_hash ($ranges) } - if $prefer_includes { validate_bool ($prefer_includes) } - if $excludes { validate_array ($excludes) } - if $includes { validate_array ($includes) } + if $display_name { validate_string($display_name) } + if $ranges { validate_hash($ranges) } + if $prefer_includes { validate_bool($prefer_includes) } + if $excludes { $_excludes = any2array($excludes) } else { $_excludes = undef } + if $includes { $_includes = any2array($includes) } else { $_includes = undef } # compose attributes $attrs = { 'display_name' => $display_name, 'ranges' => $ranges, 'prefer_includes' => $prefer_includes, - 'excludes' => $excludes, - 'includes' => $includes, + 'excludes' => $_excludes, + 'includes' => $_includes, } # create object diff --git a/spec/defines/timeperiod_spec.rb b/spec/defines/timeperiod_spec.rb index 7a59327ee..0ee18c884 100644 --- a/spec/defines/timeperiod_spec.rb +++ b/spec/defines/timeperiod_spec.rb @@ -19,6 +19,8 @@ it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') .with({'target' => '/bar/baz'}) .with_content(/object TimePeriod "bar"/) + .without_content(/excludes =/) + .without_content(/includes =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -86,10 +88,12 @@ end - context "#{os} with excludes => foo (not a valid array)" do + context "#{os} with excludes => foo" do let(:params) { {:excludes => 'foo', :target => '/bar/baz', :ranges => { 'foo' => "bar", 'bar' => "foo"} }} - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') + .with({'target' => '/bar/baz'}) + .with_content(/excludes = \[ "foo", \]/) } end @@ -102,10 +106,12 @@ end - context "#{os} with includes => foo (not a valid array)" do + context "#{os} with includes => foo" do let(:params) { {:includes => 'foo', :target => '/bar/baz', :ranges => { 'foo' => "bar", 'bar' => "foo"} }} - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') + .with({'target' => '/bar/baz'}) + .with_content(/includes = \[ "foo", \]/) } end end end @@ -141,6 +147,8 @@ it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object TimePeriod "bar"/) + .without_content(/excludes =/) + .without_content(/includes =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -208,10 +216,12 @@ end - context "Windows 2012 R2 with excludes => foo (not a valid array)" do + context "Windows 2012 R2 with excludes => foo" do let(:params) { {:excludes => 'foo', :target => 'C:/bar/baz', :ranges => { 'foo' => "bar", 'bar' => "foo"} }} - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/excludes = \[ "foo", \]/) } end @@ -224,10 +234,12 @@ end - context "Windows 2012 R2 with includes => foo (not a valid array)" do + context "Windows 2012 R2 with includes => foo" do let(:params) { {:includes => 'foo', :target => 'C:/bar/baz', :ranges => { 'foo' => "bar", 'bar' => "foo"} }} - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::TimePeriod::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/includes = \[ "foo", \]/) } end end From 7a7d5ebdcd8e02bba21c0f5c17d8c49c32fc2a98 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:18:27 +0100 Subject: [PATCH 18/22] fix object user --- manifests/object/user.pp | 23 ++++++++++----------- spec/defines/user_spec.rb | 42 ++++++++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/manifests/object/user.pp b/manifests/object/user.pp index dcb9496f8..50c4bb495 100644 --- a/manifests/object/user.pp +++ b/manifests/object/user.pp @@ -80,19 +80,18 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($user_name) - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - if $display_name { validate_string ($display_name) } - if $email { validate_string ($email) } - if $pager { validate_string ($pager) } - if $groups { validate_array ($groups) } - if $enable_notifications { validate_bool ($enable_notifications) } - if $period { validate_string ($period) } - if $types { validate_array ($types) } - if $states { validate_array ($states) } + if $display_name { validate_string($display_name) } + if $email { validate_string($email) } + if $pager { validate_string($pager) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } + if $enable_notifications { validate_bool($enable_notifications) } + if $period { validate_string($period) } + if $types { $_types = any2array($types) } else { $_types = undef } + if $states { $_states = any2array ($states) } else { $_states = undef } validate_integer ( $order ) @@ -102,11 +101,11 @@ 'email' => $email, 'pager' => $pager, 'vars' => $vars, - 'groups' => $groups, + 'groups' => $_groups, 'enable_notifications' => $enable_notifications, 'period' => $period, - 'types' => $types, - 'states' => $states, + 'types' => $_types, + 'states' => $_states, } # create object diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 3bc10f69f..692eb682b 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -19,6 +19,9 @@ it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') .with({'target' => '/bar/baz'}) .with_content(/object User "bar"/) + .without_content(/groups =/) + .without_content(/types =/) + .without_content(/states =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -82,10 +85,12 @@ end - context "#{os} with groups => foo (not a valid array)" do + context "#{os} with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end @@ -123,10 +128,12 @@ end - context "#{os} with types => foo (not a valid array)" do + context "#{os} with types => foo" do let(:params) { {:types => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => '/bar/baz'}) + .with_content(/types = \[ "foo", \]/) } end @@ -139,10 +146,12 @@ end - context "#{os} with states => foo (not a valid array)" do + context "#{os} with states => foo" do let(:params) { {:states => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => '/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end end end @@ -178,6 +187,9 @@ it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object User "bar"/) + .without_content(/groups =/) + .without_content(/types =/) + .without_content(/states =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -241,10 +253,12 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do + context "Windows 2012 R2 with groups => foo" do let(:params) { {:groups => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end @@ -282,10 +296,12 @@ end - context "Windows 2012 R2 with types => foo (not a valid array)" do + context "Windows 2012 R2 with types => foo" do let(:params) { {:types => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/types = \[ "foo", \]/) } end @@ -298,10 +314,12 @@ end - context "Windows 2012 R2 with states => foo (not a valid array)" do + context "Windows 2012 R2 with states => foo" do let(:params) { {:states => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::User::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/states = \[ "foo", \]/) } end end From b5d99a0e72f9033697d93e290170497c1dd6b5b9 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:22:05 +0100 Subject: [PATCH 19/22] fix object usergroup --- manifests/object/usergroup.pp | 9 ++++----- spec/defines/usergroup_spec.rb | 14 ++++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/manifests/object/usergroup.pp b/manifests/object/usergroup.pp index 92bd7d82b..ceb8c3caf 100644 --- a/manifests/object/usergroup.pp +++ b/manifests/object/usergroup.pp @@ -41,7 +41,7 @@ $ensure = present, $usergroup_name = $title, $display_name = undef, - $groups = [], + $groups = undef, $assign = [], $ignore = [], $import = [], @@ -56,13 +56,12 @@ validate_re($ensure, [ '^present$', '^absent$' ], "${ensure} isn't supported. Valid values are 'present' and 'absent'.") validate_string($usergroup_name) - validate_array($import) validate_bool($template) validate_absolute_path($target) validate_string($order) - if $display_name { validate_string ($display_name) } - if $groups { validate_array ($groups) } + if $display_name { validate_string($display_name) } + if $groups { $_groups = any2array($groups) } else { $_groups = undef } if $ignore != [] and $assign == [] { fail('When attribute ignore is used, assign must be set.') @@ -71,7 +70,7 @@ # compose attributes $attrs = { 'display_name' => $display_name, - 'groups' => $groups, + 'groups' => $_groups, } # create object diff --git a/spec/defines/usergroup_spec.rb b/spec/defines/usergroup_spec.rb index d4d34caea..3259efa47 100644 --- a/spec/defines/usergroup_spec.rb +++ b/spec/defines/usergroup_spec.rb @@ -19,6 +19,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::UserGroup::bar') .with({'target' => '/bar/baz'}) .with_content(/object UserGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -54,10 +55,12 @@ end - context "#{os} with groups => foo (not a valid array)" do + context "#{os} with groups => foo" do let(:params) { {:groups => 'foo', :target => '/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::UserGroup::bar') + .with({'target' => '/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end @@ -100,6 +103,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::UserGroup::bar') .with({'target' => 'C:/bar/baz'}) .with_content(/object UserGroup "bar"/) + .without_content(/groups =/) .without_content(/assign where/) .without_content(/ignore where/) } @@ -135,10 +139,12 @@ end - context "Windows 2012 R2 with groups => foo (not a valid array)" do + context "Windows 2012 R2 with groups => foo" do let(:params) { {:groups => 'foo', :target => 'C:/bar/baz'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::UserGroup::bar') + .with({'target' => 'C:/bar/baz'}) + .with_content(/groups = \[ "foo", \]/) } end From ca2e2d6e2e8f64e287a3251c514d5facc477ed16 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:34:25 +0100 Subject: [PATCH 20/22] fix feature idomysql --- manifests/feature/idomysql.pp | 4 ++-- spec/classes/idomysql_spec.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/manifests/feature/idomysql.pp b/manifests/feature/idomysql.pp index 6a10e81a8..1d2441f57 100644 --- a/manifests/feature/idomysql.pp +++ b/manifests/feature/idomysql.pp @@ -179,7 +179,7 @@ validate_bool($enable_ha) validate_re($failover_timeout, '^\d+[ms]*$') if $cleanup { validate_hash($cleanup) } - if $categories { validate_array($categories) } + if $categories { $_categories = any2array($categories) } else { $_categories = undef } validate_bool($import_schema) if $ssl_capath { validate_absolute_path($ssl_capath) } if $ssl_cipher { validate_string($ssl_cipher) } @@ -311,7 +311,7 @@ enable_ha => $enable_ha, failover_timeout => $failover_timeout, cleanup => $cleanup, - categories => $categories, + categories => $_categories, } diff --git a/spec/classes/idomysql_spec.rb b/spec/classes/idomysql_spec.rb index a36540c2a..7317387f5 100644 --- a/spec/classes/idomysql_spec.rb +++ b/spec/classes/idomysql_spec.rb @@ -33,6 +33,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') .with({ 'target' => '/etc/icinga2/features-available/ido-mysql.conf' }) + .without_content(/categories =/) .with_content(/host = "127.0.0.1"/) .with_content(/port = 3306/) .with_content(/user = "icinga"/) @@ -306,10 +307,12 @@ end - context "#{os} with categories => 'foo' (not a valid array)" do + context "#{os} with categories => 'foo'" do let(:params) { {:categories => 'foo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') + .with({ 'target' => '/etc/icinga2/features-available/ido-mysql.conf' }) + .with_content(/categories = \[ "foo", \]/) } end @@ -373,6 +376,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/ido-mysql.conf' }) + .without_content(/categories =/) .with_content(/host = "127.0.0.1"/) .with_content(/port = 3306/) .with_content(/user = "icinga"/) @@ -645,10 +649,12 @@ end - context "Windows 2012 R2 with categories => 'foo' (not a valid array)" do + context "Windows 2012 R2 with categories => 'foo'" do let(:params) { {:categories => 'foo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::IdoMysqlConnection::ido-mysql') + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/ido-mysql.conf' }) + .with_content(/categories = \[ "foo", \]/) } end From 2adef5c3a80ea4ec92eb75185e864261d98ffc54 Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:39:30 +0100 Subject: [PATCH 21/22] fix feature idopgsql --- manifests/feature/idopgsql.pp | 4 ++-- spec/classes/idopgsql_spec.rb | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/manifests/feature/idopgsql.pp b/manifests/feature/idopgsql.pp index ff0d8da0c..d31a2d206 100644 --- a/manifests/feature/idopgsql.pp +++ b/manifests/feature/idopgsql.pp @@ -104,7 +104,7 @@ validate_bool($enable_ha) validate_re($failover_timeout, '^\d+[ms]*$') if $cleanup { validate_hash($cleanup) } - if $categories { validate_array($categories) } + if $categories { $_categories = any2array($categories) } else { $_categories = undef } validate_bool($import_schema) package { 'icinga2-ido-pgsql': @@ -134,7 +134,7 @@ enable_ha => $enable_ha, failover_timeout => $failover_timeout, cleanup => $cleanup, - categories => $categories, + categories => $_categories, } # create object diff --git a/spec/classes/idopgsql_spec.rb b/spec/classes/idopgsql_spec.rb index f881fe5a1..23c8a96eb 100644 --- a/spec/classes/idopgsql_spec.rb +++ b/spec/classes/idopgsql_spec.rb @@ -29,6 +29,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql') .with({ 'target' => '/etc/icinga2/features-available/ido-pgsql.conf' }) + .without_content(/categories =/) .with_content(/host = "127.0.0.1"/) .with_content(/port = 5432/) .with_content(/user = "icinga"/) @@ -167,10 +168,12 @@ end - context "#{os} with categories => 'foo' (not a valid array)" do + context "#{os} with categories => 'foo'" do let(:params) { {:categories => 'foo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql') + .with({ 'target' => '/etc/icinga2/features-available/ido-pgsql.conf' }) + .with_content(/categories = \[ "foo", \]/) } end @@ -231,6 +234,7 @@ it { is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql') .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/ido-pgsql.conf' }) + .without_content(/categories =/) .with_content(/host = "127.0.0.1"/) .with_content(/port = 5432/) .with_content(/user = "icinga"/) @@ -369,10 +373,12 @@ end - context "Windows 2012 R2 with categories => 'foo' (not a valid array)" do + context "Windows 2012 R2 with categories => 'foo'" do let(:params) { {:categories => 'foo'} } - it { is_expected.to raise_error(Puppet::Error, /"foo" is not an Array/) } + it { is_expected.to contain_concat__fragment('icinga2::object::IdoPgsqlConnection::ido-pgsql') + .with({ 'target' => 'C:/ProgramData/icinga2/etc/icinga2/features-available/ido-pgsql.conf' }) + .with_content(/categories = \[ "foo", \]/) } end From e3954758f7bd769dfd9d3c8863fa184bf990fccc Mon Sep 17 00:00:00 2001 From: Lennart Betz Date: Tue, 17 Jan 2017 21:46:49 +0100 Subject: [PATCH 22/22] fix main class --- manifests/init.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index b92d4d877..c5bfbcfdd 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -138,7 +138,6 @@ validate_bool($enable) validate_bool($manage_repo) validate_bool($manage_service) - validate_array($features) validate_bool($purge_features) validate_hash($constants) validate_array($plugins) @@ -169,5 +168,5 @@ subscribe => Class['::icinga2::config'] } - include prefix($features, '::icinga2::feature::') + include prefix(any2array($features), '::icinga2::feature::') }