]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #489 from mhaskel/2.0.0-prep
authorHunter Haugen <hunter@puppetlabs.com>
Tue, 14 Apr 2015 18:19:40 +0000 (11:19 -0700)
committerHunter Haugen <hunter@puppetlabs.com>
Tue, 14 Apr 2015 18:19:40 +0000 (11:19 -0700)
2.0.0 prep

16 files changed:
README.md
examples/backports.pp
examples/force.pp
examples/key.pp
examples/source.pp
manifests/backports.pp [new file with mode: 0644]
manifests/conf.pp
manifests/params.pp
manifests/ppa.pp
manifests/source.pp
spec/classes/apt_backports_spec.rb [new file with mode: 0644]
spec/classes/apt_spec.rb
spec/classes/params_spec.rb
spec/defines/conf_spec.rb
spec/defines/ppa_spec.rb
spec/defines/source_spec.rb

index 26feda3818cc2f758bf9d5289dc764b72c798e71..318bc53d2c13b732eb599001841f779b30412486 100644 (file)
--- a/README.md
+++ b/README.md
@@ -39,8 +39,14 @@ class { 'apt': }
 
 ### Classes
 
-* `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`: 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 not purge 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:
@@ -189,10 +195,10 @@ apt::sources:
   * 'timeout': Overrides the exec timeout in seconds for `apt-get update`. Defaults to exec default (300).
   * 'tries': Sets how many times to attempt running `apt-get update`. Use this to work around transient DNS and HTTP errors. By default, the command runs only once.
 * `purge`: Hash to configure various purge settings. Valid keys are:
-  * 'sources.list': If set to 'true', Puppet purges all unmanaged entries from sources.list. Accepts `true` or `false`. Defaults to `true`.
-  * 'sources.list.d': If set to 'true', Puppet purges all unmanaged entries from sources.list.d. Accepts `true` or `false`. Defaults to `true`.
-  * 'preferences.list': If set to 'true', Puppet purges all unmanaged entries from preferences.list. Accepts `true` or `false`. Defaults to `true`.
-  * 'preferences.list.d': If set to 'true', Puppet purges all unmanaged entries from preferences.list.d. Accepts `true` or `false`. Defaults to `true`.
+  * 'sources.list': If set to 'true', Puppet purges all unmanaged entries from sources.list. Accepts `true` or `false`. Defaults to `false`.
+  * 'sources.list.d': If set to 'true', Puppet purges all unmanaged entries from sources.list.d. Accepts `true` or `false`. Defaults to `false`.
+  * 'preferences.list': If set to 'true', Puppet purges all unmanaged entries from preferences.list. Accepts `true` or `false`. Defaults to `false`.
+  * 'preferences.list.d': If set to 'true', Puppet purges all unmanaged entries from preferences.list.d. Accepts `true` or `false`. Defaults to `false`.
 * `proxy`: Hash to configure various proxy settings. Valid keys are:
   * 'host': Configures a proxy host and stores the configuration in /etc/apt/apt.conf.d/01proxy.
   * 'port': Configures a proxy port and stores the configuration in /etc/apt/apt.conf.d/01proxy.
@@ -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..0dfe084850cf774e121172c3ab8846f8894652d5 100644 (file)
@@ -1,31 +1,11 @@
-$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
+class { 'apt': }
+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 355d91f03a2e7a96cf7899b2140a24b967e4c103..4cfaa96fd9bd357d39883e0752dc8c7363b4a115 100644 (file)
@@ -1,10 +1,10 @@
 #if you need to specify a release
-$rel_string = "-t ${release}"
+$rel_string = '-t <release>'
 #else
 $rel_string = ''
 
 #if you need to specify a version
-$ensure = $version
+$ensure = '<version>'
 #else 
 $ensure = installed
 
@@ -22,7 +22,7 @@ $config_missing = '-o Dpkg::Options::="--force-confmiss"'
 #else
 $config_missing = ''
 
-package { $package:
+package { '<package>':
   ensure          => $ensure,
-  install_options => "${config_files} ${config_missing} ${release_string}",
+  install_options => "${config_files} ${config_missing} ${rel_string}",
 }
index 79e0e1b749ab17bb853548ba8188fa665d8529ab..cc8681fbf8aadfb315c143b2065e4d4ee19b8f43 100644 (file)
@@ -1,6 +1,6 @@
 # Declare Apt key for apt.puppetlabs.com source
 apt::key { 'puppetlabs':
-  key         => '4BD6EC30',
-  key_server  => 'pgp.mit.edu',
-  key_options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"',
+  id      => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
+  server  => 'pgp.mit.edu',
+  options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"',
 }
index 823b37b73632667f88d165e9559890cdb5decfcd..33dc2a1938601cdc8bde6492be77f1e38baa66fe 100644 (file)
@@ -4,26 +4,32 @@ class { 'apt': }
 # Install the puppetlabs apt source
 # Release is automatically obtained from lsbdistcodename fact if available.
 apt::source { 'puppetlabs':
-  location   => 'http://apt.puppetlabs.com',
-  repos      => 'main',
-  key        => '4BD6EC30',
-  key_server => 'pgp.mit.edu',
+  location => 'http://apt.puppetlabs.com',
+  repos    => 'main',
+  key      => {
+    id     => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
+    server => 'pgp.mit.edu',
+  },
 }
 
 # test two sources with the same key
 apt::source { 'debian_testing':
-  location   => 'http://debian.mirror.iweb.ca/debian/',
-  release    => 'testing',
-  repos      => 'main contrib non-free',
-  key        => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
-  key_server => 'subkeys.pgp.net',
-  pin        => '-10',
+  location => 'http://debian.mirror.iweb.ca/debian/',
+  release  => 'testing',
+  repos    => 'main contrib non-free',
+  key      => {
+    id     => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+    server => 'subkeys.pgp.net',
+  },
+  pin      => '-10',
 }
 apt::source { 'debian_unstable':
-  location   => 'http://debian.mirror.iweb.ca/debian/',
-  release    => 'unstable',
-  repos      => 'main contrib non-free',
-  key        => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
-  key_server => 'subkeys.pgp.net',
-  pin        => '-10',
+  location => 'http://debian.mirror.iweb.ca/debian/',
+  release  => 'unstable',
+  repos    => 'main contrib non-free',
+  key      => {
+    id     => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+    server => 'subkeys.pgp.net',
+  },
+  pin      => '-10',
 }
diff --git a/manifests/backports.pp b/manifests/backports.pp
new file mode 100644 (file)
index 0000000..3cac0b5
--- /dev/null
@@ -0,0 +1,59 @@
+class apt::backports (
+  $location = undef,
+  $release  = undef,
+  $repos    = undef,
+  $key      = undef,
+  $pin      = 200,
+){
+  if $location {
+    validate_string($location)
+    $_location = $location
+  }
+  if $release {
+    validate_string($release)
+    $_release = $release
+  }
+  if $repos {
+    validate_string($repos)
+    $_repos = $repos
+  }
+  if $key {
+    unless is_hash($key) {
+      validate_string($key)
+    }
+    $_key = $key
+  }
+  unless is_hash($pin) {
+    unless (is_numeric($pin) or is_string($pin)) {
+      fail('pin must be either a string, number or hash')
+    }
+  }
+
+  if ($::apt::xfacts['lsbdistid'] == 'debian' or $::apt::xfacts['lsbdistid'] == 'ubuntu') {
+    unless $location {
+      $_location = $::apt::backports['location']
+    }
+    unless $release {
+      $_release = "${::apt::xfacts['lsbdistcodename']}-backports"
+    }
+    unless $repos {
+      $_repos = $::apt::backports['repos']
+    }
+    unless $key {
+      $_key =  $::apt::backports['key']
+    }
+  } else {
+    unless $location and $release and $repos and $key {
+      fail('If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key')
+    }
+  }
+
+  apt::source { 'backports':
+    location => $_location,
+    release  => $_release,
+    repos    => $_repos,
+    key      => $_key,
+    pin      => $pin,
+  }
+
+}
index 28502052814b73a238d7fc6704a05ae70811cd47..da6d64e738ba8269a053ade34567c3d15624b61a 100644 (file)
@@ -1,8 +1,15 @@
 define apt::conf (
-  $content,
+  $content  = undef,
   $ensure   = present,
   $priority = '50',
 ) {
+
+  unless $ensure == 'absent' {
+    unless $content {
+      fail('Need to pass in content parameter')
+    }
+  }
+
   apt::setting { "conf-${name}":
     ensure   => $ensure,
     priority => $priority,
index 57cee5007d65ee75a21f06c4a6afa4ec315db807..5a0c170d9120ddc1ce14b62fe2e9167d10b4d216 100644 (file)
@@ -69,10 +69,10 @@ class apt::params {
   }
 
   $purge_defaults = {
-    'sources.list'   => true,
-    'sources.list.d' => true,
-    'preferences'    => true,
-    'preferences.d'  => true,
+    'sources.list'   => false,
+    'sources.list.d' => false,
+    'preferences'    => false,
+    'preferences.d'  => false,
   }
 
   $source_key_defaults = {
@@ -88,39 +88,32 @@ class apt::params {
   }
 
   case $xfacts['lsbdistid'] {
-    'ubuntu', 'debian': {
-      $distid = $xfacts['lsbdistid']
-      $distcodename = $xfacts['lsbdistcodename']
-    }
-    'linuxmint': {
-      if $xfacts['lsbdistcodename'] == 'debian' {
-        $distid = 'debian'
-        $distcodename = 'wheezy'
-      } else {
-        $distid = 'ubuntu'
-        $distcodename = $xfacts['lsbdistcodename'] ? {
-          'qiana'  => 'trusty',
-          'petra'  => 'saucy',
-          'olivia' => 'raring',
-          'nadia'  => 'quantal',
-          'maya'   => 'precise',
+    'debian': {
+      case $xfacts['lsbdistcodename'] {
+        'squeeze': {
+          $backports = {
+            'location' => 'http://backports.debian.org/debian-backports',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
+        }
+        default: {
+          $backports = {
+            'location' => 'http://ftp.debian.org/debian/',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
         }
       }
     }
-    'Cumulus Networks': {
-      $distid = 'debian'
-      $distcodename = $::lsbdistcodename
-    }
-    undef: {
-      fail('Unable to determine lsbdistid, is lsb-release installed?')
-    }
-    default: {
-      fail("Unsupported lsbdistid (${::lsbdistid})")
-    }
-  }
-  case $distid {
     'ubuntu': {
-      case $distcodename {
+      $backports = {
+        'location' => 'http://archive.ubuntu.com/ubuntu',
+        'key'      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        'repos'    => 'main universe multiverse restricted',
+      }
+
+      case $xfacts['lsbdistcodename'] {
         'lucid': {
           $ppa_options        = undef
           $ppa_package        = 'python-software-properties'
@@ -139,9 +132,13 @@ class apt::params {
         }
       }
     }
-    '', default: {
+    undef: {
+      fail('Unable to determine lsbdistid, is lsb-release installed?')
+    }
+    default: {
       $ppa_options = undef
       $ppa_package = undef
+      $backports   = undef
     }
   }
 }
index 5d4c8903d5c6d9968c64e255f63cc61466554326..808c9751a042b32196dfc8c918216699f5085748 100644 (file)
@@ -10,8 +10,8 @@ define apt::ppa(
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  if $::apt::distid != 'ubuntu' {
-    fail('apt::ppa is currently supported on Ubuntu and LinuxMint only.')
+  if $::apt::xfacts['lsbdistid'] == 'Debian' {
+    fail('apt::ppa is not currently supported on Debian.')
   }
 
   $filename_without_slashes = regsubst($name, '/', '-', 'G')
index 163a411bb21f426f1ae1f43aeeffc4cd4c188464..40fc015bb6e8a194038d50e1f7444cb0bfc965b8 100644 (file)
@@ -8,7 +8,7 @@ define apt::source(
   $repos          = 'main',
   $include        = {},
   $key            = undef,
-  $pin            = false,
+  $pin            = undef,
   $architecture   = undef,
   $allow_unsigned = false,
 ) {
@@ -44,17 +44,22 @@ define apt::source(
     content => template('apt/_header.erb', 'apt/source.list.erb'),
   }
 
-  if ($pin != false) {
-    # Get the host portion out of the url so we can pin to origin
-    $url_split = split($location, '/')
-    $host      = $url_split[2]
-
-    apt::pin { $name:
-      ensure   => $ensure,
-      priority => $pin,
-      before   => $_before,
-      origin   => $host,
+  if $pin {
+    if is_hash($pin) {
+      $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
+    } elsif (is_numeric($pin) or is_string($pin)) {
+      $url_split = split($location, '/')
+      $host      = $url_split[2]
+      $_pin = {
+        'ensure'   => $ensure,
+        'priority' => $pin,
+        'before'   => $_before,
+        'origin'   => $host,
+      }
+    } else {
+      fail('Received invalid value for pin parameter')
     }
+    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
index 81d5d1bee676ca218070904bbbf8d44eadc5e9cb..ee7cd33a24e04610aef6a894d87e2c841dfb4d27 100644 (file)
@@ -9,7 +9,6 @@ describe 'apt' do
       :owner   => 'root',
       :group   => 'root',
       :mode    => '0644',
-      :content => "# Repos managed by puppet.\n",
       :notify  => 'Exec[apt_update]',
     })}
 
@@ -19,13 +18,13 @@ describe 'apt' do
       :owner   => 'root',
       :group   => 'root',
       :mode    => '0644',
-      :purge   => true,
-      :recurse => true,
+      :purge   => false,
+      :recurse => false,
       :notify  => 'Exec[apt_update]',
     })}
 
     it { is_expected.to contain_file('preferences').that_notifies('Exec[apt_update]').only_with({
-      :ensure  => 'absent',
+      :ensure  => 'file',
       :path    => '/etc/apt/preferences',
       :owner   => 'root',
       :group   => 'root',
@@ -39,8 +38,8 @@ describe 'apt' do
       :owner   => 'root',
       :group   => 'root',
       :mode    => '0644',
-      :purge   => true,
-      :recurse => true,
+      :purge   => false,
+      :recurse => false,
       :notify  => 'Exec[apt_update]',
     })}
 
index f8ca89f2a33f9ec04e73dc459dfaa85e204ba194..f8599b36998d0fb3f6629c8118f6d6ee5dc5bca6 100644 (file)
@@ -12,19 +12,6 @@ describe 'apt::params', :type => :class do
     expect(subject.resources.size).to eq(4)
   end
 
-  describe "With unknown lsbdistid" do
-
-    let(:facts) { { :lsbdistid => 'CentOS', :osfamily => 'Debian' } }
-    let (:title) { 'my_package' }
-
-    it do
-      expect {
-       is_expected.to compile
-      }.to raise_error(Puppet::Error, /Unsupported lsbdistid/)
-    end
-
-  end
-
   describe "With lsb-release not installed" do
     let(:facts) { { :lsbdistid => '', :osfamily => 'Debian' } }
     let (:title) { 'my_package' }
index a7db4e61e3f54ffed20db74884cf93ef63304525..e96f8bcd8299b9c2c3902f4603ba25ed802a6244 100644 (file)
@@ -30,12 +30,23 @@ describe 'apt::conf', :type => :define do
       }
   end
 
+  describe "when creating a preference without content" do
+    let :params do
+      {
+        :priority => '00',
+      }
+    end
+
+    it 'fails' do
+      expect { subject } .to raise_error(/pass in content/)
+    end
+  end
+
   describe "when removing an apt preference" do
     let :params do
       {
         :ensure   => 'absent',
         :priority => '00',
-        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
       }
     end
 
@@ -45,7 +56,6 @@ describe 'apt::conf', :type => :define do
 
     it { is_expected.to contain_file(filename).with({
         'ensure'    => 'absent',
-        'content'   => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/,
         'owner'     => 'root',
         'group'     => 'root',
         'mode'      => '0644',
index 7903e470377410d2df8320148c066970bb331445..521b42ba2b47897fc99b9c8b59f5769b73dfac59 100644 (file)
@@ -298,7 +298,7 @@ describe 'apt::ppa' do
       it do
         expect {
           is_expected.to compile
-        }.to raise_error(Puppet::Error, /supported on Ubuntu and LinuxMint only/)
+        }.to raise_error(Puppet::Error, /not currently supported on Debian/)
       end
     end
   end
index 7fd86b56ff0ff35e98ff8a4e5abd90fdfb31c13b..3900158a1612cc48b8995195c40e5dae655515d0 100644 (file)
@@ -51,6 +51,31 @@ describe 'apt::source' do
         :osfamily        => 'Debian'
       }
     end
+
+    context 'with complex pin' do
+      let :params do
+        {
+          :location => 'hello.there',
+          :pin      => { 'release'     => 'wishwash',
+                         'explanation' => 'wishwash',
+                         'priority'    => 1001, },
+        }
+      end
+
+      it { is_expected.to contain_apt__setting('list-my_source').with({
+        :ensure => 'present',
+      }).with_content(/hello.there wheezy main\n/)
+      }
+
+      it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[list-my_source]').with({
+        :ensure       => 'present',
+        :priority     => 1001,
+        :explanation  => 'wishwash',
+        :release      => 'wishwash',
+      })
+      }
+    end
+
     context 'with simple key' do
       let :params do
         {
@@ -235,5 +260,28 @@ describe 'apt::source' do
         }.to raise_error(Puppet::Error, /lsbdistcodename fact not available: release parameter required/)
       end
     end
+
+    context 'invalid pin' do
+      let :facts do
+        {
+          :lsbdistid       => 'Debian',
+          :lsbdistcodename => 'wheezy',
+          :osfamily        => 'Debian'
+        }
+      end
+      let :params do
+        {
+          :location => 'hello.there',
+          :pin      => true,
+        }
+      end
+
+      it do
+        expect {
+          is_expected.to compile
+        }.to raise_error(Puppet::Error, /invalid value for pin/)
+      end
+    end
+
   end
 end