2013-09-14 01:39:09 +02:00
|
|
|
require 'spec_helper'
|
2013-09-16 09:53:01 +02:00
|
|
|
describe 'apt::unattended_upgrades', :type => :class do
|
2013-09-16 13:34:07 +02:00
|
|
|
let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
|
|
|
|
let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
|
2014-02-24 23:31:16 +01:00
|
|
|
let(:facts) { { :lsbdistid => 'Debian' } }
|
2013-09-14 01:39:09 +02:00
|
|
|
|
|
|
|
it { should contain_package("unattended-upgrades") }
|
|
|
|
|
2013-09-16 14:56:14 +02:00
|
|
|
it {
|
2013-09-14 01:39:09 +02:00
|
|
|
should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
|
|
|
|
"owner" => "root",
|
|
|
|
"group" => "root",
|
|
|
|
"mode" => "0644",
|
2013-09-16 14:45:03 +02:00
|
|
|
"require" => "Package[unattended-upgrades]",
|
2013-09-14 01:39:09 +02:00
|
|
|
})
|
|
|
|
}
|
2013-09-16 14:56:14 +02:00
|
|
|
|
|
|
|
it {
|
2013-09-14 01:39:09 +02:00
|
|
|
should create_file("/etc/apt/apt.conf.d/10periodic").with({
|
|
|
|
"owner" => "root",
|
|
|
|
"group" => "root",
|
|
|
|
"mode" => "0644",
|
2013-09-16 14:45:03 +02:00
|
|
|
"require" => "Package[unattended-upgrades]",
|
2013-09-14 01:39:09 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-09-16 14:35:09 +02:00
|
|
|
describe "origins" do
|
2014-03-27 13:51:08 +01:00
|
|
|
describe 'on Debian' do
|
|
|
|
default_facts = { :lsbdistid => 'Debian' }
|
|
|
|
context 'defaults' do
|
|
|
|
let :facts do default_facts end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Origins-Pattern/
|
|
|
|
).with_content(
|
|
|
|
/"origin=Debian,archive=stable,label=Debian-Security";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'defaults with custom origin' do
|
|
|
|
let :facts do default_facts end
|
|
|
|
let :params do { :origins => ['bananana']} end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Origins-Pattern/
|
|
|
|
).with_content(
|
|
|
|
/"bananana";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'defaults with invalid origin' do
|
|
|
|
let :facts do default_facts end
|
|
|
|
let :params do { :origins => 'bananana'} end
|
|
|
|
it {
|
|
|
|
expect {subject}.to raise_error(/is not an Array/)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'squeeze' do
|
|
|
|
let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Allowed-Origins/
|
|
|
|
).with_content(
|
|
|
|
/"\${distro_id} \${distro_codename}-security";/
|
2014-04-02 11:17:04 +02:00
|
|
|
).with_content(
|
|
|
|
/"\${distro_id} oldstable";/
|
2014-03-27 13:51:08 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'wheezy' do
|
|
|
|
let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Origins-Pattern/
|
|
|
|
).with_content(
|
|
|
|
/"origin=Debian,archive=stable,label=Debian-Security";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
2013-09-16 14:35:09 +02:00
|
|
|
end
|
|
|
|
|
2014-03-27 13:51:08 +01:00
|
|
|
describe 'on Ubuntu' do
|
|
|
|
default_facts = { :lsbdistid => 'Ubuntu' }
|
|
|
|
context 'default' do
|
|
|
|
let :facts do default_facts end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Allowed-Origins/
|
|
|
|
).with_content(
|
|
|
|
/"\${distro_id}\:\${distro_codename}-security";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'lucid' do
|
|
|
|
let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Allowed-Origins/
|
|
|
|
).with_content(
|
|
|
|
/"\${distro_id} \${distro_codename}-security";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'precise' do
|
|
|
|
let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Allowed-Origins/
|
|
|
|
).with_content(
|
|
|
|
/"\${distro_id}\:\${distro_codename}-security";/
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
context 'trusty' do
|
|
|
|
let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
|
|
|
|
it {
|
|
|
|
should contain_file(file_unattended).with_content(
|
|
|
|
/^Unattended-Upgrade::Allowed-Origins/
|
|
|
|
).with_content(
|
|
|
|
/"\${distro_id}\:\${distro_codename}-security";/
|
|
|
|
)
|
|
|
|
}
|
2013-09-16 14:35:09 +02:00
|
|
|
end
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-16 14:35:09 +02:00
|
|
|
describe "blacklist" do
|
|
|
|
describe "with param defaults" do
|
|
|
|
let(:params) {{ }}
|
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with blacklist => []" do
|
|
|
|
let :params do
|
|
|
|
{ :blacklist => ['libc6', 'libc6-dev'] }
|
|
|
|
end
|
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with update => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :update => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with download => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :download => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with upgrade => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :upgrade => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with autoclean => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :autoclean => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with auto_fix => false" do
|
|
|
|
let :params do
|
2013-09-16 10:06:15 +02:00
|
|
|
{ :auto_fix => false }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with minimal_steps => true" do
|
|
|
|
let :params do
|
2013-09-16 10:06:15 +02:00
|
|
|
{ :minimal_steps => true }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with install_on_shutdown => true" do
|
|
|
|
let :params do
|
2013-09-16 10:06:15 +02:00
|
|
|
{ :install_on_shutdown => true }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-16 14:35:09 +02:00
|
|
|
describe "mail_to" do
|
|
|
|
describe "param defaults" do
|
|
|
|
let(:params) {{ }}
|
|
|
|
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
|
|
|
|
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:35:09 +02:00
|
|
|
|
|
|
|
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(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
|
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with remove_unused => false" do
|
|
|
|
let :params do
|
2013-09-16 10:06:15 +02:00
|
|
|
{ :remove_unused => false }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with auto_reboot => true" do
|
|
|
|
let :params do
|
2013-09-16 10:06:15 +02:00
|
|
|
{ :auto_reboot => true }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-16 14:35:09 +02:00
|
|
|
describe "dl_limit" do
|
|
|
|
describe "param defaults" do
|
|
|
|
let(:params) {{ }}
|
|
|
|
it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "with dl_limit => 70" do
|
|
|
|
let :params do
|
|
|
|
{ :dl_limit => "70" }
|
|
|
|
end
|
|
|
|
it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with enable => 0" do
|
|
|
|
let :params do
|
|
|
|
{ :enable => "0" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with backup_interval => 1" do
|
|
|
|
let :params do
|
|
|
|
{ :backup_interval => "1" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with backup_level => 0" do
|
|
|
|
let :params do
|
|
|
|
{ :backup_level => "0" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with max_age => 1" do
|
|
|
|
let :params do
|
|
|
|
{ :max_age => "1" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with min_age => 1" do
|
|
|
|
let :params do
|
|
|
|
{ :min_age => "1" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with max_size => 1" do
|
|
|
|
let :params do
|
|
|
|
{ :max_size => "1" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with download_delta => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :download_delta => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
describe "with verbose => 2" do
|
|
|
|
let :params do
|
|
|
|
{ :verbose => "2" }
|
|
|
|
end
|
2013-09-16 13:34:07 +02:00
|
|
|
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|
2013-09-16 14:56:14 +02:00
|
|
|
|
2013-09-14 01:39:09 +02:00
|
|
|
end
|