Skip to content

Commit

Permalink
Merge pull request #49 from nanliu/tb/11966
Browse files Browse the repository at this point in the history
(#11966) Only invoke apt-get update once.
  • Loading branch information
branan committed May 4, 2012
2 parents a840dd8 + f13f3cf commit 669f5b5
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 41 deletions.
1 change: 0 additions & 1 deletion manifests/backports.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@
},
key_server => 'pgp.mit.edu',
pin => '200',
notify => Exec['apt_update'],
}
}
8 changes: 2 additions & 6 deletions manifests/builddep.pp
Original file line number Diff line number Diff line change
@@ -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'],
}
}
22 changes: 10 additions & 12 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@
) {

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': }
}
Expand All @@ -46,6 +42,12 @@
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
Expand All @@ -58,6 +60,7 @@
group => root,
mode => '0644',
content => $sources_list_content,
notify => Exec['apt_update'],
}

file { 'sources.list.d':
Expand All @@ -67,12 +70,7 @@
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 {
Expand All @@ -89,7 +87,7 @@
path => "${apt_conf_d}/99unauth",
}
}
undef: { } # do nothing
undef: { } # do nothing
default: { fail('Valid values for disable_keys are true or false') }
}

Expand Down
7 changes: 2 additions & 5 deletions manifests/ppa.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@
Class['apt'] -> Apt::Ppa[$title]

include apt::params
include apt::update

$sources_list_d = $apt::params::sources_list_d

if ! $release {
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')
$sources_list_d_filename = "${filename_without_ppa}-${release}.list"

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}":
Expand Down
8 changes: 2 additions & 6 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
) {

include apt::params
include apt::update

$sources_list_d = $apt::params::sources_list_d
$provider = $apt::params::provider
Expand All @@ -31,6 +32,7 @@
group => root,
mode => '0644',
content => template("${module_name}/source.list.erb"),
notify => Exec['apt_update'],
}

if ($pin != false) and ($ensure == 'present') {
Expand All @@ -40,12 +42,6 @@
}
}

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}",
Expand Down
8 changes: 8 additions & 0 deletions manifests/update.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class apt::update {
include apt::params

exec { 'apt_update':
command => "${apt::params::provider} update",
refreshonly => true,
}
}
7 changes: 4 additions & 3 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
'owner' => "root",
'group' => "root",
'purge' => true,
'recurse' => true
'recurse' => true,
'notify' => 'Exec[apt_update]'
})
else
should create_file("sources.list.d").with({
Expand All @@ -81,15 +82,15 @@
'owner' => "root",
'group' => "root",
'purge' => false,
'recurse' => false
'recurse' => false,
'notify' => 'Exec[apt_update]'
})
end
}

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
})
}
Expand Down
3 changes: 0 additions & 3 deletions spec/classes/backports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
'key' => '437D05B5',
'key_server' => 'pgp.mit.edu',
'pin' => '200',
'notify' => 'Exec[apt_update]'
})
}
end
Expand All @@ -38,7 +37,6 @@
'key' => '55BE302B',
'key_server' => 'pgp.mit.edu',
'pin' => '200',
'notify' => 'Exec[apt_update]'
})
}
end
Expand Down Expand Up @@ -67,7 +65,6 @@
'key' => '55BE302B',
'key_server' => 'pgp.mit.edu',
'pin' => '200',
'notify' => 'Exec[apt_update]'
})
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/builddep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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
})
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/ppa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
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
)
}

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}"
)
}
Expand Down
3 changes: 1 addition & 2 deletions spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@
}

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
})
}
Expand Down

0 comments on commit 669f5b5

Please sign in to comment.