3 sources_list = { ensure: 'file',
4 path: '/etc/apt/sources.list',
8 notify: 'Class[Apt::Update]' }
10 sources_list_d = { ensure: 'directory',
11 path: '/etc/apt/sources.list.d',
17 notify: 'Class[Apt::Update]' }
19 preferences = { ensure: 'file',
20 path: '/etc/apt/preferences',
24 notify: 'Class[Apt::Update]' }
26 preferences_d = { ensure: 'directory',
27 path: '/etc/apt/preferences.d',
33 notify: 'Class[Apt::Update]' }
38 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
41 lsbdistcodename: 'jessie',
45 context 'with defaults' do
47 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
51 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
55 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
59 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
62 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
64 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
65 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
67 owner: 'root').with_content(
68 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
73 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
76 it { is_expected.not_to contain_apt__setting('conf-proxy') }
80 context 'when host=localhost' do
81 let(:params) { { proxy: { 'host' => 'localhost' } } }
84 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
85 %r{Acquire::http::proxy "http://localhost:8080/";},
87 %r{Acquire::https::proxy},
92 context 'when host=localhost and port=8180' do
93 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
96 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
97 %r{Acquire::http::proxy "http://localhost:8180/";},
99 %r{Acquire::https::proxy},
104 context 'when host=localhost and https=true' do
105 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
108 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
109 %r{Acquire::http::proxy "http://localhost:8080/";},
111 %r{Acquire::https::proxy "https://localhost:8080/";},
116 context 'when host=localhost and direct=true' do
117 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
120 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
121 %r{Acquire::http::proxy "http://localhost:8080/";},
123 %r{Acquire::https::proxy "DIRECT";},
128 context 'when host=localhost and https=true and direct=true' do
129 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
132 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
133 %r{Acquire::http::proxy "http://localhost:8080/";},
135 %r{Acquire::https::proxy "https://localhost:8080/";},
139 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
140 %r{Acquire::http::proxy "http://localhost:8080/";},
142 %r{Acquire::https::proxy "DIRECT";},
147 context 'when ensure=absent' do
148 let(:params) { { proxy: { 'ensure' => 'absent' } } }
151 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
156 context 'with lots of non-defaults' do
159 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
160 purge: { 'sources.list' => false, 'sources.list.d' => false,
161 'preferences' => false, 'preferences.d' => false },
166 is_expected.to contain_file('sources.list').with(content: nil)
170 is_expected.to contain_file('sources.list.d').with(purge: false,
175 is_expected.to contain_file('preferences').with(ensure: 'file')
179 is_expected.to contain_file('preferences.d').with(purge: false,
184 is_expected.to contain_exec('apt_update').with(refreshonly: false,
190 context 'with entries for /etc/apt/auth.conf' do
193 os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
195 lsbdistcodename: 'trusty',
197 lsbdistrelease: '14.04',
200 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
202 lsbdistcodename: 'xenial',
204 lsbdistrelease: '16.04',
207 os: { family: 'Debian', name: 'Ubuntu', release: { major: '18', full: '18.04' } },
209 lsbdistcodename: 'bionic',
211 lsbdistrelease: '18.04',
214 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
217 lsbdistcodename: 'wheezy',
220 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
223 lsbdistcodename: 'jessie',
226 os: { family: 'Debian', name: 'Debian', release: { major: '9', full: '9.0' } },
229 lsbdistcodename: 'stretch',
233 facts_hash.each do |os, facts|
234 context "on #{os}" do
242 machine: 'deb.example.net',
247 machine: 'apt.example.com',
249 password: 'supersecret',
255 context 'with manage_auth_conf => true' do
257 super().merge(manage_auth_conf: true)
260 # Going forward starting with Ubuntu 16.04 and Debian 9.0
261 # /etc/apt/auth.conf is owned by _apt. In previous versions it is
263 auth_conf_owner = case os
264 when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
270 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
271 machine deb.example.net login foologin password secret
272 machine apt.example.com login aptlogin password supersecret
276 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
277 owner: auth_conf_owner,
280 notify: 'Class[Apt::Update]',
281 content: auth_conf_content)
285 context 'with manage_auth_conf => false' do
287 super().merge(manage_auth_conf: false)
291 is_expected.not_to contain_file('/etc/apt/auth.conf')
296 context 'with improperly specified entries for /etc/apt/auth.conf' do
301 machinn: 'deb.example.net',
302 username: 'foologin',
306 machine: 'apt.example.com',
308 password: 'supersecret',
314 it { is_expected.to raise_error(Puppet::Error) }
319 context 'with sources defined on valid osfamily' do
322 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
324 lsbdistcodename: 'xenial',
326 lsbdistrelease: '16.04',
331 'debian_unstable' => {
332 'location' => 'http://debian.mirror.iweb.ca/debian/',
333 'release' => 'unstable',
334 'repos' => 'main contrib non-free',
335 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
337 'include' => { 'src' => true },
340 'location' => 'http://apt.puppetlabs.com',
342 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
348 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
351 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
352 it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(%r{^deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free$}) }
355 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
358 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
361 context 'with confs defined on valid osfamily' do
364 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
366 lsbdistcodename: 'xenial',
382 is_expected.to contain_apt__conf('foo').with(content: 'foo')
386 is_expected.to contain_apt__conf('bar').with(content: 'bar')
390 context 'with keys defined on valid osfamily' do
393 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
395 lsbdistcodename: 'xenial',
402 'server' => 'subkeys.pgp.net',
405 'server' => 'pgp.mit.edu',
411 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
415 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
419 context 'with ppas defined on valid osfamily' do
422 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
424 lsbdistcodename: 'xenial',
426 lsbdistrelease: '16.04',
431 'ppa:drizzle-developers/ppa' => {},
432 'ppa:nginx/stable' => {},
436 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
437 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
440 context 'with settings defined on valid osfamily' do
443 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
445 lsbdistcodename: 'xenial',
451 'conf-banana' => { 'content' => 'banana' },
452 'pref-banana' => { 'content' => 'banana' },
456 it { is_expected.to contain_apt__setting('conf-banana') }
457 it { is_expected.to contain_apt__setting('pref-banana') }
460 context 'with pins defined on valid osfamily' do
463 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
465 lsbdistcodename: 'xenial',
471 'stable' => { 'priority' => 600, 'order' => 50 },
472 'testing' => { 'priority' => 700, 'order' => 100 },
476 it { is_expected.to contain_apt__pin('stable') }
477 it { is_expected.to contain_apt__pin('testing') }
480 describe 'failing tests' do
481 context "with purge['sources.list']=>'banana'" do
482 let(:params) { { purge: { 'sources.list' => 'banana' } } }
485 is_expected.to raise_error(Puppet::Error)
489 context "with purge['sources.list.d']=>'banana'" do
490 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
493 is_expected.to raise_error(Puppet::Error)
497 context "with purge['preferences']=>'banana'" do
498 let(:params) { { purge: { 'preferences' => 'banana' } } }
501 is_expected.to raise_error(Puppet::Error)
505 context "with purge['preferences.d']=>'banana'" do
506 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
509 is_expected.to raise_error(Puppet::Error)