From ef7d149d5a6b014b53b12925bb5d6638192ac08d Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Fri, 14 Feb 2014 16:13:14 +0100 Subject: [PATCH] apt::pin: Allow for packages to be an array. --- README.md | 4 ++++ manifests/pin.pp | 8 +++++++- spec/acceptance/pin_spec.rb | 20 ++++++++++++++++++++ spec/defines/pin_spec.rb | 8 +++++++- templates/pin.pref.erb | 2 +- 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d07bbb0..3a7bc8c 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/manifests/pin.pp b/manifests/pin.pp index 402e79e..9cb4a8e 100644 --- a/manifests/pin.pp +++ b/manifests/pin.pp @@ -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 diff --git a/spec/acceptance/pin_spec.rb b/spec/acceptance/pin_spec.rb index b5a0044..a38dfa4 100644 --- a/spec/acceptance/pin_spec.rb +++ b/spec/acceptance/pin_spec.rb @@ -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 diff --git a/spec/defines/pin_spec.rb b/spec/defines/pin_spec.rb index 7a58e78..179a2f3 100644 --- a/spec/defines/pin_spec.rb +++ b/spec/defines/pin_spec.rb @@ -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 diff --git a/templates/pin.pref.erb b/templates/pin.pref.erb index 62c44c7..42e23c7 100644 --- a/templates/pin.pref.erb +++ b/templates/pin.pref.erb @@ -17,6 +17,6 @@ end -%> # <%= @name %> Explanation: <%= @explanation %> -Package: <%= @packages %> +Package: <%= @packages_string %> Pin: <%= @pin %> Pin-Priority: <%= @priority %> -- 2.45.2