Added modules

This commit is contained in:
Ciaby 2014-07-11 13:30:23 -05:00
parent c53c931217
commit 59ec520742
646 changed files with 35182 additions and 0 deletions

View file

@ -0,0 +1,36 @@
require 'spec_helper_acceptance'
describe 'apt::builddep', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'reset' do
it 'removes packages' do
shell('apt-get -y remove znc')
shell('apt-get -y remove g++')
end
end
context 'apt::builddep' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::builddep { 'znc': }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe 'should install g++ as a dependency' do
describe package('g++') do
it { should be_installed }
end
end
end
context 'reset' do
it 'removes packages' do
shell('apt-get -y remove znc')
shell('apt-get -y remove g++')
end
end
end

View file

@ -0,0 +1,446 @@
require 'spec_helper_acceptance'
PUPPETLABS_GPG_KEY_ID = '4BD6EC30'
PUPPETLABS_APT_URL = 'apt.puppetlabs.com'
PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg'
CENTOS_GPG_KEY_ID = 'C105B9DE'
CENTOS_REPO_URL = 'ftp.cvut.cz/centos'
CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6'
describe 'apt_key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
before(:each) do
shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
:acceptable_exit_codes => [0,1,2])
end
describe 'default options' do
key_versions = {
'32bit key id' => '4BD6EC30',
'64bit key id' => '1054B7A24BD6EC30',
'32bit lowercase key id' => '4bd6ec30',
'64bit lowercase key id' => '1054b7a24bd6ec30',
'0x formatted 32bit key id' => '0x4BD6EC30',
'0x formatted 64bit key id' => '0x1054B7A24BD6EC30',
'0x formatted 32bit lowercase key id' => '0x4bd6ec30',
'0x formatted 64bit lowercase key id' => '0x1054b7a24bd6ec30',
}
key_versions.each do |key, value|
context "#{key}" do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{value}',
ensure => 'present',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
end
end
context 'invalid length key id' do
it 'fails' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4B7A24BD6EC30',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/Valid values match/)
end
end
end
end
describe 'ensure =>' do
context 'absent' do
it 'is removed' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'absent',
}
EOS
# Install the key first
shell("apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys #{PUPPETLABS_GPG_KEY_ID}")
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
# Time to remove it using Puppet
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}",
:acceptable_exit_codes => [1])
end
end
end
describe 'content =>' do
context 'puppetlabs gpg key' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
content => "-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: GPGTools - http://gpgtools.org
mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b
fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg
5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+
S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY
GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH
Ppp3Ku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wb+ZkdI77m1YY95QRNgG/hqh77IuWWg1MtTSgQnP+F2
7mfo0/522hObhdAe73VO3ttEPiriWy7tw3bS9daP2TAVbYyFqkvptkBb1OXRUSzq
UuWjBmZ35UlXjKQsGeUHlOiEh84aondF90A7gx0X/ktNIPRrfCGkHJcDu+HVnR7x
Kk+F0qb9+/pGLiT3rqeQTr8fYsb4xLHT7uEg1gVFB1g0kd+RQHzV74kCPgQTAQIA
KAIbAwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AFAk/x5PoFCQtIMjoACgkQEFS3
okvW7DAIKQ/9HvZyf+LHVSkCk92Kb6gckniin3+5ooz67hSr8miGBfK4eocqQ0H7
bdtWjAILzR/IBY0xj6OHKhYP2k8TLc7QhQjt0dRpNkX+Iton2AZryV7vUADreYz4
4B0bPmhiE+LL46ET5IThLKu/KfihzkEEBa9/t178+dO9zCM2xsXaiDhMOxVE32gX
vSZKP3hmvnK/FdylUY3nWtPedr+lHpBLoHGaPH7cjI+MEEugU3oAJ0jpq3V8n4w0
jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y
ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD
7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR
M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf
REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y
DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk
ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
=a34C
-----END PGP PUBLIC KEY BLOCK-----",
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
end
context 'bogus key' do
it 'fails' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
content => 'For posterity: such content, much bogus, wow',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/no valid OpenPGP data found/)
end
end
end
end
describe 'server =>' do
context 'pgp.mit.edu' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
server => 'pgp.mit.edu',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
end
context 'nonexistant.key.server' do
it 'fails' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
server => 'nonexistant.key.server',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/(Host not found|Couldn't resolve host)/)
end
end
end
end
describe 'source =>' do
context 'http://' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => 'http://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
it 'fails with a 404' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => 'http://#{PUPPETLABS_APT_URL}/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/404 Not Found/)
end
end
it 'fails with a socket error' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => 'http://apt.puppetlabss.com/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/could not resolve/)
end
end
end
context 'ftp://' do
before(:each) do
shell("apt-key del #{CENTOS_GPG_KEY_ID}",
:acceptable_exit_codes => [0,1,2])
end
it 'works' do
pp = <<-EOS
apt_key { 'CentOS 6':
id => '#{CENTOS_GPG_KEY_ID}',
ensure => 'present',
source => 'ftp://#{CENTOS_REPO_URL}/#{CENTOS_GPG_KEY_FILE}',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{CENTOS_GPG_KEY_ID}")
end
it 'fails with a 550' do
pp = <<-EOS
apt_key { 'CentOS 6':
id => '#{CENTOS_GPG_KEY_ID}',
ensure => 'present',
source => 'ftp://#{CENTOS_REPO_URL}/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/550 Failed to open/)
end
end
it 'fails with a socket error' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => 'ftp://apt.puppetlabss.com/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/could not resolve/)
end
end
end
context 'https://' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => 'https://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
it 'fails with a 404' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4BD6EC30',
ensure => 'present',
source => 'https://#{PUPPETLABS_APT_URL}/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/404 Not Found/)
end
end
it 'fails with a socket error' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4BD6EC30',
ensure => 'present',
source => 'https://apt.puppetlabss.com/herpderp.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/could not resolve/)
end
end
end
context '/path/that/exists' do
before(:each) do
shell("curl -o /tmp/puppetlabs-pubkey.gpg \
http://#{PUPPETLABS_APT_URL}/#{PUPPETLABS_GPG_KEY_FILE}")
end
after(:each) do
shell('rm /tmp/puppetlabs-pubkey.gpg')
end
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4BD6EC30',
ensure => 'present',
source => '/tmp/puppetlabs-pubkey.gpg',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
end
context '/path/that/does/not/exist' do
it 'fails' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => '/tmp/totally_bogus.file',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/does not exist/)
end
end
end
context '/path/that/exists/with/bogus/content' do
before(:each) do
shell('echo "here be dragons" > /tmp/fake-key.gpg')
end
after(:each) do
shell('rm /tmp/fake-key.gpg')
end
it 'fails' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
source => '/tmp/fake-key.gpg',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/no valid OpenPGP data found/)
end
end
end
end
describe 'keyserver_options =>' do
context 'debug' do
it 'works' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
keyserver_options => 'debug',
}
EOS
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end
it 'fails on invalid options' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '#{PUPPETLABS_GPG_KEY_ID}',
ensure => 'present',
keyserver_options => 'this is totally bonkers',
}
EOS
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/--keyserver-options this is totally/)
end
end
end
end
end

View file

@ -0,0 +1,200 @@
require 'spec_helper_acceptance'
describe 'apt::key', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'apt::key' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::key { 'puppetlabs':
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
}
apt::key { 'jenkins':
key => 'D50582E6',
key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
it 'finds jenkins key' do
shell('apt-key list | grep D50582E6')
end
end
end
context 'ensure' do
context 'absent' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::key { 'puppetlabs':
ensure => absent,
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
}
apt::key { 'jenkins':
ensure => absent,
key => 'D50582E6',
key_source => 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe 'keys shouldnt exist' do
it 'fails' do
shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [1])
end
it 'fails' do
shell('apt-key list | grep D50582E6', :acceptable_exit_codes => [1])
end
end
end
end
context 'reset' do
it 'clean up keys' do
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
shell('apt-key del D50582E6', :acceptable_exit_codes => [0,1,2])
end
end
context 'key options' do
context 'key_content' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::key { 'puppetlabs':
key => '4BD6EC30',
key_content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: GPGTools - http://gpgtools.org
mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b
fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg
5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+
S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY
GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH
Ppp3KuLFNorjPqWY5jSgKl94W/CO2x591e++a1PhwUn7iVUwVVe+mOEWnK5+Fd0v
VMQebYCXS+3dNf6gxSvhz8etpw20T9Ytg4EdhLvCJRV/pYlqhcq+E9le1jFOHOc0
Nc5FQweUtHGaNVyn8S1hvnvWJBMxpXq+Bezfk3X8PhPT/l9O2lLFOOO08jo0OYiI
wrjhMQQOOSZOb3vBRvBZNnnxPrcdjUUm/9cVB8VcgI5KFhG7hmMCwH70tpUWcZCN
NlI1wj/PJ7Tlxjy44f1o4CQ5FxuozkiITJvh9CTg+k3wEmiaGz65w9jRl9ny2gEl
f4CR5+ba+w2dpuDeMwiHJIs5JsGyJjmA5/0xytB7QvgMs2q25vWhygsmUQARAQAB
tEdQdXBwZXQgTGFicyBSZWxlYXNlIEtleSAoUHVwcGV0IExhYnMgUmVsZWFzZSBL
ZXkpIDxpbmZvQHB1cHBldGxhYnMuY29tPokCPgQTAQIAKAUCTDe7QAIbAwUJA8Jn
AAYLCQgHAwIGFQgCCQ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oAJ0jpq3V8n4w0
jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y
ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD
7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR
M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf
REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y
DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk
ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
=a34C
-----END PGP PUBLIC KEY BLOCK-----
',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
end
context 'key_source' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::key { 'puppetlabs':
key => '4BD6EC30',
key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
end
end
context 'key_options' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::key { 'puppetlabs':
key => '4BD6EC30',
key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
key_options => 'debug'
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
end
end
end
end

View file

@ -0,0 +1,138 @@
require 'spec_helper_acceptance'
if fact('operatingsystem') == 'Ubuntu'
describe 'apt::ppa', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'reset' do
it 'removes ppa' do
shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0,1,2])
shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*', :acceptable_exit_codes => [0,1,2])
end
end
context 'adding a ppa that doesnt exist' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:canonical-kernel-team/ppa': }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe 'contains the source file' do
it 'contains a kernel ppa source' do
shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
end
end
end
context 'reading a removed ppa.' do
it 'setup' do
# This leaves a blank file
shell('echo > /etc/apt/sources.list.d/raravena80-collectd5-$(lsb_release -c -s).list')
end
it 'should read it successfully' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:raravena80/collectd5': }
EOS
apply_manifest(pp, :catch_failures => true)
end
end
context 'reset' do
it 'removes added ppas' do
shell('rm /etc/apt/sources.list.d/canonical-kernel-team-ppa-*')
shell('rm /etc/apt/sources.list.d/raravena80-collectd5-*')
end
end
context 'ensure' do
context 'present' do
it 'works without failure' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => present }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe 'contains the source file' do
it 'contains a kernel ppa source' do
shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [0])
end
end
end
end
context 'ensure' do
context 'absent' do
it 'works without failure' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:canonical-kernel-team/ppa': ensure => absent }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe 'doesnt contain the source file' do
it 'fails' do
shell('ls /etc/apt/sources.list.d/canonical-kernel-team-ppa-*', :acceptable_exit_codes => [2])
end
end
end
end
context 'release' do
context 'precise' do
it 'works without failure' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:canonical-kernel-team/ppa':
ensure => present,
release => precise,
}
EOS
shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
it { should be_file }
end
end
end
context 'options' do
context '-y', :unless => default[:platform].match(/10\.04/) do
it 'works without failure' do
pp = <<-EOS
include '::apt'
apt::ppa { 'ppa:canonical-kernel-team/ppa':
ensure => present,
release => precise,
options => '-y',
}
EOS
shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/canonical-kernel-team-ppa-precise.list') do
it { should be_file }
end
end
end
context 'reset' do
it { shell('rm -rf /etc/apt/sources.list.d/canonical-kernel-team-ppa*', :acceptable_exit_codes => [0,1,2]) }
end
end
end

View file

@ -0,0 +1,326 @@
require 'spec_helper_acceptance'
describe 'apt::source', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'apt::source' do
context 'ensure => present' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
shell('rm /etc/apt/sources.list.d/puppetlabs.list', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe 'key should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0])
end
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
end
end
context 'ensure => absent' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => absent,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
# The key should remain -we don't delete those when deleting a source.
describe 'key should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30', :acceptable_exit_codes => [0])
end
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should_not be_file }
end
end
end
context 'release' do
context 'test' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
release => 'precise',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
it { should contain 'deb http://apt.puppetlabs.com precise main' }
end
end
end
context 'include_src' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
include_src => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
it { should contain 'deb-src http://apt.puppetlabs.com' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
include_src => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
it { should_not contain 'deb-src http://apt.puppetlabs.com' }
end
end
end
context 'required_packages' do
context 'vim' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
required_packages => 'vim',
}
EOS
shell('apt-get -y remove vim')
apply_manifest(pp, :catch_failures => true)
end
describe package('vim') do
it { should be_installed }
end
end
end
context 'key content' do
context 'giant key' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: GPGTools - http://gpgtools.org
mQINBEw3u0ABEAC1+aJQpU59fwZ4mxFjqNCgfZgDhONDSYQFMRnYC1dzBpJHzI6b
fUBQeaZ8rh6N4kZ+wq1eL86YDXkCt4sCvNTP0eF2XaOLbmxtV9bdpTIBep9bQiKg
5iZaz+brUZlFk/MyJ0Yz//VQ68N1uvXccmD6uxQsVO+gx7rnarg/BGuCNaVtGwy+
S98g8Begwxs9JmGa8pMCcSxtC7fAfAEZ02cYyrw5KfBvFI3cHDdBqrEJQKwKeLKY
GHK3+H1TM4ZMxPsLuR/XKCbvTyl+OCPxU2OxPjufAxLlr8BWUzgJv6ztPe9imqpH
Ppp3KuLFNorjPqWY5jSgKl94W/CO2x591e++a1PhwUn7iVUwVVe+mOEWnK5+Fd0v
VMQebYCXS+3dNf6gxSvhz8etpw20T9Ytg4EdhLvCJRV/pYlqhcq+E9le1jFOHOc0
Nc5FQweUtHGaNVyn8S1hvnvWJBMxpXq+Bezfk3X8PhPT/l9O2lLFOOO08jo0OYiI
wrjhMQQOOSZOb3vBRvBZNnnxPrcdjUUm/9cVB8VcgI5KFhG7hmMCwH70tpUWcZCN
NlI1wj/PJ7Tlxjy44f1o4CQ5FxuozkiITJvh9CTg+k3wEmiaGz65w9jRl9ny2gEl
f4CR5+ba+w2dpuDeMwiHJIs5JsGyJjmA5/0xytB7QvgMs2q25vWhygsmUQARAQAB
tEdQdXBwZXQgTGFicyBSZWxlYXNlIEtleSAoUHV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
4B0bPmhiE+LL46ET5IThLKu/KfihzkEEBa9/t178+dO9zCM2xsXaiDhMOxVE32gX
vSZKP3hmvnK/FdylUY3nWtPedr+lHpBLoHGaPH7cjI+MEEugU3oAJ0jpq3V8n4w0
jIq2V77wfmbD9byIV7dXcxApzciK+ekwpQNQMSaceuxLlTZKcdSqo0/qmS2A863Y
ZQ0ZBe+Xyf5OI33+y+Mry+vl6Lre2VfPm3udgR10E4tWXJ9Q2CmG+zNPWt73U1FD
7xBI7PPvOlyzCX4QJhy2Fn/fvzaNjHp4/FSiCw0HvX01epcersyun3xxPkRIjwwR
M9m5MJ0o4hhPfa97zibXSh8XXBnosBQxeg6nEnb26eorVQbqGx0ruu/W2m5/JpUf
REsFmNOBUbi8xlKNS5CZypH3Zh88EZiTFolOMEh+hT6s0l6znBAGGZ4m/Unacm5y
DHmg7unCk4JyVopQ2KHMoqG886elu+rm0ASkhyqBAk9sWKptMl3NHiYTRE/m9VAk
ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
=a34C
-----END PGP PUBLIC KEY BLOCK-----',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
end
end
end
context 'key_source' do
context 'http://apt.puppetlabs.com/pubkey.gpg' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
release => 'precise',
repos => 'main',
key => '4BD6EC30',
key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
}
EOS
shell('apt-key del 4BD6EC30', :acceptable_exit_codes => [0,1,2])
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/puppetlabs.list') do
it { should be_file }
it { should contain 'deb http://apt.puppetlabs.com precise main' }
end
describe 'keys should exist' do
it 'finds puppetlabs key' do
shell('apt-key list | grep 4BD6EC30')
end
end
end
end
context 'pin' do
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
pin => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/puppetlabs.pref') do
it { should_not be_file }
end
end
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include '::apt'
apt::source { 'puppetlabs':
ensure => present,
location => 'http://apt.puppetlabs.com',
repos => 'main',
key => '4BD6EC30',
key_server => 'pgp.mit.edu',
pin => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/puppetlabs.pref') do
it { should be_file }
end
end
end
end

View file

@ -0,0 +1,280 @@
require 'spec_helper_acceptance'
describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'reset' do
it 'fixes the sources.list' do
shell('cp /etc/apt/sources.list /tmp')
end
end
context 'always_apt_update => true' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': always_apt_update => true }
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/apt_update/)
end
end
end
context 'always_apt_update => false' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': always_apt_update => false }
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to_not match(/apt_update/)
end
end
end
# disable_keys drops in a 99unauth file to ignore keys in
# other files.
context 'disable_keys => true' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': disable_keys => true }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/99unauth') do
it { should be_file }
it { should contain 'APT::Get::AllowUnauthenticated 1;' }
end
end
context 'disable_keys => false' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': disable_keys => false }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/99unauth') do
it { should_not be_file }
end
end
# proxy_host sets the proxy to use for transfers.
# proxy_port sets the proxy port to use.
context 'proxy settings' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt':
proxy_host => 'localhost',
proxy_port => '7042',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/01proxy') do
it { should be_file }
it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
end
describe file('/etc/apt/apt.conf.d/proxy') do
it { should_not be_file }
end
end
context 'purge_sources' do
it 'creates a fake apt file' do
shell('touch /etc/apt/sources.list.d/fake.list')
shell('echo "deb fake" >> /etc/apt/sources.list')
end
it 'purge_sources_list and purge_sources_list_d => true' do
pp = <<-EOS
class { 'apt':
purge_sources_list => true,
purge_sources_list_d => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list') do
it { should_not contain 'deb fake' }
end
describe file('/etc/apt/sources.list.d/fake.list') do
it { should_not be_file }
end
end
context 'proxy settings' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt':
proxy_host => 'localhost',
proxy_port => '7042',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/01proxy') do
it { should be_file }
it { should contain 'Acquire::http::Proxy "http://localhost:7042\";' }
end
describe file('/etc/apt/apt.conf.d/proxy') do
it { should_not be_file }
end
end
context 'purge_sources' do
context 'false' do
it 'creates a fake apt file' do
shell('touch /etc/apt/sources.list.d/fake.list')
shell('echo "deb fake" >> /etc/apt/sources.list')
end
it 'purge_sources_list and purge_sources_list_d => false' do
pp = <<-EOS
class { 'apt':
purge_sources_list => false,
purge_sources_list_d => false,
}
EOS
apply_manifest(pp, :catch_failures => false)
end
describe file('/etc/apt/sources.list') do
it { should contain 'deb fake' }
end
describe file('/etc/apt/sources.list.d/fake.list') do
it { should be_file }
end
end
context 'true' do
it 'creates a fake apt file' do
shell('touch /etc/apt/sources.list.d/fake.list')
shell('echo "deb fake" >> /etc/apt/sources.list')
end
it 'purge_sources_list and purge_sources_list_d => true' do
pp = <<-EOS
class { 'apt':
purge_sources_list => true,
purge_sources_list_d => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list') do
it { should_not contain 'deb fake' }
end
describe file('/etc/apt/sources.list.d/fake.list') do
it { should_not be_file }
end
end
end
context 'purge_preferences' do
context 'false' do
it 'creates a preferences file' do
shell("echo 'original' > /etc/apt/preferences")
end
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences => false }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences') do
it { should be_file }
it 'is not managed by Puppet' do
shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0})
end
end
end
context 'true' do
it 'creates a preferences file' do
shell('touch /etc/apt/preferences')
end
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences => true }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences') do
it { should_not be_file }
end
end
end
context 'purge_preferences_d' do
context 'false' do
it 'creates a preferences file' do
shell('touch /etc/apt/preferences.d/test')
end
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences_d => false }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/test') do
it { should be_file }
end
end
context 'true' do
it 'creates a preferences file' do
shell('touch /etc/apt/preferences.d/test')
end
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences_d => true }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/test') do
it { should_not be_file }
end
end
end
context 'update_timeout' do
context '5000' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': update_timeout => '5000' }
EOS
apply_manifest(pp, :catch_failures => true)
end
end
end
context 'reset' do
it 'fixes the sources.list' do
shell('cp /tmp/sources.list /etc/apt')
end
end
end

View file

@ -0,0 +1,73 @@
require 'spec_helper_acceptance'
codename = fact('lsbdistcodename')
case fact('operatingsystem')
when 'Ubuntu'
repos = 'main universe multiverse restricted'
when 'Debian'
repos = 'main contrib non-free'
end
describe 'apt::backports class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'defaults' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt::backports': }
EOS
apply_manifest(pp, :catch_failures => true)
end
end
context 'release' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt::backports': release => '#{codename}' }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/backports.list') do
it { should be_file }
it { should contain "#{codename}-backports #{repos}" }
end
end
context 'location' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt::backports': release => 'precise', location => 'http://localhost/ubuntu' }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/sources.list.d/backports.list') do
it { should be_file }
it { should contain "deb http://localhost/ubuntu precise-backports #{repos}" }
end
end
context 'pin_priority' do
it 'should work with no errors' do
pp = <<-EOS
class { 'apt::backports': pin_priority => 500, }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/backports.pref') do
it { should be_file }
it { should contain "Pin-Priority: 500" }
end
end
context 'reset' do
it 'deletes backport files' do
shell('rm -rf /etc/apt/sources.list.d/backports.list')
shell('rm -rf /etc/apt/preferences.d/backports.pref')
end
end
end

View file

@ -0,0 +1,17 @@
require 'spec_helper_acceptance'
describe 'apt class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'default parameters' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'apt': }
EOS
# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
end
end

View file

@ -0,0 +1,66 @@
require 'spec_helper_acceptance'
describe 'apt::conf define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'defaults' do
it 'should work with no errors' do
pp = <<-EOS
apt::conf { 'test':
content => 'test',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50test') do
it { should be_file }
it { should contain 'test' }
end
end
context 'ensure' do
context 'absent' do
it 'should work with no errors' do
pp = <<-EOS
apt::conf { 'test':
ensure => absent,
content => 'test',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50test') do
it { should_not be_file }
end
end
end
context 'priority' do
context '99' do
it 'should work with no errors' do
pp = <<-EOS
apt::conf { 'test':
ensure => present,
content => 'test',
priority => '99',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/99test') do
it { should be_file }
it { should contain 'test' }
end
end
end
context 'cleanup' do
it 'deletes 99test' do
shell ('rm -rf /etc/apt/apt.conf.d/99test')
end
end
end

View file

@ -0,0 +1,76 @@
require 'spec_helper_acceptance'
codename = fact('lsbdistcodename')
describe 'apt::force define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'defaults' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::force { 'vim': }
EOS
shell('apt-get remove -y vim')
apply_manifest(pp, :catch_failures => true)
end
describe package('vim') do
it { should be_installed }
end
end
context 'release' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::force { 'vim': release => '#{codename}' }
EOS
shell('apt-get remove -y vim')
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/apt-get -y -t #{codename} install vim/)
end
end
describe package('vim') do
it { should be_installed }
end
end
context 'version' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::force { 'vim': version => '1.1.1' }
EOS
shell('apt-get remove -y vim')
apply_manifest(pp, :catch_failures => false) do |r|
expect(r.stdout).to match(/apt-get -y install vim=1.1.1/)
end
end
describe package('vim') do
it { should_not be_installed }
end
end
context 'timeout' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::force { 'ocaml': timeout => '1' }
EOS
shell('apt-get clean')
apply_manifest(pp, :expect_failures => true) do |r|
expect(r.stderr).to match(/Error: Command exceeded timeout/)
end
end
describe package('ocaml') do
it { should_not be_installed }
end
end
end

View file

@ -0,0 +1,10 @@
HOSTS:
debian-70rc1-x64:
roles:
- master
platform: debian-70rc1-x64
box : debian-70rc1-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,11 @@
HOSTS:
debian-73-x64:
roles:
- master
platform: debian-7-amd64
box : debian-73-x64-virtualbox-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-73-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: git

View file

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-server-12.04-amd64
box : ubuntu-server-12042-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss
vagrant_ssh_port_random: true

View file

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-10044-x64:
roles:
- master
platform: ubuntu-10.04-amd64
box : ubuntu-server-10044-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: git

View file

@ -0,0 +1,10 @@
HOSTS:
ubuntu-server-12042-x64:
roles:
- master
platform: ubuntu-server-12.04-amd64
box : ubuntu-server-12042-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
type: foss

View file

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1404-x64:
roles:
- master
platform: ubuntu-14.04-amd64
box : puppetlabs/ubuntu-14.04-64-nocm
box_url : https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm
hypervisor : vagrant
CONFIG:
log_level : debug
type: git

View file

@ -0,0 +1,286 @@
require 'spec_helper_acceptance'
describe 'apt::pin define', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'defaults' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet': }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release a=vim-puppet' }
end
end
context 'ensure' do
context 'present' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet': ensure => present }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release a=vim-puppet' }
end
end
context 'absent' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet': ensure => absent }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should_not be_file }
end
end
end
context 'order' do
context '99' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
order => '99',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/99-vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release a=vim-puppet' }
end
end
end
context 'packages' do
context 'test' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
packages => 'test',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Package: test' }
it { should contain 'Pin: release a=vim-puppet' }
end
end
context 'array' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'array':
ensure => present,
packages => ['apache', 'ntop'],
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/array.pref') do
it { should be_file }
it { should contain 'Package: apache ntop' }
it { should contain 'Pin: release a=array' }
end
end
end
context 'release' do
context 'testrelease' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
release => 'testrelease',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release a=testrelease' }
end
end
end
context 'origin' do
context 'testrelease' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
origin => 'testrelease',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: origin testrelease' }
end
end
end
context 'version' do
context '1.0.0' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
packages => 'test',
version => '1.0.0',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Package: test' }
it { should contain 'Pin: version 1.0.0' }
end
end
end
context 'codename' do
context 'testname' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
codename => 'testname',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release n=testname' }
end
end
end
context 'release_version' do
context '1.1.1' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
release_version => '1.1.1',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release v=1.1.1' }
end
end
end
context 'component' do
context 'testcomponent' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
component => 'testcomponent',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release c=testcomponent' }
end
end
end
context 'originator' do
context 'testorigin' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
originator => 'testorigin',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release o=testorigin' }
end
end
end
context 'label' do
context 'testlabel' do
it 'should work with no errors' do
pp = <<-EOS
include apt
apt::pin { 'vim-puppet':
ensure => present,
label => 'testlabel',
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/preferences.d/vim-puppet.pref') do
it { should be_file }
it { should contain 'Pin: release l=testlabel' }
end
end
end
end

View file

@ -0,0 +1,26 @@
require 'spec_helper_acceptance'
describe 'apt::release class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'release_id' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::release': release_id => 'precise', }
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/01release') do
it { should be_file }
it { should contain 'APT::Default-Release "precise";' }
end
end
context 'reset' do
it 'cleans up' do
shell('rm -rf /etc/apt/apt.conf.d/01release')
end
end
end

View file

@ -0,0 +1,562 @@
require 'spec_helper_acceptance'
describe 'apt::unattended_upgrades class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
context 'defaults' do
it 'should work with no errors' do
pp = <<-EOS
include apt
include apt::unattended_upgrades
EOS
# Attempted workaround for problems seen on debian with
# something holding the package database open.
#shell('killall -9 apt-get')
#shell('killall -9 dpkg')
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
end
end
context 'origins' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
origins => ['${distro_id}:${distro_codename}-test'],
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain '${distro_id}:${distro_codename}-test' }
end
end
context 'blacklist' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
blacklist => ['puppet']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'puppet' }
end
end
context 'update' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
update => '99'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Update-Package-Lists "99";' }
end
end
context 'download' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
download => '99'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Download-Upgradeable-Packages "99";' }
end
end
context 'upgrade' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
upgrade => '99'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Unattended-Upgrade "99";' }
end
end
context 'autoclean' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
autoclean => '99'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::AutocleanInterval "99";' }
end
end
context 'auto_fix' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
auto_fix => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
auto_fix => false
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::AutoFixInterruptedDpkg "false";' }
end
end
end
context 'minimal_steps' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
minimal_steps => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::MinimalSteps "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
minimal_steps => false
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::MinimalSteps "false";' }
end
end
end
context 'install_on_shutdown' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
install_on_shutdown => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::InstallOnShutdown "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
install_on_shutdown => false
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::InstallOnShutdown "false";' }
end
end
end
context 'mail_to' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
mail_to => 'test@example.com'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::Mail "test@example.com";' }
end
end
context 'mail_only_on_error' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
mail_to => 'test@example.com',
mail_only_on_error => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
mail_to => 'test@example.com',
mail_only_on_error => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::MailOnlyOnError "false";' }
end
end
context 'mail_to missing' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
mail_only_on_error => true,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should_not contain 'Unattended-Upgrade::MailOnlyOnError "true";' }
end
end
end
context 'remove_unused' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
remove_unused => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
remove_unused => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::Remove-Unused-Dependencies "false";' }
end
end
end
context 'auto_reboot' do
context 'true' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
auto_reboot => true
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::Automatic-Reboot "true";' }
end
end
context 'false' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
auto_reboot => false,
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Unattended-Upgrade::Automatic-Reboot "false";' }
end
end
end
context 'dl_limit' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
dl_limit => '99'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/50unattended-upgrades') do
it { should be_file }
it { should contain 'Acquire::http::Dl-Limit "99"' }
end
end
context 'enable' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
enable => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Enable "2"' }
end
end
context 'backup_interval' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
backup_interval => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::BackUpArchiveInterval "2";' }
end
end
context 'backup_level' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
backup_level => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::BackUpLevel "2";' }
end
end
context 'max_age' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
max_age => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::MaxAge "2";' }
end
end
context 'min_age' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
min_age => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::MinAge "2";' }
end
end
context 'max_size' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
max_size => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::MaxSize "2";' }
end
end
context 'download_delta' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
download_delta => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";' }
end
end
context 'verbose' do
it 'should work with no errors' do
pp = <<-EOS
include apt
class { 'apt::unattended_upgrades':
verbose => '2'
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/apt/apt.conf.d/10periodic') do
it { should be_file }
it { should contain 'APT::Periodic::Verbose "2";' }
end
end
end

View file

@ -0,0 +1,10 @@
require 'spec_helper_acceptance'
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
it 'class apt fails' do
pp = <<-EOS
class { 'apt': }
EOS
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/This module only works on Debian or derivatives like Ubuntu/i)
end
end

View file

@ -0,0 +1,170 @@
require 'spec_helper'
describe 'apt', :type => :class do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let :default_params do
{
:disable_keys => :undef,
:always_apt_update => false,
:purge_sources_list => false,
:purge_sources_list_d => false,
}
end
[{},
{
:disable_keys => true,
:always_apt_update => true,
:proxy_host => true,
:proxy_port => '3128',
:purge_sources_list => true,
:purge_sources_list_d => true,
},
{
:purge_preferences => true,
:purge_preferences_d => true,
},
{
:disable_keys => false
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
default_params.merge(param_set)
end
let :params do
param_set
end
let :refresh_only_apt_update do
if param_hash[:always_apt_update]
false
else
true
end
end
it { should contain_class("apt::params") }
it {
if param_hash[:purge_sources_list]
should contain_file("sources.list").with({
'path' => "/etc/apt/sources.list",
'ensure' => "present",
'owner' => "root",
'group' => "root",
'mode' => "0644",
"content" => "# Repos managed by puppet.\n"
})
else
should contain_file("sources.list").with({
'path' => "/etc/apt/sources.list",
'ensure' => "present",
'owner' => "root",
'group' => "root",
'mode' => "0644",
'content' => nil
})
end
}
it {
if param_hash[:purge_sources_list_d]
should create_file("sources.list.d").with({
'path' => "/etc/apt/sources.list.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => true,
'recurse' => true,
'notify' => 'Exec[apt_update]'
})
else
should create_file("sources.list.d").with({
'path' => "/etc/apt/sources.list.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => false,
'recurse' => false,
'notify' => 'Exec[apt_update]'
})
end
}
it {
if param_hash[:purge_preferences]
should create_file('apt-preferences').with({
:ensure => 'absent',
:path => '/etc/apt/preferences',
})
else
should_not contain_file('apt-preferences')
end
}
it {
if param_hash[:purge_preferences_d]
should create_file("preferences.d").with({
'path' => "/etc/apt/preferences.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => true,
'recurse' => true,
})
else
should create_file("preferences.d").with({
'path' => "/etc/apt/preferences.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => false,
'recurse' => false,
})
end
}
it {
should contain_exec("apt_update").with({
'command' => "/usr/bin/apt-get update",
'refreshonly' => refresh_only_apt_update
})
}
it {
if param_hash[:disable_keys] == true
should create_file("99unauth").with({
'content' => "APT::Get::AllowUnauthenticated 1;\n",
'ensure' => "present",
'path' => "/etc/apt/apt.conf.d/99unauth"
})
elsif param_hash[:disable_keys] == false
should create_file("99unauth").with({
'ensure' => "absent",
'path' => "/etc/apt/apt.conf.d/99unauth"
})
elsif param_hash[:disable_keys] != :undef
should_not create_file("99unauth").with({
'path' => "/etc/apt/apt.conf.d/99unauth"
})
end
}
describe 'when setting a proxy' do
it {
if param_hash[:proxy_host]
should contain_file('01proxy').with(
'path' => '/etc/apt/apt.conf.d/01proxy',
'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";\n",
'notify' => "Exec[apt_update]"
)
else
should contain_file('01proxy').with(
'path' => '/etc/apt/apt.conf.d/01proxy',
'notify' => 'Exec[apt_update]',
'ensure' => 'absent'
)
end
}
end
end
end
end

View file

@ -0,0 +1,101 @@
require 'spec_helper'
describe 'apt::backports', :type => :class do
describe 'when asigning a custom priority to backports' do
let :facts do
{
'lsbdistcodename' => 'Karmic',
'lsbdistid' => 'Ubuntu'
}
end
context 'integer priority' do
let :params do { :pin_priority => 500 } end
it { should contain_apt__source('backports').with({
'location' => 'http://old-releases.ubuntu.com/ubuntu',
'release' => 'karmic-backports',
'repos' => 'main universe multiverse restricted',
'key' => '437D05B5',
'key_server' => 'pgp.mit.edu',
'pin' => 500,
})
}
end
context 'invalid priority' do
let :params do { :pin_priority => 'banana' } end
it 'should fail' do
expect { subject }.to raise_error(/must be an integer/)
end
end
end
describe 'when turning on backports for ubuntu karmic' do
let :facts do
{
'lsbdistcodename' => 'Karmic',
'lsbdistid' => 'Ubuntu'
}
end
it { should contain_apt__source('backports').with({
'location' => 'http://old-releases.ubuntu.com/ubuntu',
'release' => 'karmic-backports',
'repos' => 'main universe multiverse restricted',
'key' => '437D05B5',
'key_server' => 'pgp.mit.edu',
'pin' => 200,
})
}
end
describe "when turning on backports for debian squeeze" do
let :facts do
{
'lsbdistcodename' => 'Squeeze',
'lsbdistid' => 'Debian',
}
end
it { should contain_apt__source('backports').with({
'location' => 'http://backports.debian.org/debian-backports',
'release' => 'squeeze-backports',
'repos' => 'main contrib non-free',
'key' => '46925553',
'key_server' => 'pgp.mit.edu',
'pin' => 200,
})
}
end
describe "when turning on backports for debian squeeze but using your own mirror" do
let :facts do
{
'lsbdistcodename' => 'Squeeze',
'lsbdistid' => 'Debian'
}
end
let :location do
'http://mirrors.example.com/debian-backports'
end
let :params do
{ 'location' => location }
end
it { should contain_apt__source('backports').with({
'location' => location,
'release' => 'squeeze-backports',
'repos' => 'main contrib non-free',
'key' => '46925553',
'key_server' => 'pgp.mit.edu',
'pin' => 200,
})
}
end
end

View file

@ -0,0 +1,15 @@
require 'spec_helper'
describe 'apt::debian::testing', :type => :class do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
it {
should contain_apt__source("debian_testing").with({
"location" => "http://debian.mirror.iweb.ca/debian/",
"release" => "testing",
"repos" => "main contrib non-free",
"required_packages" => "debian-keyring debian-archive-keyring",
"key" => "46925553",
"key_server" => "subkeys.pgp.net",
"pin" => "-10"
})
}
end

View file

@ -0,0 +1,15 @@
require 'spec_helper'
describe 'apt::debian::unstable', :type => :class do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
it {
should contain_apt__source("debian_unstable").with({
"location" => "http://debian.mirror.iweb.ca/debian/",
"release" => "unstable",
"repos" => "main contrib non-free",
"required_packages" => "debian-keyring debian-archive-keyring",
"key" => "46925553",
"key_server" => "subkeys.pgp.net",
"pin" => "-10"
})
}
end

View file

@ -0,0 +1,57 @@
require 'spec_helper'
describe 'apt' do
context 'with sources defined on valid osfamily' do
let :facts do
{ :osfamily => 'Debian',
:lsbdistcodename => 'precise',
:lsbdistid => 'Debian',
}
end
let(:params) { { :sources => {
'debian_unstable' => {
'location' => 'http://debian.mirror.iweb.ca/debian/',
'release' => 'unstable',
'repos' => 'main contrib non-free',
'required_packages' => 'debian-keyring debian-archive-keyring',
'key' => '55BE302B',
'key_server' => 'subkeys.pgp.net',
'pin' => '-10',
'include_src' => true
},
'puppetlabs' => {
'location' => 'http://apt.puppetlabs.com',
'repos' => 'main',
'key' => '4BD6EC30',
'key_server' => 'pgp.mit.edu',
}
} } }
it {
should contain_file('debian_unstable.list').with({
'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/debian_unstable.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'notify' => 'Exec[apt_update]',
})
}
it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) }
it {
should contain_file('puppetlabs.list').with({
'ensure' => 'present',
'path' => '/etc/apt/sources.list.d/puppetlabs.list',
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'notify' => 'Exec[apt_update]',
})
}
it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
end
end

View file

@ -0,0 +1,27 @@
require 'spec_helper'
describe 'apt::params', :type => :class do
let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
let (:title) { 'my_package' }
it { should contain_apt__params }
# There are 4 resources in this class currently
# there should not be any more resources because it is a params class
# The resources are class[apt::params], class[main], class[settings], stage[main]
it "Should not contain any resources" do
subject.resources.size.should == 4
end
describe "With unknown lsbdistid" do
let(:facts) { { :lsbdistid => 'CentOS' } }
let (:title) { 'my_package' }
it do
expect {
should compile
}.to raise_error(Puppet::Error, /Unsupported lsbdistid/)
end
end
end

View file

@ -0,0 +1,23 @@
require 'spec_helper'
describe 'apt::release', :type => :class do
let(:facts) { { :lsbdistid => 'Debian' } }
let (:title) { 'my_package' }
let :param_set do
{ :release_id => 'precise' }
end
let (:params) { param_set }
it { should contain_class("apt::params") }
it {
should contain_file("/etc/apt/apt.conf.d/01release").with({
"mode" => "0644",
"owner" => "root",
"group" => "root",
"content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
})
}
end

View file

@ -0,0 +1,291 @@
require 'spec_helper'
describe 'apt::unattended_upgrades', :type => :class do
let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' }
let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' }
let(:facts) { { :lsbdistid => 'Debian' } }
it { should contain_package("unattended-upgrades") }
it {
should create_file("/etc/apt/apt.conf.d/50unattended-upgrades").with({
"owner" => "root",
"group" => "root",
"mode" => "0644",
"require" => "Package[unattended-upgrades]",
})
}
it {
should create_file("/etc/apt/apt.conf.d/10periodic").with({
"owner" => "root",
"group" => "root",
"mode" => "0644",
"require" => "Package[unattended-upgrades]",
})
}
describe "origins" do
describe 'on Debian' do
default_facts = { :lsbdistid => 'Debian' }
context 'defaults' do
let :facts do default_facts end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Origins-Pattern/
).with_content(
/"origin=Debian,archive=stable,label=Debian-Security";/
)
}
end
context 'defaults with custom origin' do
let :facts do default_facts end
let :params do { :origins => ['bananana']} end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Origins-Pattern/
).with_content(
/"bananana";/
)
}
end
context 'defaults with invalid origin' do
let :facts do default_facts end
let :params do { :origins => 'bananana'} end
it {
expect {subject}.to raise_error(/is not an Array/)
}
end
context 'squeeze' do
let :facts do default_facts.merge({:lsbdistcodename => 'squeeze'}) end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Allowed-Origins/
).with_content(
/"\${distro_id} \${distro_codename}-security";/
).with_content(
/"\${distro_id} oldstable";/
)
}
end
context 'wheezy' do
let :facts do default_facts.merge({:lsbdistcodename => 'wheezy'}) end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Origins-Pattern/
).with_content(
/"origin=Debian,archive=stable,label=Debian-Security";/
)
}
end
end
describe 'on Ubuntu' do
default_facts = { :lsbdistid => 'Ubuntu' }
context 'default' do
let :facts do default_facts end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Allowed-Origins/
).with_content(
/"\${distro_id}\:\${distro_codename}-security";/
)
}
end
context 'lucid' do
let :facts do default_facts.merge({:lsbdistcodename => 'lucid'}) end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Allowed-Origins/
).with_content(
/"\${distro_id} \${distro_codename}-security";/
)
}
end
context 'precise' do
let :facts do default_facts.merge({:lsbdistcodename => 'precise'}) end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Allowed-Origins/
).with_content(
/"\${distro_id}\:\${distro_codename}-security";/
)
}
end
context 'trusty' do
let :facts do default_facts.merge({:lsbdistcodename => 'trusty'}) end
it {
should contain_file(file_unattended).with_content(
/^Unattended-Upgrade::Allowed-Origins/
).with_content(
/"\${distro_id}\:\${distro_codename}-security";/
)
}
end
end
end
describe "blacklist" do
describe "with param defaults" do
let(:params) {{ }}
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\};$/) }
end
describe "with blacklist => []" do
let :params do
{ :blacklist => ['libc6', 'libc6-dev'] }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Package-Blacklist \{\n\t"libc6";\n\t"libc6-dev";\n\};$/) }
end
end
describe "with update => 2" do
let :params do
{ :update => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Update-Package-Lists "2";$/) }
end
describe "with download => 2" do
let :params do
{ :download => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages "2";$/) }
end
describe "with upgrade => 2" do
let :params do
{ :upgrade => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Unattended-Upgrade "2";$/) }
end
describe "with autoclean => 2" do
let :params do
{ :autoclean => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::AutocleanInterval "2";$/) }
end
describe "with auto_fix => false" do
let :params do
{ :auto_fix => false }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::AutoFixInterruptedDpkg "false";$/) }
end
describe "with minimal_steps => true" do
let :params do
{ :minimal_steps => true }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MinimalSteps "true";$/) }
end
describe "with install_on_shutdown => true" do
let :params do
{ :install_on_shutdown => true }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::InstallOnShutdown "true";$/) }
end
describe "mail_to" do
describe "param defaults" do
let(:params) {{ }}
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail /) }
it { should_not contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError /) }
end
describe "with mail_to => user@website, mail_only_on_error => true" do
let :params do
{ :mail_to => "user@website",
:mail_only_on_error => true }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Mail "user@website";$/) }
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::MailOnlyOnError "true";$/) }
end
end
describe "with remove_unused => false" do
let :params do
{ :remove_unused => false }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Remove-Unused-Dependencies "false";$/) }
end
describe "with auto_reboot => true" do
let :params do
{ :auto_reboot => true }
end
it { should contain_file(file_unattended).with_content(/^Unattended-Upgrade::Automatic-Reboot "true";$/) }
end
describe "dl_limit" do
describe "param defaults" do
let(:params) {{ }}
it { should_not contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit /) }
end
describe "with dl_limit => 70" do
let :params do
{ :dl_limit => "70" }
end
it { should contain_file(file_unattended).with_content(/^Acquire::http::Dl-Limit "70";$/) }
end
end
describe "with enable => 0" do
let :params do
{ :enable => "0" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Enable "0";$/) }
end
describe "with backup_interval => 1" do
let :params do
{ :backup_interval => "1" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpArchiveInterval "1";$/) }
end
describe "with backup_level => 0" do
let :params do
{ :backup_level => "0" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::BackUpLevel "0";$/) }
end
describe "with max_age => 1" do
let :params do
{ :max_age => "1" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxAge "1";$/) }
end
describe "with min_age => 1" do
let :params do
{ :min_age => "1" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MinAge "1";$/) }
end
describe "with max_size => 1" do
let :params do
{ :max_size => "1" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::MaxSize "1";$/) }
end
describe "with download_delta => 2" do
let :params do
{ :download_delta => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Download-Upgradeable-Packages-Debdelta "2";$/) }
end
describe "with verbose => 2" do
let :params do
{ :verbose => "2" }
end
it { should contain_file(file_periodic).with_content(/^APT::Periodic::Verbose "2";$/) }
end
end

View file

@ -0,0 +1,19 @@
require 'spec_helper'
describe 'apt::builddep', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
let(:title) { 'my_package' }
describe "should require apt-get update" do
it { should contain_exec("apt_update").with({
'command' => "/usr/bin/apt-get update",
'refreshonly' => true
})
}
it { should contain_anchor("apt::builddep::my_package").with({
'require' => 'Class[Apt::Update]',
})
}
end
end

View file

@ -0,0 +1,58 @@
require 'spec_helper'
describe 'apt::conf', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
let :title do
'norecommends'
end
describe "when creating an apt preference" do
let :params do
{
:priority => '00',
:content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
}
end
let :filename do
"/etc/apt/apt.conf.d/00norecommends"
end
it { should contain_apt__conf('norecommends').with({
'priority' => '00',
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
})
}
it { should contain_file(filename).with({
'ensure' => 'present',
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})
}
end
describe "when removing an apt preference" do
let :params do
{
:ensure => 'absent',
:priority => '00',
:content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
}
end
let :filename do
"/etc/apt/apt.conf.d/00norecommends"
end
it { should contain_file(filename).with({
'ensure' => 'absent',
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})
}
end
end

View file

@ -0,0 +1,58 @@
require 'spec_helper'
describe 'apt::force', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
let :pre_condition do
'include apt::params'
end
let :title do
'my_package'
end
let :default_params do
{
:release => false,
:version => false
}
end
describe "when using default parameters" do
let :params do
default_params
end
it { should contain_exec("/usr/bin/apt-get -y install #{title}").with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Status: install'",
:timeout => '300'
) }
end
describe "when specifying release parameter" do
let :params do
default_params.merge(:release => 'testing')
end
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}").with(
:unless => "/usr/bin/test \$(/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1"
) }
end
describe "when specifying version parameter" do
let :params do
default_params.merge(:version => '1')
end
it { should contain_exec("/usr/bin/apt-get -y install #{title}=#{params[:version]}").with(
:unless => "/usr/bin/dpkg -s #{title} | grep -q 'Version: #{params[:version]}'"
) }
end
describe "when specifying release and version parameters" do
let :params do
default_params.merge(
:release => 'testing',
:version => '1'
)
end
it { should contain_exec("/usr/bin/apt-get -y -t #{params[:release]} install #{title}=1").with(
:unless => "/usr/bin/apt-cache policy -t #{params[:release]} #{title} | /bin/grep -q 'Installed: #{params[:version]}'"
) }
end
end

View file

@ -0,0 +1,100 @@
require 'spec_helper'
describe 'apt::hold' do
let :facts do {
:osfamily => 'Debian',
:lsbdistid => 'Debian',
:lsbrelease => 'wheezy',
} end
let :title do
'vim'
end
let :default_params do {
:version => '1.1.1',
} end
describe 'default params' do
let :params do default_params end
it 'creates an apt preferences file' do
should contain_apt__hold(title).with({
:ensure => 'present',
:package => title,
:version => params[:version],
:priority => 1001,
})
should contain_apt__pin("hold #{title} at #{params[:version]}").with({
:ensure => 'present',
:packages => title,
:version => params[:version],
:priority => 1001,
})
end
end
describe 'ensure => absent' do
let :params do default_params.merge({:ensure => 'absent',}) end
it 'creates an apt preferences file' do
should contain_apt__hold(title).with({
:ensure => params[:ensure],
})
should contain_apt__pin("hold #{title} at #{params[:version]}").with({
:ensure => params[:ensure],
})
end
end
describe 'priority => 990' do
let :params do default_params.merge({:priority => 990,}) end
it 'creates an apt preferences file' do
should contain_apt__hold(title).with({
:ensure => 'present',
:package => title,
:version => params[:version],
:priority => params[:priority],
})
should contain_apt__pin("hold #{title} at #{params[:version]}").with({
:ensure => 'present',
:packages => title,
:version => params[:version],
:priority => params[:priority],
})
end
end
describe 'validation' do
context 'version => {}' do
let :params do { :version => {}, } end
it 'should fail' do
expect { subject }.to raise_error(/is not a string/)
end
end
context 'ensure => bananana' do
let :params do default_params.merge({:ensure => 'bananana',}) end
it 'should fail' do
expect { subject }.to raise_error(/does not match/)
end
end
context 'package => []' do
let :params do default_params.merge({:package => [],}) end
it 'should fail' do
expect { subject }.to raise_error(/is not a string/)
end
end
context 'priority => bananana' do
let :params do default_params.merge({:priority => 'bananana',}) end
it 'should fail' do
expect { subject }.to raise_error(/must be an integer/)
end
end
end
end

View file

@ -0,0 +1,285 @@
require 'spec_helper'
describe 'apt::key', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
GPG_KEY_ID = '4BD6EC30'
let :title do
GPG_KEY_ID
end
describe 'normal operation' do
describe 'default options' do
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:content => nil,
:keyserver_options => nil,
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{title} present")
end
end
describe 'title and key =>' do
let :title do
'puppetlabs'
end
let :params do {
:key => GPG_KEY_ID,
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => GPG_KEY_ID,
:ensure => 'present',
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => GPG_KEY_ID,
:ensure => 'present',
:source => nil,
:server => nil,
:content => nil,
:keyserver_options => nil,
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{GPG_KEY_ID} present")
end
end
describe 'ensure => absent' do
let :params do {
:ensure => 'absent',
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'absent',
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'absent',
:source => nil,
:server => nil,
:content => nil,
:keyserver_options => nil,
})
end
it 'contains the apt_key absent anchor' do
should contain_anchor("apt_key #{title} absent")
end
end
describe 'key_content =>' do
let :params do {
:key_content => 'GPG key content',
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
:key_content => params[:key_content],
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:content => params[:key_content],
:keyserver_options => nil,
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{title} present")
end
end
describe 'key_source =>' do
let :params do {
:key_source => 'http://apt.puppetlabs.com/pubkey.gpg',
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
:key_source => params[:key_source],
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'present',
:source => params[:key_source],
:server => nil,
:content => nil,
:keyserver_options => nil,
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{title} present")
end
end
describe 'key_server =>' do
let :params do {
:key_server => 'pgp.mit.edu',
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
:key_server => 'pgp.mit.edu',
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'present',
:source => nil,
:server => params[:key_server],
:content => nil,
:keyserver_options => nil,
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{title} present")
end
end
describe 'key_options =>' do
let :params do {
:key_options => 'debug',
} end
it 'contains the apt::key' do
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
:key_options => 'debug',
})
end
it 'contains the apt_key' do
should contain_apt_key(title).with({
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:content => nil,
:keyserver_options => params[:key_options],
})
end
it 'contains the apt_key present anchor' do
should contain_anchor("apt_key #{title} present")
end
end
end
describe 'validation' do
context 'invalid key' do
let :title do
'Out of rum. Why? Why are we out of rum?'
end
it 'fails' do
expect { subject }.to raise_error(/does not match/)
end
end
context 'invalid source' do
let :params do {
:key_source => 'afp://puppetlabs.com/key.gpg',
} end
it 'fails' do
expect { subject }.to raise_error(/does not match/)
end
end
context 'invalid content' do
let :params do {
:key_content => [],
} end
it 'fails' do
expect { subject }.to raise_error(/is not a string/)
end
end
context 'invalid server' do
let :params do {
:key_server => 'two bottles of rum',
} end
it 'fails' do
expect { subject }.to raise_error(/must be a valid domain name/)
end
end
context 'invalid keyserver_options' do
let :params do {
:key_options => {},
} end
it 'fails' do
expect { subject }.to raise_error(/is not a string/)
end
end
end
describe 'duplication' do
context 'two apt::key resources for same key, different titles' do
let :pre_condition do
"apt::key { 'duplicate': key => #{title}, }"
end
it 'contains two apt::key resources' do
should contain_apt__key('duplicate').with({
:key => title,
:ensure => 'present',
})
should contain_apt__key(title).with({
:key => title,
:ensure => 'present',
})
end
it 'contains only a single apt_key' do
should contain_apt_key('duplicate').with({
:id => title,
:ensure => 'present',
:source => nil,
:server => nil,
:content => nil,
:keyserver_options => nil,
})
should_not contain_apt_key(title)
end
end
context 'two apt::key resources, different ensure' do
let :pre_condition do
"apt::key { 'duplicate': key => #{title}, ensure => 'absent', }"
end
it 'informs the user of the impossibility' do
expect { subject }.to raise_error(/already ensured as absent/)
end
end
end
end

View file

@ -0,0 +1,120 @@
require 'spec_helper'
describe 'apt::pin', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
let(:title) { 'my_pin' }
let :default_params do
{
:ensure => 'present',
:order => '',
:packages => '*',
:priority => '0',
:release => nil
}
end
[
{ :params => {},
:content => "Explanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
},
{
:params => {
:packages => 'apache',
:priority => '1'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
},
{
:params => {
:order => 50,
:packages => 'apache',
:priority => '1'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
},
{
:params => {
:ensure => 'absent',
:packages => 'apache',
:priority => '1'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
},
{
:params => {
:packages => 'apache',
:priority => '1',
:release => 'my_newpin'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
},
{
:params => {
:packages => 'apache',
:priority => '1',
:version => '2.2.16*'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
},
{
:params => {
:priority => '1',
:origin => 'ftp.de.debian.org'
},
:content => "Explanation: : my_pin\nPackage: *\nPin: origin ftp.de.debian.org\nPin-Priority: 1\n"
},
{
:params => {
:packages => 'apache',
:priority => '1',
:release => 'stable',
:codename => 'wheezy',
:release_version => '3.0',
:component => 'main',
:originator => 'Debian',
:label => 'Debian'
},
:content => "Explanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
},
{
:params => {
:packages => ['apache', 'ntop'],
},
:content => "Explanation: : my_pin\nPackage: apache ntop\nPin: release a=my_pin\nPin-Priority: 0\n"
},
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
let :param_hash do
default_params.merge(param_set[:params])
end
let :params do
param_set[:params]
end
it { should contain_class("apt::params") }
it { should contain_file("#{title}.pref").with({
'ensure' => param_hash[:ensure],
'path' => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'content' => param_set[:content],
})
}
end
end
describe 'resource title with invalid chars' do
context 'spaces' do
let(:title) { 'oh my god this is not valid' }
it { should contain_file('oh_my_god_this_is_not_valid.pref') }
end
context '#$&*$' do
let(:title) { 'so && many $* invalid @! things' }
it { should contain_file('so____many____invalid____things.pref') }
end
end
end

View file

@ -0,0 +1,158 @@
require 'spec_helper'
describe 'apt::ppa', :type => :define do
[
{
:lsbdistrelease => '11.04',
:lsbdistcodename => 'natty',
:operatingsystem => 'Ubuntu',
:lsbdistid => 'Ubuntu',
:package => 'python-software-properties'
},
{
:lsbdistrelease => '12.10',
:lsbdistcodename => 'quantal',
:operatingsystem => 'Ubuntu',
:lsbdistid => 'Ubuntu',
:package => 'software-properties-common'
},
].each do |platform|
context "on #{platform[:lsbdistcodename]}" do
let :facts do
{
:lsbdistrelease => platform[:lsbdistrelease],
:lsbdistcodename => platform[:lsbdistcodename],
:operatingsystem => platform[:operatingsystem],
:lsbdistid => platform[:lsbdistid],
:osfamily => 'Debian',
}
end
let :release do
"#{platform[:lsbdistcodename]}"
end
let :package do
"#{platform[:package]}"
end
let :options do
"-y"
end
['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
describe "with title #{t}" do
let :pre_condition do
'class { "apt": }'
end
let :title do
t
end
let :filename do
t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
end
it { should contain_package("#{package}") }
it { should contain_exec("apt_update").with(
'command' => '/usr/bin/apt-get update',
'refreshonly' => true
)
}
it { should contain_exec("add-apt-repository-#{t}").with(
'command' => "/usr/bin/add-apt-repository #{options} #{t}",
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
'require' => ["File[sources.list.d]", "Package[#{package}]"],
'notify' => "Exec[apt_update]"
)
}
it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
'ensure' => 'file',
'require' => "Exec[add-apt-repository-#{t}]"
)
}
end
end
describe 'without a proxy defined' do
let :title do
'rspec_ppa'
end
let :pre_condition do
'class { "apt":
proxy_host => false
}'
end
let :filename do
"#{title}-#{release}.list"
end
it { should contain_exec("add-apt-repository-#{title}").with(
'environment' => [],
'command' => "/usr/bin/add-apt-repository #{options} #{title}",
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
'require' => ["File[sources.list.d]", "Package[#{package}]"],
'notify' => "Exec[apt_update]"
)
}
end
describe 'behind a proxy' do
let :title do
'rspec_ppa'
end
let :pre_condition do
'class { "apt":
proxy_host => "user:pass@proxy",
}'
end
let :filename do
"#{title}-#{release}.list"
end
it { should contain_exec("add-apt-repository-#{title}").with(
'environment' => [
"http_proxy=http://user:pass@proxy:8080",
"https_proxy=http://user:pass@proxy:8080",
],
'command' => "/usr/bin/add-apt-repository #{options} #{title}",
'unless' => "/usr/bin/test -s /etc/apt/sources.list.d/#{filename}",
'require' => ["File[sources.list.d]", "Package[#{package}]"],
'notify' => "Exec[apt_update]"
)
}
end
end
end
[ { :lsbdistcodename => 'natty',
:package => 'python-software-properties' },
{ :lsbdistcodename => 'quantal',
:package => 'software-properties-common'},
].each do |platform|
context "on #{platform[:lsbdistcodename]}" do
describe "it should not error if package['#{platform[:package]}'] is already defined" do
let :pre_condition do
'class {"apt": }' +
'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
end
let :facts do
{:lsbdistcodename => '#{platform[:lsbdistcodename]}',
:operatingsystem => 'Ubuntu',
:lsbdistid => 'Ubuntu',
:osfamily => 'Debian'}
end
let(:title) { "ppa" }
let(:release) { "#{platform[:lsbdistcodename]}" }
it { should contain_package('#{platform[:package]}') }
end
end
end
describe "without Class[apt] should raise a Puppet::Error" do
let(:release) { "natty" }
let(:title) { "ppa" }
it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
end
describe "without release should raise a Puppet::Error" do
let(:title) { "ppa:" }
it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
end
end

View file

@ -0,0 +1,172 @@
require 'spec_helper'
describe 'apt::source', :type => :define do
let(:facts) { { :lsbdistid => 'Debian' } }
GPG_KEY_ID = '4BD6EC30'
let :title do
'my_source'
end
let :default_params do
{
:ensure => 'present',
:location => '',
:release => 'karmic',
:repos => 'main',
:include_src => true,
:required_packages => false,
:key => false,
:key_server => false,
:key_content => false,
:key_source => false,
:pin => false
}
end
[{},
{
:location => 'http://example.com',
:release => 'precise',
:repos => 'security',
:include_src => false,
:required_packages => 'apache',
:key => GPG_KEY_ID,
:key_server => 'keyserver.debian.com',
:pin => '600',
:key_content => 'ABCD1234'
},
{
:key => GPG_KEY_ID,
:key_server => 'keyserver.debian.com',
},
{
:ensure => 'absent',
:location => 'http://example.com',
:release => 'precise',
:repos => 'security',
},
{
:release => '',
},
{
:release => 'custom',
},
{
:architecture => 'amd64',
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
let :param_hash do
default_params.merge(param_set)
end
let :facts do
{:lsbdistcodename => 'karmic', :lsbdistid => 'Ubuntu'}
end
let :params do
param_set
end
let :filename do
"/etc/apt/sources.list.d/#{title}.list"
end
let :content do
content = "# #{title}"
if param_hash[:architecture]
arch = "[arch=#{param_hash[:architecture]}] "
end
content << "\ndeb #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
if param_hash[:include_src]
content << "deb-src #{arch}#{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
end
content
end
it { should contain_apt__params }
it { should contain_file("#{title}.list").with({
'ensure' => param_hash[:ensure],
'path' => filename,
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
'content' => content,
})
}
it {
if param_hash[:pin]
should contain_apt__pin(title).with({
"priority" => param_hash[:pin],
"before" => "File[#{title}.list]"
})
else
should_not contain_apt__pin(title).with({
"priority" => param_hash[:pin],
"before" => "File[#{title}.list]"
})
end
}
it {
should contain_exec("apt_update").with({
"command" => "/usr/bin/apt-get update",
"refreshonly" => true
})
}
it {
if param_hash[:required_packages]
should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
"command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
"subscribe" => "File[#{title}.list]",
"refreshonly" => true,
"before" => 'Exec[apt_update]',
})
else
should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
"command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
"subscribe" => "File[#{title}.list]",
"refreshonly" => true
})
end
}
it {
key_server = param_hash[:key_server] || nil
key_content = param_hash[:key_content] || nil
key_source = param_hash[:key_source] || nil
if param_hash[:key]
should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
"key" => param_hash[:key],
"ensure" => :present,
"key_server" => key_server,
"key_content" => key_content,
"key_source" => key_source,
"before" => "File[#{title}.list]"
})
else
should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
"key" => param_hash[:key],
"ensure" => :present,
"key_server" => param_hash[:key_server],
"key_content" => param_hash[:key_content],
"key_source" => param_hash[:key_source],
"before" => "File[#{title}.list]"
})
end
}
end
end
describe "without release should raise a Puppet::Error" do
let(:default_params) { Hash.new }
let(:facts) { Hash.new }
it { expect { should raise_error(Puppet::Error) } }
let(:facts) { { :lsbdistcodename => 'lucid', :lsbdistid => 'Ubuntu' } }
it { should contain_apt__source(title) }
end
end

View file

@ -0,0 +1 @@
require 'puppetlabs_spec_helper/module_spec_helper'

View file

@ -0,0 +1,33 @@
require 'beaker-rspec'
# Install Puppet
unless ENV['RS_PROVISION'] == 'no'
hosts.each do |host|
if host.is_pe?
install_pe
else
install_puppet
on host, "mkdir -p #{host['distmoduledir']}"
end
end
end
UNSUPPORTED_PLATFORMS = ['RedHat','Suse','windows','AIX','Solaris']
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'apt')
hosts.each do |host|
shell('/bin/touch /etc/puppet/hiera.yaml')
shell('puppet module install puppetlabs-stdlib --version 2.2.1', { :acceptable_exit_codes => [0,1] })
end
end
end

View file

@ -0,0 +1,160 @@
require 'spec_helper'
require 'puppet'
describe Puppet::Type::type(:apt_key) do
context 'only namevar 32bit key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
it 'name is set to id' do
resource[:name].should eq '4BD6EC30'
end
it 'keyserver is default' do
resource[:server].should eq :'keyserver.ubuntu.com'
end
it 'source is not set' do
resource[:source].should eq nil
end
it 'content is not set' do
resource[:content].should eq nil
end
end
context 'with a lowercase 32bit key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '4bd6ec30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
end
context 'with a 64bit key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => 'FFFFFFFF4BD6EC30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
end
context 'with a 0x formatted key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '0x4BD6EC30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
end
context 'with a 0x formatted lowercase key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '0x4bd6ec30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
end
context 'with a 0x formatted 64bit key id' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '0xFFFFFFFF4BD6EC30'
)}
it 'id is set' do
resource[:id].should eq '4BD6EC30'
end
end
context 'with source' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'http://apt.puppetlabs.com/pubkey.gpg'
)}
it 'source is set to the URL' do
resource[:source].should eq 'http://apt.puppetlabs.com/pubkey.gpg'
end
end
context 'with content' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:content => 'http://apt.puppetlabs.com/pubkey.gpg'
)}
it 'content is set to the string' do
resource[:content].should eq 'http://apt.puppetlabs.com/pubkey.gpg'
end
end
context 'with keyserver' do
let(:resource) { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:server => 'http://keyring.debian.org'
)}
it 'keyserver is set to Debian' do
resource[:server].should eq 'http://keyring.debian.org'
end
end
context 'validation' do
it 'raises an error if content and source are set' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'http://apt.puppetlabs.com/pubkey.gpg',
:content => 'Completely invalid as a GPG key'
)}.to raise_error(/content and source are mutually exclusive/)
end
it 'raises an error if a weird length key is used' do
expect { Puppet::Type.type(:apt_key).new(
:id => 'F4BD6EC30',
:source => 'http://apt.puppetlabs.com/pubkey.gpg',
:content => 'Completely invalid as a GPG key'
)}.to raise_error(/Valid values match/)
end
it 'raises an error when an invalid URI scheme is used in source' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'hkp://pgp.mit.edu'
)}.to raise_error(/Valid values match/)
end
it 'allows the http URI scheme in source' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'http://pgp.mit.edu'
)}.to_not raise_error
end
it 'allows the https URI scheme in source' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'https://pgp.mit.edu'
)}.to_not raise_error
end
it 'allows the ftp URI scheme in source' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => 'ftp://pgp.mit.edu'
)}.to_not raise_error
end
it 'allows an absolute path in source' do
expect { Puppet::Type.type(:apt_key).new(
:id => '4BD6EC30',
:source => '/path/to/a/file'
)}.to_not raise_error
end
end
end