2012-01-23 22:08:00 +01:00
|
|
|
require 'spec_helper'
|
2015-02-27 12:07:56 +01:00
|
|
|
describe 'apt' do
|
2015-03-02 22:40:06 +01:00
|
|
|
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy'} }
|
2014-08-01 00:11:57 +02:00
|
|
|
|
|
|
|
context 'defaults' do
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('sources.list').that_notifies('Exec[apt_update]').only_with({
|
2015-02-28 16:12:47 +01:00
|
|
|
:ensure => 'file',
|
|
|
|
:path => '/etc/apt/sources.list',
|
|
|
|
:owner => 'root',
|
|
|
|
:group => 'root',
|
|
|
|
:mode => '0644',
|
|
|
|
:notify => 'Exec[apt_update]',
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('sources.list.d').that_notifies('Exec[apt_update]').only_with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:ensure => 'directory',
|
|
|
|
:path => '/etc/apt/sources.list.d',
|
|
|
|
:owner => 'root',
|
|
|
|
:group => 'root',
|
2015-02-28 16:12:47 +01:00
|
|
|
:mode => '0644',
|
2015-04-14 20:03:17 +02:00
|
|
|
:purge => false,
|
|
|
|
:recurse => false,
|
2015-02-27 12:07:56 +01:00
|
|
|
:notify => 'Exec[apt_update]',
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
it { is_expected.to contain_file('preferences').that_notifies('Exec[apt_update]').only_with({
|
2015-04-14 20:03:17 +02:00
|
|
|
:ensure => 'file',
|
2015-02-28 16:12:47 +01:00
|
|
|
:path => '/etc/apt/preferences',
|
|
|
|
:owner => 'root',
|
|
|
|
:group => 'root',
|
|
|
|
:mode => '0644',
|
|
|
|
:notify => 'Exec[apt_update]',
|
|
|
|
})}
|
|
|
|
|
|
|
|
it { is_expected.to contain_file('preferences.d').that_notifies('Exec[apt_update]').only_with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:ensure => 'directory',
|
|
|
|
:path => '/etc/apt/preferences.d',
|
|
|
|
:owner => 'root',
|
|
|
|
:group => 'root',
|
2015-02-28 16:12:47 +01:00
|
|
|
:mode => '0644',
|
2015-04-14 20:03:17 +02:00
|
|
|
:purge => false,
|
|
|
|
:recurse => false,
|
2015-02-28 16:12:47 +01:00
|
|
|
:notify => 'Exec[apt_update]',
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
2014-08-18 22:12:55 +02:00
|
|
|
it 'should lay down /etc/apt/apt.conf.d/15update-stamp' do
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to contain_file('/etc/apt/apt.conf.d/15update-stamp').with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:group => 'root',
|
|
|
|
:mode => '0644',
|
|
|
|
:owner => 'root',
|
2014-08-31 15:46:57 +02:00
|
|
|
}).with_content(/APT::Update::Post-Invoke-Success \{"touch \/var\/lib\/apt\/periodic\/update-success-stamp 2>\/dev\/null \|\| true";\};/)
|
2014-08-18 22:12:55 +02:00
|
|
|
end
|
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_exec('apt_update').with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:refreshonly => 'true',
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
2015-02-27 12:34:05 +01:00
|
|
|
|
|
|
|
it { is_expected.not_to contain_apt__setting('conf-proxy') }
|
2012-01-23 22:08:00 +01:00
|
|
|
end
|
|
|
|
|
2015-02-27 12:34:05 +01:00
|
|
|
describe 'proxy=' do
|
|
|
|
context 'host=localhost' do
|
|
|
|
let(:params) { { :proxy => { 'host' => 'localhost'} } }
|
|
|
|
it { is_expected.to contain_apt__setting('conf-proxy').with({
|
|
|
|
:priority => '01',
|
|
|
|
}).with_content(
|
|
|
|
/Acquire::http::proxy "http:\/\/localhost:8080\/";/
|
|
|
|
).without_content(
|
|
|
|
/Acquire::https::proxy/
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'host=localhost and port=8180' do
|
|
|
|
let(:params) { { :proxy => { 'host' => 'localhost', 'port' => 8180} } }
|
|
|
|
it { is_expected.to contain_apt__setting('conf-proxy').with({
|
|
|
|
:priority => '01',
|
|
|
|
}).with_content(
|
|
|
|
/Acquire::http::proxy "http:\/\/localhost:8180\/";/
|
|
|
|
).without_content(
|
|
|
|
/Acquire::https::proxy/
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'host=localhost and https=true' do
|
|
|
|
let(:params) { { :proxy => { 'host' => 'localhost', 'https' => true} } }
|
|
|
|
it { is_expected.to contain_apt__setting('conf-proxy').with({
|
|
|
|
:priority => '01',
|
|
|
|
}).with_content(
|
|
|
|
/Acquire::http::proxy "http:\/\/localhost:8080\/";/
|
|
|
|
).with_content(
|
|
|
|
/Acquire::https::proxy "https:\/\/localhost:8080\/";/
|
|
|
|
)}
|
|
|
|
end
|
|
|
|
end
|
2014-08-01 00:11:57 +02:00
|
|
|
context 'lots of non-defaults' do
|
|
|
|
let :params do
|
|
|
|
{
|
2015-03-18 21:52:12 +01:00
|
|
|
:update => { 'frequency' => 'always', 'timeout' => 1, 'tries' => 3 },
|
2015-02-28 16:48:48 +01:00
|
|
|
:purge => { 'sources.list' => false, 'sources.list.d' => false,
|
|
|
|
'preferences' => false, 'preferences.d' => false, },
|
2014-08-01 00:11:57 +02:00
|
|
|
}
|
|
|
|
end
|
2012-01-23 22:08:00 +01:00
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
it { is_expected.to contain_file('sources.list').without({
|
|
|
|
:content => "# Repos managed by puppet.\n",
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
2012-01-23 22:08:00 +01:00
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('sources.list.d').with({
|
2015-02-28 16:12:47 +01:00
|
|
|
:purge => false,
|
|
|
|
:recurse => false,
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
it { is_expected.to contain_file('preferences').with({
|
|
|
|
:ensure => 'file',
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('preferences.d').with({
|
2015-02-28 16:12:47 +01:00
|
|
|
:purge => false,
|
|
|
|
:recurse => false,
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
2012-01-23 22:08:00 +01:00
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_exec('apt_update').with({
|
2015-02-28 16:48:48 +01:00
|
|
|
:refreshonly => false,
|
|
|
|
:timeout => 1,
|
|
|
|
:tries => 3,
|
2014-08-01 00:11:57 +02:00
|
|
|
})}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with sources defined on valid osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'Debian',
|
|
|
|
:lsbdistcodename => 'precise',
|
|
|
|
:lsbdistid => 'Debian',
|
2012-01-23 22:08:00 +01:00
|
|
|
}
|
2014-08-01 00:11:57 +02:00
|
|
|
end
|
|
|
|
let(:params) { { :sources => {
|
|
|
|
'debian_unstable' => {
|
|
|
|
'location' => 'http://debian.mirror.iweb.ca/debian/',
|
|
|
|
'release' => 'unstable',
|
|
|
|
'repos' => 'main contrib non-free',
|
2015-03-25 23:32:09 +01:00
|
|
|
'key' => { 'id' => '150C8614919D8446E01E83AF9AA38DCD55BE302B', 'server' => 'subkeys.pgp.net' },
|
2014-08-01 00:11:57 +02:00
|
|
|
'pin' => '-10',
|
2015-03-05 17:37:51 +01:00
|
|
|
'include' => {'src' => true,},
|
2014-08-01 00:11:57 +02:00
|
|
|
},
|
|
|
|
'puppetlabs' => {
|
|
|
|
'location' => 'http://apt.puppetlabs.com',
|
|
|
|
'repos' => 'main',
|
2015-03-25 23:32:09 +01:00
|
|
|
'key' => { 'id' => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30', 'server' => 'pgp.mit.edu' },
|
2014-02-22 10:56:50 +01:00
|
|
|
}
|
2014-08-01 00:11:57 +02:00
|
|
|
} } }
|
2014-02-22 10:56:50 +01:00
|
|
|
|
2014-08-01 00:11:57 +02:00
|
|
|
it {
|
2015-02-24 23:57:31 +01:00
|
|
|
is_expected.to contain_apt__setting('list-debian_unstable').with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:ensure => 'present',
|
2014-08-01 00:11:57 +02:00
|
|
|
})
|
|
|
|
}
|
2012-01-23 22:08:00 +01:00
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
|
|
|
it { is_expected.to contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
|
2012-01-23 22:08:00 +01:00
|
|
|
|
2014-08-01 00:11:57 +02:00
|
|
|
it {
|
2015-02-24 23:57:31 +01:00
|
|
|
is_expected.to contain_apt__setting('list-puppetlabs').with({
|
2015-02-27 12:07:56 +01:00
|
|
|
:ensure => 'present',
|
2014-08-01 00:11:57 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:20:29 +01:00
|
|
|
it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
|
2014-08-01 00:11:57 +02:00
|
|
|
end
|
|
|
|
|
2015-02-28 17:04:47 +01:00
|
|
|
context 'with keys defined on valid osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'Debian',
|
|
|
|
:lsbdistcodename => 'precise',
|
|
|
|
:lsbdistid => 'Debian',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:params) { { :keys => {
|
|
|
|
'55BE302B' => {
|
2015-02-28 17:35:25 +01:00
|
|
|
'server' => 'subkeys.pgp.net',
|
2015-02-28 17:04:47 +01:00
|
|
|
},
|
|
|
|
'4BD6EC30' => {
|
2015-02-28 17:35:25 +01:00
|
|
|
'server' => 'pgp.mit.edu',
|
2015-02-28 17:04:47 +01:00
|
|
|
}
|
|
|
|
} } }
|
|
|
|
|
|
|
|
it { is_expected.to contain_apt__key('55BE302B').with({
|
2015-02-28 17:35:25 +01:00
|
|
|
:server => 'subkeys.pgp.net',
|
2015-02-28 17:04:47 +01:00
|
|
|
})}
|
|
|
|
|
|
|
|
it { is_expected.to contain_apt__key('4BD6EC30').with({
|
2015-02-28 17:35:25 +01:00
|
|
|
:server => 'pgp.mit.edu',
|
2015-02-28 17:04:47 +01:00
|
|
|
})}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with ppas defined on valid osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'Debian',
|
|
|
|
:lsbdistcodename => 'precise',
|
|
|
|
:lsbdistid => 'ubuntu',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:params) { { :ppas => {
|
|
|
|
'ppa:drizzle-developers/ppa' => {},
|
|
|
|
'ppa:nginx/stable' => {},
|
|
|
|
} } }
|
|
|
|
|
|
|
|
it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
|
|
|
|
it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with settings defined on valid osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'Debian',
|
|
|
|
:lsbdistcodename => 'precise',
|
|
|
|
:lsbdistid => 'Debian',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:params) { { :settings => {
|
|
|
|
'conf-banana' => { 'content' => 'banana' },
|
|
|
|
'pref-banana' => { 'content' => 'banana' },
|
|
|
|
} } }
|
|
|
|
|
|
|
|
it { is_expected.to contain_apt__setting('conf-banana')}
|
|
|
|
it { is_expected.to contain_apt__setting('pref-banana')}
|
|
|
|
end
|
|
|
|
|
2014-08-01 00:11:57 +02:00
|
|
|
describe 'failing tests' do
|
2015-02-28 16:12:47 +01:00
|
|
|
context "purge['sources.list']=>'banana'" do
|
|
|
|
let(:params) { { :purge => { 'sources.list' => 'banana' }, } }
|
2014-08-01 00:11:57 +02:00
|
|
|
it do
|
|
|
|
expect {
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to compile
|
2014-08-01 00:11:57 +02:00
|
|
|
}.to raise_error(Puppet::Error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
context "purge['sources.list.d']=>'banana'" do
|
|
|
|
let(:params) { { :purge => { 'sources.list.d' => 'banana' }, } }
|
2014-08-01 00:11:57 +02:00
|
|
|
it do
|
|
|
|
expect {
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to compile
|
2014-08-01 00:11:57 +02:00
|
|
|
}.to raise_error(Puppet::Error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
context "purge['preferences']=>'banana'" do
|
|
|
|
let(:params) { { :purge => { 'preferences' => 'banana' }, } }
|
2014-08-01 00:11:57 +02:00
|
|
|
it do
|
|
|
|
expect {
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to compile
|
2014-08-01 00:11:57 +02:00
|
|
|
}.to raise_error(Puppet::Error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-28 16:12:47 +01:00
|
|
|
context "purge['preferences.d']=>'banana'" do
|
|
|
|
let(:params) { { :purge => { 'preferences.d' => 'banana' }, } }
|
2014-08-01 00:11:57 +02:00
|
|
|
it do
|
|
|
|
expect {
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to compile
|
2014-08-01 00:11:57 +02:00
|
|
|
}.to raise_error(Puppet::Error)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with unsupported osfamily' do
|
|
|
|
let :facts do
|
|
|
|
{ :osfamily => 'Darwin', }
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect {
|
2015-02-24 22:20:29 +01:00
|
|
|
is_expected.to compile
|
2014-08-01 00:11:57 +02:00
|
|
|
}.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
|
|
|
|
end
|
2012-01-23 22:08:00 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|