Merge pull request #134 from spali/my_changes
authorHunter Haugen <h.haugen@gmail.com>
Tue, 2 Jul 2013 20:54:12 +0000 (13:54 -0700)
committerHunter Haugen <h.haugen@gmail.com>
Tue, 2 Jul 2013 20:54:12 +0000 (13:54 -0700)
replace aptitude with apt in apt::force

16 files changed:
.gitignore
.project [new file with mode: 0644]
.travis.yml
CHANGELOG
Gemfile
Modulefile
README.md
manifests/key.pp
manifests/params.pp
manifests/pin.pp
manifests/source.pp
spec/defines/pin_spec.rb
spec/defines/source_spec.rb
templates/pin.pref.erb
templates/source.list.erb
tests/key.pp

index b77434bea0792513cdff50c8759df47957f77965..0485a727cb7e84e60542c3c943b3430b3f99a3df 100644 (file)
@@ -2,3 +2,4 @@
 pkg/
 Gemfile.lock
 spec/fixtures/manifests
+metadata.json
diff --git a/.project b/.project
new file mode 100644 (file)
index 0000000..6523c6d
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>apt</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.cloudsmith.geppetto.pp.dsl.ui.modulefileBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.cloudsmith.geppetto.pp.dsl.ui.puppetNature</nature>
+               <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+       </natures>
+</projectDescription>
index a19074d0b8412434d76d5d32f489c4210f9615e2..71054bb2eaac34cf7b97353c0f9c02a378126a84 100644 (file)
@@ -4,26 +4,23 @@ script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
 rvm:
   - 1.8.7
   - 1.9.3
-  - ruby-head
+  - 2.0.0
 env:
-  - PUPPET_GEM_VERSION="~> 2.6.0"
   - PUPPET_GEM_VERSION="~> 2.7.0"
   - PUPPET_GEM_VERSION="~> 3.0.0"
   - PUPPET_GEM_VERSION="~> 3.1.0"
   - PUPPET_GEM_VERSION="~> 3.2.0"
 matrix:
   exclude:
-    - rvm: ruby-head
-      env: PUPPET_GEM_VERSION="~> 3.0.0"
-    - rvm: ruby-head
-      env: PUPPET_GEM_VERSION="~> 3.1.0"
     - rvm: 1.9.3
       env: PUPPET_GEM_VERSION="~> 2.7.0"
-    - rvm: ruby-head
+    - rvm: 2.0.0
       env: PUPPET_GEM_VERSION="~> 2.7.0"
-    - rvm: 1.9.3
-      env: PUPPET_GEM_VERSION="~> 2.6.0"
-    - rvm: ruby-head
-      env: PUPPET_GEM_VERSION="~> 2.6.0"
+    - rvm: 2.0.0
+      env: PUPPET_GEM_VERSION="~> 3.0.0"
+    - rvm: 2.0.0
+      env: PUPPET_GEM_VERSION="~> 3.1.0"
+    - rvm: 1.8.7
+      env: PUPPET_GEM_VERSION="~> 3.2.0"
 notifications:
   email: false
index da4072f2528acfbb620f2ad307e6b43766f352a0..44fa88abb22ff66cd0a16563a24e7feb2b16f6ba 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,48 @@
+## puppetlabs-apt changelog
+
+Release notes for the puppetlabs-apt module.
+
+1.1.1
+=====
+
+This is a bug fix release that resolves a number of issues:
+
+* By changing template variable usage, we remove the deprecation warnings
+  for Puppet 3.2.x
+* Fixed proxy file removal, when proxy absent
+
+Some documentation, style and whitespaces changes were also merged. This
+release also introduced proper rspec-puppet unit testing on Travis-CI to help
+reduce regression.
+
+Thanks to all the community contributors below that made this patch possible.
+
+#### Detail Changes
+
+* fix minor comment type (Chris Rutter)
+* whitespace fixes (Michael Moll)
+* Update travis config file (William Van Hevelingen)
+* Build all branches on travis (William Van Hevelingen)
+* Standardize travis.yml on pattern introduced in stdlib (William Van Hevelingen)
+* Updated content to conform to README best practices template (Lauren Rother)
+* Fix apt::release example in readme (Brian Galey)
+* add @ to variables in template (Peter Hoeg)
+* Remove deprecation warnings for pin.pref.erb as well (Ken Barber)
+* Update travis.yml to latest versions of puppet (Ken Barber)
+* Fix proxy file removal (Scott Barber)
+* Add spec test for removing proxy configuration (Dean Reilly)
+* Fix apt::key listing longer than 8 chars (Benjamin Knofe)
+
+
+---------------------------------------
+
+1.1.0
+=====
+
+This release includes Ubuntu 12.10 (Quantal) support for PPAs.
+
+---------------------------------------
+
 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
diff --git a/Gemfile b/Gemfile
index 8e5e04d744ce24eb8f62dc1d1390e62805fe790d..881fc90e21cf98c7fe8994ca6ad6062d1632632a 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -1,6 +1,8 @@
-source :rubygems
+source 'https://rubygems.org'
 
 group :development, :test do
+  gem 'rake',                   :require => false
+  gem 'rspec-puppet',           :require => false
   gem 'puppetlabs_spec_helper', :require => false
 end
 
index d3511424645f8a5a70447f370cdd7b13559f5c81..2b1b21c3f83ba825dc747fd285184a6c1115b942 100644 (file)
@@ -1,5 +1,5 @@
 name    'puppetlabs-apt'
-version '1.1.0'
+version '1.1.1'
 source  'https://github.com/puppetlabs/puppetlabs-apt'
 author  'Evolving Web / Puppet Labs'
 license 'Apache License 2.0'
index 5082e343376ca01fb5551e91fd12b3631682d9dd..402d7ab021982244b61a07ab923405c536418cd3 100644 (file)
--- a/README.md
+++ b/README.md
@@ -101,6 +101,16 @@ Adds an apt pin for a certain release.
     apt::pin { 'karmic-updates': priority => 700 }
     apt::pin { 'karmic-security': priority => 700 }
 
+Note you can also specifying more complex pins using distribution properties.
+
+    apt::pin { 'stable':
+      priority        => -10,
+      originator      => 'Debian',
+      release_version => '3.0',
+      component       => 'main',
+      label           => 'Debian'
+    }
+
 ###apt::ppa
 
 Adds a ppa repository using `add-apt-repository`.
@@ -213,10 +223,3 @@ A lot of great people have contributed to this module. A somewhat current list f
 * Spencer Krum <spencer@puppetlabs.com>  
 * William Van Hevelingen <blkperl@cat.pdx.edu> <wvan13@gmail.com>  
 * Zach Leslie <zach@puppetlabs.com>  
-
-Release Notes
--------------
-
-**1.1.0**
-
-This release includes Ubuntu 12.10 (Quantal) support for PPAs.
index 98a0f3a32c4b42192f33f6795689b3df939b24ea..c78bf658ce984a538aad7552ca3dd98581b3f29c 100644 (file)
@@ -3,12 +3,15 @@ define apt::key (
   $ensure = present,
   $key_content = false,
   $key_source = false,
-  $key_server = 'keyserver.ubuntu.com'
+  $key_server = 'keyserver.ubuntu.com',
+  $key_options = false
 ) {
 
   include apt::params
 
   $upkey = upcase($key)
+  # trim the key to the last 8 chars so we can match longer keys with apt-key list too
+  $trimmedkey = regsubst($upkey, '^.*(.{8})$', '\1')
 
   if $key_content {
     $method = 'content'
@@ -39,16 +42,23 @@ define apt::key (
         anchor { "apt::key ${upkey} present": }
       }
 
+      if $key_options{
+        $options_string = "--keyserver-options ${key_options}"
+      }
+      else{
+        $options_string = ''
+      }
+
       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}'",
+          'server'  => "apt-key adv --keyserver '${key_server}' ${options_string} --recv-keys '${upkey}'",
         }
         exec { $digest:
           command   => $digest_command,
           path      => '/bin:/usr/bin',
-          unless    => "/usr/bin/apt-key list | /bin/grep '${upkey}'",
+          unless    => "/usr/bin/apt-key list | /bin/grep '${trimmedkey}'",
           logoutput => 'on_failure',
           before    => Anchor["apt::key ${upkey} present"],
         }
@@ -66,7 +76,7 @@ define apt::key (
       exec { "apt::key ${upkey} absent":
         command   => "apt-key del '${upkey}'",
         path      => '/bin:/usr/bin',
-        onlyif    => "apt-key list | grep '${upkey}'",
+        onlyif    => "apt-key list | grep '${trimmedkey}'",
         user      => 'root',
         group     => 'root',
         logoutput => 'on_failure',
index ed698e72bed8bba502d2081483e3052b2103d0c6..aa0f80d60c9d292e04545898ce972c303feaa97b 100644 (file)
@@ -7,7 +7,14 @@ class apt::params {
 
   case $::lsbdistid {
     'debian': {
-      $backports_location = 'http://backports.debian.org/debian-backports'
+      case $::lsbdistcodename {
+        'squeeze': {
+          $backports_location = 'http://backports.debian.org/debian-backports'
+        }
+        default: {
+          $backports_location = 'http://ftp.debian.org/debian/'
+        }
+      }
     }
     'ubuntu': {
       case $::lsbdistcodename {
index 21cc3ffdefc0294c0c91c37de474971b94b26869..39de3d8f1f688bbf1f79b5903c094558923efb07 100644 (file)
@@ -2,15 +2,19 @@
 # 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    = ''
+  $ensure          = present,
+  $explanation     = "${::caller_module_name}: ${name}",
+  $order           = '',
+  $packages        = '*',
+  $priority        = 0,
+  $release         = '', # a=
+  $origin          = '',
+  $version         = '',
+  $codename        = '', # n=
+  $release_version = '', # v=
+  $component       = '', # c=
+  $originator      = '', # o=
+  $label           = ''  # l=
 ) {
 
   include apt::params
@@ -21,16 +25,37 @@ define apt::pin(
     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}"
+  $pin_release_array = [
+    $release,
+    $codename,
+    $release_version,
+    $component,
+    $originator,
+    $label] 
+  $pin_release = join($pin_release_array, '')
+
+  # Read the manpage 'apt_preferences(5)', especially the chapter
+  # 'Thea Effect of APT Preferences' to understand the following logic
+  # and the difference between specific and general form
+  if $packages != '*' { # specific form
+
+    if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
+      ( $origin != '' and ( $pin_release != '' or $version != '' )) or
+      ( $version != '' and ( $pin_release != '' or $origin != '' )) {
+      fail('parameters release, origin, and version are mutually exclusive')
+    }
+
+  } else { # general form
+
+    if $version != '' {
+      fail('parameter version cannot be used in general form')
+    }
+
+    if ( $pin_release != '' and $origin != '' ) or
+      ( $origin != '' and $pin_release != '' ) {
+      fail('parmeters release and origin are mutually exclusive')
+    }
+
   }
 
   $path = $order ? {
index a859174a1aaef9296a74bc8ec8c6acd51d096f1a..713c7e933ac1f75263fdffd09c7a056eb3161538 100644 (file)
@@ -12,7 +12,8 @@ define apt::source(
   $key_server        = 'keyserver.ubuntu.com',
   $key_content       = false,
   $key_source        = false,
-  $pin               = false
+  $pin               = false,
+  $architecture      = undef
 ) {
 
   include apt::params
@@ -61,6 +62,7 @@ define apt::source(
       logoutput   => 'on_failure',
       refreshonly => true,
       subscribe   => File["${name}.list"],
+      before      => Exec['apt_update'],
     }
   }
 
index 3aaf49cef494e79f3b4fce0c2e2e02ba91d7915d..a4cb1e26e3ad74f0ef67a58b52af2f9119278aa9 100644 (file)
@@ -12,34 +12,77 @@ describe 'apt::pin', :type => :define do
     }
   end
 
-  [ {},
+  [ 
+    { :params  => {},
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: release a=my_pin\nPin-Priority: 0\n"
+    },
     {
-      :packages  => 'apache',
-      :priority  => '1'
+      :params => {
+        :packages => 'apache', 
+        :priority => '1'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
     },
     {
-      :order     => 50,
-      :packages  => 'apache',
-      :priority  => '1'
+      :params => {
+        :order    => 50, 
+        :packages => 'apache', 
+        :priority => '1'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
     },
     {
-      :ensure    => 'absent',
-      :packages  => 'apache',
-      :priority  => '1'
+      :params => {
+        :ensure   => 'absent',
+        :packages => 'apache',
+        :priority => '1'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_pin\nPin-Priority: 1\n"
     },
     {
-      :packages  => 'apache',
-      :priority  => '1',
-      :release   => 'my_newpin'
-    }
+      :params => {
+        :packages => 'apache',
+        :priority => '1',
+        :release  => 'my_newpin'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=my_newpin\nPin-Priority: 1\n"
+    },
+    {
+      :params => {
+        :packages => 'apache',
+        :priority => '1',
+        :version  => '2.2.16*'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: version 2.2.16*\nPin-Priority: 1\n"
+    },
+    {
+      :params => {
+        :priority => '1',
+        :origin   => 'ftp.de.debian.org'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: *\nPin: origin \"ftp.de.debian.org\"\nPin-Priority: 1\n"
+    },
+    {
+      :params => {
+        :packages        => 'apache',
+        :priority        => '1',  
+        :release         => 'stable',
+        :codename        => 'wheezy',
+        :release_version => '3.0',
+        :component       => 'main',
+        :originator      => 'Debian',
+        :label           => 'Debian'
+      },
+      :content => "# my_pin\nExplanation: : my_pin\nPackage: apache\nPin: release a=stable, n=wheezy, v=3.0, c=main, o=Debian, l=Debian\nPin-Priority: 1\n"
+    },
   ].each do |param_set|
     describe "when #{param_set == {} ? "using default" : "specifying"} define parameters" do
       let :param_hash do
-        default_params.merge(param_set)
+        default_params.merge(param_set[:params])
       end
 
       let :params do
-        param_set
+        param_set[:params]
       end
 
       it { should include_class("apt::params") }
@@ -50,7 +93,7 @@ describe 'apt::pin', :type => :define do
           '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",
+          'content' => param_set[:content],
         })
       }
     end
index 0f37f6367bcbd761d966fe448caf18ea9dd71163..0a8da3d5a6a70b433536050f8796cb6ff1b7d419 100644 (file)
@@ -48,6 +48,9 @@ describe 'apt::source', :type => :define do
     },
     {
       :release            => 'custom',
+    },
+    {
+      :architecture       => 'amd64',
     }
   ].each do |param_set|
     describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
@@ -69,9 +72,13 @@ describe 'apt::source', :type => :define do
 
       let :content do
         content = "# #{title}"
-        content << "\ndeb #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
+        if param_hash[:architecture]
+          arch = "[arch=#{param_hash[:architecture]}]"
+        end
+        content << "\ndeb #{arch} #{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"
+          content << "deb-src #{arch} #{param_hash[:location]} #{param_hash[:release]} #{param_hash[:repos]}\n"
         end
         content
       end
@@ -114,7 +121,8 @@ describe 'apt::source', :type => :define do
           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
+            "refreshonly" => true,
+            "before"      => 'Exec[apt_update]',
           })
         else
           should_not contain_exec("Required packages: '#{param_hash[:required_packages]}' for #{title}").with({
index 74df8b79c45b54b36400e7d942da2f67df6c9e4d..62c44c72414b41551ad8334c468ec70ba8ccc80f 100644 (file)
@@ -1,3 +1,20 @@
+<%-
+@pin = "release a=#{@name}" # default value
+if @pin_release.length > 0
+  options = []
+  options.push("a=#{@release}") if @release.length > 0
+  options.push("n=#{@codename}") if @codename.length > 0
+  options.push("v=#{@release_version}") if @release_version.length > 0
+  options.push("c=#{@component}") if @component.length > 0
+  options.push("o=#{@originator}") if @originator.length > 0
+  options.push("l=#{@label}") if @label.length > 0
+  @pin = "release #{options.join(', ')}"
+elsif @version.length > 0
+  @pin = "version #{@version}"
+elsif @origin.length > 0
+  @pin = "origin \"#{@origin}\""
+end
+-%>
 # <%= @name %>
 Explanation: <%= @explanation %>
 Package: <%= @packages %>
index 65764b2612cac71780f8cbef50cb2b2d9faaf9d6..845b8ae161726ade3f617868362dfc9da975fec4 100644 (file)
@@ -1,5 +1,5 @@
 # <%= @name %>
-deb <%= @location %> <%= @release_real %> <%= @repos %>
+deb <% if @architecture %>[arch=<%= @architecture %>]<% end %> <%= @location %> <%= @release_real %> <%= @repos %>
 <%- if @include_src then -%>
-deb-src <%= @location %> <%= @release_real %> <%= @repos %>
+deb-src <% if @architecture %>[arch=<%= @architecture %>]<% end %> <%= @location %> <%= @release_real %> <%= @repos %>
 <%- end -%>
index 92679cf6be6e41a04b1bad1d0b820eeac026ce3a..cc90f909c091f2ee56700b6c91bcc3aae9a5ebea 100644 (file)
@@ -2,4 +2,5 @@
 apt::key { 'puppetlabs':
   key        => '4BD6EC30',
   key_server => 'pgp.mit.edu',
+  key_options => "http-proxy=\"http://proxyuser:proxypass@example.org:3128\"",
 }