(#12522) Adding purge option to apt class

Adds a purge option to the apt class to remove repositories
that are not managed by apt::source
This commit is contained in:
William Van Hevelingen 2012-02-08 11:40:09 -08:00
parent 52adc3555c
commit 8c279636f5
2 changed files with 52 additions and 17 deletions

View file

@ -15,14 +15,17 @@
# Sample Usage:
# class { 'apt': }
class apt(
$disable_keys = false,
$always_apt_update = false,
$disable_keys = false,
$proxy_host = false,
$proxy_port = '8080'
$proxy_port = '8080',
$purge = false
) {
include apt::params
validate_bool($purge)
$refresh_only_apt_update = $always_apt_update? {
true => false,
false => true
@ -36,6 +39,10 @@ class apt(
owner => root,
group => root,
mode => 644,
content => $purge ? {
false => undef,
true => "# Repos managed by puppet.\n",
},
}
file { "sources.list.d":
@ -43,6 +50,8 @@ class apt(
ensure => directory,
owner => root,
group => root,
purge => $purge,
recurse => $purge,
}
exec { "apt_update":

View file

@ -3,7 +3,8 @@ describe 'apt', :type => :class do
let :default_params do
{
:disable_keys => false,
:always_apt_update => false
:always_apt_update => false,
:purge => false
}
end
@ -12,7 +13,8 @@ describe 'apt', :type => :class do
:disable_keys => true,
:always_apt_update => true,
:proxy_host => true,
:proxy_port => '3128'
:proxy_port => '3128',
:purge => true
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
@ -37,22 +39,46 @@ describe 'apt', :type => :class do
it { should contain_package("python-software-properties") }
it {
if param_hash[:purge]
should contain_file("sources.list").with({
'path' => "/etc/apt/sources.list",
'ensure' => "present",
'owner' => "root",
'group' => "root",
'mode' => 644
})
'path' => "/etc/apt/sources.list",
'ensure' => "present",
'owner' => "root",
'group' => "root",
'mode' => 644,
"content" => "# Repos managed by puppet.\n"
})
else
should contain_file("sources.list").with({
'path' => "/etc/apt/sources.list",
'ensure' => "present",
'owner' => "root",
'group' => "root",
'mode' => 644,
'content' => nil
})
end
}
it {
should create_file("sources.list.d").with({
"path" => "/etc/apt/sources.list.d",
"ensure" => "directory",
"owner" => "root",
"group" => "root"
})
if param_hash[:purge]
should create_file("sources.list.d").with({
'path' => "/etc/apt/sources.list.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => true,
'recurse' => true
})
else
should create_file("sources.list.d").with({
'path' => "/etc/apt/sources.list.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => false,
'recurse' => false
})
end
}
it {