diff --git a/manifests/plugin/disk.pp b/manifests/plugin/disk.pp index 4f69530ff..c805c0c21 100644 --- a/manifests/plugin/disk.pp +++ b/manifests/plugin/disk.pp @@ -4,6 +4,7 @@ $disks = [], $ignoreselected = false, $interval = undef, + $udevnameattr = undef, ) { validate_array($disks) diff --git a/spec/classes/collectd_plugin_disk_spec.rb b/spec/classes/collectd_plugin_disk_spec.rb index d9d2089bb..44cfe69ee 100644 --- a/spec/classes/collectd_plugin_disk_spec.rb +++ b/spec/classes/collectd_plugin_disk_spec.rb @@ -38,5 +38,39 @@ should compile.and_raise_error(/String/) end end -end + context ':udevnameattr on collectd < 5.5' do + let :params do + {:udevnameattr => 'DM_NAME'} + end + let :facts do + { :osfamily => 'RedHat', + :collectd_version => '5.4', + } + end + it 'Will not include the setting' do + should contain_file('disk.load').with({ + :ensure => 'present', + :path => '/etc/collectd.d/10-disk.conf', + }).without_content(/UdevNameAttr DM_NAME/) + end + end + + context ':udevnameattr on collectd >= 5.5' do + let :params do + {:udevnameattr => 'DM_NAME'} + end + let :facts do + { :osfamily => 'RedHat', + :collectd_version => '5.5', + } + end + it 'Will include the setting' do + should contain_file('disk.load').with({ + :ensure => 'present', + :path => '/etc/collectd.d/10-disk.conf', + :content => /UdevNameAttr DM_NAME/, + }) + end + end +end diff --git a/templates/plugin/disk.conf.erb b/templates/plugin/disk.conf.erb index 7b4836d7d..3d92ecf2a 100644 --- a/templates/plugin/disk.conf.erb +++ b/templates/plugin/disk.conf.erb @@ -3,4 +3,7 @@ Disk "<%=disk %>" <% end -%> IgnoreSelected <%= @ignoreselected %> +<% if @udevnameattr and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.5']) >= 0) -%> + UdevNameAttr <%= @udevnameattr %> +<% end -%>