]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #324 from cmurphy/master
authorAshley Penney <ashley.penney@puppetlabs.com>
Thu, 3 Jul 2014 21:43:27 +0000 (17:43 -0400)
committerAshley Penney <ashley.penney@puppetlabs.com>
Thu, 3 Jul 2014 21:43:27 +0000 (17:43 -0400)
Add validate and lint tasks to travis script

21 files changed:
CHANGELOG.md
Modulefile
README.md
lib/facter/apt_package_updates.rb [new file with mode: 0644]
lib/facter/apt_security_updates.rb [new file with mode: 0644]
lib/facter/apt_updates.rb [new file with mode: 0644]
lib/puppet/provider/apt_key/apt_key.rb
lib/puppet/type/apt_key.rb
manifests/init.pp
manifests/key.pp
manifests/params.pp
manifests/ppa.pp
manifests/unattended_upgrades.pp
metadata.json
spec/acceptance/apt_key_provider_spec.rb
spec/classes/init_spec.rb
spec/classes/unattended_upgrades_spec.rb
spec/defines/key_spec.rb
spec/unit/facter/apt_package_updates_spec.rb [new file with mode: 0644]
spec/unit/facter/apt_security_updates_spec.rb [new file with mode: 0644]
spec/unit/facter/apt_updates_spec.rb [new file with mode: 0644]

index 10503c9144cd4e18867df3c50adf6f9ceb29f3d1..bf8553d8b606c6c710e53f3b8cef34a94c77b966 100644 (file)
@@ -1,3 +1,29 @@
+##2014-06-04 - Release 1.5.0
+###Summary
+
+This release adds support for Ubuntu 14.04.  It also includes many new features 
+and important bugfixes.  One huge change is that apt::key was replaced with
+apt_key, which allows you to use puppet resource apt_key to inventory keys on
+your system.
+
+Special thanks to daenney, our intrepid unofficial apt maintainer!
+
+####Features
+- Add support for Ubuntu Trusty!
+- Add apt::hold define
+- Generate valid *.pref files in apt::pin
+- Made pin_priority configurable for apt::backports
+- Add apt_key type and provider
+- Rename "${apt_conf_d}/proxy" to "${apt_conf_d}/01proxy"
+- apt::key rewritten to use apt_key type
+- Add support for update_tries to apt::update
+
+####Bugfixes
+- Typo fixes
+- Fix unattended upgrades
+- Removed bogus line when using purge_preferences
+- Fix apt::force to upgrade allow packages to be upgraded to the pacakge from the specified release
+
 ##2014-03-04 - Supported Release 1.4.2
 ###Summary
 
index 40a87f4ef3967d56c9ee7c18985ff9524d7384f7..45169b31e8305b2016a7e0e662f3209d3298730d 100644 (file)
@@ -1,5 +1,5 @@
 name    'puppetlabs-apt'
-version '1.4.2'
+version '1.5.0'
 source  'https://github.com/puppetlabs/puppetlabs-apt'
 author  'Evolving Web / Puppet Labs'
 license 'Apache License 2.0'
index f92122fb348330e0753d8411b6d63065907d3363..9c52c77f74ac324147f81c5aa173407cbaae9fbb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -214,6 +214,13 @@ If you would like to configure your system so the source is the Puppet Labs APT
       key_server => 'pgp.mit.edu',
     }
 
+### Facts
+
+There are a few facts included within the apt module describing the state of the apt system:
+
+* `apt_updates` - the number of updates available on the system
+* `apt_security_updates` - the number of updates which are security updates
+* `apt_package_updates` - the package names that are available for update. On Facter 2.0 and newer this will be a list type, in earlier versions it is a comma delimitered string.
 
 #### Hiera example
 <pre>
diff --git a/lib/facter/apt_package_updates.rb b/lib/facter/apt_package_updates.rb
new file mode 100644 (file)
index 0000000..97c75c6
--- /dev/null
@@ -0,0 +1,13 @@
+Facter.add("apt_package_updates") do
+  confine :osfamily => 'Debian'
+  setcode do
+    if File.executable?("/usr/lib/update-notifier/apt-check")
+      packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1')
+      packages = packages.split("\n")
+      if Facter.version < '2.0.0'
+        packages = packages.join(',')
+      end
+      packages
+    end
+  end
+end
diff --git a/lib/facter/apt_security_updates.rb b/lib/facter/apt_security_updates.rb
new file mode 100644 (file)
index 0000000..19bae75
--- /dev/null
@@ -0,0 +1,9 @@
+Facter.add("apt_security_updates") do
+  confine :osfamily => 'Debian'
+  setcode do
+    if File.executable?("/usr/lib/update-notifier/apt-check")
+      updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
+      Integer(updates.strip.split(';')[1])
+    end
+  end
+end
diff --git a/lib/facter/apt_updates.rb b/lib/facter/apt_updates.rb
new file mode 100644 (file)
index 0000000..ee17738
--- /dev/null
@@ -0,0 +1,9 @@
+Facter.add("apt_updates") do
+  confine :osfamily => 'Debian'
+  setcode do
+    if File.executable?("/usr/lib/update-notifier/apt-check")
+      updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1')
+      Integer(updates.strip.split(';')[0])
+    end
+  end
+end
index f8d40728b04a13727d32f1ede6cd2eebe4eb52ac..1d3c1744b586ccd5ee0d2fb0e3eed29007a986ad 100644 (file)
@@ -26,6 +26,11 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
   commands   :apt_key  => 'apt-key'
 
   def self.instances
+    if RUBY_VERSION > '1.8.7'
+      key_output = apt_key('list').encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '')
+    else
+      key_output = apt_key('list')
+    end
     key_array = apt_key('list').split("\n").collect do |line|
       line_hash = key_line_hash(line)
       next unless line_hash
index fa7b0c676c77e2c4c1d48eeaa37a1cd677a27076..e2cb8d9cf92695dded9d331b627dc7759abc9092 100644 (file)
@@ -60,10 +60,10 @@ Puppet::Type.newtype(:apt_key) do
   end
 
   newparam(:server) do
-    desc 'The key server to fetch the key from based on the ID.'
+    desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
     defaultto :'keyserver.ubuntu.com'
-    # Need to validate this, preferably through stdlib is_fqdn
-    # but still working on getting to that.
+    
+    newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,4})?$/)
   end
 
   newparam(:keyserver_options) do
index c32c5daca4b0cf753756f419a1a298e00e1dc2a4..597774c8338775a56e1e64c1d3a03ffe8ceb59ce 100644 (file)
@@ -153,7 +153,7 @@ class apt(
     owner   => root,
     group   => root,
   }
-  
+
   file { 'old-proxy-file':
     ensure  => absent,
     path    => "${apt_conf_d}/proxy",
index 9ccbfcb6bbf6990a426f8664904a134f407fcc4f..8d3bcf045c58f59df310046853e646b0c538191a 100644 (file)
@@ -39,7 +39,8 @@
 # [*key_server*]
 #   _default_: +undef+
 #
-#   The keyserver from where to fetch our GPG key. It defaults to
+#   The keyserver from where to fetch our GPG key. It can either be a domain
+#   name or url. It defaults to
 #   undef which results in apt_key's default keyserver being used,
 #   currently +keyserver.ubuntu.com+.
 #
@@ -68,9 +69,7 @@ define apt::key (
   }
 
   if $key_server {
-    if !is_domain_name($key_server) {
-      fail('$key_server must be a valid domain name')
-    }
+    validate_re($key_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,4})?$'])
   }
 
   if $key_options {
index 4e974ba48b894efea81590aa94b1b2432f1600c9..f635b5801cd98889582d19c088f6923a2708ace0 100644 (file)
@@ -12,7 +12,8 @@ class apt::params {
           $backports_location = 'http://backports.debian.org/debian-backports'
           $legacy_origin       = true
           $origins             = ['${distro_id} oldstable',
-                                  '${distro_id} ${distro_codename}-security']
+                                  '${distro_id} ${distro_codename}-security',
+                                  '${distro_id} ${distro_codename}-lts']
         }
         'wheezy': {
           $backports_location = 'http://ftp.debian.org/debian/'
index ab79b9417904664542386c572a607772f51638b2..a55e1e0e5c7a075b04ee4861370d40e107a42254 100644 (file)
@@ -15,7 +15,7 @@ define apt::ppa(
   }
 
   if $::operatingsystem != 'Ubuntu' {
-    fail("apt::ppa is currently supported on Ubuntu only.")
+    fail('apt::ppa is currently supported on Ubuntu only.')
   }
 
   $filename_without_slashes = regsubst($name, '/', '-', 'G')
index c57a9ee7f533b79b9a38e74d73d72909f8c1af7b..7e3ccc44b07637ee1a21d86b88f68a7eb03d516d 100644 (file)
 class apt::unattended_upgrades (
   $origins             = $::apt::params::origins,
   $blacklist           = [],
-  $update              = "1",
-  $download            = "1",
-  $upgrade             = "1",
-  $autoclean           = "7",
+  $update              = '1',
+  $download            = '1',
+  $upgrade             = '1',
+  $autoclean           = '7',
   $auto_fix            = true,
   $minimal_steps       = false,
   $install_on_shutdown = false,
-  $mail_to             = "NONE",
+  $mail_to             = 'NONE',
   $mail_only_on_error  = false,
   $remove_unused       = true,
   $auto_reboot         = false,
-  $dl_limit            = "NONE",
-  $enable              = "1",
-  $backup_interval     = "0",
-  $backup_level        = "3",
-  $max_age             = "0",
-  $min_age             = "0",
-  $max_size            = "0",
-  $download_delta      = "0",
-  $verbose             = "0",
+  $dl_limit            = 'NONE',
+  $enable              = '1',
+  $backup_interval     = '0',
+  $backup_level        = '3',
+  $max_age             = '0',
+  $min_age             = '0',
+  $max_size            = '0',
+  $download_delta      = '0',
+  $verbose             = '0',
 ) inherits ::apt::params {
 
   validate_bool(
index f1e8663059bcf2825130052fb0c30b10b92272f9..7365c67f86cbc4c10453b0a1042a2e485ababa20 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name": "puppetlabs-apt",
-    "version": "1.4.1",
+    "version": "1.5.0",
     "source": "https://github.com/puppetlabs/puppetlabs-apt",
     "author": "Puppet Labs",
     "license": "Apache-2.0",
         "operatingsystem": "Ubuntu",
         "operatingsystemrelease": [
           "10.04",
-          "12.04"
+          "12.04",
+          "14.04"
         ]
       }
     ],
     "requirements": [
-      { "name": "pe", "version_requirement": "3.2.x" },
+      { "name": "pe", "version_requirement": ">= 3.2.0 < 3.4.0" },
       { "name": "puppet", "version_requirement": "3.x" }
     ],
     "dependencies": []
index 0a314959577c953ed7b99a8a3519de4c2986ce57..d9c2c0d7518c8534b8c89e12933926277124e2cf 100644 (file)
@@ -192,6 +192,22 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
       end
     end
 
+    context 'hkp://pgp.mit.edu:80' do
+      it 'works' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_ID}',
+          ensure => 'present',
+          server => 'hkp://pgp.mit.edu:80',
+        }
+        EOS
+
+        apply_manifest(pp, :catch_failures => true)
+        expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
+        shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
+      end
+    end
+
     context 'nonexistant.key.server' do
       it 'fails' do
         pp = <<-EOS
@@ -207,6 +223,22 @@ ugVIB2pi+8u84f+an4Hml4xlyijgYu05pqNvnLRyJDLd61hviLC8GYU=
         end
       end
     end
+
+    context 'key server start with dot' do
+      it 'fails' do
+        pp = <<-EOS
+        apt_key { 'puppetlabs':
+          id     => '#{PUPPETLABS_GPG_KEY_ID}',
+          ensure => 'present',
+          server => '.pgp.key.server',
+        }
+        EOS
+
+        apply_manifest(pp, :expect_failures => true) do |r|
+          expect(r.stderr).to match(/Invalid value \".pgp.key.server\"/)
+        end
+      end
+    end
   end
 
   describe 'source =>' do
index 120b7e8239849894097695ff70049a50298b0a99..c5e938a9aa72130496bebaa8fb37874ee9491753 100644 (file)
@@ -54,4 +54,16 @@ describe 'apt' do
     it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
     it { should contain_file('puppetlabs.list').with_content(/^deb-src http:\/\/apt.puppetlabs.com precise main$/) }
   end
+
+  context 'with unsupported osfamily' do
+    let :facts do
+      { :osfamily        => 'Darwin', }
+    end
+
+    it do
+      expect {
+       should compile
+      }.to raise_error(Puppet::Error, /This module only works on Debian or derivatives like Ubuntu/)
+    end
+  end
 end
index a2fb48b12600e5bc0e3fbc6a43a5e22fa1c8c8d1..8494f0410d9b6f7631721673e7314e69857aea72 100644 (file)
@@ -60,6 +60,8 @@ describe 'apt::unattended_upgrades', :type => :class do
         it {
           should contain_file(file_unattended).with_content(
             /^Unattended-Upgrade::Allowed-Origins/
+          ).with_content(
+            /"\${distro_id} \${distro_codename}-lts";/
           ).with_content(
             /"\${distro_id} \${distro_codename}-security";/
           ).with_content(
index a85d1710b4e565b7f5bfdf33c19a7ab51791a460..005c95e4698ab6c426186e4d23b39e8fc4a92cc3 100644 (file)
@@ -142,31 +142,159 @@ describe 'apt::key', :type => :define do
     end
 
     describe 'key_server =>' do
-      let :params do {
-        :key_server => 'pgp.mit.edu',
-      } end
+       context 'domain name' do
+        let :params do {
+          :key_server => 'pgp.mit.edu',
+       } end
 
-      it 'contains the apt::key' do
-        should contain_apt__key(title).with({
-          :key         => title,
-          :ensure      => 'present',
-          :key_server  => 'pgp.mit.edu',
-        })
+       it 'contains the apt::key' do
+          should contain_apt__key(title).with({
+            :key         => title,
+            :ensure      => 'present',
+            :key_server  => 'pgp.mit.edu',
+          })
+       end
+       it 'contains the apt_key' do
+          should contain_apt_key(title).with({
+            :id                => title,
+            :ensure            => 'present',
+            :source            => nil,
+            :server            => params[:key_server],
+            :content           => nil,
+            :keyserver_options => nil,
+          })
+       end
+       it 'contains the apt_key present anchor' do
+          should contain_anchor("apt_key #{title} present")
+       end
+                       end
+
+      context "domain with dash" do
+        let(:params) do{
+          :key_server => 'p-gp.m-it.edu',
+        } end
+        it "should contain apt::key" do
+          should contain_apt__key(title).with({
+            :key        => title,
+            :ensure     => 'present',
+            :key_server => 'p-gp.m-it.edu',
+          })
+        end
       end
-      it 'contains the apt_key' do
-        should contain_apt_key(title).with({
-          :id                => title,
-          :ensure            => 'present',
-          :source            => nil,
-          :server            => params[:key_server],
-          :content           => nil,
-          :keyserver_options => nil,
-        })
+
+      context "domain begin with dash" do
+        let(:params) do{
+          :key_server => '-pgp.mit.edu',
+        } end
+        it 'fails' do
+          expect { subject } .to raise_error(/does not match/)
+        end
       end
-      it 'contains the apt_key present anchor' do
-        should contain_anchor("apt_key #{title} present")
+
+      context "domain begin with dot" do
+        let(:params) do{
+          :key_server => '.pgp.mit.edu',
+        } end
+        it 'fails' do
+          expect { subject } .to raise_error(/does not match/)
+        end
       end
-    end
+
+      context "domain end with dot" do
+        let(:params) do{
+          :key_server => "pgp.mit.edu.",
+        } end
+        it 'fails' do
+          expect { subject } .to raise_error(/does not match/)
+        end
+      end
+
+      context "url" do
+        let (:params) do{
+          :key_server => 'hkp://pgp.mit.edu',
+        } end
+        it "should contain apt::key" do
+         should contain_apt__key(title).with({
+           :key         => title,
+           :ensure      => 'present',
+           :key_server  => 'hkp://pgp.mit.edu',
+         })
+        end
+      end
+      context "url with port number" do
+        let (:params) do{
+          :key_server => 'hkp://pgp.mit.edu:80',
+        } end
+        it "should contain apt::key" do
+         should contain_apt__key(title).with({
+            :key        => title,
+            :ensure     => 'present',
+            :key_server => 'hkp://pgp.mit.edu:80',
+         })
+        end
+      end
+
+      context "incorrect port number url" do
+        let (:params) do{
+          :key_server => 'hkp://pgp.mit.edu:8008080'
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+      context "incorrect protocol for  url" do
+        let (:params) do{
+          :key_server => 'abc://pgp.mit.edu:80'
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+      context "missing port number url" do
+        let (:params) do{
+          :key_server => 'hkp://pgp.mit.edu:'
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+      context "url ending with a dot" do
+        let (:params) do{
+          :key_server => 'hkp://pgp.mit.edu.'
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+      context "url begin with a dash" do
+        let(:params) do{
+          :key_server => "hkp://-pgp.mit.edu",
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+      context "url with dash" do
+        let(:params) do{
+          :key_server => 'hkp://p-gp.m-it.edu',
+        } end
+        it "should contain apt::key" do
+          should contain_apt__key(title).with({
+            :key        => title,
+            :ensure     => 'present',
+            :key_server => 'hkp://p-gp.m-it.edu',
+          })
+        end
+      end
+      context "exceed characher url" do
+        let (:params) do{
+          :key_server => 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu'
+        } end
+        it 'fails' do
+          expect { subject }.to raise_error(/does not match/)
+        end
+      end
+               end
 
     describe 'key_options =>' do
       let :params do {
@@ -229,7 +357,7 @@ describe 'apt::key', :type => :define do
         :key_server => 'two bottles of rum',
       } end
       it 'fails' do
-        expect { subject }.to raise_error(/must be a valid domain name/)
+        expect { subject }.to raise_error(/does not match/)
       end
     end
 
diff --git a/spec/unit/facter/apt_package_updates_spec.rb b/spec/unit/facter/apt_package_updates_spec.rb
new file mode 100644 (file)
index 0000000..dfa0927
--- /dev/null
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'apt_package_updates fact' do
+  subject { Facter.fact(:apt_package_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'on Debian based distro missing update-notifier-common' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns false
+  }
+  it { should == nil }
+  end
+
+  describe 'on Debian based distro' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns true
+    Facter::Util::Resolution.stubs(:exec).returns "puppet-common\nlinux-generic\nlinux-image-generic"
+  }
+  it {
+    if Facter.version < '2.0.0'
+      should == 'puppet-common,linux-generic,linux-image-generic'
+    else
+      should == ['puppet-common', 'linux-generic', 'linux-image-generic']
+    end
+  }
+  end
+end
diff --git a/spec/unit/facter/apt_security_updates_spec.rb b/spec/unit/facter/apt_security_updates_spec.rb
new file mode 100644 (file)
index 0000000..999603b
--- /dev/null
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'apt_security_updates fact' do
+  subject { Facter.fact(:apt_security_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'on Debian based distro missing update-notifier-common' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns false
+  }
+  it { should == nil }
+  end
+
+  describe 'on Debian based distro' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns true
+    Facter::Util::Resolution.stubs(:exec).returns '14;7'
+  }
+  it { should == 7 }
+  end
+
+end
diff --git a/spec/unit/facter/apt_updates_spec.rb b/spec/unit/facter/apt_updates_spec.rb
new file mode 100644 (file)
index 0000000..2f343bd
--- /dev/null
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'apt_updates fact' do
+  subject { Facter.fact(:apt_updates).value }
+  after(:each) { Facter.clear }
+
+  describe 'on Debian based distro missing update-notifier-common' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns false
+  }
+  it { should == nil }
+  end
+
+  describe 'on Debian based distro' do
+    before { 
+    Facter.fact(:osfamily).stubs(:value).returns 'Debian'
+    File.stubs(:executable?).returns true
+    Facter::Util::Resolution.stubs(:exec).returns '14;7'
+  }
+  it { should == 14 }
+  end
+
+end