]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #41 from tbroyer/install-proxy-first
authorNan Liu <nan.liu@gmail.com>
Thu, 3 May 2012 00:31:57 +0000 (17:31 -0700)
committerNan Liu <nan.liu@gmail.com>
Thu, 3 May 2012 00:31:57 +0000 (17:31 -0700)
Make sure we configure the proxy before doing apt-get update.

13 files changed:
manifests/backports.pp [new file with mode: 0644]
manifests/conf.pp [new file with mode: 0644]
manifests/debian/testing.pp
manifests/debian/unstable.pp
manifests/force.pp
manifests/init.pp
manifests/params.pp
manifests/pin.pp
manifests/ppa.pp
manifests/release.pp
manifests/source.pp
spec/classes/backports_spec.rb [new file with mode: 0644]
spec/defines/conf_spec.rb [new file with mode: 0644]

diff --git a/manifests/backports.pp b/manifests/backports.pp
new file mode 100644 (file)
index 0000000..1526890
--- /dev/null
@@ -0,0 +1,46 @@
+# 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)
+
+  apt::source { 'backports.list':
+    location   => $location,
+    release    => "${release_real}-backports",
+    repos      => $lsbdistid ? {
+      'debian' => 'main contrib non-free',
+      'ubuntu' => 'universe multiverse restricted',
+    },
+    key        => $lsbdistid ? {
+      'debian' => '55BE302B',
+      'ubuntu' => '437D05B5',
+    },
+    key_server => 'pgp.mit.edu',
+    pin        => '200',
+    notify => Exec["apt_update"],
+  }
+}
diff --git a/manifests/conf.pp b/manifests/conf.pp
new file mode 100644 (file)
index 0000000..c1af710
--- /dev/null
@@ -0,0 +1,17 @@
+define apt::conf (
+  $priority = '50',
+  $content
+  ) {
+
+  include apt::params
+
+  $apt_conf_d = $apt::params::apt_conf_d
+
+  file { "${apt_conf_d}/${priority}${name}":
+    ensure  => file,
+    content => $content,
+    owner   => root,
+    group   => root,
+    mode    => '0644',
+  }
+}
index cfdeb3cf73ebfd8f063340f28735115942997744..45133470fa4c6c229825079ba38ac9aa1dbbe60b 100644 (file)
@@ -1,6 +1,7 @@
 # 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
@@ -17,5 +18,4 @@ class apt::debian::testing {
     key_server        => 'subkeys.pgp.net',
     pin               => '-10',
   }
-
 }
index 3991023d17e0c4160844f4f08d27d183d13b0b8d..401c9c5cda7401afbc5988c58260af62fb277015 100644 (file)
@@ -1,6 +1,7 @@
 # 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
@@ -17,5 +18,4 @@ class apt::debian::unstable {
     key_server        => 'subkeys.pgp.net',
     pin               => '-10',
   }
-
 }
index 45c5679292b601c9d13954efc401b5377d071130..0089bbd75393d02044e62427a7470a0528405b31 100644 (file)
@@ -18,5 +18,4 @@ define apt::force(
   exec { "/usr/bin/aptitude -y -t ${release} install ${name}${version_string}":
     unless => $install_check,
   }
-
 }
index ba53fd2a23f2f04fd163b0cc0532b6355c180971..068fb497c4933d3e9d7fb6af925c0a0ab459a581 100644 (file)
@@ -45,9 +45,15 @@ class apt(
     false =>  undef,
     true  => "# Repos managed by puppet.\n",
   }
+
+  $root           = $apt::params::root
+  $apt_conf_d     = $apt::params::apt_conf_d
+  $sources_list_d = $apt::params::sources_list_d
+  $provider       = $apt::params::provider
+
   file { 'sources.list':
     ensure  => present,
-    path    => "${apt::params::root}/sources.list",
+    path    => "${root}/sources.list",
     owner   => root,
     group   => root,
     mode    => '0644',
@@ -56,7 +62,7 @@ class apt(
 
   file { 'sources.list.d':
     ensure  => directory,
-    path    => "${apt::params::root}/sources.list.d",
+    path    => $sources_list_d,
     owner   => root,
     group   => root,
     purge   => $purge_sources_list_d,
@@ -64,7 +70,7 @@ class apt(
   }
 
   exec { 'apt_update':
-    command     => "${apt::params::provider} update",
+    command     => "${provider} update",
     subscribe   => [ File['sources.list'], File['sources.list.d'] ],
     refreshonly => $refresh_only_apt_update,
   }
@@ -74,13 +80,13 @@ class apt(
       file { '99unauth':
         ensure  => present,
         content => "APT::Get::AllowUnauthenticated 1;\n",
-        path    => '/etc/apt/apt.conf.d/99unauth',
+        path    => "${apt_conf_d}/99unauth",
       }
     }
     false: {
       file { '99unauth':
         ensure => absent,
-        path   => '/etc/apt/apt.conf.d/99unauth',
+        path   => "${apt_conf_d}/99unauth",
       }
     }
     undef: { } # do nothing
@@ -89,7 +95,7 @@ class apt(
 
   if ($proxy_host) {
     file { 'configure-apt-proxy':
-      path    => '/etc/apt/apt.conf.d/proxy',
+      path    => "${apt_conf_d}/proxy",
       content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";",
       notify  => Exec['apt_update'],
     }
index ca5d65521d22b915c96e09430b33a2c06ffb8ef2..8e4fa932b17cbe873daef887f9c7df69e1df8b9d 100644 (file)
@@ -2,4 +2,22 @@ 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'
+        }
+      }
+    }
+  }
 }
index 46613667ebc0eabe9ad7a299dd0008748d99cba6..2899fce77a568fad54f418f6943d7c5678269da0 100644 (file)
@@ -8,9 +8,11 @@ define apt::pin(
 
   include apt::params
 
+  $preferences_d = $apt::params::preferences_d
+
   file { "${name}.pref":
     ensure  => file,
-    path    => "${apt::params::root}/preferences.d/${name}",
+    path    => "${preferences_d}/${name}",
     owner   => root,
     group   => root,
     mode    => '0644',
index 095d8f17b2b86d6318ca3ab24586ad90d314458a..bda392c9461138602a6c7a32e52c4d6c1b11eac0 100644 (file)
@@ -8,12 +8,14 @@ define apt::ppa(
 
   include apt::params
 
+  $sources_list_d = $apt::params::sources_list_d
+
   if ! $release {
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
   exec { "apt-update-${name}":
-    command     => '/usr/bin/aptitude update',
+    command     => "${apt::params::provider} update",
     refreshonly => true,
   }
 
@@ -24,13 +26,12 @@ define apt::ppa(
   exec { "add-apt-repository-${name}":
     command => "/usr/bin/add-apt-repository ${name}",
     notify  => Exec["apt-update-${name}"],
-    creates => "${apt::params::sources_list_d}/${sources_list_d_filename}",
+    creates => "${sources_list_d}/${sources_list_d_filename}",
   }
 
-  file { "${apt::params::sources_list_d}/${sources_list_d_filename}":
+  file { "${sources_list_d}/${sources_list_d_filename}":
     ensure  => file,
     require => Exec["add-apt-repository-${name}"];
   }
-
 }
 
index ee94e139faa83d55019114111b3613c85eea015e..6e0a38f73f7889cdc21ce3193c9440dddc3eb797 100644 (file)
@@ -6,7 +6,9 @@ class apt::release (
 
   include apt::params
 
-  file { "${apt::params::root}/apt.conf.d/01release":
+  $root = $apt::params::root
+
+  file { "${root}/apt.conf.d/01release":
     owner   => root,
     group   => root,
     mode    => '0644',
index 95768dcfaa81f919d781294223e286cb1e72ae35..17d2d8e5a2a2ad61f8bf58f5287edfd487dde70f 100644 (file)
@@ -16,13 +16,16 @@ define apt::source(
 
   include apt::params
 
+  $sources_list_d = $apt::params::sources_list_d
+  $provider       = $apt::params::provider
+
   if $release == undef {
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
   file { "${name}.list":
     ensure  => file,
-    path    => "${apt::params::root}/sources.list.d/${name}.list",
+    path    => "${sources_list_d}/${name}.list",
     owner   => root,
     group   => root,
     mode    => '0644',
@@ -30,18 +33,21 @@ define apt::source(
   }
 
   if $pin != false {
-    apt::pin { $release: priority => $pin } -> File["${name}.list"]
+    apt::pin { $release:
+      priority => $pin,
+      before   => File["${name}.list"]
+    }
   }
 
   exec { "${name} apt update":
-    command     => "${apt::params::provider} update",
+    command     => "${provider} update",
     subscribe   => File["${name}.list"],
     refreshonly => true,
   }
 
   if $required_packages != false {
     exec { "Required packages: '${required_packages}' for ${name}":
-      command     => "${apt::params::provider} -y install ${required_packages}",
+      command     => "${provider} -y install ${required_packages}",
       subscribe   => File["${name}.list"],
       refreshonly => true,
     }
diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb
new file mode 100644 (file)
index 0000000..feabef1
--- /dev/null
@@ -0,0 +1,74 @@
+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.list').with({
+        'location'   => 'http://old-releases.ubuntu.com/ubuntu',
+        'release'    => 'karmic-backports',
+        'repos'      => 'universe multiverse restricted',
+        'key'        => '437D05B5',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  end
+
+  describe "when turning on backports for debian squeeze" do
+
+    let :facts do
+      {
+        'lsbdistcodename' => 'Squeeze',
+        'lsbdistid'       => 'Debian',
+      }
+    end
+
+    it { should contain_apt__source('backports.list').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',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  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.list').with({
+        'location'   => location,
+        'release'    => 'squeeze-backports',
+        'repos'      => 'main contrib non-free',
+        'key'        => '55BE302B',
+        'key_server' => 'pgp.mit.edu',
+        'pin'        => '200',
+        'notify'     => 'Exec[apt_update]'
+      })
+    }
+  end
+end
diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb
new file mode 100644 (file)
index 0000000..7c04db1
--- /dev/null
@@ -0,0 +1,34 @@
+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'    => 'file',
+          'content'   => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
+          'owner'     => 'root',
+          'group'     => 'root',
+          'mode'      => '0644',
+        })
+      }
+  end
+end