apt::pin: Allow for packages to be an array.

This commit is contained in:
Daniele Sluijters 2014-02-14 16:13:14 +01:00
parent 3be1f4323f
commit ef7d149d5a
5 changed files with 39 additions and 3 deletions

View file

@ -115,6 +115,10 @@ Note you can also specifying more complex pins using distribution properties.
label => 'Debian'
}
If you wish to pin a number of packages you may specify the packages as a space
delimited string using the `packages` attribute or pass in an array of package
names.
### apt::ppa
Adds a ppa repository using `add-apt-repository`.

View file

@ -37,7 +37,13 @@ define apt::pin(
# Read the manpage 'apt_preferences(5)', especially the chapter
# 'Thea Effect of APT Preferences' to understand the following logic
# and the difference between specific and general form
if $packages != '*' { # specific form
if is_array($packages) {
$packages_string = join($packages, ' ')
} else {
$packages_string = $packages
}
if $packages_string != '*' { # specific form
if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
( $origin != '' and ( $pin_release != '' or $version != '' )) or

View file

@ -91,6 +91,26 @@ describe 'apt::pin define' do
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

View file

@ -65,7 +65,7 @@ describe 'apt::pin', :type => :define do
{
:params => {
:packages => 'apache',
:priority => '1',
:priority => '1',
:release => 'stable',
:codename => 'wheezy',
:release_version => '3.0',
@ -75,6 +75,12 @@ describe 'apt::pin', :type => :define do
},
:content => "# my_pin\nExplanation: : 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 => "# my_pin\nExplanation: : 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

View file

@ -17,6 +17,6 @@ end
-%>
# <%= @name %>
Explanation: <%= @explanation %>
Package: <%= @packages %>
Package: <%= @packages_string %>
Pin: <%= @pin %>
Pin-Priority: <%= @priority %>