Skip to content

Commit

Permalink
Merge 20494e4 into f2c4a3d
Browse files Browse the repository at this point in the history
  • Loading branch information
leifmadsen committed Sep 18, 2020
2 parents f2c4a3d + 20494e4 commit 4c3a6f7
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
23 changes: 12 additions & 11 deletions manifests/plugin/virt.pp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# https://collectd.org/wiki/index.php/Plugin:virt
class collectd::plugin::virt (
String $connection,
$ensure = 'present',
$manage_package = undef,
Optional[Pattern[/^\d+$/]] $refresh_interval = undef,
Optional[String] $domain = undef,
Optional[String] $block_device = undef,
Optional[String] $interface_device = undef,
Optional[Boolean] $ignore_selected = undef,
Optional[String] $hostname_format = undef,
Optional[String] $interface_format = undef,
Optional[String] $extra_stats = undef,
$interval = undef,
$ensure = 'present',
$manage_package = undef,
Optional[Pattern[/^\d+$/]] $refresh_interval = undef,
Optional[String] $domain = undef,
Optional[String] $block_device = undef,
Optional[String] $interface_device = undef,
Optional[Boolean] $ignore_selected = undef,
Optional[Enum['none', 'name', 'uuid', 'metadata']] $plugin_instance_format = undef,
Optional[String] $hostname_format = undef,
Optional[String] $interface_format = undef,
Optional[String] $extra_stats = undef,
$interval = undef,
) {
include collectd

Expand Down
51 changes: 51 additions & 0 deletions spec/classes/collectd_plugin_virt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,57 @@
'include collectd'
end

context 'plugin_instance_format in virt.conf' do
let :params do
{
connection: 'qemu:///system',
plugin_instance_format: 'name'
}
end

context 'with collectd_version < 5.0' do
let :facts do
facts.merge(collectd_version: '4.10.1')
end

it 'is ignored' do
is_expected.to contain_file('libvirt.load').
without_content(%r{.*PluginInstanceFormat name.*})
end
end

context 'with collectd_version >= 5.0' do
let :facts do
facts.merge(collectd_version: '5.0.0')
end

it 'is included' do
is_expected.to contain_file('libvirt.load').
without_content(%r{.*PluginInstanceFormat name.*})
end
end

context 'with collectd_version >= 5.5.0' do
let :facts do
facts.merge(collectd_version: '5.5.0')
end

it 'is included' do
is_expected.to contain_file('virt.load').
with_content(%r{.*PluginInstanceFormat name.*})
end
end

case facts[:os]['family']
when 'RedHat'
context 'on osfamily => RedHat' do
it 'Will delete packaging config file' do
is_expected.to contain_file('package_virt.load').with_ensure('absent')
end
end
end
end

context 'interface_format in virt.conf' do
let :params do
{
Expand Down
5 changes: 5 additions & 0 deletions templates/plugin/virt.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<% if @ignore_selected != nil -%>
IgnoreSelected <%= @ignore_selected %>
<% end -%>
<%- if scope.lookupvar('collectd::collectd_version_real') and (scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.5']) >= 0) -%>
<% if @plugin_instance_format != nil -%>
PluginInstanceFormat <%= @plugin_instance_format %>
<% end -%>
<%- end -%>
<% if @hostname_format != nil -%>
HostnameFormat "<%= @hostname_format %>"
<% end -%>
Expand Down

0 comments on commit 4c3a6f7

Please sign in to comment.