Separate apt::pin for apt::backports to allow pin by release instead of origin
[puppet-modules/puppetlabs-apt.git] / spec / classes / unattended_upgrades_spec.rb
1 require 'spec_helper'
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' } }
6
7   it { should contain_package("unattended-upgrades") }
8
9   it {
10     should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
11       "owner"   => "root",
12       "group"   => "root",
13       "mode"    => "0644",
14       "require" => "Package[unattended-upgrades]",
15     })
16   }
17
18   it {
19     should create_file("/etc/apt/apt.conf.d/10periodic").with({
20       "owner"   => "root",
21       "group"   => "root",
22       "mode"    => "0644",
23       "require" => "Package[unattended-upgrades]",
24     })
25   }
26
27   describe 'failing' do
28     let :facts do
29       {
30         'lsbdistid'       => 'debian',
31         'lsbdistcodename' => 'squeeze',
32       }
33     end
34     context 'bad auto_fix' do
35       let :params do
36         {
37           'auto_fix' => 'foo',
38         }
39       end
40       it { expect { should raise_error(Puppet::Error) } }
41     end
42
43     context 'bad minimal_steps' do
44       let :params do
45         {
46           'minimal_steps' => 'foo',
47         }
48       end
49       it { expect { should raise_error(Puppet::Error) } }
50     end
51
52     context 'bad install_on_shutdown' do
53       let :params do
54         {
55           'install_on_shutdown' => 'foo',
56         }
57       end
58       it { expect { should raise_error(Puppet::Error) } }
59     end
60
61     context 'bad mail_only_on_error' do
62       let :params do
63         {
64           'mail_only_on_error' => 'foo',
65         }
66       end
67       it { expect { should raise_error(Puppet::Error) } }
68     end
69
70     context 'bad remove_unused' do
71       let :params do
72         {
73           'remove_unused' => 'foo',
74         }
75       end
76       it { expect { should raise_error(Puppet::Error) } }
77     end
78
79     context 'bad auto_reboot' do
80       let :params do
81         {
82           'auto_reboot' => 'foo',
83         }
84       end
85       it { expect { should raise_error(Puppet::Error) } }
86     end
87
88     context 'bad origins' do
89       let :params do
90         {
91           'origins' => 'foo'
92         }
93       end
94       it { expect { should raise_error(Puppet::Error) } }
95     end
96
97     context 'bad randomsleep' do
98       let :params do
99         {
100           'randomsleep' => '4ever'
101         }
102       end
103       it { expect { should raise_error(Puppet::Error) } }
104     end
105   end
106
107   context 'defaults' do
108     let :facts do
109       {
110         'lsbdistid'       => 'debian',
111         'lsbdistcodename' => 'squeeze',
112       }
113     end
114
115     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\};} }
116     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "true";}}
117     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "false";}}
118     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "false";}}
119     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "true";}}
120     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "false";}}
121
122     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "1";}}
123     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "0";}}
124     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "3";}}
125     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "0";}}
126     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "0";}}
127     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "0";}}
128     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "1";}}
129     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "1";}}
130     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "0";}}
131     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "1";}}
132     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "7";}}
133     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "0";}}
134     it { is_expected.to_not contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep}}
135   end
136
137   context 'wheezy' do
138     let :facts do
139       {
140         'lsbdistid'       => 'debian',
141         'lsbdistcodename' => 'wheezy',
142       }
143     end
144
145     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\};} }
146   end
147
148   context 'anything but defaults' do
149     let :facts do
150       {
151         'lsbdistid'       => 'debian',
152         'lsbdistcodename' => 'wheezy',
153       }
154     end
155
156     let :params do
157       {
158         'enable'              => '0',
159         'backup_interval'     => '3',
160         'backup_level'        => '1',
161         'max_age'             => '7',
162         'min_age'             => '1',
163         'max_size'            => '100',
164         'update'              => '0',
165         'download'            => '0',
166         'download_delta'      => '1',
167         'upgrade'             => '0',
168         'autoclean'           => '0',
169         'verbose'             => '1',
170         'origins'             => ['bananas'],
171         'blacklist'           => ['foo', 'bar'],
172         'auto_fix'            => false,
173         'minimal_steps'       => true,
174         'install_on_shutdown' => true,
175         'mail_to'             => 'root@localhost',
176         'mail_only_on_error'  => true,
177         'remove_unused'       => false,
178         'auto_reboot'         => true,
179         'dl_limit'            => '70',
180         'randomsleep'         => '1799',
181       }
182     end
183
184     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Origins-Pattern \{\n\t"bananas";\n\};} }
185     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\};} }
186     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::AutoFixInterruptedDpkg "false";}}
187     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MinimalSteps "true";}}
188     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::InstallOnShutdown "true";}}
189     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Mail "root@localhost";}}
190     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::MailOnlyOnError "true";}}
191     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Remove-Unused-Dependencies "false";}}
192     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Unattended-Upgrade::Automatic-Reboot "true";}}
193     it { is_expected.to contain_file("/etc/apt/apt.conf.d/50unattended-upgrades").with_content %r{Acquire::http::Dl-Limit "70";}}
194
195     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Enable "0";}}
196     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpArchiveInterval "3";}}
197     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::BackUpLevel "1";}}
198     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxAge "7";}}
199     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MinAge "1";}}
200     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::MaxSize "100";}}
201     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Update-Package-Lists "0";}}
202     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages "0";}}
203     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Download-Upgradeable-Packages-Debdelta "1";}}
204     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Unattended-Upgrade "0";}}
205     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::AutocleanInterval "0";}}
206     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::Verbose "1";}}
207     it { is_expected.to contain_file("/etc/apt/apt.conf.d/10periodic").with_content %r{APT::Periodic::RandomSleep "1799";}}
208
209   end
210 end