3 sources_list = { ensure: 'file',
4 path: '/etc/apt/sources.list',
7 notify: 'Class[Apt::Update]' }
9 sources_list_d = { ensure: 'directory',
10 path: '/etc/apt/sources.list.d',
15 notify: 'Class[Apt::Update]' }
17 preferences = { ensure: 'file',
18 path: '/etc/apt/preferences',
21 notify: 'Class[Apt::Update]' }
23 preferences_d = { ensure: 'directory',
24 path: '/etc/apt/preferences.d',
29 notify: 'Class[Apt::Update]' }
31 apt_conf_d = { ensure: 'directory',
32 path: '/etc/apt/apt.conf.d',
37 notify: 'Class[Apt::Update]' }
42 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
45 lsbdistcodename: 'jessie',
49 context 'with defaults' do
51 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
55 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
59 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
63 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
67 is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
70 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
72 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
73 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
74 owner: 'root').with_content(
75 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
80 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
83 it { is_expected.not_to contain_apt__setting('conf-proxy') }
87 context 'when host=localhost' do
88 let(:params) { { proxy: { 'host' => 'localhost' } } }
91 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
92 %r{Acquire::http::proxy "http://localhost:8080/";},
94 %r{Acquire::https::proxy},
99 context 'when host=localhost and port=8180' do
100 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
103 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
104 %r{Acquire::http::proxy "http://localhost:8180/";},
106 %r{Acquire::https::proxy},
111 context 'when host=localhost and https=true' do
112 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
115 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
116 %r{Acquire::http::proxy "http://localhost:8080/";},
118 %r{Acquire::https::proxy "https://localhost:8080/";},
123 context 'when host=localhost and direct=true' do
124 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
127 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
128 %r{Acquire::http::proxy "http://localhost:8080/";},
130 %r{Acquire::https::proxy "DIRECT";},
135 context 'when host=localhost and https=true and direct=true' do
136 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
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 "https://localhost:8080/";},
146 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
147 %r{Acquire::http::proxy "http://localhost:8080/";},
149 %r{Acquire::https::proxy "DIRECT";},
154 context 'when ensure=absent' do
155 let(:params) { { proxy: { 'ensure' => 'absent' } } }
158 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
163 context 'with lots of non-defaults' do
166 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
167 purge: { 'sources.list' => false, 'sources.list.d' => false,
168 'preferences' => false, 'preferences.d' => false,
169 'apt.conf.d' => false },
174 is_expected.to contain_file('sources.list').with(content: nil)
178 is_expected.to contain_file('sources.list.d').with(purge: false,
183 is_expected.to contain_file('preferences').with(ensure: 'file')
187 is_expected.to contain_file('preferences.d').with(purge: false,
192 is_expected.to contain_file('apt.conf.d').with(purge: false,
197 is_expected.to contain_exec('apt_update').with(refreshonly: false,
203 context 'with entries for /etc/apt/auth.conf' do
206 os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
208 lsbdistcodename: 'trusty',
210 lsbdistrelease: '14.04',
213 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
215 lsbdistcodename: 'xenial',
217 lsbdistrelease: '16.04',
220 os: { family: 'Debian', name: 'Ubuntu', release: { major: '18', full: '18.04' } },
222 lsbdistcodename: 'bionic',
224 lsbdistrelease: '18.04',
227 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
230 lsbdistcodename: 'wheezy',
233 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
236 lsbdistcodename: 'jessie',
239 os: { family: 'Debian', name: 'Debian', release: { major: '9', full: '9.0' } },
242 lsbdistcodename: 'stretch',
245 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
248 lsbdistcodename: 'buster',
252 facts_hash.each do |os, facts|
253 context "on #{os}" do
261 machine: 'deb.example.net',
266 machine: 'apt.example.com',
268 password: 'supersecret',
274 context 'with manage_auth_conf => true' do
276 super().merge(manage_auth_conf: true)
279 # Going forward starting with Ubuntu 16.04 and Debian 9.0
280 # /etc/apt/auth.conf is owned by _apt. In previous versions it is
282 auth_conf_owner = case os
283 when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
289 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
290 machine deb.example.net login foologin password secret
291 machine apt.example.com login aptlogin password supersecret
295 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
296 owner: auth_conf_owner,
299 notify: 'Class[Apt::Update]',
300 content: auth_conf_content)
304 context 'with manage_auth_conf => false' do
306 super().merge(manage_auth_conf: false)
310 is_expected.not_to contain_file('/etc/apt/auth.conf')
315 context 'with improperly specified entries for /etc/apt/auth.conf' do
320 machinn: 'deb.example.net',
321 username: 'foologin',
325 machine: 'apt.example.com',
327 password: 'supersecret',
333 it { is_expected.to raise_error(Puppet::Error) }
338 context 'with sources defined on valid osfamily' do
341 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
343 lsbdistcodename: 'xenial',
345 lsbdistrelease: '16.04',
350 'debian_unstable' => {
351 'location' => 'http://debian.mirror.iweb.ca/debian/',
352 'release' => 'unstable',
353 'repos' => 'main contrib non-free',
354 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
356 'include' => { 'src' => true },
359 'location' => 'http://apt.puppetlabs.com',
361 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
367 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
370 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$}) }
371 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$}) }
374 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
377 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
380 context 'with confs defined on valid osfamily' do
383 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
385 lsbdistcodename: 'xenial',
401 is_expected.to contain_apt__conf('foo').with(content: 'foo')
405 is_expected.to contain_apt__conf('bar').with(content: 'bar')
409 context 'with keys defined on valid osfamily' do
412 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
414 lsbdistcodename: 'xenial',
421 'server' => 'subkeys.pgp.net',
424 'server' => 'pgp.mit.edu',
430 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
434 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
438 context 'with ppas defined on valid osfamily' do
441 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
443 lsbdistcodename: 'xenial',
445 lsbdistrelease: '16.04',
450 'ppa:drizzle-developers/ppa' => {},
451 'ppa:nginx/stable' => {},
455 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
456 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
459 context 'with settings defined on valid osfamily' do
462 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
464 lsbdistcodename: 'xenial',
470 'conf-banana' => { 'content' => 'banana' },
471 'pref-banana' => { 'content' => 'banana' },
475 it { is_expected.to contain_apt__setting('conf-banana') }
476 it { is_expected.to contain_apt__setting('pref-banana') }
479 context 'with pins defined on valid osfamily' do
482 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
484 lsbdistcodename: 'xenial',
490 'stable' => { 'priority' => 600, 'order' => 50 },
491 'testing' => { 'priority' => 700, 'order' => 100 },
495 it { is_expected.to contain_apt__pin('stable') }
496 it { is_expected.to contain_apt__pin('testing') }
499 describe 'failing tests' do
500 context "with purge['sources.list']=>'banana'" do
501 let(:params) { { purge: { 'sources.list' => 'banana' } } }
504 is_expected.to raise_error(Puppet::Error)
508 context "with purge['sources.list.d']=>'banana'" do
509 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
512 is_expected.to raise_error(Puppet::Error)
516 context "with purge['preferences']=>'banana'" do
517 let(:params) { { purge: { 'preferences' => 'banana' } } }
520 is_expected.to raise_error(Puppet::Error)
524 context "with purge['preferences.d']=>'banana'" do
525 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
528 is_expected.to raise_error(Puppet::Error)
532 context "with purge['apt.conf.d']=>'banana'" do
533 let(:params) { { purge: { 'apt.conf.d' => 'banana' } } }
536 is_expected.to raise_error(Puppet::Error)