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

Convert apt::key to use anchors #32

Merged
merged 1 commit into from
Mar 15, 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
25 changes: 16 additions & 9 deletions manifests/key.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,39 @@
# apt::source resources that all reference the same key.
case $ensure {
present: {

anchor { "apt::key/$title":; }

if defined(Exec["apt::key $key absent"]) {
fail ("Cannot ensure Apt::Key[$key] present; $key already ensured absent")
} elsif !defined(Exec["apt::key $key present"]) {
# this is a marker to ensure we don't simultaneously define a key
# ensure => absent AND ensure => present
exec { "apt::key $key present":
path => "/",
onlyif => "/bin/false",
noop => true;
}
}

if !defined(Anchor["apt::key $key present"]) {
anchor { "apt::key $key present":; }
}

if !defined(Exec[$digest]) {
exec { $digest:
path => "/bin:/usr/bin",
unless => "/usr/bin/apt-key list | /bin/grep '${key}'",
before => Anchor["apt::key $key present"],
command => $method ? {
"content" => "echo '${key_content}' | /usr/bin/apt-key add -",
"source" => "wget -q '${key_source}' -O- | apt-key add -",
"server" => "apt-key adv --keyserver '${key_server}' --recv-keys '${key}'",
};
}
}

Anchor["apt::key $key present"] -> Anchor["apt::key/$title"]

}
absent: {
if defined(Exec["apt::key $key present"]) {

if defined(Anchor["apt::key $key present"]) {
fail ("Cannot ensure Apt::Key[$key] absent; $key already ensured present")
}

exec { "apt::key $key absent":
path => "/bin:/usr/bin",
onlyif => "apt-key list | grep '$key'",
Expand All @@ -61,6 +67,7 @@
group => "root",
}
}

default: {
fail "Invalid 'ensure' value '$ensure' for aptkey"
}
Expand Down
21 changes: 14 additions & 7 deletions spec/defines/key_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
it {
if [:present, 'present'].include? param_hash[:ensure]
should_not contain_exec("apt::key #{param_hash[:key]} absent")
should contain_exec("apt::key #{param_hash[:key]} present")
should contain_anchor("apt::key #{param_hash[:key]} present")
should contain_exec(digest).with({
"path" => "/bin:/usr/bin",
"unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
})
elsif [:absent, 'absent'].include? param_hash[:ensure]
should_not contain_exec("apt::key #{param_hash[:key]} present")
should_not contain_anchor("apt::key #{param_hash[:key]} present")
should contain_exec("apt::key #{param_hash[:key]} absent").with({
"path" => "/bin:/usr/bin",
"onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
Expand Down Expand Up @@ -93,22 +93,29 @@
}

end
end

[{ :ensure => 'present' }, { :ensure => 'absent' }].each do |param_set|
describe "should correctly handle duplicate definitions" do

let :pre_condition do
"apt::key { 'duplicate': key => '#{params[:key]}'; }"
"apt::key { 'duplicate': key => '#{title}'; }"
end

let(:params) { param_set }

it {
if [:present, 'present'].include? param_hash[:ensure]
should contain_exec("apt::key #{param_hash[:key]} present")
should contain_apt__key("duplicate")
if param_set[:ensure] == 'present'
should contain_anchor("apt::key #{title} present")
should contain_apt__key(title)
elsif [:absent, 'absent'].include? params[:ensure]
should contain_apt__key("duplicate")
elsif param_set[:ensure] == 'absent'
expect { should raise_error(Puppet::Error) }
end
}

end
end

end