Merge pull request #17 from blkperl/ticket_12526_apt_disable_keys

(#12526) Add ability to reverse apt { disable_keys => true }

Reviewed by Ryan Coleman (ryan@puppetlabs.com)
This commit is contained in:
Ryan Coleman 2012-02-23 14:55:55 -08:00
commit 44510890b4
2 changed files with 35 additions and 15 deletions

View file

@ -16,7 +16,7 @@
# class { 'apt': }
class apt(
$always_apt_update = false,
$disable_keys = false,
$disable_keys = undef,
$proxy_host = false,
$proxy_port = '8080',
$purge = false
@ -59,11 +59,23 @@ class apt(
subscribe => [ File["sources.list"], File["sources.list.d"] ],
refreshonly => $refresh_only_apt_update,
}
if($disable_keys) {
exec { 'make-apt-insecure':
command => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
creates => '/etc/apt/apt.conf.d/99unauth'
case $disable_keys {
true: {
file { "99unauth":
content => "APT::Get::AllowUnauthenticated 1;\n",
ensure => present,
path => "/etc/apt/apt.conf.d/99unauth",
}
}
false: {
file { "99unauth":
ensure => absent,
path => "/etc/apt/apt.conf.d/99unauth",
}
}
undef: { } # do nothing
default: { fail("Valid values for disable_keys are true or false") }
}
if($proxy_host) {

View file

@ -2,19 +2,22 @@ require 'spec_helper'
describe 'apt', :type => :class do
let :default_params do
{
:disable_keys => false,
:disable_keys => :undef,
:always_apt_update => false,
:purge => false
}
end
[{},
{
{
:disable_keys => true,
:always_apt_update => true,
:proxy_host => true,
:proxy_port => '3128',
:purge => true
},
{
:disable_keys => false
}
].each do |param_set|
describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do
@ -90,15 +93,20 @@ describe 'apt', :type => :class do
}
it {
if param_hash[:disable_keys]
should contain_exec("make-apt-insecure").with({
'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
'creates' => '/etc/apt/apt.conf.d/99unauth'
if param_hash[:disable_keys] == true
should create_file("99unauth").with({
'content' => "APT::Get::AllowUnauthenticated 1;\n",
'ensure' => "present",
'path' => "/etc/apt/apt.conf.d/99unauth"
})
else
should_not contain_exec("make-apt-insecure").with({
'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth',
'creates' => '/etc/apt/apt.conf.d/99unauth'
elsif param_hash[:disable_keys] == false
should create_file("99unauth").with({
'ensure' => "absent",
'path' => "/etc/apt/apt.conf.d/99unauth"
})
elsif param_hash[:disable_keys] != :undef
should_not create_file("99unauth").with({
'path' => "/etc/apt/apt.conf.d/99unauth"
})
end
}