Commit dcfcf234 authored by Stefan Schulte's avatar Stefan Schulte
Browse files

Dont crash on unexpected rpm output

parent 69814831
......@@ -12,10 +12,11 @@ Puppet::Type.type(:rpmkey).provide(:rpm) do
end
rpm_query.each_line do |line|
line.chomp!
if match = /^gpg-pubkey-([0-9a-f]*)-[0-9a-f]*/.match(line)
keys << new(:name => match.captures[0].upcase, :ensure => :present)
else
warning "Unexpected rpm output #{line.expect}. Ignoring this line."
warning "Unexpected rpm output #{line.inspect}. Ignoring this line."
end
end
keys
......
gpg-pubkey-db42a60e-37ea5438
gpg-pubkey-4f2a6fd2-3f9d9d3b
gpg-pubkey-4f2a6fd3
gpg-pubkey-23a254d4-41ddbc46
......@@ -26,6 +26,16 @@ describe Puppet::Type.type(:rpmkey).provider(:rpm) do
described_class.expects(:rpm).with('-q', 'gpg-pubkey').raises Puppet::ExecutionFailure, 'package gpg-pubkey is not installed'
expect(described_class.instances).to be_empty
end
it "should warn and ignore unexpected output" do
described_class.expects(:rpm).with('-q', 'gpg-pubkey').returns File.read(my_fixture('rpm_q_unexpected'))
described_class.expects(:warning).with('Unexpected rpm output "gpg-pubkey-4f2a6fd3". Ignoring this line.')
expect(described_class.instances.map(&:name)).to eq([
'DB42A60E',
'4F2A6FD2',
'23A254D4'
])
end
end
describe "#exists?" do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment