Skip to content

Commit

Permalink
Merge pull request #818 from traylenator/int
Browse files Browse the repository at this point in the history
Fixes #662 accept numbers into configuration file
  • Loading branch information
bastelfreak authored Jun 13, 2018
2 parents e69dd24 + a8d6696 commit 3abffed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,9 @@ collectd::plugin::python::module {'my-module':
modulepath => '/var/share/collectd',
script_source => 'puppet:///modules/myorg/my-module.py',
config => [
{'Key' => "value"}
{'Key' => "value",
'Value' => 3.4,
}
]
}
```
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/collectd_plugin_python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
},
'foo' => {
'config' => [{ 'Verbose' => true, 'Bar' => '"bar"' }]
},
'alpha' => {
'config' => [{ 'Beta' => 4.2, 'Gamma' => 'b', 'Delta' => ['a', 4, 5] }]
}
}
}
Expand Down Expand Up @@ -140,6 +143,18 @@
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_foo').with(content: %r{Verbose true})
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_foo').with(content: %r{Bar "bar"})
end

it 'includes alpha module configuration' do
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(
content: %r{<Module "alpha">},
target: "#{options[:plugin_conf_dir]}/python-config.conf"
)
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(content: %r{Beta 4.2})
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(content: %r{Delta "a"})
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(content: %r{Delta 4})
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(content: %r{Delta 5})
is_expected.to contain_concat__fragment('collectd_plugin_python_conf_alpha').with(content: %r{Gamma "b"})
end
end

context 'allow changing module path' do
Expand Down
8 changes: 5 additions & 3 deletions templates/plugin/python/module.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
<%- configuration.sort.each do |key,value| -%>
<%- if value.is_a?(Array) -%>
<%- value.each do |v| -%>
<%= key %> <% if !!v == v %><%= v %><% else %>"<%= Shellwords.split(v).join('" "') %>"<% end %>
<%= key %> <% if !!v == v %><%= v %><% elsif v.is_a?(Numeric) %><%= v.to_s %><% else %>"<%= Shellwords.split(v).join('" "') %>"<% end %>
<%- end -%>
<% elsif value.is_a?(Numeric) -%>
<%= key %> <%= value.to_s %>
<%- elsif value.is_a?(Hash) -%>
<%- value.sort.each do |k,v| -%>
<%= key %> <%= k %> <% if !!v == v %><%= v %><% else %>"<%= Shellwords.split(v).join('" "') %>"<% end %>
<%= key %> <%= k %> <% if !!v == v %><%= v %><% elsif v.is_a?(Numeric) %><%= v.to_s %><% else %>"<%= Shellwords.split(v).join('" "') %>"<% end %>
<%- end -%>
<%- else -%>
<%= key %> <% if !!value == value %><%= value %><% else %>"<%= Shellwords.split(value).join('" "') %>"<% end %>
<%= key %> <% if !!value == value %><%= value %><% elsif value.is_a?(Numeric) %><%= value.to_s %><% else %>"<%= Shellwords.split(value).join('" "') %>"<% end %>
<%- end -%>
<%- end -%>
</Module>
Expand Down

0 comments on commit 3abffed

Please sign in to comment.