From 9b35dd8030f910572602efac3d5502e93948432b Mon Sep 17 00:00:00 2001 From: Michael Arnold Date: Sat, 3 Aug 2013 16:30:33 -0700 Subject: [PATCH] Updated rspec tests to deal with fix to template. Added shell_config to .fixtures.yml. Added a whole lot of testing of various parameters and template configurations on all supported osfamilies. --- .fixtures.yml | 4 +- spec/classes/smartd_spec.rb | 215 +++++++++++++++++++++++++++++++++++- 2 files changed, 216 insertions(+), 3 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 5f0d362..2257e31 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,6 @@ fixtures: repositories: - "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" +# "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git" + "shell_config": "http://tig.csail.mit.edu/git-public/shell_config.git/" symlinks: "smartd": "#{source_dir}" - diff --git a/spec/classes/smartd_spec.rb b/spec/classes/smartd_spec.rb index c54692d..371c196 100644 --- a/spec/classes/smartd_spec.rb +++ b/spec/classes/smartd_spec.rb @@ -1,6 +1,219 @@ require 'spec_helper' -describe 'smartd' do +describe 'smartd', :type => 'class' do + + context 'on a non-supported osfamily' do + let(:params) {{}} + let(:facts) {{ :osfamily => 'foo' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /smartd: unsupported OS family bar/) + } + end + end + + context 'on a supported osfamily, default parameters' do + describe 'for osfamily RedHat' do + let(:params) {{}} + let(:facts) {{ :osfamily => 'RedHat' }} + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with( + :ensure => 'running', + :enable => true, + :hasrestart => true + )} + it { should contain_file('/etc/smartd.conf').with( + :ensure => 'present', + :owner => 'root', + :group => '0', + :mode => '0644', + :require => 'Package[smartmontools]', + :before => 'Service[smartd]', + :notify => 'Service[smartd]' + )} + it 'should contain File[/etc/smartd.conf] with correct contents' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + 'DEVICESCAN', + ]) + end + it { should_not contain_shell_config('start_smartd') } + end + + describe 'for osfamily Debian' do + let(:params) {{}} + let(:facts) {{ :osfamily => 'Debian' }} + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with( + :ensure => 'running', + :enable => true, + :hasrestart => true + )} + it { should contain_file('/etc/smartd.conf').with( + :ensure => 'present', + :owner => 'root', + :group => '0', + :mode => '0644', + :require => 'Package[smartmontools]', + :before => 'Service[smartd]', + :notify => 'Service[smartd]' + )} + it 'should contain File[/etc/smartd.conf] with correct contents' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + 'DEVICESCAN', + ]) + end + it { should contain_shell_config('start_smartd').with( + :ensure => 'present', + :file => '/etc/default/smartmontools', + :key => 'start_smartd', + :value => 'yes', + :before => 'Service[smartd]' + )} + end + + describe 'for osfamily FreeBSD' do + let(:params) {{}} + let(:facts) {{ :osfamily => 'FreeBSD' }} + it { should contain_package('smartmontools').with_ensure('present') } + it { should contain_service('smartd').with( + :ensure => 'running', + :enable => true, + :hasrestart => true + )} + it { should contain_file('/usr/local/etc/smartd.conf').with( + :ensure => 'present', + :owner => 'root', + :group => '0', + :mode => '0644', + :require => 'Package[smartmontools]', + :before => 'Service[smartd]', + :notify => 'Service[smartd]' + )} + it 'should contain File[/usr/local/etc/smartd.conf] with correct contents' do + verify_contents(subject, '/usr/local/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + 'DEVICESCAN', + ]) + end + it { should_not contain_shell_config('start_smartd') } + end + + end + + context 'on a supported osfamily, custom parameters' do + let(:facts) {{ :osfamily => 'RedHat' }} + + describe 'ensure => absent' do + let(:params) {{ :ensure => 'absent' }} + it { should contain_package('smartmontools').with_ensure('absent') } + it { should contain_service('smartd').with_ensure('stopped').with_enable(false) } + it { should contain_file('/etc/smartd.conf').with_ensure('absent') } + end + + describe 'ensure => badvalue' do + let(:params) {{ :ensure => 'badvalue' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /unsupported value of $ensure: badvalue/) + } + end + end + + describe 'autoupdate => true' do + let(:params) {{ :autoupdate => true }} + 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 'autoupdate => badvalue' do + let(:params) {{ :autoupdate => 'badvalue' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /"badvalue" is not a boolean./) + } + end + end + + describe 'devicescan => false' do + let(:params) {{ :devicescan => false }} + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it { should_not contain_file('/etc/smartd.conf').with_content(/^DEVICESCAN$/) } + end + + 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 "DEVICESCAN somevalue"' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + 'DEVICESCAN somevalue', + ]) + end + end + + describe 'devices => [ /dev/sg1, /dev/sg2 ]' do + let(:params) {{ :devices => [ '/dev/sg1', '/dev/sg2', ] }} + it { should contain_file('/etc/smartd.conf').with_ensure('present') } + it 'should contain File[/etc/smartd.conf] with contents "/dev/sg1\n/dev/sg2"' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + '/dev/sg1', + '/dev/sg2', + ]) + end + end + + describe 'device_opts => "{ /dev/sg1 => -o on -S on -a, /dev/sg2 => -o on -S on -a }"' do + let :params do { + :devices => [ '/dev/sg1', '/dev/sg2', ], + :device_opts => { '/dev/sg1' => '-o on -S on -a', '/dev/sg2' => '-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 "/dev/sg1 -o on -S on -a\n/dev/sg2 -o on -S on -a"' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M daily', + '/dev/sg1 -o on -S on -a', + '/dev/sg2 -o on -S on -a', + ]) + end + 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 "DEFAULT -m someguy@localdomain -M daily"' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m someguy@localdomain -M daily', + ]) + end + end + + 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 "DEFAULT -m root -M diminishing"' do + verify_contents(subject, '/etc/smartd.conf', [ + 'DEFAULT -m root -M diminishing', + ]) + end + end + + describe 'warning_schedule => badvalue' do + let(:params) {{ :warning_schedule => 'badvalue' }} + it 'should fail' do + expect { + should raise_error(Puppet::Error, /$warning_schedule must be either daily, once, or diminishing./) + } + end + end + + end + + let(:title) { 'redhat' } let(:facts) { {:osfamily=> 'RedHat', :lsbmajordistrelease => 6} }