apt: Add settings, keys and ppas.
authorDaniele Sluijters <daenney@users.noreply.github.com>
Sat, 28 Feb 2015 16:04:47 +0000 (17:04 +0100)
committerDaniele Sluijters <daenney@users.noreply.github.com>
Sun, 1 Mar 2015 13:20:45 +0000 (14:20 +0100)
* Allow any configuration of apt to be done through data bindings by
  passing in hashes representing the resources.
* Switch apt::ppa to use `distid` as set in `apt::params. This makes
  `apt::ppa` also work for LinuxMint.

manifests/init.pp
manifests/ppa.pp
spec/classes/apt_spec.rb
spec/defines/ppa_spec.rb

index ea546dc55ef8badde4921cf4b5a77715d8571186..dbf03329586177846ddf5c0bdad09663eefff347 100644 (file)
@@ -1,12 +1,14 @@
 #
 class apt(
-  $update               = {},
-  $purge                = {},
-  $proxy                = {},
-  $sources              = undef,
+  $update   = {},
+  $purge    = {},
+  $proxy    = {},
+  $sources  = {},
+  $keys     = {},
+  $ppas     = {},
+  $settings = {},
 ) inherits ::apt::params {
 
-
   $frequency_options = ['always','daily','weekly','reluctantly']
   validate_hash($update)
   if $update['frequency'] {
@@ -60,6 +62,11 @@ class apt(
 
   $_proxy = merge($apt::proxy_defaults, $proxy)
 
+  validate_hash($sources)
+  validate_hash($keys)
+  validate_hash($settings)
+  validate_hash($ppas)
+
   if $proxy['host'] {
     apt::setting { 'conf-proxy':
       priority => '01',
@@ -135,8 +142,19 @@ class apt(
   }
 
   # manage sources if present
-  if $sources != undef {
-    validate_hash($sources)
+  if $sources {
     create_resources('apt::source', $sources)
   }
+  # manage keys if present
+  if $keys {
+    create_resources('apt::key', $keys)
+  }
+  # manage ppas if present
+  if $ppas {
+    create_resources('apt::ppa', $ppas)
+  }
+  # manage settings if present
+  if $settings {
+    create_resources('apt::setting', $settings)
+  }
 }
index 4a08dce6fd413134590962f8ad11091b171f5958..33cd60d586c1b7d42e9357edca8f7904abf07d13 100644 (file)
@@ -10,8 +10,8 @@ define apt::ppa(
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  if $::operatingsystem != 'Ubuntu' {
-    fail('apt::ppa is currently supported on Ubuntu only.')
+  if $::apt::distid != 'ubuntu' {
+    fail('apt::ppa is currently supported on Ubuntu and LinuxMint only.')
   }
 
   $filename_without_slashes = regsubst($name, '/', '-', 'G')
index d3559e4cef9453e6f944a88515275960571c13ec..8e8a6c6613c5d1b2cf7636040697e59c342c14d3 100644 (file)
@@ -171,6 +171,63 @@ describe 'apt' do
     it { is_expected.to contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) }
   end
 
+  context 'with keys defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+      }
+    end
+    let(:params) { { :keys => {
+      '55BE302B' => {
+        'key_server' => 'subkeys.pgp.net',
+      },
+      '4BD6EC30' => {
+        'key_server' => 'pgp.mit.edu',
+      }
+    } } }
+
+    it { is_expected.to contain_apt__key('55BE302B').with({
+        :key_server => 'subkeys.pgp.net',
+    })}
+
+    it { is_expected.to contain_apt__key('4BD6EC30').with({
+        :key_server => 'pgp.mit.edu',
+    })}
+  end
+
+  context 'with ppas defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'ubuntu',
+      }
+    end
+    let(:params) { { :ppas => {
+      'ppa:drizzle-developers/ppa' => {},
+      'ppa:nginx/stable' => {},
+    } } }
+
+    it { is_expected.to contain_apt__ppa('ppa:drizzle-developers/ppa')}
+    it { is_expected.to contain_apt__ppa('ppa:nginx/stable')}
+  end
+
+  context 'with settings defined on valid osfamily' do
+    let :facts do
+      { :osfamily        => 'Debian',
+        :lsbdistcodename => 'precise',
+        :lsbdistid       => 'Debian',
+      }
+    end
+    let(:params) { { :settings => {
+      'conf-banana' => { 'content' => 'banana' },
+      'pref-banana' => { 'content' => 'banana' },
+    } } }
+
+    it { is_expected.to contain_apt__setting('conf-banana')}
+    it { is_expected.to contain_apt__setting('pref-banana')}
+  end
+
   describe 'failing tests' do
     context "purge['sources.list']=>'banana'" do
       let(:params) { { :purge => { 'sources.list' => 'banana' }, } }
index 14a5139c3ba4d465b52c37f8bc3d98c8d9e03923..f29a8dfee5664b07098fda9485696daa4b477553 100644 (file)
@@ -214,7 +214,7 @@ describe 'apt::ppa' do
       it do
         expect {
           is_expected.to compile
-        }.to raise_error(Puppet::Error, /apt::ppa is currently supported on Ubuntu only./)
+        }.to raise_error(Puppet::Error, /supported on Ubuntu and LinuxMint only/)
       end
     end
   end