apt::pin: Allow for packages to be an array.
authorDaniele Sluijters <github@daenney.net>
Fri, 14 Feb 2014 15:13:14 +0000 (16:13 +0100)
committerDaniele Sluijters <github@daenney.net>
Sun, 16 Feb 2014 13:51:39 +0000 (14:51 +0100)
README.md
manifests/pin.pp
spec/acceptance/pin_spec.rb
spec/defines/pin_spec.rb
templates/pin.pref.erb

index d07bbb0eced9d969a322e9f408bdb27057c81888..3a7bc8ca0c2a061fc2d99266336cb041d9650f24 100644 (file)
--- 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`.
index 402e79ede7a813327ec956935e07a2d9ee4e15d0..9cb4a8e798ba5ef3a0e1caa05275e5ba53137201 100644 (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
index b5a004429b72ae2429f708ed1e95277d30e97e6c..a38dfa4b2702d0e3e2af33b4e4e7acb35b2d4360 100644 (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
index 7a58e78d1f18ef4fc6bd02e02a1576390f45e023..179a2f3ac5bcf48e7bfc80b67c54334f76da093b 100644 (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
index 62c44c72414b41551ad8334c468ec70ba8ccc80f..42e23c7edd2a1ec694fbc6265495d268dfb354d8 100644 (file)
@@ -17,6 +17,6 @@ end
 -%>
 # <%= @name %>
 Explanation: <%= @explanation %>
-Package: <%= @packages %>
+Package: <%= @packages_string %>
 Pin: <%= @pin %>
 Pin-Priority: <%= @priority %>