From 3684f88372959cb8dd6eb5bce99b6a07db43f058 Mon Sep 17 00:00:00 2001 From: Nan Liu Date: Fri, 4 May 2012 13:35:13 -0700 Subject: [PATCH] (#11966) Only invoke apt-get update once. Move apt-get update exec to a seperate class to minimize the number of apt-get updates invoked by configuration changes. * remove apt_update exec resource in apt class. * remove apt-get-${name} in defines. * apt::source notify Exec['apt update']. * Remove dependency to Exec['apt_update']. * fix rspec-puppet tests. Conflicts: manifests/source.pp --- manifests/backports.pp | 1 - manifests/builddep.pp | 8 ++------ manifests/init.pp | 24 +++++++++++------------- manifests/source.pp | 8 ++------ manifests/update.pp | 8 ++++++++ spec/classes/apt_spec.rb | 11 ++++++----- spec/classes/backports_spec.rb | 3 --- spec/defines/builddep_spec.rb | 2 +- spec/defines/source_spec.rb | 3 +-- 9 files changed, 31 insertions(+), 37 deletions(-) create mode 100644 manifests/update.pp diff --git a/manifests/backports.pp b/manifests/backports.pp index 007a1ee..ecc7504 100644 --- a/manifests/backports.pp +++ b/manifests/backports.pp @@ -41,6 +41,5 @@ class apt::backports( }, key_server => 'pgp.mit.edu', pin => '200', - notify => Exec['apt_update'], } } diff --git a/manifests/builddep.pp b/manifests/builddep.pp index de6191c..7a9dd33 100644 --- a/manifests/builddep.pp +++ b/manifests/builddep.pp @@ -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"], } } diff --git a/manifests/init.pp b/manifests/init.pp index 7d243ed..ce88c3b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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') } } @@ -97,7 +95,7 @@ class apt( file { 'configure-apt-proxy': path => "${apt_conf_d}/proxy", content => "Acquire::http::Proxy \"http://${proxy_host}:${proxy_port}\";", - notify => Exec['apt_update'], + notify => Exec['apt update'], } } } diff --git a/manifests/source.pp b/manifests/source.pp index c63fc2f..e9eb654 100644 --- a/manifests/source.pp +++ b/manifests/source.pp @@ -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 index 0000000..b079c1f --- /dev/null +++ b/manifests/update.pp @@ -0,0 +1,8 @@ +class apt::update { + include apt::params + + exec { 'apt update': + command => "${apt::params::provider} update", + refreshonly => true, + } +} diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 079bd59..4d44bcc 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -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,15 +82,15 @@ describe 'apt', :type => :class do 'owner' => "root", 'group' => "root", 'purge' => false, - 'recurse' => false + 'recurse' => false, + 'notify' => 'Exec[apt update]' }) end } it { - should contain_exec("apt_update").with({ + 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 }) } @@ -118,7 +119,7 @@ describe 'apt', :type => :class do should contain_file('configure-apt-proxy').with( 'path' => '/etc/apt/apt.conf.d/proxy', 'content' => "Acquire::http::Proxy \"http://#{param_hash[:proxy_host]}:#{param_hash[:proxy_port]}\";", - 'notify' => "Exec[apt_update]" + 'notify' => "Exec[apt update]" ) else should_not contain_file('configure_apt_proxy') diff --git a/spec/classes/backports_spec.rb b/spec/classes/backports_spec.rb index feabef1..efac860 100644 --- a/spec/classes/backports_spec.rb +++ b/spec/classes/backports_spec.rb @@ -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 diff --git a/spec/defines/builddep_spec.rb b/spec/defines/builddep_spec.rb index 52a0704..39ee988 100644 --- a/spec/defines/builddep_spec.rb +++ b/spec/defines/builddep_spec.rb @@ -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 }) diff --git a/spec/defines/source_spec.rb b/spec/defines/source_spec.rb index 02bc45f..a6c5e5f 100644 --- a/spec/defines/source_spec.rb +++ b/spec/defines/source_spec.rb @@ -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 }) } -- 2.32.3