Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #662 accept numbers into configuration file #818

Merged
merged 1 commit into from Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
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
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
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 %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably makes sense to convert this to epp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #819

<%- 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