From 10f313cfb4138b34481e219e231251c15acc84da Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Sat, 21 Feb 2015 12:11:57 -0800 Subject: [PATCH] Convert apt::source to use apt::setting May as well use the define since we added it --- manifests/source.pp | 18 +++++++----------- spec/classes/apt_spec.rb | 18 +++++------------- spec/defines/source_spec.rb | 30 +++++++----------------------- 3 files changed, 19 insertions(+), 47 deletions(-) diff --git a/manifests/source.pp b/manifests/source.pp index 0ca5212..bbd504e 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -23,17 +23,13 @@ define apt::source( fail('lsbdistcodename fact not available: release parameter required') } - file { "${name}.list": - ensure => $ensure, - path => "${::apt::sources_list_d}/${name}.list", - owner => root, - group => root, - mode => '0644', - content => template('apt/_header.erb', 'apt/source.list.erb'), - notify => Exec['apt_update'], + apt::setting { $name: + ensure => $ensure, + setting_type => 'list', + content => template('apt/_header.erb', 'apt/source.list.erb'), + notify => Exec['apt_update'], } - if ($pin != false) { # Get the host portion out of the url so we can pin to origin $url_split = split($location, '/') @@ -42,7 +38,7 @@ define apt::source( apt::pin { $name: ensure => $ensure, priority => $pin, - before => File["${name}.list"], + before => Apt::Setting[$name], origin => $host, } } @@ -55,7 +51,7 @@ define apt::source( key_server => $key_server, key_content => $key_content, key_source => $key_source, - before => File["${name}.list"], + before => Apt::Setting[$name], } } diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index d4be964..f8e8c17 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -110,31 +110,23 @@ describe 'apt', :type => :class do } } } it { - should contain_file('debian_unstable.list').with({ + should contain_apt__setting('debian_unstable').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/debian_unstable.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', 'notify' => 'Exec[apt_update]', }) } - it { should contain_file('debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } - it { should contain_file('debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } + it { should contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } + it { should contain_file('/etc/apt/sources.list.d/debian_unstable.list').with_content(/^deb-src http:\/\/debian.mirror.iweb.ca\/debian\/ unstable main contrib non-free$/) } it { - should contain_file('puppetlabs.list').with({ + should contain_apt__setting('puppetlabs').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/puppetlabs.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', 'notify' => 'Exec[apt_update]', }) } - it { should contain_file('puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } + it { should contain_file('/etc/apt/sources.list.d/puppetlabs.list').with_content(/^deb http:\/\/apt.puppetlabs.com precise main$/) } end describe 'failing tests' do diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index ff236bd..85a6d76 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -27,12 +27,8 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/my_source.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', }).with_content(/# my_source\ndeb-src wheezy main\n/) } end @@ -62,23 +58,19 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/my_source.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) } - it { is_expected.to contain_apt__pin('my_source').that_comes_before('File[my_source.list]').with({ + it { is_expected.to contain_apt__pin('my_source').that_comes_before('Apt::Setting[my_source]').with({ 'ensure' => 'present', 'priority' => '10', 'origin' => 'debian.mirror.iweb.ca', }) } - it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('File[my_source.list]').with({ + it { is_expected.to contain_apt__key("Add key: #{GPG_KEY_ID} from Apt::Source my_source").that_comes_before('Apt::Setting[my_source]').with({ 'ensure' => 'present', 'key' => GPG_KEY_ID, 'key_server' => 'pgp.mit.edu', @@ -103,12 +95,8 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/my_source.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', }).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) } end @@ -129,12 +117,8 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({ 'ensure' => 'present', - 'path' => '/etc/apt/sources.list.d/my_source.list', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0644', }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/) } end @@ -153,7 +137,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_file('my_source.list').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('my_source').that_notifies('Exec[apt_update]').with({ 'ensure' => 'absent' }) } -- 2.45.2