X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fclasses%2Funattended_upgrades_spec.rb;h=e0a6ebf72236cd411314fcf9af24c150ad0ec13f;hb=61080fb6760e3d28b04158a3a2e1f3a055a2854e;hp=6695550abc7dd36df7a84b82c9101cce275ae6b4;hpb=2fea399a09d64addb9413a67697211a93cb803bd;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb index 6695550..e0a6ebf 100644 --- a/spec/classes/unattended_upgrades_spec.rb +++ b/spec/classes/unattended_upgrades_spec.rb @@ -1,179 +1,214 @@ require 'spec_helper' describe 'apt::unattended_upgrades', :type => :class do + let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' } + let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' } + let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } it { should contain_package("unattended-upgrades") } - it { + it { should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({ "owner" => "root", "group" => "root", "mode" => "0644", + "require" => "Package[unattended-upgrades]", }) } - - it { + + it { should create_file("/etc/apt/apt.conf.d/10periodic").with({ "owner" => "root", "group" => "root", "mode" => "0644", + "require" => "Package[unattended-upgrades]", }) } - describe "with origins => ['ubuntu:precise-security']" do - let :params do - { :origins => ['ubuntu:precise-security'] } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Allowed-Origins \{\n\t"ubuntu:precise-security";\n\};$/) } - end - - describe "with blacklist => []" do - let :params do - { :blacklist => [] } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) } - end - - describe "with update => 2" do - let :params do - { :update => "2" } - end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Update-Package-Lists "2";$/) } - end - - describe "with download => 2" do - let :params do - { :download => "2" } - end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) } - end - - describe "with upgrade => 2" do - let :params do - { :upgrade => "2" } - end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) } - end - - describe "with autoclean => 2" do - let :params do - { :autoclean => "2" } + describe 'failing' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'squeeze', + 'osfamily' => 'Debian', + } + end + context 'bad auto_fix' do + let :params do + { + 'auto_fix' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::AutocleanInterval "2";$/) } - end - - describe "with auto_fix => false" do - let :params do - { :auto_fix => "false" } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) } - end - - describe "with minimal_steps => true" do - let :params do - { :minimal_steps => "true" } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) } - end - - describe "with install_on_shutdown => true" do - let :params do - { :install_on_shutdown => "true" } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) } - end - - describe "with mail_to => NONE" do - let :params do - { :mail_to => "NONE" } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^\/\/ 'mailx' must be installed.\n$/) } - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^\/\/ is to always send a mail if Unattended-Upgrade::Mail is set\n$/) } - end - - describe "with mail_to => user@website, mail_only_on_error => true" do - let :params do - { :mail_to => "user@website", - :mail_only_on_error => "true" } - end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Mail "user@website";$/) } - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) } - end - - describe "with remove_unused => false" do - let :params do - { :remove_unused => "false" } + + context 'bad minimal_steps' do + let :params do + { + 'minimal_steps' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) } - end - - describe "with auto_reboot => true" do - let :params do - { :auto_reboot => "true" } + + context 'bad install_on_shutdown' do + let :params do + { + 'install_on_shutdown' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) } - end - - describe "with dl_limit => 70" do - let :params do - { :dl_limit => "70" } + + context 'bad mail_only_on_error' do + let :params do + { + 'mail_only_on_error' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/50unattended-upgrades').with_content(/^Acquire::http::Dl-Limit "70";$/) } - end - - describe "with enable => 0" do - let :params do - { :enable => "0" } + + context 'bad remove_unused' do + let :params do + { + 'remove_unused' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Enable "0";$/) } - end - - describe "with backup_interval => 1" do - let :params do - { :backup_interval => "1" } + + context 'bad auto_reboot' do + let :params do + { + 'auto_reboot' => 'foo', + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) } - end - - describe "with backup_level => 0" do - let :params do - { :backup_level => "0" } + + context 'bad origins' do + let :params do + { + 'origins' => 'foo' + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::BackUpLevel "0";$/) } - end - - describe "with max_age => 1" do - let :params do - { :max_age => "1" } + + context 'bad randomsleep' do + let :params do + { + 'randomsleep' => '4ever' + } + end + it { expect { should raise_error(Puppet::Error) } } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MaxAge "1";$/) } end - - describe "with min_age => 1" do - let :params do - { :min_age => "1" } + + context 'defaults' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'squeeze', + 'osfamily' => 'Debian', + } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MinAge "1";$/) } + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Allowed-Origins \{\n\t"\${distro_id} oldstable";\n\t"\${distro_id} \${distro_codename}-security";\n\t"\${distro_id} \${distro_codename}-lts";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "false";}} + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "3";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}} + it { is_expected.to_not contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep}} end - - describe "with max_size => 1" do - let :params do - { :max_size => "1" } + + context 'wheezy' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'wheezy', + 'osfamily' => 'Debian', + } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::MaxSize "1";$/) } + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"origin=Debian,archive=stable,label=Debian-Security";\n\t"origin=Debian,archive=oldstable,label=Debian-Security";\n\};} } end - - describe "with download_delta => 2" do - let :params do - { :download_delta => "2" } + + context 'anything but defaults' do + let :facts do + { + 'lsbdistid' => 'debian', + 'lsbdistcodename' => 'wheezy', + 'osfamily' => 'Debian', + } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) } - end - - describe "with verbose => 2" do + let :params do - { :verbose => "2" } + { + 'enable' => '0', + 'backup_interval' => '3', + 'backup_level' => '1', + 'max_age' => '7', + 'min_age' => '1', + 'max_size' => '100', + 'update' => '0', + 'download' => '0', + 'download_delta' => '1', + 'upgrade' => '0', + 'autoclean' => '0', + 'verbose' => '1', + 'origins' => ['bananas'], + 'blacklist' => ['foo', 'bar'], + 'auto_fix' => false, + 'minimal_steps' => true, + 'install_on_shutdown' => true, + 'mail_to' => 'root@localhost', + 'mail_only_on_error' => true, + 'remove_unused' => false, + 'auto_reboot' => true, + 'dl_limit' => '70', + 'randomsleep' => '1799', + } end - it { should contain_file('/etc/apt/apt.conf.d/10periodic').with_content(/^APT::Periodic::Verbose "2";$/) } + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"bananas";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Package-Blacklist \{\n\t"foo";\n\t"bar";\n\};} } + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Mail "root@localhost";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MailOnlyOnError "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "false";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "true";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Acquire::http::Dl-Limit "70";}} + + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "3";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "7";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "100";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}} + it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep "1799";}} + end - end