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 lots of non-defaults' do
206 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
207 purge: { 'sources.list' => true, 'sources.list.d' => true,
208 'preferences' => true, 'preferences.d' => true,
209 'apt.conf.d' => true },
214 is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
218 is_expected.to contain_file('sources.list.d').with(purge: true,
223 is_expected.to contain_file('preferences').with(ensure: 'absent')
227 is_expected.to contain_file('preferences.d').with(purge: true,
232 is_expected.to contain_file('apt.conf.d').with(purge: true,
237 is_expected.to contain_exec('apt_update').with(refreshonly: false,
243 context 'with defaults for sources_list_force' do
246 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
247 purge: { 'sources.list' => true },
248 sources_list_force: false,
253 is_expected.to contain_file('sources.list').with(content: "# Repos managed by puppet.\n")
257 context 'with non defaults for sources_list_force' do
260 update: { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
261 purge: { 'sources.list' => true },
262 sources_list_force: true,
267 is_expected.to contain_file('sources.list').with(ensure: 'absent')
271 context 'with entries for /etc/apt/auth.conf' do
274 os: { family: 'Debian', name: 'Ubuntu', release: { major: '14', full: '14.04' } },
276 lsbdistcodename: 'trusty',
278 lsbdistrelease: '14.04',
281 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
283 lsbdistcodename: 'xenial',
285 lsbdistrelease: '16.04',
288 os: { family: 'Debian', name: 'Ubuntu', release: { major: '18', full: '18.04' } },
290 lsbdistcodename: 'bionic',
292 lsbdistrelease: '18.04',
295 os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
298 lsbdistcodename: 'wheezy',
301 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
304 lsbdistcodename: 'jessie',
307 os: { family: 'Debian', name: 'Debian', release: { major: '9', full: '9.0' } },
310 lsbdistcodename: 'stretch',
313 os: { family: 'Debian', name: 'Debian', release: { major: '10', full: '10.0' } },
316 lsbdistcodename: 'buster',
320 facts_hash.each do |os, facts|
321 context "on #{os}" do
329 machine: 'deb.example.net',
334 machine: 'apt.example.com',
336 password: 'supersecret',
342 context 'with manage_auth_conf => true' do
344 super().merge(manage_auth_conf: true)
347 # Going forward starting with Ubuntu 16.04 and Debian 9.0
348 # /etc/apt/auth.conf is owned by _apt. In previous versions it is
350 auth_conf_owner = case os
351 when 'Ubuntu 14.04', 'Debian 7.0', 'Debian 8.0'
357 auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
358 machine deb.example.net login foologin password secret
359 machine apt.example.com login aptlogin password supersecret
363 is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
364 owner: auth_conf_owner,
367 notify: 'Class[Apt::Update]',
368 content: sensitive(auth_conf_content))
372 context 'with manage_auth_conf => false' do
374 super().merge(manage_auth_conf: false)
378 is_expected.not_to contain_file('/etc/apt/auth.conf')
383 context 'with improperly specified entries for /etc/apt/auth.conf' do
388 machinn: 'deb.example.net',
389 username: 'foologin',
393 machine: 'apt.example.com',
395 password: 'supersecret',
401 it { is_expected.to raise_error(Puppet::Error) }
406 context 'with sources defined on valid osfamily' do
409 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
411 lsbdistcodename: 'xenial',
413 lsbdistrelease: '16.04',
418 'debian_unstable' => {
419 'location' => 'http://debian.mirror.iweb.ca/debian/',
420 'release' => 'unstable',
421 'repos' => 'main contrib non-free',
422 'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
424 'include' => { 'src' => true },
427 'location' => 'http://apt.puppetlabs.com',
429 'key' => { 'id' => '6F6B15509CF8E59E6E469F327F438280EF8D349F', 'server' => 'pgp.mit.edu' },
435 is_expected.to contain_apt__setting('list-debian_unstable').with(ensure: 'present')
438 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$}) }
439 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$}) }
442 is_expected.to contain_apt__setting('list-puppetlabs').with(ensure: 'present')
445 it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(%r{^deb http://apt.puppetlabs.com xenial main$}) }
448 context 'with confs defined on valid osfamily' do
451 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
453 lsbdistcodename: 'xenial',
469 is_expected.to contain_apt__conf('foo').with(content: 'foo')
473 is_expected.to contain_apt__conf('bar').with(content: 'bar')
477 context 'with keys defined on valid osfamily' do
480 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
482 lsbdistcodename: 'xenial',
489 'server' => 'subkeys.pgp.net',
492 'server' => 'pgp.mit.edu',
498 is_expected.to contain_apt__key('55BE302B').with(server: 'subkeys.pgp.net')
502 is_expected.to contain_apt__key('EF8D349F').with(server: 'pgp.mit.edu')
506 context 'with ppas defined on valid osfamily' do
509 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
511 lsbdistcodename: 'xenial',
513 lsbdistrelease: '16.04',
518 'ppa:drizzle-developers/ppa' => {},
519 'ppa:nginx/stable' => {},
523 it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa') }
524 it { is_expected.to contain_apt__ppa('ppa:nginx/stable') }
527 context 'with settings defined on valid osfamily' do
530 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
532 lsbdistcodename: 'xenial',
538 'conf-banana' => { 'content' => 'banana' },
539 'pref-banana' => { 'content' => 'banana' },
543 it { is_expected.to contain_apt__setting('conf-banana') }
544 it { is_expected.to contain_apt__setting('pref-banana') }
547 context 'with pins defined on valid osfamily' do
550 os: { family: 'Debian', name: 'Ubuntu', release: { major: '16', full: '16.04' } },
552 lsbdistcodename: 'xenial',
558 'stable' => { 'priority' => 600, 'order' => 50 },
559 'testing' => { 'priority' => 700, 'order' => 100 },
563 it { is_expected.to contain_apt__pin('stable') }
564 it { is_expected.to contain_apt__pin('testing') }
567 describe 'failing tests' do
568 context "with purge['sources.list']=>'banana'" do
569 let(:params) { { purge: { 'sources.list' => 'banana' } } }
572 is_expected.to raise_error(Puppet::Error)
576 context "with purge['sources.list.d']=>'banana'" do
577 let(:params) { { purge: { 'sources.list.d' => 'banana' } } }
580 is_expected.to raise_error(Puppet::Error)
584 context "with purge['preferences']=>'banana'" do
585 let(:params) { { purge: { 'preferences' => 'banana' } } }
588 is_expected.to raise_error(Puppet::Error)
592 context "with purge['preferences.d']=>'banana'" do
593 let(:params) { { purge: { 'preferences.d' => 'banana' } } }
596 is_expected.to raise_error(Puppet::Error)
600 context "with purge['apt.conf.d']=>'banana'" do
601 let(:params) { { purge: { 'apt.conf.d' => 'banana' } } }
604 is_expected.to raise_error(Puppet::Error)