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

apt: Allow managing of preferences file. #240

Merged
merged 1 commit into from
Feb 25, 2014
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
20 changes: 19 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,29 @@
$proxy_port = '8080',
$purge_sources_list = false,
$purge_sources_list_d = false,
$purge_preferences = false,
$purge_preferences_d = false,
$update_timeout = undef
) {

include apt::params
include apt::update

validate_bool($purge_sources_list, $purge_sources_list_d, $purge_preferences_d)
validate_bool($purge_sources_list, $purge_sources_list_d,
$purge_preferences, $purge_preferences_d)

$sources_list_content = $purge_sources_list ? {
false => undef,
true => "# Repos managed by puppet.\n",
}

$preferences_content = $purge_preferences ? {
false => undef,
true => "Explanation: Preferences managed by Puppet\n
Explanation: We need a bogus package line because of Debian Bug #732746\n
Package: bogus-package\n",
}

if $always_apt_update == true {
Exec <| title=='apt_update' |> {
refreshonly => false,
Expand Down Expand Up @@ -75,6 +84,15 @@
notify => Exec['apt_update'],
}

file { 'apt-preferences':
ensure => present,
path => "${root}/preferences",
owner => root,
group => root,
mode => '0644',
content => $preferences_content,
}

file { 'preferences.d':
ensure => directory,
path => $preferences_d,
Expand Down
44 changes: 44 additions & 0 deletions spec/acceptance/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,50 @@ class { 'apt':
end
end

context 'purge_preferences' do
context 'false' do
it 'creates a preferences file' do
shell("echo 'original' > /etc/apt/preferences")
end

it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences => false }
EOS

apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/apt/preferences') do
it { should be_file }
it 'is not managed by Puppet' do
shell("grep 'original' /etc/apt/preferences", {:acceptable_exit_codes => 0})
end
end
end

context 'true' do
it 'creates a preferences file' do
shell('touch /etc/apt/preferences')
end

it 'should work with no errors' do
pp = <<-EOS
class { 'apt': purge_preferences => true }
EOS

apply_manifest(pp, :catch_failures => true)
end

describe file('/etc/apt/preferences') do
it { should be_file }
it 'is managed by Puppet' do
shell("grep 'Explanation' /etc/apt/preferences", {:acceptable_exit_codes => 0})
end
end
end
end

context 'purge_preferences_d' do
context 'false' do
it 'creates a preferences file' do
Expand Down
47 changes: 47 additions & 0 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
:purge_sources_list => true,
:purge_sources_list_d => true,
},
{
:purge_preferences => true,
:purge_preferences_d => true,
},
{
:disable_keys => false
}
Expand Down Expand Up @@ -85,6 +89,49 @@
})
end
}
it {
if param_hash[:purge_preferences]
should create_file('apt-preferences').with({
:ensure => 'present',
:path => '/etc/apt/preferences',
:owner => 'root',
:group => 'root',
:mode => '0644',
:content => /Explanation/,
})
else
should create_file('apt-preferences').with({
:ensure => 'present',
:path => '/etc/apt/preferences',
:owner => 'root',
:group => 'root',
:mode => '0644',
:content => nil,
})
end
}

it {
if param_hash[:purge_preferences_d]
should create_file("preferences.d").with({
'path' => "/etc/apt/preferences.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => true,
'recurse' => true,
})
else
should create_file("preferences.d").with({
'path' => "/etc/apt/preferences.d",
'ensure' => "directory",
'owner' => "root",
'group' => "root",
'purge' => false,
'recurse' => false,
})
end
}

it {
should contain_exec("apt_update").with({
Expand Down