Merge pull request #651 from nhinds/MODULES-4265-ubuntu-security-updates
[puppet-modules/puppetlabs-apt.git] / spec / acceptance / apt_spec.rb
1 require 'spec_helper_acceptance'
2
3 MAX_TIMEOUT_RETRY              = 3
4 TIMEOUT_RETRY_WAIT             = 5
5 TIMEOUT_ERROR_MATCHER    = /no valid OpenPGP data found/
6
7 describe 'apt class' do
8
9   context 'reset' do
10     it 'fixes the sources.list' do
11       shell('cp /etc/apt/sources.list /tmp')
12     end
13   end
14
15   context 'all the things' do
16     it 'should work with no errors' do
17       pp = <<-EOS
18       if $::lsbdistcodename == 'lucid' {
19         $sources = undef
20       } else {
21         $sources = {
22           'puppetlabs' => {
23             'ensure'   => present,
24             'location' => 'http://apt.puppetlabs.com',
25             'repos'    => 'main',
26             'key'      => {
27               'id'     => '6F6B15509CF8E59E6E469F327F438280EF8D349F',
28               'server' => 'hkps.pool.sks-keyservers.net',
29             },
30           },
31         }
32       }
33       class { 'apt':
34         update => {
35           'frequency' => 'always',
36           'timeout'   => 400,
37           'tries'     => 3,
38         },
39         purge => {
40           'sources.list'   => true,
41           'sources.list.d' => true,
42           'preferences'    => true,
43           'preferences.d'  => true,
44         },
45         sources => $sources,
46       }
47       EOS
48
49       #Apply the manifest (Retry if timeout error is received from key pool)
50       retry_on_error_matching(MAX_TIMEOUT_RETRY, TIMEOUT_RETRY_WAIT, TIMEOUT_ERROR_MATCHER) do
51         apply_manifest(pp, :catch_failures => true)
52       end
53
54       apply_manifest(pp, :catch_failures => true)
55     end
56     it 'should still work' do
57       shell('apt-get update')
58       shell('apt-get -y --force-yes upgrade')
59     end
60   end
61
62   context 'reset' do
63     it 'fixes the sources.list' do
64       shell('cp /tmp/sources.list /etc/apt')
65     end
66   end
67
68 end