Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#14308) Add ensure=>absent for define resource. #52

Merged
merged 1 commit into from
May 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion manifests/conf.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define apt::conf (
$ensure = present,
$priority = '50',
$content
) {
Expand All @@ -8,7 +9,7 @@
$apt_conf_d = $apt::params::apt_conf_d

file { "${apt_conf_d}/${priority}${name}":
ensure => file,
ensure => $ensure,
content => $content,
owner => root,
group => root,
Expand Down
3 changes: 2 additions & 1 deletion manifests/pin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# pin a release in apt, useful for unstable repositories

define apt::pin(
$ensure = present,
$packages = '*',
$priority = 0
) {
Expand All @@ -11,7 +12,7 @@
$preferences_d = $apt::params::preferences_d

file { "${name}.pref":
ensure => file,
ensure => $ensure,
path => "${preferences_d}/${name}",
owner => root,
group => root,
Expand Down
10 changes: 6 additions & 4 deletions manifests/source.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# add an apt source

define apt::source(
$ensure = present,
$location = '',
$release = $lsbdistcodename,
$repos = 'main',
Expand All @@ -24,15 +25,15 @@
}

file { "${name}.list":
ensure => file,
ensure => $ensure,
path => "${sources_list_d}/${name}.list",
owner => root,
group => root,
mode => '0644',
content => template("${module_name}/source.list.erb"),
}

if $pin != false {
if ($pin != false) and ($ensure == 'present') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks weird since we won't remove a pin on $ensure=='absent', but I've confirmed that apt doesn't seem to care.

apt::pin { $release:
priority => $pin,
before => File["${name}.list"]
Expand All @@ -45,15 +46,16 @@
refreshonly => true,
}

if $required_packages != false {
if ($required_packages != false) and ($ensure == 'present') {
exec { "Required packages: '${required_packages}' for ${name}":
command => "${provider} -y install ${required_packages}",
subscribe => File["${name}.list"],
refreshonly => true,
}
}

if $key != false {
# We do not want to remove keys when the source is absent.
if ($key != false) and ($ensure == 'present') {
apt::key { "Add key: ${key} from Apt::Source ${title}":
ensure => present,
key => $key,
Expand Down
25 changes: 24 additions & 1 deletion spec/defines/conf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,35 @@
}

it { should contain_file(filename).with({
'ensure' => 'file',
'ensure' => 'present',
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})
}
end

describe "when removing an apt preference" do
let :params do
{
:ensure => 'absent',
:priority => '00',
:content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n"
}
end

let :filename do
"/etc/apt/apt.conf.d/00norecommends"
end

it { should contain_file(filename).with({
'ensure' => 'absent',
'content' => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n",
'owner' => 'root',
'group' => 'root',
'mode' => '0644',
})
}
end
end
12 changes: 9 additions & 3 deletions spec/defines/pin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

let :default_params do
{
:ensure => 'present',
:packages => '*',
:priority => '0'
}
end

[{},
{
[ {},
{
:packages => 'apache',
:priority => '1'
},
{
:ensure => 'absent',
:packages => 'apache',
:priority => '1'
}
Expand All @@ -27,7 +33,7 @@
it { should include_class("apt::params") }

it { should contain_file("#{title}.pref").with({
'ensure' => 'file',
'ensure' => param_hash[:ensure],
'path' => "/etc/apt/preferences.d/#{title}",
'owner' => 'root',
'group' => 'root',
Expand Down
9 changes: 8 additions & 1 deletion spec/defines/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

let :default_params do
{
:ensure => 'present',
:location => '',
:release => 'karmic',
:repos => 'main',
Expand Down Expand Up @@ -35,6 +36,12 @@
:key => 'key_name',
:key_server => 'keyserver.debian.com',
:key_content => false,
},
{
:ensure => 'absent',
:location => 'somewhere',
:release => 'precise',
:repos => 'security',
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
Expand Down Expand Up @@ -66,7 +73,7 @@
it { should contain_apt__params }

it { should contain_file("#{title}.list").with({
'ensure' => 'file',
'ensure' => param_hash[:ensure],
'path' => filename,
'owner' => 'root',
'group' => 'root',
Expand Down