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,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