]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Make apt::setting notify Exec['apt_update'] by default
authorMorgan Haskel <morgan@puppetlabs.com>
Thu, 26 Feb 2015 20:44:06 +0000 (12:44 -0800)
committerMorgan Haskel <morgan@puppetlabs.com>
Thu, 26 Feb 2015 20:44:06 +0000 (12:44 -0800)
Can be disabled by setting `notify_update => false`

manifests/setting.pp
manifests/source.pp
spec/classes/apt_spec.rb
spec/defines/setting_spec.rb
spec/defines/source_spec.rb

index f6f0bc0c2275821a3656d9e14cb73b30f1202f88..c288b35d7ec00ce545af777de09bfe977026738c 100644 (file)
@@ -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']
+    }
   }
 }
index 9a3a7912aa0c8159925c304ab9807bcb6d7ac292..b7d150c2233b8448710f7690315606e9bef4e461 100644 (file)
@@ -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'],
-  }
 }
index f66bf540498b7aa069383c541a34ae0cdc4dac51..b8ff37ea312caee1153a9c574c73b2520c9b4723 100644 (file)
@@ -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]',
       })
     }
 
index 5e88eea16ed90b72a6778f9c8c9b1da60d9eb442..e01fdbfe44e7c605152133ac7a6e4adc9d7ca575 100644 (file)
@@ -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
index ad986e96843b28ac50efe2138d634092908fa608..5e2728b25138274c5e9515f86f40fa6d5f8a065b 100644 (file)
@@ -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'
     })
     }