Skip to content

Commit

Permalink
MODULES-1661 Fix issue with apt_key destroy, also added mutliple deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Fields committed Jan 14, 2015
1 parent 1a7d079 commit c913469
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/puppet/provider/apt_key/apt_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.instances

new(
:name => line_hash[:key_fingerprint],
:id => line_hash[:key_fingerprint],
:id => line_hash[:key_short],
:fingerprint => line_hash[:key_fingerprint],
:short => line_hash[:key_short],
:long => line_hash[:key_long],
Expand Down Expand Up @@ -166,8 +166,10 @@ def create
end

def destroy
#Currently del only removes the first key, we need to recursively list and ensure all with id are absent.
apt_key('del', resource[:id])
begin
apt_key('del', resource.provider.short)
r = execute(["#{command(:apt_key)} list | grep #{resource.provider.short}"], :failonfail => false)
end while r.exitstatus == 0
@property_hash.clear
end

Expand Down
8 changes: 5 additions & 3 deletions spec/acceptance/apt_key_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
CENTOS_REPO_URL = 'ftp.cvut.cz/centos'
CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6'

SHOULD_NEVER_EXIST_ID = '4BD6EC30'

KEY_CHECK_COMMAND = "apt-key adv --list-keys --with-colons --fingerprint | grep "
PUPPETLABS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{PUPPETLABS_GPG_KEY_FINGERPRINT}"
CENTOS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{CENTOS_GPG_KEY_FINGERPRINT}"
Expand Down Expand Up @@ -351,7 +353,7 @@
it 'fails with a 550' do
pp = <<-EOS
apt_key { 'CentOS 6':
id => '#{CENTOS_GPG_KEY_LONG_ID}',
id => '#{SHOULD_NEVER_EXIST_ID}',
ensure => 'present',
source => 'ftp://#{CENTOS_REPO_URL}/herpderp.gpg',
}
Expand Down Expand Up @@ -395,7 +397,7 @@
it 'fails with a 404' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4BD6EC30',
id => '#{SHOULD_NEVER_EXIST_ID}',
ensure => 'present',
source => 'https://#{PUPPETLABS_APT_URL}/herpderp.gpg',
}
Expand All @@ -409,7 +411,7 @@
it 'fails with a socket error' do
pp = <<-EOS
apt_key { 'puppetlabs':
id => '4BD6EC30',
id => '#{SHOULD_NEVER_EXIST_ID}',
ensure => 'present',
source => 'https://apt.puppetlabss.com/herpderp.gpg',
}
Expand Down

0 comments on commit c913469

Please sign in to comment.