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";/
69 let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
71 should contain_file(file_unattended).with_content(
72 /^Unattended-Upgrade::Origins-Pattern/
74 /"origin=Debian,archive=stable,label=Debian-Security";/
80 describe 'on Ubuntu' do
81 default_facts = { :lsbdistid => 'Ubuntu' }
83 let :facts do default_facts end
85 should contain_file(file_unattended).with_content(
86 /^Unattended-Upgrade::Allowed-Origins/
88 /"\${distro_id}\:\${distro_codename}-security";/
93 let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
95 should contain_file(file_unattended).with_content(
96 /^Unattended-Upgrade::Allowed-Origins/
98 /"\${distro_id} \${distro_codename}-security";/
103 let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
105 should contain_file(file_unattended).with_content(
106 /^Unattended-Upgrade::Allowed-Origins/
108 /"\${distro_id}\:\${distro_codename}-security";/
113 let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
115 should contain_file(file_unattended).with_content(
116 /^Unattended-Upgrade::Allowed-Origins/
118 /"\${distro_id}\:\${distro_codename}-security";/
125 describe "blacklist" do
126 describe "with param defaults" do
128 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
131 describe "with blacklist => []" do
133 { :blacklist => ['libc6', 'libc6-dev'] }
135 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
139 describe "with update => 2" do
143 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
146 describe "with download => 2" do
150 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
153 describe "with upgrade => 2" do
157 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
160 describe "with autoclean => 2" do
162 { :autoclean => "2" }
164 it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
167 describe "with auto_fix => false" do
169 { :auto_fix => false }
171 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
174 describe "with minimal_steps => true" do
176 { :minimal_steps => true }
178 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
181 describe "with install_on_shutdown => true" do
183 { :install_on_shutdown => true }
185 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
188 describe "mail_to" do
189 describe "param defaults" do
191 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
192 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
195 describe "with mail_to => user@website, mail_only_on_error => true" do
197 { :mail_to => "user@website",
198 :mail_only_on_error => true }
200 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
201 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
205 describe "with remove_unused => false" do
207 { :remove_unused => false }
209 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
212 describe "with auto_reboot => true" do
214 { :auto_reboot => true }
216 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
219 describe "dl_limit" do
220 describe "param defaults" do
222 it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
225 describe "with dl_limit => 70" do
227 { :dl_limit => "70" }
229 it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
233 describe "with enable => 0" do
237 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
240 describe "with backup_interval => 1" do
242 { :backup_interval => "1" }
244 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
247 describe "with backup_level => 0" do
249 { :backup_level => "0" }
251 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
254 describe "with max_age => 1" do
258 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
261 describe "with min_age => 1" do
265 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
268 describe "with max_size => 1" do
272 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
275 describe "with download_delta => 2" do
277 { :download_delta => "2" }
279 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
282 describe "with verbose => 2" do
286 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }