]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #49 from nanliu/tb/11966
authorBranan Purvine-Riley <branan@gmail.com>
Fri, 4 May 2012 20:37:46 +0000 (13:37 -0700)
committerBranan Purvine-Riley <branan@gmail.com>
Fri, 4 May 2012 20:37:46 +0000 (13:37 -0700)
(#11966) Only invoke apt-get update once.

manifests/backports.pp
manifests/builddep.pp
manifests/init.pp
manifests/ppa.pp
manifests/source.pp
manifests/update.pp [new file with mode: 0644]
spec/classes/apt_spec.rb
spec/classes/backports_spec.rb
spec/defines/builddep_spec.rb
spec/defines/ppa_spec.rb
spec/defines/source_spec.rb

index 007a1ee3fa9c38157e2ab52dc24deda5682a3232..ecc75048e6c10ff523dbb20355a7d6ab4cbc5374 100644 (file)
@@ -41,6 +41,5 @@ class apt::backports(
     },
     key_server => 'pgp.mit.edu',
     pin        => '200',
-    notify     => Exec['apt_update'],
   }
 }
index de6191c31b2ff86701a82005e659b5d58343e934..f7537fbb251dc0ab6cf5d0c605b0509ea9880953 100644 (file)
@@ -1,16 +1,12 @@
 # builddep.pp
 
 define apt::builddep() {
+  include apt::update
 
   Class['apt'] -> Apt::Builddep[$name]
 
-  exec { "apt-update-${name}":
-    command     => '/usr/bin/apt-get update',
-    refreshonly => true,
-  }
-
   exec { "apt-builddep-${name}":
     command => "/usr/bin/apt-get -y --force-yes build-dep ${name}",
-    notify  => Exec["apt-update-${name}"],
+    notify  => Exec['apt_update'],
   }
 }
index 7d243edd7b947369f0334f096a4d8f98c08b2688..53e25dca0ec26363a300aca2ef9bf9d10467cded 100644 (file)
@@ -29,14 +29,10 @@ class apt(
 ) {
 
   include apt::params
+  include apt::update
 
   validate_bool($purge_sources_list, $purge_sources_list_d)
 
-  $refresh_only_apt_update = $always_apt_update? {
-    true  => false,
-    false => true,
-  }
-
   if ! defined(Package['python-software-properties']) {
     package { 'python-software-properties': }
   }
@@ -46,6 +42,12 @@ class apt(
     true  => "# Repos managed by puppet.\n",
   }
 
+  if $always_apt_update == true {
+    Exec <| title=='apt_update' |> {
+      refreshonly => false,
+    }
+  }
+
   $root           = $apt::params::root
   $apt_conf_d     = $apt::params::apt_conf_d
   $sources_list_d = $apt::params::sources_list_d
@@ -58,6 +60,7 @@ class apt(
     group   => root,
     mode    => '0644',
     content => $sources_list_content,
+    notify  => Exec['apt_update'],
   }
 
   file { 'sources.list.d':
@@ -67,12 +70,7 @@ class apt(
     group   => root,
     purge   => $purge_sources_list_d,
     recurse => $purge_sources_list_d,
-  }
-
-  exec { 'apt_update':
-    command     => "${provider} update",
-    subscribe   => [ File['sources.list'], File['sources.list.d'] ],
-    refreshonly => $refresh_only_apt_update,
+    notify  => Exec['apt_update'],
   }
 
   case $disable_keys {
@@ -89,7 +87,7 @@ class apt(
         path   => "${apt_conf_d}/99unauth",
       }
     }
-    undef: { } # do nothing
+    undef:   { } # do nothing
     default: { fail('Valid values for disable_keys are true or false') }
   }
 
index d27aca4442ee8253f19333e79f3449a2876d8b04..c0dfaa0f8212b78f46720540cdebe4240c9d5423 100644 (file)
@@ -7,6 +7,7 @@ define apt::ppa(
   Class['apt'] -> Apt::Ppa[$title]
 
   include apt::params
+  include apt::update
 
   $sources_list_d = $apt::params::sources_list_d
 
@@ -14,10 +15,6 @@ define apt::ppa(
     fail('lsbdistcodename fact not available: release parameter required')
   }
 
-  exec { "apt-update-${name}":
-    command     => "${apt::params::provider} update",
-    refreshonly => true,
-  }
 
   $filename_without_slashes = regsubst($name,'/','-','G')
   $filename_without_ppa = regsubst($filename_without_slashes, '^ppa:','','G')
@@ -25,8 +22,8 @@ define apt::ppa(
 
   exec { "add-apt-repository-${name}":
     command => "/usr/bin/add-apt-repository ${name}",
-    notify  => Exec["apt-update-${name}"],
     creates => "${sources_list_d}/${sources_list_d_filename}",
+    notify  => Exec['apt_update'],
   }
 
   file { "${sources_list_d}/${sources_list_d_filename}":
index c63fc2fb2282d5bd2dc457a256442683747b6b13..cbf2fd4566ae43bf9312156ef14a88161a7f7eb1 100644 (file)
@@ -16,6 +16,7 @@ define apt::source(
 ) {
 
   include apt::params
+  include apt::update
 
   $sources_list_d = $apt::params::sources_list_d
   $provider       = $apt::params::provider
@@ -31,6 +32,7 @@ define apt::source(
     group   => root,
     mode    => '0644',
     content => template("${module_name}/source.list.erb"),
+    notify  => Exec['apt_update'],
   }
 
   if ($pin != false) and ($ensure == 'present') {
@@ -40,12 +42,6 @@ define apt::source(
     }
   }
 
-  exec { "${name} apt update":
-    command     => "${provider} update",
-    subscribe   => File["${name}.list"],
-    refreshonly => true,
-  }
-
   if ($required_packages != false) and ($ensure == 'present') {
     exec { "Required packages: '${required_packages}' for ${name}":
       command     => "${provider} -y install ${required_packages}",
diff --git a/manifests/update.pp b/manifests/update.pp
new file mode 100644 (file)
index 0000000..016df7d
--- /dev/null
@@ -0,0 +1,8 @@
+class apt::update {
+  include apt::params
+
+  exec { 'apt_update':
+    command     => "${apt::params::provider} update",
+    refreshonly => true,
+  }
+}
index 079bd59c5b58f8828122f0270aa671deb8b15b28..ac626d291ef2d27f746a577268410086bebaec32 100644 (file)
@@ -72,7 +72,8 @@ describe 'apt', :type => :class do
             'owner'   => "root",
             'group'   => "root",
             'purge'   => true,
-            'recurse' => true
+            'recurse' => true,
+            'notify'  => 'Exec[apt_update]'
           })
         else
           should create_file("sources.list.d").with({
@@ -81,7 +82,8 @@ describe 'apt', :type => :class do
             'owner'   => "root",
             'group'   => "root",
             'purge'   => false,
-            'recurse' => false
+            'recurse' => false,
+            'notify'  => 'Exec[apt_update]'
           })
         end
       }
@@ -89,7 +91,6 @@ describe 'apt', :type => :class do
       it {
         should contain_exec("apt_update").with({
           'command'     => "/usr/bin/apt-get update",
-          'subscribe'   => ["File[sources.list]", "File[sources.list.d]"],
           'refreshonly' => refresh_only_apt_update
         })
       }
index feabef1a1105e0e177bea12a70c9c5931f85a87e..efac8607553376ce57653f9ca319a429e8fef953 100644 (file)
@@ -17,7 +17,6 @@ describe 'apt::backports', :type => :class do
         'key'        => '437D05B5',
         'key_server' => 'pgp.mit.edu',
         'pin'        => '200',
-        'notify'     => 'Exec[apt_update]'
       })
     }
   end
@@ -38,7 +37,6 @@ describe 'apt::backports', :type => :class do
         'key'        => '55BE302B',
         'key_server' => 'pgp.mit.edu',
         'pin'        => '200',
-        'notify'     => 'Exec[apt_update]'
       })
     }
   end
@@ -67,7 +65,6 @@ describe 'apt::backports', :type => :class do
         'key'        => '55BE302B',
         'key_server' => 'pgp.mit.edu',
         'pin'        => '200',
-        'notify'     => 'Exec[apt_update]'
       })
     }
   end
index 52a0704a3bde7592f01c4670cb77bd2b5e3cc4c1..940c60c97b99ac6e5400e5f7bbe36c5760079910 100644 (file)
@@ -6,7 +6,7 @@ describe 'apt::builddep', :type => :define do
   describe "should succeed with a Class['apt']" do
     let(:pre_condition) { 'class {"apt": } ' }
 
-    it { should contain_exec("apt-update-#{title}").with({
+    it { should contain_exec("apt_update").with({
         'command' => "/usr/bin/apt-get update",
         'refreshonly' => true
       })
index 95830169b73099060b20cf6eea06c6fdfdfe12fa..18c1a4f91e8c87411c20c98ba00e348c229aa8f1 100644 (file)
@@ -18,7 +18,7 @@ describe 'apt::ppa', :type => :define do
         t.sub(/^ppa:/,'').gsub('/','-') << "-" << "#{release}.list"
       end
 
-      it { should contain_exec("apt-update-#{t}").with(
+      it { should contain_exec("apt_update").with(
         'command'     => '/usr/bin/apt-get update',
         'refreshonly' => true
         )
@@ -26,7 +26,7 @@ describe 'apt::ppa', :type => :define do
 
       it { should contain_exec("add-apt-repository-#{t}").with(
         'command' => "/usr/bin/add-apt-repository #{t}",
-        'notify'  => "Exec[apt-update-#{t}]",
+        'notify'  => "Exec[apt_update]",
         'creates' => "/etc/apt/sources.list.d/#{filename}"
         )
       }
index 02bc45fcbebd3256b0f8256b292be68611828adc..110e8c21b6b5dad446fdb00d4829dea47e4df63e 100644 (file)
@@ -97,9 +97,8 @@ describe 'apt::source', :type => :define do
       }
 
       it {
-        should contain_exec("#{title} apt update").with({
+        should contain_exec("apt_update").with({
           "command"     => "/usr/bin/apt-get update",
-          "subscribe"   => "File[#{title}.list]",
           "refreshonly" => true
         })
       }