2 describe 'apt::unattended_upgrades', :type => :class do
3 let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
4 let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
5 let(:facts) { { :lsbdistid => 'Debian' } }
7 it { should contain_package("unattended-upgrades") }
10 should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
14 "require" => "Package[unattended-upgrades]",
19 should create_file("/etc/apt/apt.conf.d/10periodic").with({
23 "require" => "Package[unattended-upgrades]",
28 describe 'on Debian' do
29 default_facts = { :lsbdistid => 'Debian' }
31 let :facts do default_facts end
33 should contain_file(file_unattended).with_content(
34 /^Unattended-Upgrade::Origins-Pattern/
36 /"origin=Debian,archive=stable,label=Debian-Security";/
40 context 'defaults with custom origin' do
41 let :facts do default_facts end
42 let :params do { :origins => ['bananana']} end
44 should contain_file(file_unattended).with_content(
45 /^Unattended-Upgrade::Origins-Pattern/
51 context 'defaults with invalid origin' do
52 let :facts do default_facts end
53 let :params do { :origins => 'bananana'} end
55 expect {subject}.to raise_error(/is not an Array/)
59 let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
61 should contain_file(file_unattended).with_content(
62 /^Unattended-Upgrade::Allowed-Origins/
64 /"\${distro_id} \${distro_codename}-security";/
66 /"\${distro_id} oldstable";/
71 let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
73 should contain_file(file_unattended).with_content(
74 /^Unattended-Upgrade::Origins-Pattern/
76 /"origin=Debian,archive=stable,label=Debian-Security";/
82 describe 'on Ubuntu' do
83 default_facts = { :lsbdistid => 'Ubuntu' }
85 let :facts do default_facts end
87 should contain_file(file_unattended).with_content(
88 /^Unattended-Upgrade::Allowed-Origins/
90 /"\${distro_id}\:\${distro_codename}-security";/
95 let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
97 should contain_file(file_unattended).with_content(
98 /^Unattended-Upgrade::Allowed-Origins/
100 /"\${distro_id} \${distro_codename}-security";/
105 let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
107 should contain_file(file_unattended).with_content(
108 /^Unattended-Upgrade::Allowed-Origins/
110 /"\${distro_id}\:\${distro_codename}-security";/
115 let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
117 should contain_file(file_unattended).with_content(
118 /^Unattended-Upgrade::Allowed-Origins/
120 /"\${distro_id}\:\${distro_codename}-security";/
127 describe "blacklist" do
128 describe "with param defaults" do
130 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
133 describe "with blacklist => []" do
135 { :blacklist => ['libc6', 'libc6-dev'] }
137 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
141 describe "with update => 2" do
145 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
148 describe "with download => 2" do
152 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
155 describe "with upgrade => 2" do
159 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
162 describe "with autoclean => 2" do
164 { :autoclean => "2" }
166 it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
169 describe "with auto_fix => false" do
171 { :auto_fix => false }
173 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
176 describe "with minimal_steps => true" do
178 { :minimal_steps => true }
180 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
183 describe "with install_on_shutdown => true" do
185 { :install_on_shutdown => true }
187 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
190 describe "mail_to" do
191 describe "param defaults" do
193 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
194 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
197 describe "with mail_to => user@website, mail_only_on_error => true" do
199 { :mail_to => "user@website",
200 :mail_only_on_error => true }
202 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
203 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
207 describe "with remove_unused => false" do
209 { :remove_unused => false }
211 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
214 describe "with auto_reboot => true" do
216 { :auto_reboot => true }
218 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
221 describe "dl_limit" do
222 describe "param defaults" do
224 it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
227 describe "with dl_limit => 70" do
229 { :dl_limit => "70" }
231 it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
235 describe "with enable => 0" do
239 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
242 describe "with backup_interval => 1" do
244 { :backup_interval => "1" }
246 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
249 describe "with backup_level => 0" do
251 { :backup_level => "0" }
253 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
256 describe "with max_age => 1" do
260 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
263 describe "with min_age => 1" do
267 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
270 describe "with max_size => 1" do
274 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
277 describe "with download_delta => 2" do
279 { :download_delta => "2" }
281 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
284 describe "with verbose => 2" do
288 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }