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}-lts";/
66 /"\${distro_id} \${distro_codename}-security";/
68 /"\${distro_id} oldstable";/
73 let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
75 should contain_file(file_unattended).with_content(
76 /^Unattended-Upgrade::Origins-Pattern/
78 /"origin=Debian,archive=stable,label=Debian-Security";/
84 describe 'on Ubuntu' do
85 default_facts = { :lsbdistid => 'Ubuntu' }
87 let :facts do default_facts end
89 should contain_file(file_unattended).with_content(
90 /^Unattended-Upgrade::Allowed-Origins/
92 /"\${distro_id}\:\${distro_codename}-security";/
97 let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
99 should contain_file(file_unattended).with_content(
100 /^Unattended-Upgrade::Allowed-Origins/
102 /"\${distro_id} \${distro_codename}-security";/
107 let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
109 should contain_file(file_unattended).with_content(
110 /^Unattended-Upgrade::Allowed-Origins/
112 /"\${distro_id}\:\${distro_codename}-security";/
117 let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
119 should contain_file(file_unattended).with_content(
120 /^Unattended-Upgrade::Allowed-Origins/
122 /"\${distro_id}\:\${distro_codename}-security";/
129 describe "blacklist" do
130 describe "with param defaults" do
132 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
135 describe "with blacklist => []" do
137 { :blacklist => ['libc6', 'libc6-dev'] }
139 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
143 describe "with update => 2" do
147 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
150 describe "with download => 2" do
154 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
157 describe "with upgrade => 2" do
161 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
164 describe "with autoclean => 2" do
166 { :autoclean => "2" }
168 it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
171 describe "with auto_fix => false" do
173 { :auto_fix => false }
175 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
178 describe "with minimal_steps => true" do
180 { :minimal_steps => true }
182 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
185 describe "with install_on_shutdown => true" do
187 { :install_on_shutdown => true }
189 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
192 describe "mail_to" do
193 describe "param defaults" do
195 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
196 it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
199 describe "with mail_to => user@website, mail_only_on_error => true" do
201 { :mail_to => "user@website",
202 :mail_only_on_error => true }
204 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
205 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
209 describe "with remove_unused => false" do
211 { :remove_unused => false }
213 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
216 describe "with auto_reboot => true" do
218 { :auto_reboot => true }
220 it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
223 describe "dl_limit" do
224 describe "param defaults" do
226 it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
229 describe "with dl_limit => 70" do
231 { :dl_limit => "70" }
233 it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
237 describe "with enable => 0" do
241 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
244 describe "with backup_interval => 1" do
246 { :backup_interval => "1" }
248 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
251 describe "with backup_level => 0" do
253 { :backup_level => "0" }
255 it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
258 describe "with max_age => 1" do
262 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
265 describe "with min_age => 1" do
269 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
272 describe "with max_size => 1" do
276 it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
279 describe "with download_delta => 2" do
281 { :download_delta => "2" }
283 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
286 describe "with verbose => 2" do
290 it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }