Get rid of hold

This commit is contained in:
Morgan Haskel 2015-02-15 10:59:00 -08:00
parent 0809774006
commit 8ef58a456d
3 changed files with 5 additions and 151 deletions

5
examples/hold.pp Normal file
View file

@ -0,0 +1,5 @@
apt::pin { 'hold-vim':
packages => 'vim',
version => '2:7.4.488-5',
priority => 1001,
}

View file

@ -1,54 +0,0 @@
# == Define apt::hold
#
# This defined type allows you to hold a package based on the version you
# require. It's implemented by dropping an apt preferences file pinning the
# package to the version you require.
#
# === Parameters
#
# [*version*]
# The version at which you wish to pin a package.
#
# This can either be the full version, such as 4:2.11.8.1-5, or
# a partial version, such as 4:2.11.*
#
# [*package*]
# _default_: +$title+, the title/name of the resource.
#
# Name of the package that apt is to hold.
#
# [*priority*]
# _default_: +1001+
#
# The default priority of 1001 causes this preference to always win. By
# setting the priority to a number greater than 1000 apt will always install
# this version even if it means downgrading the currently installed version.
define apt::hold(
$version,
$ensure = 'present',
$package = $title,
$priority = 1001,
){
validate_string($title)
validate_re($ensure, ['^present|absent',])
validate_string($package)
validate_string($version)
if ! is_integer($priority) {
fail('$priority must be an integer')
}
if $ensure == 'present' {
::apt::pin { "hold_${package}":
packages => $package,
version => $version,
priority => $priority,
}
} else {
::apt::pin { "hold_${package}":
ensure => 'absent',
}
}
}

View file

@ -1,97 +0,0 @@
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__pin("hold_#{title}").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__pin("hold_#{title}").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__pin("hold_#{title}").with({
:ensure => 'present',
:packages => title,
:version => params[:version],
:priority => params[:priority],
})
end
end
describe 'package => foo' do
let :params do default_params.merge({:package => 'foo'}) end
it 'creates an apt preferences file' do
should contain_apt__pin("hold_foo").with({
:ensure => 'present',
:packages => 'foo',
:version => params[:version],
:priority => 1001,
})
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