From 0475e50be8e4994e4c1c22ce103e903f52c2c599 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 26 Feb 2015 12:44:06 -0800 Subject: [PATCH] Make apt::setting notify Exec['apt_update'] by default Can be disabled by setting `notify_update => false` --- manifests/setting.pp | 25 ++++++++++++++++++++----- manifests/source.pp | 6 ------ spec/classes/apt_spec.rb | 2 -- spec/defines/setting_spec.rb | 27 +++++++++++++++++---------- spec/defines/source_spec.rb | 10 +++++----- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/manifests/setting.pp b/manifests/setting.pp index f6f0bc0..c288b35 100644 --- a/manifests/setting.pp +++ b/manifests/setting.pp @@ -1,9 +1,10 @@ define apt::setting ( - $priority = 50, - $ensure = file, - $source = undef, - $content = undef, - $file_perms = {}, + $priority = 50, + $ensure = file, + $source = undef, + $content = undef, + $file_perms = {}, + $notify_update = true, ) { $_file = merge($::apt::file_defaults, $file_perms) @@ -17,6 +18,7 @@ define apt::setting ( } validate_re($ensure, ['file', 'present', 'absent']) + validate_bool($notify_update) $title_array = split($title, '-') $setting_type = $title_array[0] @@ -46,6 +48,12 @@ define apt::setting ( $_path = $::apt::config_files[$setting_type]['path'] $_ext = $::apt::config_files[$setting_type]['ext'] + if $notify_update { + $_notify = Exec['apt_update'] + } else { + $_notify = undef + } + file { "${_path}/${_priority}${base_name}${_ext}": ensure => $ensure, owner => $_file['owner'], @@ -53,5 +61,12 @@ define apt::setting ( mode => $_file['mode'], content => $content, source => $source, + notify => $_notify, + } + + if $notify_update { + anchor { "apt::setting::${name}": + require => Class['apt::update'] + } } } diff --git a/manifests/source.pp b/manifests/source.pp index 9a3a791..b7d150c 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -26,7 +26,6 @@ define apt::source( apt::setting { "list-${name}": ensure => $ensure, content => template('apt/_header.erb', 'apt/source.list.erb'), - notify => Exec['apt_update'], } if ($pin != false) { @@ -53,9 +52,4 @@ define apt::source( before => Apt::Setting["list-${name}"], } } - - # Need anchor to provide containment for dependencies. - anchor { "apt::source::${name}": - require => Class['apt::update'], - } } diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index f66bf54..b8ff37e 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -112,7 +112,6 @@ describe 'apt', :type => :class do it { is_expected.to contain_apt__setting('list-debian_unstable').with({ 'ensure' => 'present', - 'notify' => 'Exec[apt_update]', }) } @@ -122,7 +121,6 @@ describe 'apt', :type => :class do it { is_expected.to contain_apt__setting('list-puppetlabs').with({ 'ensure' => 'present', - 'notify' => 'Exec[apt_update]', }) } diff --git a/spec/defines/setting_spec.rb b/spec/defines/setting_spec.rb index 5e88eea..e01fdbf 100644 --- a/spec/defines/setting_spec.rb +++ b/spec/defines/setting_spec.rb @@ -16,25 +16,25 @@ describe 'apt::setting' do context 'with title=conf-teddybear ' do let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]') } end context 'with title=pref-teddybear' do let(:title) { 'pref-teddybear' } let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/preferences.d/50teddybear') } + it { is_expected.to contain_file('/etc/apt/preferences.d/50teddybear').that_notifies('Exec[apt_update]') } end context 'with title=list-teddybear' do let(:title) { 'list-teddybear' } let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list') } + it { is_expected.to contain_file('/etc/apt/sources.list.d/teddybear.list').that_notifies('Exec[apt_update]') } end context 'with source' do let(:params) { { :source => 'puppet:///la/die/dah' } } it { - is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -45,7 +45,7 @@ describe 'apt::setting' do context 'with content' do let(:params) { default_params } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :ensure => 'file', :owner => 'root', :group => 'root', @@ -88,12 +88,12 @@ describe 'apt::setting' do describe 'with priority=100' do let(:params) { default_params.merge({ :priority => 100 }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear') } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/100teddybear').that_notifies('Exec[apt_update]') } end describe 'with ensure=absent' do let(:params) { default_params.merge({ :ensure => 'absent' }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :ensure => 'absent', })} end @@ -101,7 +101,7 @@ describe 'apt::setting' do describe 'with file_perms' do context "{'owner' => 'roosevelt'}" do let(:params) { default_params.merge({ :file_perms => {'owner' => 'roosevelt'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :owner => 'roosevelt', :group => 'root', :mode => '0644', @@ -110,7 +110,7 @@ describe 'apt::setting' do context "'group' => 'roosevelt'}" do let(:params) { default_params.merge({ :file_perms => {'group' => 'roosevelt'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :owner => 'root', :group => 'roosevelt', :mode => '0644', @@ -119,11 +119,18 @@ describe 'apt::setting' do context "'owner' => 'roosevelt'}" do let(:params) { default_params.merge({ :file_perms => {'mode' => '0600'} }) } - it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').with({ + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]').with({ :owner => 'root', :group => 'root', :mode => '0600', })} end + + context "'notify_update' => false}" do + let(:params) { default_params.merge({ :notify_update => false }) } + it { is_expected.to contain_file('/etc/apt/apt.conf.d/50teddybear') } + it { is_expected.not_to contain_file('/etc/apt/apt.conf.d/50teddybear').that_notifies('Exec[apt_update]') } + end + end end diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index ad986e9..5e2728b 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -27,7 +27,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('list-my_source').with({ 'ensure' => 'present', }).with_content(/# my_source\ndeb-src wheezy main\n/) } @@ -58,7 +58,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('list-my_source').with({ 'ensure' => 'present', }).with_content(/# foo\ndeb \[arch=x86_64 trusted=yes\] http:\/\/debian\.mirror\.iweb\.ca\/debian\/ sid testing\n/).without_content(/deb-src/) } @@ -95,7 +95,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('list-my_source').with({ 'ensure' => 'present', }).with_content(/# my_source\ndeb \[trusted=yes\] wheezy main\n/) } @@ -117,7 +117,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('list-my_source').with({ 'ensure' => 'present', }).with_content(/# my_source\ndeb-src \[arch=x86_64 \] wheezy main\n/) } @@ -137,7 +137,7 @@ describe 'apt::source', :type => :define do } end - it { is_expected.to contain_apt__setting('list-my_source').that_notifies('Exec[apt_update]').with({ + it { is_expected.to contain_apt__setting('list-my_source').with({ 'ensure' => 'absent' }) } -- 2.32.3