From 95ae9ab48ffd76f765d7a7bf7bf5baf2c1299a41 Mon Sep 17 00:00:00 2001 From: Daniele Sluijters Date: Sat, 28 Feb 2015 17:04:47 +0100 Subject: [PATCH 1/1] apt: Add settings, keys and ppas. * 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 | 32 +++++++++++++++++----- manifests/ppa.pp | 4 +-- spec/classes/apt_spec.rb | 57 ++++++++++++++++++++++++++++++++++++++++ spec/defines/ppa_spec.rb | 2 +- 4 files changed, 85 insertions(+), 10 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index ea546dc..dbf0332 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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) + } } diff --git a/manifests/ppa.pp b/manifests/ppa.pp index 4a08dce..33cd60d 100644 --- a/manifests/ppa.pp +++ b/manifests/ppa.pp @@ -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') diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index d3559e4..8e8a6c6 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -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' }, } } diff --git a/spec/defines/ppa_spec.rb b/spec/defines/ppa_spec.rb index 14a5139..f29a8df 100644 --- a/spec/defines/ppa_spec.rb +++ b/spec/defines/ppa_spec.rb @@ -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 -- 2.32.3