Add testing, docs, and examples for backports
authorMorgan Haskel <morgan@puppetlabs.com>
Tue, 7 Apr 2015 19:12:06 +0000 (12:12 -0700)
committerMorgan Haskel <morgan@puppetlabs.com>
Sun, 12 Apr 2015 18:25:47 +0000 (11:25 -0700)
README.md
examples/backports.pp
manifests/params.pp
manifests/source.pp
spec/classes/apt_backports_spec.rb [new file with mode: 0644]

index 26feda3818cc2f758bf9d5289dc764b72c798e71..d461d05d2b6d0d3cf6de47c3b8ab0f86efa1186f 100644 (file)
--- a/README.md
+++ b/README.md
@@ -41,6 +41,12 @@ class { 'apt': }
 
 * `apt`: Main class, provides common resources and options. Allows Puppet to manage your system's sources.list file and sources.list.d directory. By default, it will purge any existing content it finds that wasn't declared with Puppet.
   
+  * `apt::backports`: This class adds the necessary components to get backports for Ubuntu and Debian. The release name defaults to "$lsbdistcodename-backports". Setting this manually can cause undefined and potentially serious behavior.
+
+    By default, this class drops a pin-file for backports, pinning it to a priority of 200. This is lower than the normal Debian archive, which gets a priority of 500 to ensure that packages with `ensure => latest` don't get magically upgraded from backports without your explicit permission.
+
+      If you raise the priority through the `pin` parameter to 500---identical to the rest of the Debian mirrors---normal policy goes into effect, and Apt installs or upgrades to the newest version. This means that if a package is available from backports, it and its dependencies are pulled in from backports unless you explicitly set the `ensure` attribute of the `package` resource to `installed`/`present` or a specific version.
+
 * `apt::params`: Sets defaults for the apt module parameters.
 
 * `apt::update`: Runs `apt-get update`, updating the list of available packages and their versions without installing or upgrading any packages. The update runs on the first Puppet run after you include the class, then whenever `notify  => Exec['apt_update']` occurs; i.e., whenever config files get updated or other relevant changes occur. If you set `update['frequency']` to `'always'`, the update runs on every Puppet run.
@@ -178,7 +184,7 @@ apt::sources:
 
 ### Parameters
 
-#### apt
+####apt
 
 * `update`: Hash to configure various update settings. Valid keys are:
   * 'frequency': The run frequency for `apt-get update`. Defaults to 'reluctantly'. Accepts the following values:
@@ -202,6 +208,14 @@ apt::sources:
 * `settings`: Passes a hash to `create\_resource` to make new `apt::setting` resources.
 * `sources`: Passes a hash to `create\_resource` to make new `apt::source` resources.
 
+####apt::backports
+
+* `location`: The URL of the apt repository. OS-dependent defaults are specifed in `apt::params` for Ubuntu and Debian. Required parameter for other OSes.
+* `release`: The distribution of the apt repository. Defaults to "${lsbdistcodename}-backports" for Ubuntu and Debian. Required parameter for other OSes.
+* `repos`: The component of the apt repository. OS-dependent defaults are speicifed in `apt::params` for Ubuntu and Debian. Required parameter for other OSes.
+* `key`: The key for the backports repository. Can either be a string or a hash. See apt::setting for details on passing key as a hash. OS-dependent defaults are specified in `apt::params` for Ubuntu and Debian. Required parameter for other OSes.
+* `pin`: The pin priority for backports repository. Can either be a number, a string, or a hash that will be passed as parameters to `apt::pin`. Defaults to `200`.
+
 ####apt::conf
 
 * `content`: The content of the configuration file.
@@ -269,7 +283,7 @@ It is recommended to read the manpage 'apt_preferences(5)'
   * 'content': See `content` in `apt::key`
   * 'source': See `source` in `apt::key`
   * 'options': See `options` in `apt::key`
-* `pin`: See apt::pin. Defaults to false.
+* `pin`: See apt::pin. Defaults to undef. Can be a string, number, or a hash to be passed as parameters to `apt::pin`.
 * `architecture`: can be used to specify for which architectures information should be downloaded. If this option is not set all architectures defined by the APT::Architectures option will be downloaded. Defaults to `undef` which means all. Example values can be 'i386' or 'i386,alpha,powerpc'.
 * `allow\_unsigned`: can be set to indicate that packages from this source are always authenticated even if the Release file is not signed or the signature can't be checked. Defaults to `false`. Can be `true` or `false`.
 
index ed8213f0fa78072f54ecb4ef05c485886fbfee34..fe77da39653e185179b69cfd225d1a87aec5bf48 100644 (file)
@@ -1,31 +1,10 @@
-$location = $::apt::distcodename ? {
-  'squeeze' => 'http://backports.debian.org/debian-backports',
-  'wheezy'  => 'http://ftp.debian.org/debian/',
-  default   => 'http://archive.ubuntu.com/ubuntu',
-}
-
-if $::apt::distid == 'debian' {
-  $repos   = 'main contrib non-free'
-  $key     = 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553'
-  $release = $::apt::distcodename
-} else {
-  $repos   = 'main universe multiverse restricted'
-  $key     = '630239CC130E1A7FD81A27B140976EAF437D05B5'
-  $release = $::apt::distcodename
-}
-
-# set up the actual backports
-apt::pin { 'backports':
-  release  => "${release}-backports",
-  priority => 200,
-}
-
-apt::source { 'backports':
-  location => $location,
-  release  => "${release}-backports",
-  repos    => $repos,
+# Set up a backport for linuxmint qiana
+apt::backports { 'qiana':
+  location => 'http://us.archive.ubuntu.com/ubuntu',
+  release  => 'trusty-backports',
+  repos    => 'main universe multiverse restricted',
   key      => {
-    id     => $key,
+    id     => '630239CC130E1A7FD81A27B140976EAF437D05B5',
     server => 'pgp.mit.edu',
   },
 }
index 6f7e5f9dc04dbc7d83f2a539ee9ffc7a428b92f7..ef9904df87a5c5d2b1899dd5220ad8a6a93277d1 100644 (file)
@@ -122,24 +122,28 @@ class apt::params {
     'debian': {
       case $distcodename {
         'squeeze': {
-          $backports = {'location' => 'http://backports.debian.org/debian-backports',
-                        'key'       => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
-                        'repos'     => 'main contrib non-free',
+          $backports = {
+            'location' => 'http://backports.debian.org/debian-backports',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
           }
         }
         default: {
-          $backports = {'location' => 'http://ftp.debian.org/debian/',
-                        'key'       => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD624692555',
-                        'repos'     => 'main contrib non-free',
+          $backports = {
+            'location' => 'http://ftp.debian.org/debian/',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
           }
         }
       }
     }
     'ubuntu': {
-      $backports = {'location' => 'http://archive.ubuntu.com/ubuntu',
-                    'key'       => '630239CC130E1A7FD81A27B140976EAF437D05B5',
-                    'repos'     => 'main universe multiverse restricted',
+      $backports = {
+        'location' => 'http://archive.ubuntu.com/ubuntu',
+        'key'      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        'repos'    => 'main universe multiverse restricted',
       }
+
       case $distcodename {
         'lucid': {
           $ppa_options        = undef
@@ -162,6 +166,7 @@ class apt::params {
     '', default: {
       $ppa_options = undef
       $ppa_package = undef
+      $backports   = undef
     }
   }
 }
index 24d0ae4b8dff795d874ee1b588170ed544e0eced..40fc015bb6e8a194038d50e1f7444cb0bfc965b8 100644 (file)
@@ -59,7 +59,7 @@ define apt::source(
     } else {
       fail('Received invalid value for pin parameter')
     }
-    create_resources('apt::pin', { $name => $_pin })
+    create_resources('apt::pin', { "${name}" => $_pin })
   }
 
   # We do not want to remove keys when the source is absent.
diff --git a/spec/classes/apt_backports_spec.rb b/spec/classes/apt_backports_spec.rb
new file mode 100644 (file)
index 0000000..b9077a6
--- /dev/null
@@ -0,0 +1,261 @@
+#!/usr/bin/env rspec
+require 'spec_helper'
+
+describe 'apt::backports', :type => :class do
+  let (:pre_condition) { "class{ '::apt': }" }
+  describe 'debian/ubuntu tests' do
+    context 'defaults on deb' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'wheezy',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://ftp.debian.org/debian/',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main contrib non-free',
+        :release  => 'wheezy-backports',
+        :pin      => 200,
+      })
+      }
+    end
+    context 'defaults on squeeze' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Debian',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'squeeze',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://backports.debian.org/debian-backports',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main contrib non-free',
+        :release  => 'squeeze-backports',
+        :pin      => 200,
+      })
+      }
+    end
+    context 'defaults on ubuntu' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu',
+        :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        :repos    => 'main universe multiverse restricted',
+        :release  => 'trusty-backports',
+        :pin      => 200,
+      })
+      }
+    end
+    context 'set everything' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+        }
+      end
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu-test',
+          :release  => 'vivid',
+          :repos    => 'main',
+          :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+          :pin      => '90',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu-test',
+        :key      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+        :repos    => 'main',
+        :release  => 'vivid',
+        :pin      => 90,
+      })
+      }
+    end
+    context 'set things with hashes' do
+      let(:facts) do
+        {
+          :lsbdistid       => 'Ubuntu',
+          :osfamily        => 'Debian',
+          :lsbdistcodename => 'trusty',
+        }
+      end
+      let(:params) do
+        {
+          :key => {
+            'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+          },
+          :pin => {
+            'priority' => '90',
+          },
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :key      => { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
+        :pin      => { 'priority' => '90' },
+      })
+      }
+    end
+  end
+  describe 'mint tests' do
+    let(:facts) do
+      {
+        :lsbdistid       => 'linuxmint',
+        :osfamily        => 'Debian',
+        :lsbdistcodename => 'qiana',
+      }
+    end
+    context 'sets all the needed things' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it { is_expected.to contain_apt__source('backports').with({
+        :location => 'http://archive.ubuntu.com/ubuntu',
+        :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        :repos    => 'main universe multiverse restricted',
+        :release  => 'trusty-backports',
+        :pin      => 200,
+      })
+      }
+    end
+    context 'missing location' do
+      let(:params) do
+        {
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing release' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :repos    => 'main universe multiverse restricted',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing repos' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :key      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+    context 'missing key' do
+      let(:params) do
+        {
+          :location => 'http://archive.ubuntu.com/ubuntu',
+          :release  => 'trusty-backports',
+          :repos    => 'main universe multiverse restricted',
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key/)
+      end
+    end
+  end
+  describe 'validation' do
+    let(:facts) do
+      {
+        :lsbdistid       => 'Ubuntu',
+        :osfamily        => 'Debian',
+        :lsbdistcodename => 'trusty',
+      }
+    end
+    context 'invalid location' do
+      let(:params) do
+        {
+          :location => true
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid release' do
+      let(:params) do
+        {
+          :release => true
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid repos' do
+      let(:params) do
+        {
+          :repos => true
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid key' do
+      let(:params) do
+        {
+          :key => true
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /is not a string/)
+      end
+    end
+    context 'invalid pin' do
+      let(:params) do
+        {
+          :pin => true
+        }
+      end
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /pin must be either a string, number or hash/)
+      end
+    end
+  end
+end