From 5530876e79d5032d3d8c475765705a2f68003db6 Mon Sep 17 00:00:00 2001 From: Lucas Yamanishi Date: Mon, 23 Nov 2015 13:55:26 -0500 Subject: [PATCH 1/2] Fix params.pp version comparison for Puppet 4 If the `$::smartmontools_version` fact does not exisist (is `undef`) then `versioncmp()` will fail with a type error. This adds a check to define it as `0.0` in such a case. --- manifests/params.pp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/params.pp b/manifests/params.pp index 81d2342..02525c7 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -23,8 +23,13 @@ $warning_schedule = 'daily' # other choices: once, diminishing $default_options = undef + $version_string = $::smartmontools_version ? { + undef => '0.0', + default => $::smartmontools_version, + } + # smartd.conf < 5.43 does not support the 'DEFAULT' directive - if versioncmp($::smartmontools_version, '5.43') >= 0 { + if versioncmp($version_string, '5.43') >= 0 { $enable_default = true } else { $enable_default = false From c51abf89d681742cca4b678a19e38e22c37c17b2 Mon Sep 17 00:00:00 2001 From: Lucas Yamanishi Date: Thu, 19 Nov 2015 18:54:40 -0500 Subject: [PATCH 2/2] Remove shell_config dependency This replaces the `shell_config` resource on Debian-based systems with an equivalent `augeas` resource. It also changes it to depend on the value of the `$svc_enable` variable instead of `$file_ensure`, bringing it in-line with its purpose. --- .fixtures.yml | 1 - README.md | 3 +- manifests/init.pp | 14 +- metadata.json | 3 +- spec/unit/classes/smartd_spec.rb | 609 +++++++++++++++++-------------- 5 files changed, 342 insertions(+), 288 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index abe6d3a..a2e8b9f 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,6 +3,5 @@ fixtures: stdlib: repo: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' ref: '4.6.0' - shell_config: 'https://github.com/jhoblitt/shell_config.git' symlinks: smartd: "#{source_dir}" diff --git a/README.md b/README.md index a132376..6f60b55 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ The module includes a facter plugin to identify drives hiding behind an LSI MegaRAID/Dell PERC/Supermicro controller on Linux systems if you have the LSI proprietary `MegaCli` tool installed; we don't have any FreeBSD machines with this controller so haven't written the necessary code to use FreeBSD's standard -`mfiutil(8)` utility instead. The `shell_config` module is required to edit a -Debian-specific configuration file; other OS families do not require it. +`mfiutil(8)` utility instead. Currently, drives behind an LSI MegaRAID controller will be automatically probed and added to the `smartd` configuration file, if the `MegaCli` utility diff --git a/manifests/init.pp b/manifests/init.pp index 59b9ea9..0d87d9b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -181,11 +181,15 @@ # Special sauce for Debian where it's not enough for the rc script # to be enabled, it also needs its own extra special config file. if $::osfamily == 'Debian' { - shell_config { 'start_smartd': - ensure => $file_ensure, - file => '/etc/default/smartmontools', - key => 'start_smartd', - value => 'yes', + $debian_augeas_changes = $svc_enable ? { + false => 'remove start_smartd', + default => 'set start_smartd "yes"', + } + + augeas { 'shell_config_start_smartd': + lens => 'Shellvars.lns', + incl => '/etc/default/smartmontools', + changes => $debian_augeas_changes, before => Service[$service_name], require => Package[$package_name], } diff --git a/metadata.json b/metadata.json index f782aa8..99b6bed 100644 --- a/metadata.json +++ b/metadata.json @@ -19,7 +19,6 @@ { "operatingsystem": "FreeBSD" } ], "dependencies": [ - { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" }, - { "name": "csail/shell_config", "version_requirement": ">= 0.0.1" } + { "name": "puppetlabs/stdlib", "version_requirement": ">= 4.6.0 < 5.0.0" } ] } diff --git a/spec/unit/classes/smartd_spec.rb b/spec/unit/classes/smartd_spec.rb index 3201e31..000793b 100644 --- a/spec/unit/classes/smartd_spec.rb +++ b/spec/unit/classes/smartd_spec.rb @@ -46,7 +46,7 @@ let(:facts) {{ :osfamily => 'SuSE', :smartmontools_version => '5.43', :gid => 'root' }} it_behaves_like 'default', {} - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartd.conf').with_notify('Service[smartd]') } end @@ -57,7 +57,7 @@ let(:facts) {{ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemmajrelease => '6', :smartmontools_version => '5.43', :gid => 'root' }} it_behaves_like 'default', {} - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartd.conf').with_notify('Service[smartd]') } end @@ -66,7 +66,7 @@ let(:facts) {{ :osfamily => 'RedHat', :operatingsystem => 'RedHat', :operatingsystemmajrelease => '7', :smartmontools_version => '6.2', :gid => 'root' }} it_behaves_like 'default', { :config_file => '/etc/smartmontools/smartd.conf' } - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartmontools/smartd.conf').with_notify('Service[smartd]') } end @@ -77,7 +77,7 @@ let(:facts) {{ :osfamily => 'RedHat', :operatingsystem => 'Fedora', :operatingsystemrelease => '18', :smartmontools_version => '5.43', :gid => 'root' }} it_behaves_like 'default', {} - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartd.conf').with_notify('Service[smartd]') } end @@ -86,7 +86,7 @@ let(:facts) {{ :osfamily => 'RedHat', :operatingsystem => 'Fedora', :operatingsystemrelease => '19', :smartmontools_version => '6.1', :gid => 'root' }} it_behaves_like 'default', { :config_file => '/etc/smartmontools/smartd.conf' } - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartmontools/smartd.conf').with_notify('Service[smartd]') } end @@ -97,7 +97,7 @@ let(:facts) {{ :osfamily => 'Debian', :smartmontools_version => '5.43', :gid => 'root' }} it_behaves_like 'default', {} - it { should contain_shell_config('start_smartd') } + it { should contain_augeas('shell_config_start_smartd').with_changes('set start_smartd "yes"') } it { should contain_service('smartmontools').with_ensure('running').with_enable(true) } it { should contain_file('/etc/smartd.conf').with_notify('Service[smartmontools]') } end @@ -106,7 +106,7 @@ let(:facts) {{ :osfamily => 'FreeBSD', :smartmontools_version => '5.43', :gid => 'wheel' }} it_behaves_like 'default', { :config_file => '/usr/local/etc/smartd.conf', :group => 'wheel' } - it { should_not contain_shell_config('start_smartd') } + it { should_not contain_augeas('shell_config_start_smartd') } it { should contain_service('smartd').with_ensure('running').with_enable(true) } it { should contain_file('/usr/local/etc/smartd.conf').with_notify('Service[smartd]') } end @@ -114,369 +114,422 @@ end describe 'on a supported osfamily, custom parameters' do - let(:facts) {{ :osfamily => 'RedHat', :smartmontools_version => '5.43' }} + describe 'for osfamily RedHat' do + let(:facts) {{ :osfamily => 'RedHat', :smartmontools_version => '5.43' }} - describe 'ensure => present' do - let(:params) {{ :ensure => 'present' }} + describe 'ensure => present' do + let(:params) {{ :ensure => 'present' }} - it { should contain_package('smartmontools').with_ensure('present') } - it { should contain_service('smartd').with_ensure('running').with_enable(true) } - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - end + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with_ensure('running').with_enable(true) } + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + end - describe 'ensure => latest' do - let(:params) {{ :ensure => 'latest' }} + describe 'ensure => latest' do + let(:params) {{ :ensure => 'latest' }} - it { should contain_package('smartmontools').with_ensure('latest') } - it { should contain_service('smartd').with_ensure('running').with_enable(true) } - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - end + it { should contain_package('smartmontools').with_ensure('latest') } + it { should contain_service('smartd').with_ensure('running').with_enable(true) } + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + end - describe 'ensure => absent' do - let(:params) {{ :ensure => 'absent' }} + describe 'ensure => absent' do + let(:params) {{ :ensure => 'absent' }} - it { should contain_package('smartmontools').with_ensure('absent') } - it { should_not contain_service('smartd') } - it { should contain_file('/etc/smartd.conf').with_ensure('absent') } - end + it { should contain_package('smartmontools').with_ensure('absent') } + it { should_not contain_service('smartd') } + it { should contain_file('/etc/smartd.conf').with_ensure('absent') } + end - describe 'ensure => purge' do - let(:params) {{ :ensure => 'purged' }} + describe 'ensure => purge' do + let(:params) {{ :ensure => 'purged' }} - it { should contain_package('smartmontools').with_ensure('purged') } - it { should_not contain_service('smartd') } - it { should contain_file('/etc/smartd.conf').with_ensure('absent') } - end + it { should contain_package('smartmontools').with_ensure('purged') } + it { should_not contain_service('smartd') } + it { should contain_file('/etc/smartd.conf').with_ensure('absent') } + end - describe 'ensure => badvalue' do - let(:params) {{ :ensure => 'badvalue' }} + describe 'ensure => badvalue' do + let(:params) {{ :ensure => 'badvalue' }} - it 'should fail' do - expect { - should raise_error(Puppet::Error, /unsupported value of $ensure: badvalue/) - } + it 'should fail' do + expect { + should raise_error(Puppet::Error, /unsupported value of $ensure: badvalue/) + } + end end - end - describe 'service_ensure => running' do - let(:params) {{ :service_ensure => 'running' }} + describe 'service_ensure => running' do + let(:params) {{ :service_ensure => 'running' }} - it { should contain_package('smartmontools').with_ensure('present') } - it { should contain_service('smartd').with_ensure('running').with_enable(true) } - end + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with_ensure('running').with_enable(true) } + end - describe 'service_ensure => stopped' do - let(:params) {{ :service_ensure => 'stopped' }} + describe 'service_ensure => stopped' do + let(:params) {{ :service_ensure => 'stopped' }} - it { should contain_package('smartmontools').with_ensure('present') } - it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } - end + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } + end - describe 'manage_service => false' do - let(:params) {{ :manage_service => false }} + describe 'manage_service => false' do + let(:params) {{ :manage_service => false }} - it { should_not contain_service('smartd') } - end + it { should_not contain_service('smartd') } + end - describe 'service_ensure => badvalue' do - let(:params) {{ :service_ensure => 'badvalue' }} + describe 'service_ensure => badvalue' do + let(:params) {{ :service_ensure => 'badvalue' }} - it 'should fail' do - expect { - should raise_error(Puppet::Error, /unsupported value of/) - } + it 'should fail' do + expect { + should raise_error(Puppet::Error, /unsupported value of/) + } + end end - end - describe 'devicescan =>' do - context '(default)' do - it do - should contain_file('/etc/smartd.conf'). - with_ensure('present'). - with_content(/^DEVICESCAN$/) - end - end # (default) + describe 'devicescan =>' do + context '(default)' do + it do + should contain_file('/etc/smartd.conf'). + with_ensure('present'). + with_content(/^DEVICESCAN$/) + end + end # (default) - context 'true' do - let(:params) {{ :devicescan => true }} + context 'true' do + let(:params) {{ :devicescan => true }} - it do - should contain_file('/etc/smartd.conf'). - with_ensure('present'). - with_content(/^DEVICESCAN$/) - end + it do + should contain_file('/etc/smartd.conf'). + with_ensure('present'). + with_content(/^DEVICESCAN$/) + end + + context 'enable_default => false' do + before { params[:enable_default] = false } + + it 'should have the same arguments as DEFAULT would have' do + should contain_file('/etc/smartd.conf'). + with_ensure('present'). + with_content(/^DEVICESCAN -m root -M daily$/) + end + end + end # true - context 'enable_default => false' do - before { params[:enable_default] = false } + context 'false' do + let(:params) {{ :devicescan => false }} - it 'should have the same arguments as DEFAULT would have' do + it do should contain_file('/etc/smartd.conf'). with_ensure('present'). - with_content(/^DEVICESCAN -m root -M daily$/) + without_content(/^DEVICESCAN$/) + end + end # false + + context 'foo' do + let(:params) {{ :devicescan => 'foo' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /is not a boolean../) + } end end - end # true + end # devicescan => - context 'false' do - let(:params) {{ :devicescan => false }} + describe 'devicescan_options => somevalue' do + let(:params) {{ :devicescan_options => 'somevalue' }} - it do - should contain_file('/etc/smartd.conf'). - with_ensure('present'). - without_content(/^DEVICESCAN$/) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + 'DEVICESCAN somevalue', + ]) end - end # false + end - context 'foo' do - let(:params) {{ :devicescan => 'foo' }} - it 'should fail' do - expect { - should raise_error(Puppet::Error, /is not a boolean../) + describe 'devices without options' do + let(:params) do + { + 'devices' => [ + { 'device' => '/dev/sg1' }, + { 'device' => '/dev/sg2' }, + ], } end - end - end # devicescan => - - describe 'devicescan_options => somevalue' do - let(:params) {{ :devicescan_options => 'somevalue' }} - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m root -M daily', - 'DEVICESCAN somevalue', - ]) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + '/dev/sg1', + '/dev/sg2', + ]) + end end - end - describe 'devices without options' do - let(:params) do - { - 'devices' => [ - { 'device' => '/dev/sg1' }, - { 'device' => '/dev/sg2' }, - ], - } - end + describe 'devices with options"' do + let :params do + { + 'devices' => [ + { 'device' => '/dev/sg1', 'options' => '-o on -S on -a' }, + { 'device' => '/dev/sg2', 'options' => '-o on -S on -a' }, + ], + } + end - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m root -M daily', - '/dev/sg1', - '/dev/sg2', - ]) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + '/dev/sg1 -o on -S on -a', + '/dev/sg2 -o on -S on -a', + ]) + end end - end - describe 'devices with options"' do - let :params do - { - 'devices' => [ - { 'device' => '/dev/sg1', 'options' => '-o on -S on -a' }, - { 'device' => '/dev/sg2', 'options' => '-o on -S on -a' }, - ], - } - end + describe 'devices with options"' do + let :params do + { + 'devices' => [ + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,0 -a -o on -S on' }, + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,1 -a -o on -S on' }, + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,2 -a -o on -S on' }, + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,3 -a -o on -S on' }, + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,4 -a -o on -S on' }, + { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,5 -a -o on -S on' }, + + ], + } + end - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m root -M daily', - '/dev/sg1 -o on -S on -a', - '/dev/sg2 -o on -S on -a', - ]) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + '/dev/cciss/c0d0 -d cciss,0 -a -o on -S on', + '/dev/cciss/c0d0 -d cciss,1 -a -o on -S on', + '/dev/cciss/c0d0 -d cciss,2 -a -o on -S on', + '/dev/cciss/c0d0 -d cciss,3 -a -o on -S on', + '/dev/cciss/c0d0 -d cciss,4 -a -o on -S on', + '/dev/cciss/c0d0 -d cciss,5 -a -o on -S on', + ]) + end end - end - describe 'devices with options"' do - let :params do - { - 'devices' => [ - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,0 -a -o on -S on' }, - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,1 -a -o on -S on' }, - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,2 -a -o on -S on' }, - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,3 -a -o on -S on' }, - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,4 -a -o on -S on' }, - { 'device' => '/dev/cciss/c0d0', 'options' => '-d cciss,5 -a -o on -S on' }, - - ], - } - end + describe 'mail_to => someguy@localdomain' do + let(:params) {{ :mail_to => 'someguy@localdomain' }} - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m root -M daily', - '/dev/cciss/c0d0 -d cciss,0 -a -o on -S on', - '/dev/cciss/c0d0 -d cciss,1 -a -o on -S on', - '/dev/cciss/c0d0 -d cciss,2 -a -o on -S on', - '/dev/cciss/c0d0 -d cciss,3 -a -o on -S on', - '/dev/cciss/c0d0 -d cciss,4 -a -o on -S on', - '/dev/cciss/c0d0 -d cciss,5 -a -o on -S on', - ]) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m someguy@localdomain -M daily', + ]) + end end - end - describe 'mail_to => someguy@localdomain' do - let(:params) {{ :mail_to => 'someguy@localdomain' }} + describe 'warning_schedule => diminishing' do + let(:params) {{ :warning_schedule => 'diminishing' }} - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m someguy@localdomain -M daily', - ]) + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain file /etc/smartd.conf with contents ...' do + verify_contents(catalogue, '/etc/smartd.conf', [ + 'DEFAULT -m root -M diminishing', + ]) + end end - end - describe 'warning_schedule => diminishing' do - let(:params) {{ :warning_schedule => 'diminishing' }} + describe 'warning_schedule => badvalue' do + let(:params) {{ :warning_schedule => 'badvalue' }} - it { should contain_file('/etc/smartd.conf').with_ensure('present') } - it 'should contain file /etc/smartd.conf with contents ...' do - verify_contents(catalogue, '/etc/smartd.conf', [ - 'DEFAULT -m root -M diminishing', - ]) + it 'should fail' do + expect { + should raise_error(Puppet::Error, /$warning_schedule must be either daily, once, or diminishing./) + } + end end - end - describe 'warning_schedule => badvalue' do - let(:params) {{ :warning_schedule => 'badvalue' }} + describe 'enable_default => ' do + context '(default)' do + context 'fact smartmontool_version = "5.43"' do + before { facts[:smartmontools_version] = '5.43' } + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + with_content(/DEFAULT -m root -M daily/) + end + end - it 'should fail' do - expect { - should raise_error(Puppet::Error, /$warning_schedule must be either daily, once, or diminishing./) - } - end - end + context 'fact smartmontool_version = "5.42"' do + before { facts[:smartmontools_version] = '5.42' } + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + without_content(/DEFAULT -m root -M daily/). + with_content(/DEVICESCAN -m root -M daily/) + end + end + end # (default) - describe 'enable_default => ' do - context '(default)' do - context 'fact smartmontool_version = "5.43"' do - before { facts[:smartmontools_version] = '5.43' } + context 'true' do + let(:params) {{ :enable_default => true }} it do should contain_file('/etc/smartd.conf').with_ensure('present'). with_content(/DEFAULT -m root -M daily/) end end - context 'fact smartmontool_version = "5.42"' do - before { facts[:smartmontools_version] = '5.42' } + context 'false' do + let(:params) {{ :enable_default => false }} it do should contain_file('/etc/smartd.conf').with_ensure('present'). without_content(/DEFAULT -m root -M daily/). with_content(/DEVICESCAN -m root -M daily/) end end - end # (default) - context 'true' do - let(:params) {{ :enable_default => true }} - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - with_content(/DEFAULT -m root -M daily/) - end - end - - context 'false' do - let(:params) {{ :enable_default => false }} - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - without_content(/DEFAULT -m root -M daily/). - with_content(/DEVICESCAN -m root -M daily/) - end - end - - context 'foo' do - let(:params) {{ :enable_default => 'foo' }} - it 'should fail' do - expect { - should raise_error(Puppet::Error, /is not a boolean../) - } + context 'foo' do + let(:params) {{ :enable_default => 'foo' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /is not a boolean../) + } + end end - end - end # enable_default => + end # enable_default => - describe 'default_options => ' do - context '(default)' do - let(:params) {{ }} + describe 'default_options => ' do + context '(default)' do + let(:params) {{ }} - context 'default => true' do - before { params[:enable_default] = true } + context 'default => true' do + before { params[:enable_default] = true } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - with_content(/DEFAULT -m root -M daily/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + with_content(/DEFAULT -m root -M daily/) + end end - end - context 'enable_default => false' do - before { params[:enable_default] = false } + context 'enable_default => false' do + before { params[:enable_default] = false } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - without_content(/DEFAULT -m root -M daily/). - with_content(/DEVICESCAN -m root -M daily/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + without_content(/DEFAULT -m root -M daily/). + with_content(/DEVICESCAN -m root -M daily/) + end end - end - end # (default) + end # (default) - context 'undef' do - let(:params) {{ :default_options => nil }} + context 'undef' do + let(:params) {{ :default_options => nil }} - context 'enable_default => true' do - before { params[:enable_default] = true } + context 'enable_default => true' do + before { params[:enable_default] = true } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - with_content(/DEFAULT -m root -M daily/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + with_content(/DEFAULT -m root -M daily/) + end end - end - context 'enable_default => false' do - before { params[:enable_default] = false } + context 'enable_default => false' do + before { params[:enable_default] = false } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - without_content(/DEFAULT -m root -M daily/). - with_content(/DEVICESCAN -m root -M daily/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + without_content(/DEFAULT -m root -M daily/). + with_content(/DEVICESCAN -m root -M daily/) + end end - end - end # undef + end # undef - context '-H' do - let(:params) {{ :default_options => '-H'}} + context '-H' do + let(:params) {{ :default_options => '-H'}} - context 'enable_default => true' do - before { params[:enable_default] = true } + context 'enable_default => true' do + before { params[:enable_default] = true } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - with_content(/DEFAULT -m root -M daily -H/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + with_content(/DEFAULT -m root -M daily -H/) + end end - end - context 'enable_default => false' do - before { params[:enable_default] = false } + context 'enable_default => false' do + before { params[:enable_default] = false } - it do - should contain_file('/etc/smartd.conf').with_ensure('present'). - without_content(/DEFAULT -m root -M daily -H/). - with_content(/DEVICESCAN -m root -M daily -H/) + it do + should contain_file('/etc/smartd.conf').with_ensure('present'). + without_content(/DEFAULT -m root -M daily -H/). + with_content(/DEVICESCAN -m root -M daily -H/) + end end - end - end # -H + end # -H + + context '[]' do + let(:params) {{ :default_options => [] }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /is not an Array../) + } + end + end # [] + end # default_options => + end - context '[]' do - let(:params) {{ :default_options => [] }} - it 'should fail' do - expect { - should raise_error(Puppet::Error, /is not an Array../) - } - end - end # [] - end # default_options => + describe 'for osfamily Debian' do + let(:facts) {{ :osfamily => 'Debian', :smartmontools_version => '5.43' }} + + describe 'ensure => present' do + let(:params) {{ :ensure => 'present' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('set start_smartd "yes"') } + end + + describe 'ensure => latest' do + let(:params) {{ :ensure => 'latest' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('set start_smartd "yes"') } + end + describe 'ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('remove start_smartd') } + end + + describe 'ensure => purged' do + let(:params) {{ :ensure => 'purged' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('remove start_smartd') } + end + + describe 'ensure => absent and service_ensure => running' do + let(:params) {{ :ensure => 'absent', :service_ensure => 'running' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('remove start_smartd') } + end + + describe 'ensure => purged and service_ensure => running' do + let(:params) {{ :ensure => 'purged', :service_ensure => 'running' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('remove start_smartd') } + end + + describe 'service_ensure => running' do + let(:params) {{ :service_ensure => 'running' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('set start_smartd "yes"') } + end + + describe 'service_ensure => stopped' do + let(:params) {{ :service_ensure => 'stopped' }} + + it { should contain_augeas('shell_config_start_smartd').with_changes('remove start_smartd') } + end + end end