Merge pull request #140 from hunner/apt_force
Handling of release parameter and apt provider in force manifest
This commit is contained in:
commit
d1e87d4774
3 changed files with 79 additions and 35 deletions
|
@ -2,21 +2,39 @@
|
||||||
# force a package from a specific release
|
# force a package from a specific release
|
||||||
|
|
||||||
define apt::force(
|
define apt::force(
|
||||||
$release = 'testing',
|
$release = false,
|
||||||
$version = false,
|
$version = false,
|
||||||
$timeout = 300
|
$timeout = 300
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
$provider = $apt::params::provider
|
||||||
|
|
||||||
$version_string = $version ? {
|
$version_string = $version ? {
|
||||||
false => undef,
|
false => undef,
|
||||||
default => "=${version}",
|
default => "=${version}",
|
||||||
}
|
}
|
||||||
|
|
||||||
$install_check = $version ? {
|
$release_string = $release ? {
|
||||||
false => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
|
false => undef,
|
||||||
default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
|
default => "-t ${release}",
|
||||||
}
|
}
|
||||||
exec { "/usr/bin/apt-get -y -t ${release} install ${name}${version_string}":
|
|
||||||
|
if $version == false {
|
||||||
|
if $release == false {
|
||||||
|
$install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'"
|
||||||
|
} else {
|
||||||
|
# If installed version and candidate version differ, this check returns 1 (false).
|
||||||
|
$install_check = "/usr/bin/test \$(/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -E 'Installed|Candidate' | /usr/bin/uniq -s 14 | /usr/bin/wc -l) -eq 1"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if $release == false {
|
||||||
|
$install_check = "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'"
|
||||||
|
} else {
|
||||||
|
$install_check = "/usr/bin/apt-cache policy -t ${release} ${name} | /bin/grep -q 'Installed: ${version}'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exec { "${provider} -y ${release_string} install ${name}${version_string}":
|
||||||
unless => $install_check,
|
unless => $install_check,
|
||||||
logoutput => 'on_failure',
|
logoutput => 'on_failure',
|
||||||
timeout => $timeout,
|
timeout => $timeout,
|
||||||
|
|
|
@ -1,41 +1,57 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
describe 'apt::force', :type => :define do
|
describe 'apt::force', :type => :define do
|
||||||
|
let :pre_condition do
|
||||||
|
'include apt::params'
|
||||||
|
end
|
||||||
|
|
||||||
let :title do
|
let :title do
|
||||||
'my_package'
|
'my_package'
|
||||||
end
|
end
|
||||||
|
|
||||||
let :default_params do
|
let :default_params do
|
||||||
{
|
{
|
||||||
:release => 'testing',
|
:release => false,
|
||||||
:version => false
|
:version => false
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
[{},
|
describe "when using default parameters" do
|
||||||
{
|
|
||||||
:release => 'stable',
|
|
||||||
:version => '1'
|
|
||||||
}
|
|
||||||
].each do |param_set|
|
|
||||||
describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
|
|
||||||
let :param_hash do
|
|
||||||
default_params.merge(param_set)
|
|
||||||
end
|
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
param_set
|
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
|
end
|
||||||
|
|
||||||
let :unless_query do
|
describe "when specifying release parameter" do
|
||||||
base_command = "/usr/bin/dpkg -s #{title} | grep -q "
|
let :params do
|
||||||
base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
|
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
|
end
|
||||||
|
|
||||||
let :exec_title do
|
describe "when specifying version parameter" do
|
||||||
base_exec = "/usr/bin/apt-get -y -t #{param_hash[:release]} install #{title}"
|
let :params do
|
||||||
base_exec + (params[:version] ? "=#{params[:version]}" : "")
|
default_params.merge(:version => '1')
|
||||||
end
|
|
||||||
it { should contain_exec(exec_title).with_unless(unless_query) }
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
# force.pp
|
# force.pp
|
||||||
# force a package from a specific release
|
|
||||||
|
|
||||||
apt::force { 'package':
|
# force a package from a specific release
|
||||||
release => 'testing',
|
apt::force { 'package1':
|
||||||
version => false
|
release => 'backports',
|
||||||
|
}
|
||||||
|
|
||||||
|
# force a package to be a specific version
|
||||||
|
apt::force { 'package2':
|
||||||
|
version => '1.0.0-1',
|
||||||
|
}
|
||||||
|
|
||||||
|
# force a package from a specific release to be a specific version
|
||||||
|
apt::force { 'package3':
|
||||||
|
release => 'sid',
|
||||||
|
version => '2.0.0-1',
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue