Skip to content

Commit

Permalink
fix voxpupuli#227 Add service name to service apply loops
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz authored and n00by committed Apr 26, 2018
1 parent 641f9ab commit 0493f2d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
11 changes: 5 additions & 6 deletions lib/puppet_x/icinga2/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ module Utils
def self.attributes(attrs, consts, indent=2)

def self.value_types(value)

if value =~ /^\d+\.?\d*[dhms]?$/ || value =~ /^(true|false)$/
result = value
else
if $constants.include?(value) || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/
if $constants.index { |x| value =~ /^!?(#{x})(\..+$|$)/ } || value =~ /^!?(host|service|user)\./ || value =~ /^\{{2}.*\}{2}$/
result = value
else
result = "\"#{value}\""
Expand Down Expand Up @@ -149,7 +150,6 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent)
end
end
elsif value.is_a?(Array)
#result += "%s%s = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ]
result += case level
when 2 then "%s[\"%s\"] = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ]
else "%s%s = [ %s]\n" % [ prefix, attribute_types(attr), process_array(value) ]
Expand All @@ -173,16 +173,15 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent)

# globals (params.pp) and all keys of attrs hash itselfs must not quoted
$constants = consts.concat(attrs.keys) << "name"
# also with added not operetor '!'
$constants += $constants.map {|x| "!#{x}"}

# initialize returned configuration
config = ''

attrs.each do |attr, value|

if attr =~ /^(assign|ignore) where$/
value.each do |x|
config += "%s%s %s\n" % [ ' ' * indent, attr, parse(x) ]
config += "%s%s %s\n" % [ ' ' * indent, attr, parse(x) ] if x != :undef
end
else
if value.is_a?(Hash)
Expand All @@ -194,7 +193,7 @@ def self.process_hash(attrs, indent=2, level=3, prefix=' '*indent)
elsif value.is_a?(Array)
config += "%s%s = [ %s]\n" % [ ' ' * indent, attr, process_array(value) ]
else
config += "%s%s = %s\n" % [ ' ' * indent, attr, parse(value) ] if value != :undef
config += "%s%s = %s\n" % [ ' ' * indent, attr, parse(value) ]
end
end
end
Expand Down
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
$plugins = [ 'plugins', 'plugins-contrib', 'windows-plugins', 'nscp' ]
$default_features = [ 'checker', 'mainlog', 'notification' ]
$globals = [
'==', '!=', '!', '||', '&&',
'Acknowledgement',
'ApplicationType',
'AttachDebugger',
Expand Down
34 changes: 18 additions & 16 deletions spec/defines/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,24 @@
end


context "#{os} with import => [bar, baz], apply => foo in host.vars.bar" do
let(:params) { {:import => ['bar', 'baz'], :apply => 'foo in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }
context "#{os} with import => [bar, baz], apply => desc in host.vars.bar, assign => [desc.bar]" do
let(:params) { {:import => ['bar', 'baz'], :apply => 'desc in host.vars.bar', :apply_target => 'Host', :assign => ['desc.bar'], :attrs => {'vars' => 'vars + desc'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/import "bar"/)
.with_content(/import "baz"/)
.with_content(/vars = vars \+ foo\n/)
.with_content(/apply foo for \(foo in host.vars.bar\) to Host/) }
.with_content(/vars = vars \+ desc\n/)
.with_content(/apply foo for \(desc in host.vars.bar\) to Host/)
.with_content(/assign where desc.bar/) }
end


context "#{os} with apply => foo => config in host.vars.bar" do
let(:params) { {:apply => 'foo => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo + config'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }
context "#{os} with apply => desc => config in host.vars.bar" do
let(:params) { {:apply => 'desc => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + desc + !config.bar'}, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/vars = vars \+ foo \+ config\n/)
.with_content(/apply foo for \(foo => config in host.vars.bar\) to Host/) }
.with_content(/vars = vars \+ desc \+ !config.bar\n/)
.with_content(/apply foo for \(desc => config in host.vars.bar\) to Host/) }
end


Expand Down Expand Up @@ -329,23 +330,24 @@
end


context "Windows 2012 R2 with import => [bar, baz], apply => foo in host.vars.bar" do
let(:params) { {:import => ['bar', 'baz'], :apply => 'foo in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }
context "Windows with import => [bar, baz], apply => desc in host.vars.bar, assign => [desc.bar]" do
let(:params) { {:import => ['bar', 'baz'], :apply => 'desc in host.vars.bar', :apply_target => 'Host', :assign => ['desc.bar'], :attrs => {'vars' => 'vars + desc'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/import "bar"/)
.with_content(/import "baz"/)
.with_content(/vars = vars \+ foo\r\n/)
.with_content(/apply foo for \(foo in host.vars.bar\) to Host/) }
.with_content(/vars = vars \+ desc\r\n/)
.with_content(/apply foo for \(desc in host.vars.bar\) to Host/)
.with_content(/assign where desc.bar/) }
end


context "Windows 2012 R2 with apply => foo => config in host.vars.bar" do
let(:params) { {:apply => 'foo => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + foo + config'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }
context "Windows 2012 R2 with apply => desc => config in host.vars.bar" do
let(:params) { {:apply => 'desc => config in host.vars.bar', :apply_target => 'Host', :attrs => {'vars' => 'vars + desc + !config.bar'}, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/vars = vars \+ foo \+ config\r\n/)
.with_content(/apply foo for \(foo => config in host.vars.bar\) to Host/) }
.with_content(/vars = vars \+ desc \+ !config.bar\r\n/)
.with_content(/apply foo for \(desc => config in host.vars.bar\) to Host/) }
end


Expand Down

0 comments on commit 0493f2d

Please sign in to comment.