Nicola Paolucci avatar Nicola Paolucci committed 5e4e2ad

un-submodule apt and stdlib puppet modules, removes one step

Comments (0)

Files changed (236)

.gitmodules

-[submodule "modules/apt"]
-	path = modules/apt
-	url = git://github.com/puppetlabs/puppetlabs-apt.git
-[submodule "modules/stdlib"]
-	path = modules/stdlib
-	url = git://github.com/puppetlabs/puppetlabs-stdlib.git
 
 - Execute:
 
-
     vagrant box add base http://files.vagrantup.com/precise32.box
 
-    git clone --recursive https://bitbucket.org/durdn/spinu12.git stash
+    git clone https://bitbucket.org/durdn/stash-vagrant-install.git
 
-    cd stash
+    cd stash-vagrant-install
 
-    git checkout -b stash origin/stash
-    
     vagrant up
     
 ## Running Stash
 
     cd /vagrant
 
-    STASH_HOME=/vagrant/stash-home /vagrant/atlassian-stash-2.0.1/bin/start-stash.sh
+    STASH_HOME=/vagrant/stash-home /vagrant/atlassian-stash-2.2.0/bin/start-stash.sh
 
 Access host browser at http://localhost:7990/setup

modules/apt/.fixtures.yml

+fixtures:
+  repositories:
+    "stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
+  symlinks:
+    "apt": "#{source_dir}"

modules/apt/.gemfile

+source :rubygems
+
+puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
+gem 'puppet', puppetversion
+gem 'puppetlabs_spec_helper', '>= 0.1.0'

modules/apt/.gitignore

+*.swp
+pkg/

modules/apt/.travis.yml

+language: ruby
+rvm:
+  - 1.8.7
+before_script:
+after_script:
+script: "rake spec"
+branches:
+  only:
+    - master
+env:
+  - PUPPET_VERSION=2.7.13
+  - PUPPET_VERSION=2.7.6
+  - PUPPET_VERSION=2.6.9
+notifications:
+  email: false
+gemfile: .gemfile

modules/apt/CHANGELOG

+2012-05-25 Puppet Labs <info@puppetlabs.com> - 0.0.4
+ * Fix ppa list filename when there is a period in the PPA name
+ * Add .pref extension to apt preferences files
+ * Allow preferences to be purged
+ * Extend pin support
+
+2012-05-04 Puppet Labs <info@puppetlabs.com> - 0.0.3
+ * only invoke apt-get update once
+ * only install python-software-properties if a ppa is added
+ * support 'ensure => absent' for all defined types
+ * add apt::conf
+ * add apt::backports
+ * fixed Modulefile for module tool dependency resolution
+ * configure proxy before doing apt-get update
+ * use apt-get update instead of aptitude for apt::ppa
+ * add support to pin release
+
+
+2012-03-26 Puppet Labs <info@puppetlabs.com> - 0.0.2
+41cedbb (#13261) Add real examples to smoke tests.
+d159a78 (#13261) Add key.pp smoke test
+7116c7a (#13261) Replace foo source with puppetlabs source
+1ead0bf Ignore pkg directory.
+9c13872 (#13289) Fix some more style violations
+0ea4ffa (#13289) Change test scaffolding to use a module & manifest dir fixture path
+a758247 (#13289) Clean up style violations and fix corresponding tests
+99c3fd3 (#13289) Add puppet lint tests to Rakefile
+5148cbf (#13125) Apt keys should be case insensitive
+b9607a4 Convert apt::key to use anchors
+
+2012-03-07 Puppet Labs <info@puppetlabs.com> - 0.0.1
+d4fec56 Modify apt::source release parameter test
+1132a07 (#12917) Add contributors to README
+8cdaf85 (#12823) Add apt::key defined type and modify apt::source to use it
+7c0d10b (#12809) $release should use $lsbdistcodename and fall back to manual input
+be2cc3e (#12522) Adjust spec test for splitting purge
+7dc60ae (#12522) Split purge option to spare sources.list
+9059c4e Fix source specs to test all key permutations
+8acb202 Add test for python-software-properties package
+a4af11f Check if python-software-properties is defined before attempting to define it.
+1dcbf3d Add tests for required_packages change
+f3735d2 Allow duplicate $required_packages
+74c8371 (#12430) Add tests for changes to apt module
+97ebb2d Test two sources with the same key
+1160bcd (#12526) Add ability to reverse apt { disable_keys => true }
+2842d73 Add Modulefile to puppet-apt
+c657742 Allow the use of the same key in multiple sources
+8c27963 (#12522) Adding purge option to apt class
+997c9fd (#12529) Add unit test for apt proxy settings
+50f3cca (#12529) Add parameter to support setting a proxy for apt
+d522877 (#12094) Replace chained .with_* with a hash
+8cf1bd0 (#12094) Remove deprecated spec.opts file
+2d688f4 (#12094) Add rspec-puppet tests for apt
+0fb5f78 (#12094) Replace name with path in file resources
+f759bc0 (#11953) Apt::force passes $version to aptitude
+f71db53 (#11413) Add spec test for apt::force to verify changes to unless
+2f5d317 (#11413) Update dpkg query used by apt::force
+cf6caa1 (#10451) Add test coverage to apt::ppa
+0dd697d include_src parameter in example; Whitespace cleanup
+b662eb8 fix typos in "repositories"
+1be7457 Fix (#10451) - apt::ppa fails to "apt-get update" when new PPA source is added
+864302a Set the pin priority before adding the source (Fix #10449)
+1de4e0a Refactored as per mlitteken
+1af9a13 Added some crazy bash madness to check if the ppa is installed already. Otherwise the manifest tries to add it on every run!
+52ca73e (#8720) Replace Apt::Ppa with Apt::Builddep
+5c05fa0 added builddep command.
+a11af50 added the ability to specify the content of a key
+c42db0f Fixes ppa test.
+77d2b0d reformatted whitespace to match recommended style of 2 space indentation.
+27ebdfc ignore swap files.
+377d58a added smoke tests for module.
+18f614b reformatted apt::ppa according to recommended style.
+d8a1e4e Created a params class to hold global data.
+636ae85 Added two params for apt class
+148fc73 Update LICENSE.
+ed2d19e Support ability to add more than one PPA
+420d537 Add call to apt-update after add-apt-repository in apt::ppa
+945be77 Add package definition for python-software-properties
+71fc425 Abs paths for all commands
+9d51cd1 Adding LICENSE
+71796e3 Heading fix in README
+87777d8 Typo in README
+f848bac First commit

modules/apt/LICENSE

+Copyright (c) 2011 Evolving Web Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

modules/apt/Modulefile

+name    'puppetlabs-apt'
+version '1.1.0'
+source  'https://github.com/puppetlabs/puppetlabs-apt'
+author  'Evolving Web / Puppet Labs'
+license 'Apache License 2.0'
+summary 'Puppet Labs Apt Module'
+description 'APT Module for Puppet'
+project_page 'https://github.com/puppetlabs/puppetlabs-apt'
+
+## Add dependencies, if any:
+#dependency 'puppetlabs/stdlib', '2.x'
+# The dependency should be written as above but librarian-puppet
+# does not support the expression as the PMT does.
+dependency 'puppetlabs/stdlib', '>= 2.2.1'

modules/apt/README.md

+# Apt module for Puppet
+
+## Description
+Provides helpful definitions for dealing with Apt.
+
+## Usage
+
+### apt
+The apt class provides a number of common resources and options which
+are shared by the various defined types in this module. This class
+should always be included in your manifests if you are using the `apt`
+module.
+
+    class { 'apt':
+      always_apt_update    => false,
+      disable_keys         => undef,
+      proxy_host           => false,
+      proxy_port           => '8080',
+      purge_sources_list   => false,
+      purge_sources_list_d => false,
+      purge_preferences_d  => false
+    }
+
+### apt::builddep
+Install the build depends of a specified package.
+
+    apt::builddep { "glusterfs-server": }
+
+### apt::force
+Force a package to be installed from a specific release.  Useful when
+using repositories like Debian unstable in Ubuntu.
+
+    apt::force { "glusterfs-server":
+	  release => "unstable",
+	  version => '3.0.3',
+	  require => Apt::Source["debian_unstable"],
+    }
+
+### apt::pin
+Add an apt pin for a certain release.
+
+    apt::pin { "karmic": priority => 700 }
+    apt::pin { "karmic-updates": priority => 700 }
+    apt::pin { "karmic-security": priority => 700 }
+
+### apt::ppa
+Add a ppa repository using `add-apt-repository`.  Somewhat experimental.
+
+    apt::ppa { "ppa:drizzle-developers/ppa": }
+
+### apt::release
+Set the default apt release.  Useful when using repositories like
+Debian unstable in Ubuntu.
+
+    apt::release { "karmic": }
+
+### apt::source
+Add an apt source to `/etc/apt/sources.list.d/`.
+
+    apt::source { "debian_unstable":
+      location          => "http://debian.mirror.iweb.ca/debian/",
+      release           => "unstable",
+      repos             => "main contrib non-free",
+      required_packages => "debian-keyring debian-archive-keyring",
+      key               => "55BE302B",
+      key_server        => "subkeys.pgp.net",
+      pin               => "-10",
+      include_src       => true
+    }
+
+This source will configure your system for the Puppet Labs APT
+repository.
+
+    apt::source { 'puppetlabs':
+      location   => 'http://apt.puppetlabs.com',
+      repos      => 'main',
+      key        => '4BD6EC30',
+      key_server => 'pgp.mit.edu',
+    }
+
+### apt::key
+Add a key to the list of keys used by apt to authenticate packages.
+
+    apt::key { "puppetlabs":
+      key        => "4BD6EC30",
+      key_server => "pgp.mit.edu",
+    }
+
+    apt::key { "jenkins":
+      key        => "D50582E6",
+      key_source => "http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key",
+    }
+
+Note that use of the "key_source" parameter requires wget to be
+installed and working.
+
+
+## Contributors
+A lot of great people have contributed to this module. A somewhat
+current list follows.
+
+Ben Godfrey <ben.godfrey@wonga.com>
+Branan Purvine-Riley <branan@puppetlabs.com>
+Christian G. Warden <cwarden@xerus.org>  
+Dan Bode <bodepd@gmail.com> <dan@puppetlabs.com>  
+Garrett Honeycutt <github@garretthoneycutt.com>  
+Jeff Wallace <jeff@evolvingweb.ca> <jeff@tjwallace.ca>  
+Ken Barber <ken@bob.sh>  
+Matthaus Litteken <matthaus@puppetlabs.com> <mlitteken@gmail.com>  
+Matthias Pigulla <mp@webfactory.de>  
+Monty Taylor <mordred@inaugust.com>  
+Peter Drake <pdrake@allplayers.com>  
+Reid Vandewiele <marut@cat.pdx.edu>  
+Robert Navarro <rnavarro@phiivo.com>  
+Ryan Coleman <ryan@puppetlabs.com>  
+Scott McLeod <scott.mcleod@theice.com>  
+Spencer Krum <spencer@puppetlabs.com>  
+William Van Hevelingen <blkperl@cat.pdx.edu> <wvan13@gmail.com>  
+Zach Leslie <zach@puppetlabs.com>  

modules/apt/Rakefile

+require 'puppetlabs_spec_helper/rake_tasks'

modules/apt/manifests/backports.pp

+# This adds the necessary components to get backports for ubuntu and debian
+#
+# == Parameters
+#
+# [*release*]
+#   The ubuntu/debian release name. Defaults to $lsbdistcodename. Setting this
+#   manually can cause undefined behavior. (Read: universe exploding)
+#
+# == Examples
+#
+#   include apt::backports
+#
+#   class { 'apt::backports':
+#     release => 'natty',
+#   }
+#
+# == Authors
+#
+# Ben Hughes, I think. At least blame him if this goes wrong.
+# I just added puppet doc.
+#
+# == Copyright
+#
+# Copyright 2011 Puppet Labs Inc, unless otherwise noted.
+class apt::backports(
+  $release  = $::lsbdistcodename,
+  $location = $apt::params::backports_location
+) inherits apt::params {
+
+  $release_real = downcase($release)
+  $key = $::lsbdistid ? {
+    'debian' => '55BE302B',
+    'ubuntu' => '437D05B5',
+  }
+  $repos = $::lsbdistid ? {
+    'debian' => 'main contrib non-free',
+    'ubuntu' => 'main universe multiverse restricted',
+  }
+
+  apt::source { 'backports':
+    location   => $location,
+    release    => "${release_real}-backports",
+    repos      => $repos,
+    key        => $key,
+    key_server => 'pgp.mit.edu',
+    pin        => '200',
+  }
+}

modules/apt/manifests/builddep.pp

+# builddep.pp
+
+define apt::builddep() {
+  include apt::update
+
+  exec { "apt-builddep-${name}":
+    command   => "/usr/bin/apt-get -y --force-yes build-dep ${name}",
+    logoutput => 'on_failure',
+    notify    => Exec['apt_update'],
+  }
+
+  # Need anchor to provide containment for dependencies.
+  anchor { "apt::builddep::${name}":
+    require => Class['apt::update'],
+  }
+}

modules/apt/manifests/conf.pp

+define apt::conf (
+  $content,
+  $ensure   = present,
+  $priority = '50'
+) {
+
+  include apt::params
+
+  $apt_conf_d = $apt::params::apt_conf_d
+
+  file { "${apt_conf_d}/${priority}${name}":
+    ensure  => $ensure,
+    content => $content,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+  }
+}

modules/apt/manifests/debian/testing.pp

+# testing.pp
+
+class apt::debian::testing {
+  include apt
+
+  # deb http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+  # deb-src http://debian.mirror.iweb.ca/debian/ testing main contrib non-free
+  # Key: 55BE302B  Server: subkeys.pgp.net
+  # debian-keyring
+  # debian-archive-keyring
+
+  apt::source { 'debian_testing':
+    location          => 'http://debian.mirror.iweb.ca/debian/',
+    release           => 'testing',
+    repos             => 'main contrib non-free',
+    required_packages => 'debian-keyring debian-archive-keyring',
+    key               => '55BE302B',
+    key_server        => 'subkeys.pgp.net',
+    pin               => '-10',
+  }
+}

modules/apt/manifests/debian/unstable.pp

+# unstable.pp
+
+class apt::debian::unstable {
+  include apt
+
+  # deb http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+  # deb-src http://debian.mirror.iweb.ca/debian/ unstable main contrib non-free
+  # Key: 55BE302B  Server: subkeys.pgp.net
+  # debian-keyring
+  # debian-archive-keyring
+
+  apt::source { 'debian_unstable':
+    location          => 'http://debian.mirror.iweb.ca/debian/',
+    release           => 'unstable',
+    repos             => 'main contrib non-free',
+    required_packages => 'debian-keyring debian-archive-keyring',
+    key               => '55BE302B',
+    key_server        => 'subkeys.pgp.net',
+    pin               => '-10',
+  }
+}

modules/apt/manifests/force.pp

+# force.pp
+# force a package from a specific release
+
+define apt::force(
+  $release = 'testing',
+  $version = false,
+  $timeout = 300
+) {
+
+  $version_string = $version ? {
+    false   => undef,
+    default => "=${version}",
+  }
+
+  $install_check = $version ? {
+    false   => "/usr/bin/dpkg -s ${name} | grep -q 'Status: install'",
+    default => "/usr/bin/dpkg -s ${name} | grep -q 'Version: ${version}'",
+  }
+  exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}":
+    unless    => $install_check,
+    logoutput => 'on_failure',
+    timeout   => $timeout,
+  }
+}

modules/apt/manifests/init.pp

+# Class: apt
+#
+# This module manages the initial configuration of apt.
+#
+# Parameters:
+#   The parameters listed here are not required in general and were
+#     added for use cases related to development environments.
+#   disable_keys - disables the requirement for all packages to be signed
+#   always_apt_update - rather apt should be updated on every run (intended
+#     for development environments where package updates are frequent)
+#   purge_sources_list - Accepts true or false. Defaults to false If set to
+#     true, Puppet will purge all unmanaged entries from sources.list
+#   purge_sources_list_d - Accepts true or false. Defaults to false. If set
+#     to true, Puppet will purge all unmanaged entries from sources.list.d
+#
+# Actions:
+#
+# Requires:
+#   puppetlabs/stdlib
+# Sample Usage:
+#  class { 'apt': }
+
+class apt(
+  $always_apt_update    = false,
+  $disable_keys         = undef,
+  $proxy_host           = false,
+  $proxy_port           = '8080',
+  $purge_sources_list   = false,
+  $purge_sources_list_d = false,
+  $purge_preferences_d  = false
+) {
+
+  include apt::params
+  include apt::update
+
+  validate_bool($purge_sources_list, $purge_sources_list_d, $purge_preferences_d)
+
+  $sources_list_content = $purge_sources_list ? {
+    false => undef,
+    true  => "# Repos managed by puppet.\n",
+  }
+
+  if $always_apt_update == true {
+    Exec <| title=='apt_update' |> {
+      refreshonly => false,
+    }
+  }
+
+  $root           = $apt::params::root
+  $apt_conf_d     = $apt::params::apt_conf_d
+  $sources_list_d = $apt::params::sources_list_d
+  $preferences_d  = $apt::params::preferences_d
+  $provider       = $apt::params::provider
+
+  file { 'sources.list':
+    ensure  => present,
+    path    => "${root}/sources.list",
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => $sources_list_content,
+    notify  => Exec['apt_update'],
+  }
+
+  file { 'sources.list.d':
+    ensure  => directory,
+    path    => $sources_list_d,
+    owner   => root,
+    group   => root,
+    purge   => $purge_sources_list_d,
+    recurse => $purge_sources_list_d,
+    notify  => Exec['apt_update'],
+  }
+
+  file { 'preferences.d':
+    ensure  => directory,
+    path    => $preferences_d,
+    owner   => root,
+    group   => root,
+    purge   => $purge_preferences_d,
+    recurse => $purge_preferences_d,
+  }
+
+  case $disable_keys {
+    true: {
+      file { '99unauth':
+        ensure  => present,
+        content => "APT::Get::AllowUnauthenticated 1;\n",
+        path    => "${apt_conf_d}/99unauth",
+      }
+    }
+    false: {
+      file { '99unauth':
+        ensure => absent,
+        path   => "${apt_conf_d}/99unauth",
+      }
+    }
+    undef:   { } # do nothing
+    default: { fail('Valid values for disable_keys are true or false') }
+  }
+
+  if ($proxy_host) {
+    file { 'configure-apt-proxy':
+      path    => "${apt_conf_d}/proxy",
+      content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
+      notify  => Exec['apt_update'],
+    }
+  }
+
+  # Need anchor to provide containment for dependencies.
+  anchor { 'apt::update':
+    require => Class['apt::update'],
+  }
+}

modules/apt/manifests/key.pp

+define apt::key (
+  $key = $title,
+  $ensure = present,
+  $key_content = false,
+  $key_source = false,
+  $key_server = 'keyserver.ubuntu.com'
+) {
+
+  include apt::params
+
+  $upkey = upcase($key)
+
+  if $key_content {
+    $method = 'content'
+  } elsif $key_source {
+    $method = 'source'
+  } elsif $key_server {
+    $method = 'server'
+  }
+
+  # This is a hash of the parts of the key definition that we care about.
+  # It is used as a unique identifier for this instance of apt::key. It gets
+  # hashed to ensure that the resource name doesn't end up being pages and
+  # pages (e.g. in the situation where key_content is specified).
+  $digest = sha1("${upkey}/${key_content}/${key_source}/${key_server}/")
+
+  # Allow multiple ensure => present for the same key to account for many
+  # apt::source resources that all reference the same key.
+  case $ensure {
+    present: {
+
+      anchor { "apt::key/${title}": }
+
+      if defined(Exec["apt::key ${upkey} absent"]) {
+        fail("Cannot ensure Apt::Key[${upkey}] present; ${upkey} already ensured absent")
+      }
+
+      if !defined(Anchor["apt::key ${upkey} present"]) {
+        anchor { "apt::key ${upkey} present": }
+      }
+
+      if !defined(Exec[$digest]) {
+        $digest_command = $method ? {
+          'content' => "echo '${key_content}' | /usr/bin/apt-key add -",
+          'source'  => "wget -q '${key_source}' -O- | apt-key add -",
+          'server'  => "apt-key adv --keyserver '${key_server}' --recv-keys '${upkey}'",
+        }
+        exec { $digest:
+          command   => $digest_command,
+          path      => '/bin:/usr/bin',
+          unless    => "/usr/bin/apt-key list | /bin/grep '${upkey}'",
+          logoutput => 'on_failure',
+          before    => Anchor["apt::key ${upkey} present"],
+        }
+      }
+
+      Anchor["apt::key ${upkey} present"] -> Anchor["apt::key/${title}"]
+
+    }
+    absent: {
+
+      if defined(Anchor["apt::key ${upkey} present"]) {
+        fail("Cannot ensure Apt::Key[${upkey}] absent; ${upkey} already ensured present")
+      }
+
+      exec { "apt::key ${upkey} absent":
+        command   => "apt-key del '${upkey}'",
+        path      => '/bin:/usr/bin',
+        onlyif    => "apt-key list | grep '${upkey}'",
+        user      => 'root',
+        group     => 'root',
+        logoutput => 'on_failure',
+      }
+    }
+
+    default: {
+      fail "Invalid 'ensure' value '${ensure}' for aptkey"
+    }
+  }
+}

modules/apt/manifests/params.pp

+class apt::params {
+  $root           = '/etc/apt'
+  $provider       = '/usr/bin/apt-get'
+  $sources_list_d = "${root}/sources.list.d"
+  $apt_conf_d     = "${root}/apt.conf.d"
+  $preferences_d  = "${root}/preferences.d"
+
+  case $::lsbdistid {
+    'debian': {
+      $backports_location = 'http://backports.debian.org/debian-backports'
+    }
+    'ubuntu': {
+      case $::lsbdistcodename {
+        'hardy','lucid','maverick','natty','oneiric','precise': {
+          $backports_location = 'http://us.archive.ubuntu.com/ubuntu'
+        }
+        default: {
+          $backports_location = 'http://old-releases.ubuntu.com/ubuntu'
+        }
+      }
+    }
+  }
+}

modules/apt/manifests/pin.pp

+# pin.pp
+# pin a release in apt, useful for unstable repositories
+
+define apt::pin(
+  $ensure     = present,
+  $explanation = "${::caller_module_name}: ${name}",
+  $order      = '',
+  $packages   = '*',
+  $priority   = 0,
+  $release    = '',
+  $origin     = '',
+  $originator = '',
+  $version    = ''
+) {
+
+  include apt::params
+
+  $preferences_d = $apt::params::preferences_d
+
+  if $order != '' and !is_integer($order) {
+    fail('Only integers are allowed in the apt::pin order param')
+  }
+
+  if $release != '' {
+    $pin = "release a=${release}"
+  } elsif $origin != '' {
+    $pin = "origin \"${origin}\""
+  } elsif $originator != '' {
+    $pin = "release o=${originator}"
+  } elsif $version != '' {
+    $pin = "version ${version}"
+  } else {
+    $pin = "release a=${name}"
+  }
+
+  $path = $order ? {
+    ''      => "${preferences_d}/${name}.pref",
+    default => "${preferences_d}/${order}-${name}.pref",
+  }
+  file { "${name}.pref":
+    ensure  => $ensure,
+    path    => $path,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => template('apt/pin.pref.erb'),
+  }
+}

modules/apt/manifests/ppa.pp

+# ppa.pp
+
+define apt::ppa(
+  $release = $::lsbdistcodename
+) {
+  include apt::params
+  include apt::update
+
+  $sources_list_d = $apt::params::sources_list_d
+
+  if ! $release {
+    fail('lsbdistcodename fact not available: release parameter required')
+  }
+
+  $filename_without_slashes = regsubst($name, '/', '-', G)
+  $filename_without_dots    = regsubst($filename_without_slashes, '\.', '_', G)
+  $filename_without_ppa     = regsubst($filename_without_dots, '^ppa:', '', G)
+  $sources_list_d_filename  = "${filename_without_ppa}-${release}.list"
+  
+  $package = $::lsbdistrelease ? {
+	  /^[1-9]\..*|1[01]\..*|12.04$/ => 'python-software-properties',
+	  default  => 'software-properties-common',
+  }
+  
+  if ! defined(Package[$package]) {
+    package { $package: }
+  }
+
+  exec { "add-apt-repository-${name}":
+    command   => "/usr/bin/add-apt-repository ${name}",
+    creates   => "${sources_list_d}/${sources_list_d_filename}",
+    logoutput => 'on_failure',
+    require   => [
+      File[$sources_list_d],
+      Package["${package}"],
+    ],
+    notify    => Exec['apt_update'],
+  }
+
+  file { "${sources_list_d}/${sources_list_d_filename}":
+    ensure  => file,
+    require => Exec["add-apt-repository-${name}"],
+  }
+
+  # Need anchor to provide containment for dependencies.
+  anchor { "apt::ppa::${name}":
+    require => Class['apt::update'],
+  }
+}

modules/apt/manifests/release.pp

+# release.pp
+
+class apt::release (
+  $release_id
+) {
+
+  include apt::params
+
+  $root = $apt::params::root
+
+  file { "${root}/apt.conf.d/01release":
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => "APT::Default-Release \"${release_id}\";"
+  }
+}

modules/apt/manifests/source.pp

+# source.pp
+# add an apt source
+
+define apt::source(
+  $ensure            = present,
+  $location          = '',
+  $release           = 'UNDEF',
+  $repos             = 'main',
+  $include_src       = true,
+  $required_packages = false,
+  $key               = false,
+  $key_server        = 'keyserver.ubuntu.com',
+  $key_content       = false,
+  $key_source        = false,
+  $pin               = false
+) {
+
+  include apt::params
+  include apt::update
+
+  $sources_list_d = $apt::params::sources_list_d
+  $provider       = $apt::params::provider
+
+  if $release == 'UNDEF' {
+    if $::lsbdistcodename == undef {
+      fail('lsbdistcodename fact not available: release parameter required')
+    } else {
+      $release_real = $::lsbdistcodename
+    }
+  } else {
+    $release_real = $release
+  }
+
+  file { "${name}.list":
+    ensure  => $ensure,
+    path    => "${sources_list_d}/${name}.list",
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+    content => template("${module_name}/source.list.erb"),
+    notify  => Exec['apt_update'],
+  }
+
+
+  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   => File["${name}.list"],
+      origin   => $host,
+    }
+  }
+
+  if ($required_packages != false) and ($ensure == 'present') {
+    exec { "Required packages: '${required_packages}' for ${name}":
+      command     => "${provider} -y install ${required_packages}",
+      logoutput   => 'on_failure',
+      refreshonly => true,
+      subscribe   => File["${name}.list"],
+    }
+  }
+
+  # We do not want to remove keys when the source is absent.
+  if ($key != false) and ($ensure == 'present') {
+    apt::key { "Add key: ${key} from Apt::Source ${title}":
+      ensure      => present,
+      key         => $key,
+      key_server  => $key_server,
+      key_content => $key_content,
+      key_source  => $key_source,
+      before      => File["${name}.list"],
+    }
+  }
+
+  # Need anchor to provide containment for dependencies.
+  anchor { "apt::source::${name}":
+    require => Class['apt::update'],
+  }
+}

modules/apt/manifests/update.pp

+class apt::update {
+  include apt::params
+
+  exec { 'apt_update':
+    command     => "${apt::params::provider} update",
+    logoutput   => 'on_failure',
+    refreshonly => true,
+  }
+}

modules/apt/spec/classes/apt_spec.rb

+require 'spec_helper'
+describe 'apt', :type => :class do
+  let :default_params do
+    {
+      :disable_keys => :undef,
+      :always_apt_update => false,
+      :purge_sources_list => false,
+      :purge_sources_list_d => false,
+    }
+  end
+
+  [{},
+    {
+      :disable_keys => true,
+      :always_apt_update => true,
+      :proxy_host => true,
+      :proxy_port => '3128',
+      :purge_sources_list => true,
+      :purge_sources_list_d => true,
+    },
+    {
+      :disable_keys => false
+    }
+  ].each do |param_set|
+    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+      let :param_hash do
+        default_params.merge(param_set)
+      end
+
+      let :params do
+        param_set
+      end
+
+      let :refresh_only_apt_update do
+        if param_hash[:always_apt_update]
+          false
+        else
+          true
+        end
+      end
+
+      it { should include_class("apt::params") }
+
+      it {
+        if param_hash[:purge_sources_list]
+        should contain_file("sources.list").with({
+            'path'    => "/etc/apt/sources.list",
+            'ensure'  => "present",
+            'owner'   => "root",
+            'group'   => "root",
+            'mode'    => "0644",
+            "content" => "# Repos managed by puppet.\n"
+          })
+        else
+        should contain_file("sources.list").with({
+            'path'    => "/etc/apt/sources.list",
+            'ensure'  => "present",
+            'owner'   => "root",
+            'group'   => "root",
+            'mode'    => "0644",
+            'content' => nil
+          })
+        end
+      }
+      it {
+        if param_hash[:purge_sources_list_d]
+          should create_file("sources.list.d").with({
+            'path'    => "/etc/apt/sources.list.d",
+            'ensure'  => "directory",
+            'owner'   => "root",
+            'group'   => "root",
+            'purge'   => true,
+            'recurse' => true,
+            'notify'  => 'Exec[apt_update]'
+          })
+        else
+          should create_file("sources.list.d").with({
+            'path'    => "/etc/apt/sources.list.d",
+            'ensure'  => "directory",
+            'owner'   => "root",
+            'group'   => "root",
+            'purge'   => false,
+            'recurse' => false,
+            'notify'  => 'Exec[apt_update]'
+          })
+        end
+      }
+
+      it {
+        should contain_exec("apt_update").with({
+          'command'     => "/usr/bin/apt-get update",
+          'refreshonly' => refresh_only_apt_update
+        })
+      }
+
+      it {
+        if param_hash[:disable_keys] == true
+          should create_file("99unauth").with({
+            'content' => "APT::Get::AllowUnauthenticated 1;\n",
+            'ensure'  => "present",
+            'path'    => "/etc/apt/apt.conf.d/99unauth"
+          })
+        elsif param_hash[:disable_keys] == false
+          should create_file("99unauth").with({
+            'ensure' => "absent",
+            'path'   => "/etc/apt/apt.conf.d/99unauth"
+          })
+        elsif param_hash[:disable_keys] != :undef
+          should_not create_file("99unauth").with({
+            'path'   => "/etc/apt/apt.conf.d/99unauth"
+          })
+        end
+      }
+      describe 'when setting a proxy' do
+        it {
+          if param_hash[:proxy_host]
+            should contain_file('configure-apt-proxy').with(
+              'path'    => '/etc/apt/apt.conf.d/proxy',
+              'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";",
+              'notify'  => "Exec[apt_update]"
+            )
+          else
+            should_not contain_file('configure_apt_proxy')
+          end
+        }
+      end
+    end
+  end
+end

modules/apt/spec/classes/backports_spec.rb

+require 'spec_helper'
+describe 'apt::backports', :type => :class do
+
+  describe 'when turning on backports for ubuntu karmic' do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Karmic',
+        'lsbdistid'       => 'Ubuntu'
+      }
+    end
+
+    it { should contain_apt__source('backports').with({
+        'location'   => 'http://old-releases.ubuntu.com/ubuntu',
+        'release'    => 'karmic-backports',
+        'repos'      => 'main universe multiverse restricted',
+        'key'        => '437D05B5',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+      })
+    }
+  end
+
+  describe "when turning on backports for debian squeeze" do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Squeeze',
+        'lsbdistid'       => 'Debian',
+      }
+    end
+
+    it { should contain_apt__source('backports').with({
+        'location'   => 'http://backports.debian.org/debian-backports',
+        'release'    => 'squeeze-backports',
+        'repos'      => 'main contrib non-free',
+        'key'        => '55BE302B',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+      })
+    }
+  end
+
+  describe "when turning on backports for debian squeeze but using your own mirror" do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Squeeze',
+        'lsbdistid'       => 'Debian'
+      }
+    end
+
+    let :location do
+      'http://mirrors.example.com/debian-backports'
+    end
+
+    let :params do
+      { 'location' => location }
+    end
+
+    it { should contain_apt__source('backports').with({
+        'location'   => location,
+        'release'    => 'squeeze-backports',
+        'repos'      => 'main contrib non-free',
+        'key'        => '55BE302B',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+      })
+    }
+  end
+end

modules/apt/spec/classes/debian_testing_spec.rb

+require 'spec_helper'
+describe 'apt::debian::testing', :type => :class do
+  it {
+    should contain_apt__source("debian_testing").with({
+      "location"            => "http://debian.mirror.iweb.ca/debian/",
+      "release"             => "testing",
+      "repos"               => "main contrib non-free",
+      "required_packages"   => "debian-keyring debian-archive-keyring",
+      "key"                 => "55BE302B",
+      "key_server"          => "subkeys.pgp.net",
+      "pin"                 => "-10"
+    })
+  }
+end

modules/apt/spec/classes/debian_unstable_spec.rb

+require 'spec_helper'
+describe 'apt::debian::unstable', :type => :class do
+  it {
+    should contain_apt__source("debian_unstable").with({
+      "location"          => "http://debian.mirror.iweb.ca/debian/",
+      "release"           => "unstable",
+      "repos"             => "main contrib non-free",
+      "required_packages" => "debian-keyring debian-archive-keyring",
+      "key"               => "55BE302B",
+      "key_server"        => "subkeys.pgp.net",
+      "pin"               => "-10"
+    })
+  }
+end

modules/apt/spec/classes/params_spec.rb

+require 'spec_helper'
+describe 'apt::params', :type => :class do
+  let (:title) { 'my_package' }
+
+  it { should contain_apt__params }
+
+  # There are 4 resources in this class currently
+  # there should not be any more resources because it is a params class
+  # The resources are class[apt::params], class[main], class[settings], stage[main]
+  it "Should not contain any resources" do
+    subject.resources.size.should == 4
+  end
+end

modules/apt/spec/classes/release_spec.rb

+require 'spec_helper'
+describe 'apt::release', :type => :class do
+  let (:title) { 'my_package' }
+
+  let :param_set do
+    { :release_id => 'precise' }
+  end
+
+  let (:params) { param_set }
+
+  it { should include_class("apt::params") }
+
+  it {
+    should contain_file("/etc/apt/apt.conf.d/01release").with({
+      "mode"    => "0644",
+      "owner"   => "root",
+      "group"   => "root",
+      "content" => "APT::Default-Release \"#{param_set[:release_id]}\";"
+    })
+  }
+end
+

modules/apt/spec/defines/builddep_spec.rb

+require 'spec_helper'
+describe 'apt::builddep', :type => :define do
+
+  let(:title) { 'my_package' }
+
+  describe "should require apt-get update" do
+    it { should contain_exec("apt_update").with({
+        'command' => "/usr/bin/apt-get update",
+        'refreshonly' => true
+      })
+    }
+    it { should contain_anchor("apt::builddep::my_package").with({
+        'require' => 'Class[Apt::Update]',
+      })
+    }
+  end
+
+end

modules/apt/spec/defines/conf_spec.rb

+require 'spec_helper'
+describe 'apt::conf', :type => :define do
+  let :title do
+    'norecommends'
+  end
+
+  describe "when creating an apt preference" do
+    let :params do
+      {
+        :priority => '00',
+        :content  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+      }
+    end
+
+    let :filename do
+      "/etc/apt/apt.conf.d/00norecommends"
+    end
+
+    it { should contain_apt__conf('norecommends').with({
+         'priority' => '00',
+         'content'  => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
+      })
+    }
+
+    it { should contain_file(filename).with({
+          'ensure'    => 'present',
+          'content'   => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+        })
+      }
+  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
+
+    let :filename do
+      "/etc/apt/apt.conf.d/00norecommends"
+    end
+
+    it { should contain_file(filename).with({
+        'ensure'    => 'absent',
+        'content'   => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+        'owner'     => 'root',
+        'group'     => 'root',
+        'mode'      => '0644',
+      })
+    }
+  end
+end

modules/apt/spec/defines/force_spec.rb

+require 'spec_helper'
+describe 'apt::force', :type => :define do
+  let :title do
+    'my_package'
+  end
+
+  let :default_params do
+    {
+      :release => 'testing',
+      :version => false
+    }
+  end
+
+  [{},
+   {
+      :release  => 'stable',
+      :version  => '1'
+    }
+  ].each do |param_set|
+    describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+      let :param_hash do
+        default_params.merge(param_set)
+      end
+
+      let :params do
+        param_set
+      end
+
+      let :unless_query do
+        base_command = "/usr/bin/dpkg -s #{title} | grep -q "
+        base_command + (params[:version] ? "'Version: #{params[:version]}'" : "'Status: install'")
+      end
+
+      let :exec_title do
+        base_exec = "/usr/bin/aptitude -y -t #{param_hash[:release]} install #{title}"
+        base_exec + (params[:version] ? "=#{params[:version]}" : "")
+      end
+      it { should contain_exec(exec_title).with_unless(unless_query) }
+    end
+  end
+end

modules/apt/spec/defines/key_spec.rb

+require 'spec_helper'
+describe 'apt::key', :type => :define do
+  let :title do
+    '8347A27F'
+  end
+
+  let :default_params do
+    {
+      :key         => title,
+      :ensure      => 'present',
+      :key_server  => "keyserver.ubuntu.com",
+      :key_source  => false,
+      :key_content => false
+    }
+  end
+
+  [{},
+    {
+      :ensure  => 'absent'
+    },
+    {
+      :ensure  => 'random'
+    },
+    {
+      :key_source => 'ftp://ftp.example.org/key',
+    },
+    {
+      :key_content => 'deadbeef',
+    }
+  ].each do |param_set|
+
+    let :param_hash do
+      param_hash = default_params.merge(param_set)
+      param_hash[:key].upcase! if param_hash[:key]
+      param_hash
+    end
+
+    let :params do
+      param_set
+    end
+
+    let :digest do
+      str = String.new
+      str << param_hash[:key].to_s         << '/'
+      str << param_hash[:key_content].to_s << '/'
+      str << param_hash[:key_source].to_s  << '/'
+      str << param_hash[:key_server].to_s  << '/'
+      Digest::SHA1.hexdigest(str)
+    end
+
+    describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+
+      it {
+        if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
+          should contain_apt__params
+        end
+      }
+
+      it {
+        if [:present, 'present'].include? param_hash[:ensure]
+          should_not contain_exec("apt::key #{param_hash[:key]} absent")
+          should contain_anchor("apt::key #{param_hash[:key]} present")
+          should contain_exec(digest).with({
+            "path"    => "/bin:/usr/bin",
+            "unless"  => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
+          })
+        elsif [:absent, 'absent'].include? param_hash[:ensure]
+          should_not contain_anchor("apt::key #{param_hash[:key]} present")
+          should contain_exec("apt::key #{param_hash[:key]} absent").with({
+            "path"    => "/bin:/usr/bin",
+            "onlyif"  => "apt-key list | grep '#{param_hash[:key]}'",
+            "command" => "apt-key del '#{param_hash[:key]}'"
+          })
+        else
+          expect { should raise_error(Puppet::Error) }
+        end
+      }
+
+      it {
+        if [:present, 'present'].include? param_hash[:ensure]
+          if param_hash[:key_content]
+            should contain_exec(digest).with({
+              "command" => "echo '#{param_hash[:key_content]}' | /usr/bin/apt-key add -"
+            })
+          elsif param_hash[:key_source]
+            should contain_exec(digest).with({
+              "command" => "wget -q '#{param_hash[:key_source]}' -O- | apt-key add -"
+            })
+          elsif param_hash[:key_server]
+            should contain_exec(digest).with({
+              "command" => "apt-key adv --keyserver '#{param_hash[:key_server]}' --recv-keys '#{param_hash[:key]}'"
+            })
+          end
+        end
+      }
+
+    end
+  end
+
+  [{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
+    describe "should correctly handle duplicate definitions" do
+
+      let :pre_condition do
+        "apt::key { 'duplicate': key => '#{title}'; }"
+      end
+
+      let(:params) { param_set }
+
+      it {
+        if param_set[:ensure] == 'present'
+          should contain_anchor("apt::key #{title} present")
+          should contain_apt__key(title)
+          should contain_apt__key("duplicate")
+        elsif param_set[:ensure] == 'absent'
+          expect { should raise_error(Puppet::Error) }
+        end
+      }
+
+    end
+  end
+
+end
+

modules/apt/spec/defines/pin_spec.rb

+require 'spec_helper'
+describe 'apt::pin', :type => :define do
+  let(:title) { 'my_pin' }
+
+  let :default_params do
+    {
+      :ensure   => 'present',
+      :order    => '',
+      :packages => '*',
+      :priority => '0',
+      :release  => nil
+    }
+  end
+
+  [ {},
+    {
+      :packages  => 'apache',
+      :priority  => '1'
+    },
+    {
+      :order     => 50,
+      :packages  => 'apache',
+      :priority  => '1'
+    },
+    {
+      :ensure    => 'absent',
+      :packages  => 'apache',
+      :priority  => '1'
+    },
+    {
+      :packages  => 'apache',
+      :priority  => '1',
+      :release   => 'my_newpin'
+    }
+  ].each do |param_set|
+    describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
+      let :param_hash do
+        default_params.merge(param_set)
+      end
+
+      let :params do
+        param_set
+      end
+
+      it { should include_class("apt::params") }
+
+      it { should contain_file("#{title}.pref").with({
+          'ensure'  => param_hash[:ensure],
+          'path'    => "/etc/apt/preferences.d/#{param_hash[:order] == '' ? "" : "#{param_hash[:order]}-"}#{title}.pref",
+          'owner'   => 'root',
+          'group'   => 'root',
+          'mode'    => '0644',
+          'content' => "# #{title}\nExplanation: : #{title}\nPackage: #{param_hash[:packages]}\nPin: release a=#{param_hash[:release] || title}\nPin-Priority: #{param_hash[:priority]}\n",
+        })
+      }
+    end
+  end
+end

modules/apt/spec/defines/ppa_spec.rb

+require 'spec_helper'
+describe 'apt::ppa', :type => :define do
+  [ { :lsbdistrelease => '11.04',
+      :lsbdistcodename => 'natty',
+      :package => 'python-software-properties'},
+    { :lsbdistrelease => '12.10',
+      :lsbdistcodename => 'quantal',
+      :package => 'software-properties-common'},
+  ].each do |platform|
+    context "on #{platform[:lsbdistcodename]}" do
+      let :facts do
+        {
+          :lsbdistrelease => platform[:lsbdistrelease],
+          :lsbdistcodename => platform[:lsbdistcodename],
+        }
+      end
+      let :release do
+        "#{platform[:lsbdistcodename]}"
+      end
+      let :package do
+        "#{platform[:package]}"
+      end
+      ['ppa:dans_ppa', 'dans_ppa','ppa:dans-daily/ubuntu'].each do |t|
+        describe "with title #{t}" do
+          let :pre_condition do
+            'class { "apt": }'
+          end
+          let :title do
+            t
+          end
+          let :filename do
+            t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
+          end
+
+          it { should contain_package("#{package}") }
+
+          it { should contain_exec("apt_update").with(
+            'command'     => '/usr/bin/apt-get update',
+            'refreshonly' => true
+            )
+          }
+
+          it { should contain_exec("add-apt-repository-#{t}").with(
+            'command' => "/usr/bin/add-apt-repository #{t}",
+            'creates' => "/etc/apt/sources.list.d/#{filename}",
+            'require' => ["File[/etc/apt/sources.list.d]", "Package[#{package}]"],
+            'notify'  => "Exec[apt_update]"
+            )
+          }
+
+          it { should create_file("/etc/apt/sources.list.d/#{filename}").with(
+            'ensure'  => 'file',
+            'require' => "Exec[add-apt-repository-#{t}]"
+            )
+          }
+        end
+      end
+    end
+  end
+
+  [ { :lsbdistcodename => 'natty', 
+      :package => 'python-software-properties' },
+    { :lsbdistcodename => 'quantal',
+      :package => 'software-properties-common'},
+  ].each do |platform|
+    context "on #{platform[:lsbdistcodename]}" do
+      describe "it should not error if package['#{platform[:package]}'] is already defined" do
+        let :pre_condition do
+           'class {"apt": }' +
+           'package { "#{platform[:package]}": }->Apt::Ppa["ppa"]'
+        end
+        let :facts do
+          {:lsbdistcodename => '#{platform[:lsbdistcodename]}'}
+        end
+        let(:title) { "ppa" }
+        let(:release) { "#{platform[:lsbdistcodename]}" }
+        it { should contain_package('#{platform[:package]}') }
+      end
+    end
+  end
+
+  describe "without Class[apt] should raise a Puppet::Error" do
+    let(:release) { "natty" }
+    let(:title) { "ppa" }
+    it { expect { should contain_apt__ppa(title) }.to raise_error(Puppet::Error) }
+  end
+
+  describe "without release should raise a Puppet::Error" do
+    let(:title) { "ppa:" }
+    it { expect { should contain_apt__ppa(:release) }.to raise_error(Puppet::Error) }
+  end
+end

modules/apt/spec/defines/source_spec.rb

+require 'spec_helper'
+describe 'apt::source', :type => :define do
+  let :title do
+    'my_source'
+  end
+
+  let :default_params do
+    {
+      :ensure             => 'present',
+      :location           => '',
+      :release            => 'karmic',
+      :repos              => 'main',
+      :include_src        => true,
+      :required_packages  => false,
+      :key                => false,
+      :key_server         => 'keyserver.ubuntu.com',
+      :key_content        => false,
+      :key_source         => false,
+      :pin                => false
+    }
+  end
+
+  [{},
+   {
+      :location           => 'http://example.com',
+      :release            => 'precise',
+      :repos              => 'security',
+      :include_src        => false,
+      :required_packages  => 'apache',
+      :key                => 'key_name',
+      :key_server         => 'keyserver.debian.com',
+      :pin                => '600',
+      :key_content        => 'ABCD1234'
+    },
+    {
+      :key                => 'key_name',
+      :key_server         => 'keyserver.debian.com',
+      :key_content        => false,
+    },
+    {
+      :ensure             => 'absent',
+      :location           => 'http://example.com',
+      :release            => 'precise',
+      :repos              => 'security',
+    },
+    {
+      :release            => '',
+    },
+    {
+      :release            => 'custom',
+    }
+  ].each do |param_set|
+    describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
+      let :param_hash do
+        default_params.merge(param_set)
+      end
+
+      let :facts do
+        {:lsbdistcodename => 'karmic'}
+      end
+
+      let :params do
+        param_set
+      end
+
+      let :filename do
+        "/etc/apt/sources.list.d/#{title}.list"
+      end
+
+      let :content do
+        content = "# #{title}"
+        content << "\ndeb #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+        if param_hash[:include_src]
+          content << "deb-src #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+        end
+        content
+      end
+
+      it { should contain_apt__params }
+
+      it { should contain_file("#{title}.list").with({
+          'ensure'    => param_hash[:ensure],
+          'path'      => filename,
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+          'content'   => content,
+        })
+      }
+
+      it {
+        if param_hash[:pin]
+          should contain_apt__pin(title).with({
+            "priority"  => param_hash[:pin],
+            "before"    => "File[#{title}.list]"
+          })
+        else
+          should_not contain_apt__pin(title).with({
+            "priority"  => param_hash[:pin],
+            "before"    => "File[#{title}.list]"
+          })
+        end
+      }
+
+      it {
+        should contain_exec("apt_update").with({
+          "command"     => "/usr/bin/apt-get update",
+          "refreshonly" => true
+        })
+      }
+
+      it {
+        if param_hash[:required_packages]
+          should contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+            "command" => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+            "subscribe"   => "File[#{title}.list]",
+            "refreshonly" => true
+          })
+        else
+          should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
+            "command"     => "/usr/bin/apt-get -y install #{param_hash[:required_packages]}",
+            "subscribe"   => "File[#{title}.list]",
+            "refreshonly" => true
+          })
+        end
+      }
+
+      it {
+        if param_hash[:key]
+          should contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+            "key"         => param_hash[:key],
+            "ensure"      => :present,
+            "key_server"  => param_hash[:key_server],
+            "key_content" => param_hash[:key_content],
+            "key_source"  => param_hash[:key_source],
+            "before"      => "File[#{title}.list]"
+          })
+        else
+          should_not contain_apt__key("Add key: #{param_hash[:key]} from Apt::Source #{title}").with({
+            "key"         => param_hash[:key],
+            "ensure"      => :present,
+            "key_server"  => param_hash[:key_server],
+            "key_content" => param_hash[:key_content],
+            "key_source"  => param_hash[:key_source],
+            "before"      => "File[#{title}.list]"
+          })
+        end
+      }
+    end
+  end
+  describe "without release should raise a Puppet::Error" do
+    let(:default_params) { Hash.new }
+    let(:facts) { Hash.new }
+    it { expect { should raise_error(Puppet::Error) } }
+    let(:facts) { { :lsbdistcodename => 'lucid' } }
+    it { should contain_apt__source(title) }
+  end
+end
Add a comment to this file

modules/apt/spec/fixtures/manifests/site.pp

Empty file added.