Merge pull request #564 from rfdrake/apt_pin
authorDavid Schmitt <david.schmitt@puppetlabs.com>
Mon, 7 Sep 2015 11:11:31 +0000 (12:11 +0100)
committerDavid Schmitt <david.schmitt@puppetlabs.com>
Mon, 7 Sep 2015 11:11:31 +0000 (12:11 +0100)
Add support for creating pins from main class

README.md
manifests/init.pp
spec/classes/apt_spec.rb

index b2b554633db17a631da51d75a51165f471402037..1c9591dcb71779a26205661f2531cecf0a57a898 100644 (file)
--- a/README.md
+++ b/README.md
@@ -243,7 +243,9 @@ Main class, includes all other classes.
 
 * `settings`: Creates new `apt::setting` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}.
 
-* `sources`: Creates new `apt::setting` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}.
+* `sources`: Creates new `apt::source` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}.
+
+* `pins`: Creates new `apt::pin` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}.
 
 * `update`: Configures various update settings. Valid options: a hash made up from the following keys:
 
index b9087cfb7abae68714edd30ab66c2c28df5216d5..2e82502622126488f41c8f312c6fc247148c6e6c 100644 (file)
@@ -6,6 +6,7 @@ class apt(
   $sources  = {},
   $keys     = {},
   $ppas     = {},
+  $pins     = {},
   $settings = {},
 ) inherits ::apt::params {
 
@@ -66,6 +67,7 @@ class apt(
   validate_hash($keys)
   validate_hash($settings)
   validate_hash($ppas)
+  validate_hash($pins)
 
   if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
     apt::setting { 'conf-proxy':
@@ -153,4 +155,9 @@ class apt(
   if $settings {
     create_resources('apt::setting', $settings)
   }
+
+  # manage pins if present
+  if $pins {
+    create_resources('apt::pin', $pins)
+  }
 }
index 7578d2eb78d80735f7a85932425e0c207f4117b9..5aded56b755bf5153001fff6185c91fd8d5f85e7 100644 (file)
@@ -237,6 +237,23 @@ describe 'apt' do
     it { is_expected.to contain_apt__setting('pref-banana')}
   end
 
+  context 'with pins defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+        :puppetversion   => Puppet.version,
+      }
+    end
+    let(:params) { { :pins => {
+      'stable' => { 'priority' => 600, 'order' => 50 },
+      'testing' =>  { 'priority' => 700, 'order' => 100 },
+    } } }
+
+    it { is_expected.to contain_apt__pin('stable') }
+    it { is_expected.to contain_apt__pin('testing') }
+  end
+
   describe 'failing tests' do
     context "purge['sources.list']=>'banana'" do
       let(:params) { { :purge => { 'sources.list' => 'banana' }, } }