Merge pull request #27 from blkperl/ticket_12809_refactor_release
(#12809) $release should use $lsbdistcodename and fall back to manual in... Reviewed and tested by Ryan Coleman (ryan@puppetlabs.com)
This commit is contained in:
commit
9f570782aa
5 changed files with 65 additions and 22 deletions
|
@ -1,4 +1,5 @@
|
||||||
class apt::params {
|
class apt::params {
|
||||||
$root = '/etc/apt'
|
$root = '/etc/apt'
|
||||||
$provider = '/usr/bin/apt-get'
|
$provider = '/usr/bin/apt-get'
|
||||||
|
$sources_list_d = "${root}/sources.list.d"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,36 @@
|
||||||
# ppa.pp
|
# ppa.pp
|
||||||
|
|
||||||
define apt::ppa() {
|
define apt::ppa(
|
||||||
|
$release = $lsbdistcodename
|
||||||
|
) {
|
||||||
|
|
||||||
Class['apt'] -> Apt::Ppa[$title]
|
Class['apt'] -> Apt::Ppa[$title]
|
||||||
|
|
||||||
|
include apt::params
|
||||||
|
|
||||||
|
if ! $release {
|
||||||
|
fail("lsbdistcodename fact not available: release parameter required")
|
||||||
|
}
|
||||||
|
|
||||||
exec { "apt-update-${name}":
|
exec { "apt-update-${name}":
|
||||||
command => "/usr/bin/aptitude update",
|
command => "/usr/bin/aptitude update",
|
||||||
refreshonly => true,
|
refreshonly => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filename_without_slashes = regsubst($name,'/','-','G')
|
||||||
|
$filename_without_ppa = regsubst($filename_without_slashes, '^ppa:','','G')
|
||||||
|
$sources_list_d_filename = "${filename_without_ppa}-${release}.list"
|
||||||
|
|
||||||
exec { "add-apt-repository-${name}":
|
exec { "add-apt-repository-${name}":
|
||||||
command => "/usr/bin/add-apt-repository ${name}",
|
command => "/usr/bin/add-apt-repository ${name}",
|
||||||
notify => Exec["apt-update-${name}"],
|
notify => Exec["apt-update-${name}"],
|
||||||
unless => $name? {
|
creates => "${apt::params::sources_list_d}/${sources_list_d_filename}",
|
||||||
/ppa:(.*)/ => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*ppa.*$1.*$'",
|
}
|
||||||
default => "/bin/cat /etc/apt/sources.list /etc/apt/sources.list.d/* | /bin/egrep '^[^#].*${title}.*$'",
|
|
||||||
}
|
file { "${apt::params::sources_list_d}/${sources_list_d_filename}":
|
||||||
}
|
ensure => file,
|
||||||
|
require => Exec["add-apt-repository-${name}"];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
define apt::source(
|
define apt::source(
|
||||||
$location = '',
|
$location = '',
|
||||||
$release = 'karmic',
|
$release = $lsbdistcodename,
|
||||||
$repos = 'main',
|
$repos = 'main',
|
||||||
$include_src = true,
|
$include_src = true,
|
||||||
$required_packages = false,
|
$required_packages = false,
|
||||||
|
@ -15,6 +15,10 @@ define apt::source(
|
||||||
|
|
||||||
include apt::params
|
include apt::params
|
||||||
|
|
||||||
|
if ! $release {
|
||||||
|
fail("lsbdistcodename fact not available: release parameter required")
|
||||||
|
}
|
||||||
|
|
||||||
file { "${name}.list":
|
file { "${name}.list":
|
||||||
path => "${apt::params::root}/sources.list.d/${name}.list",
|
path => "${apt::params::root}/sources.list.d/${name}.list",
|
||||||
ensure => file,
|
ensure => file,
|
||||||
|
|
|
@ -1,37 +1,53 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe 'apt::ppa', :type => :define do
|
describe 'apt::ppa', :type => :define do
|
||||||
['ppa:dans_ppa', 'dans_ppa'].each do |t|
|
['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
|
||||||
describe "with title #{t}" do
|
describe "with title #{t}" do
|
||||||
let :pre_condition do
|
let :pre_condition do
|
||||||
'class { "apt": }'
|
'class { "apt": }'
|
||||||
end
|
end
|
||||||
|
let :facts do
|
||||||
|
{:lsbdistcodename => 'natty'}
|
||||||
|
end
|
||||||
let :title do
|
let :title do
|
||||||
t
|
t
|
||||||
end
|
end
|
||||||
let :unless_statement do
|
let :release do
|
||||||
if t =~ /ppa:(.*)/
|
"natty"
|
||||||
/^[^#].*ppa.*#{$1}.*$/
|
|
||||||
else
|
|
||||||
/^[^#].*#{t}.*$/
|
|
||||||
end
|
end
|
||||||
|
let :filename do
|
||||||
|
t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
|
||||||
end
|
end
|
||||||
it { should contain_exec("add-apt-repository-#{t}").with(
|
|
||||||
'command' => "/usr/bin/add-apt-repository #{t}",
|
|
||||||
'notify' => "Exec[apt-update-#{t}]"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
it { should contain_exec("add-apt-repository-#{t}").with({"unless" => unless_statement}) }
|
|
||||||
it { should contain_exec("apt-update-#{t}").with(
|
it { should contain_exec("apt-update-#{t}").with(
|
||||||
'command' => '/usr/bin/aptitude update',
|
'command' => '/usr/bin/aptitude update',
|
||||||
'refreshonly' => true
|
'refreshonly' => true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
it { should contain_exec("apt-update-#{t}").without_unless }
|
|
||||||
|
it { should contain_exec("add-apt-repository-#{t}").with(
|
||||||
|
'command' => "/usr/bin/add-apt-repository #{t}",
|
||||||
|
'notify' => "Exec[apt-update-#{t}]",
|
||||||
|
'creates' => "/etc/apt/sources.list.d/#{filename}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
|
||||||
|
'ensure' => 'file',
|
||||||
|
'require' => "Exec[add-apt-repository-#{t}]"
|
||||||
|
)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "without Class[apt] should raise a Puppet::Error" do
|
describe "without Class[apt] should raise a Puppet::Error" do
|
||||||
|
let(:release) { "natty" }
|
||||||
let(:title) { "ppa" }
|
let(:title) { "ppa" }
|
||||||
it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
|
it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -41,6 +41,10 @@ describe 'apt::source', :type => :define do
|
||||||
default_params.merge(param_set)
|
default_params.merge(param_set)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let :facts do
|
||||||
|
{:lsbdistcodename => 'karmic'}
|
||||||
|
end
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
param_set
|
param_set
|
||||||
end
|
end
|
||||||
|
@ -157,5 +161,8 @@ describe 'apt::source', :type => :define do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
describe "without release should raise a Puppet::Error" do
|
||||||
|
it { expect { should contain_apt__source(:release) }.to raise_error(Puppet::Error) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue