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]' }
35 apt_conf_d = { ensure: 'directory',
36 path: '/etc/apt/apt.conf.d',
42 notify: 'Class[Apt::Update]' }
47 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
50 lsbdistcodename: 'jessie',
54 context 'with defaults' do
56 is_expected.to contain_file('sources.list').that_notifies('Class[Apt::Update]').only_with(sources_list)
60 is_expected.to contain_file('sources.list.d').that_notifies('Class[Apt::Update]').only_with(sources_list_d)
64 is_expected.to contain_file('preferences').that_notifies('Class[Apt::Update]').only_with(preferences)
68 is_expected.to contain_file('preferences.d').that_notifies('Class[Apt::Update]').only_with(preferences_d)
72 is_expected.to contain_file('apt.conf.d').that_notifies('Class[Apt::Update]').only_with(apt_conf_d)
75 it { is_expected.to contain_file('/etc/apt/auth.conf').with_ensure('absent') }
77 it 'lays down /etc/apt/apt.conf.d/15update-stamp' do
78 is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with(group: 'root',
80 owner: 'root').with_content(
81 %r{APT::Update::Post-Invoke-Success {"touch /var/lib/apt/periodic/update-success-stamp 2>/dev/null || true";};},
86 is_expected.to contain_exec('apt_update').with(refreshonly: 'true')
89 it { is_expected.not_to contain_apt__setting('conf-proxy') }
93 context 'when host=localhost' do
94 let(:params) { { proxy: { 'host' => 'localhost' } } }
97 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
98 %r{Acquire::http::proxy "http://localhost:8080/";},
100 %r{Acquire::https::proxy},
105 context 'when host=localhost and port=8180' do
106 let(:params) { { proxy: { 'host' => 'localhost', 'port' => 8180 } } }
109 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
110 %r{Acquire::http::proxy "http://localhost:8180/";},
112 %r{Acquire::https::proxy},
117 context 'when host=localhost and https=true' do
118 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true } } }
121 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
122 %r{Acquire::http::proxy "http://localhost:8080/";},
124 %r{Acquire::https::proxy "https://localhost:8080/";},
129 context 'when host=localhost and direct=true' do
130 let(:params) { { proxy: { 'host' => 'localhost', 'direct' => true } } }
133 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
134 %r{Acquire::http::proxy "http://localhost:8080/";},
136 %r{Acquire::https::proxy "DIRECT";},
141 context 'when host=localhost and https=true and direct=true' do
142 let(:params) { { proxy: { 'host' => 'localhost', 'https' => true, 'direct' => true } } }
145 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
146 %r{Acquire::http::proxy "http://localhost:8080/";},
148 %r{Acquire::https::proxy "https://localhost:8080/";},
152 is_expected.to contain_apt__setting('conf-proxy').with(priority: '01').with_content(
153 %r{Acquire::http::proxy "http://localhost:8080/";},
155 %r{Acquire::https::proxy "DIRECT";},
160 context 'when ensure=absent' do
161 let(:params) { { proxy: { 'ensure' => 'absent' } } }
164 is_expected.to contain_apt__setting('conf-proxy').with(ensure: 'absent',
169 context 'with lots of non-defaults' do
172 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
173 purge: { 'sources.list' => false, 'sources.list.d' => false,
174 'preferences' => false, 'preferences.d' => false,
175 'apt.conf.d' => false },
180 is_expected.to contain_file('sources.list').with(content: nil)
184 is_expected.to contain_file('sources.list.d').with(purge: false,
189 is_expected.to contain_file('preferences').with(ensure: 'file')
193 is_expected.to contain_file('preferences.d').with(purge: false,
198 is_expected.to contain_file('apt.conf.d').with(purge: false,
203 is_expected.to contain_exec('apt_update').with(refreshonly: false,
209 context 'with entries for /etc/apt/auth.conf' do
212 os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
214 lsbdistcodename: 'trusty',
216 lsbdistrelease: '14.04',
219 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
221 lsbdistcodename: 'xenial',
223 lsbdistrelease: '16.04',
226 os: { family: 'Debian', name: 'Ubuntu', release: { major: '18', full: '18.04' } },
228 lsbdistcodename: 'bionic',
230 lsbdistrelease: '18.04',
233 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
236 lsbdistcodename: 'wheezy',
239 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
242 lsbdistcodename: 'jessie',
245 os: { family: 'Debian', name: 'Debian', release: { major: '9', full: '9.0' } },
248 lsbdistcodename: 'stretch',
251 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
254 lsbdistcodename: 'buster',
258 facts_hash.each do |os, facts|
259 context "on #{os}" do
267 machine: 'deb.example.net',
272 machine: 'apt.example.com',
274 password: 'supersecret',
280 context 'with manage_auth_conf => true' do
282 super().merge(manage_auth_conf: true)
285 # Going forward starting with Ubuntu 16.04 and Debian 9.0
286 # /etc/apt/auth.conf is owned by _apt. In previous versions it is
288 auth_conf_owner = case os
289 when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
295 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
296 machine deb.example.net login foologin password secret
297 machine apt.example.com login aptlogin password supersecret
301 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
302 owner: auth_conf_owner,
305 notify: 'Class[Apt::Update]',
306 content: auth_conf_content)
310 context 'with manage_auth_conf => false' do
312 super().merge(manage_auth_conf: false)
316 is_expected.not_to contain_file('/etc/apt/auth.conf')
321 context 'with improperly specified entries for /etc/apt/auth.conf' do
326 machinn: 'deb.example.net',
327 username: 'foologin',
331 machine: 'apt.example.com',
333 password: 'supersecret',
339 it { is_expected.to raise_error(Puppet::Error) }
344 context 'with sources defined on valid osfamily' do
347 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
349 lsbdistcodename: 'xenial',
351 lsbdistrelease: '16.04',
356 'debian_unstable' => {
357 'location' => 'http://debian.mirror.iweb.ca/debian/',
358 'release' => 'unstable',
359 'repos' => 'main contrib non-free',
360 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
362 'include' => { 'src' => true },
365 'location' => 'http://apt.puppetlabs.com',
367 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
373 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
376 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$}) }
377 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$}) }
380 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
383 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
386 context 'with confs defined on valid osfamily' do
389 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
391 lsbdistcodename: 'xenial',
407 is_expected.to contain_apt__conf('foo').with(content: 'foo')
411 is_expected.to contain_apt__conf('bar').with(content: 'bar')
415 context 'with keys defined on valid osfamily' do
418 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
420 lsbdistcodename: 'xenial',
427 'server' => 'subkeys.pgp.net',
430 'server' => 'pgp.mit.edu',
436 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
440 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
444 context 'with ppas defined on valid osfamily' do
447 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
449 lsbdistcodename: 'xenial',
451 lsbdistrelease: '16.04',
456 'ppa:drizzle-developers/ppa' => {},
457 'ppa:nginx/stable' => {},
461 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
462 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
465 context 'with settings defined on valid osfamily' do
468 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
470 lsbdistcodename: 'xenial',
476 'conf-banana' => { 'content' => 'banana' },
477 'pref-banana' => { 'content' => 'banana' },
481 it { is_expected.to contain_apt__setting('conf-banana') }
482 it { is_expected.to contain_apt__setting('pref-banana') }
485 context 'with pins defined on valid osfamily' do
488 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
490 lsbdistcodename: 'xenial',
496 'stable' => { 'priority' => 600, 'order' => 50 },
497 'testing' => { 'priority' => 700, 'order' => 100 },
501 it { is_expected.to contain_apt__pin('stable') }
502 it { is_expected.to contain_apt__pin('testing') }
505 describe 'failing tests' do
506 context "with purge['sources.list']=>'banana'" do
507 let(:params) { { purge: { 'sources.list' => 'banana' } } }
510 is_expected.to raise_error(Puppet::Error)
514 context "with purge['sources.list.d']=>'banana'" do
515 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
518 is_expected.to raise_error(Puppet::Error)
522 context "with purge['preferences']=>'banana'" do
523 let(:params) { { purge: { 'preferences' => 'banana' } } }
526 is_expected.to raise_error(Puppet::Error)
530 context "with purge['preferences.d']=>'banana'" do
531 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
534 is_expected.to raise_error(Puppet::Error)
538 context "with purge['apt.conf.d']=>'banana'" do
539 let(:params) { { purge: { 'apt.conf.d' => 'banana' } } }
542 is_expected.to raise_error(Puppet::Error)