Skip to content

Commit

Permalink
The check for existing exchanges was flawed, and therefore, on each
Browse files Browse the repository at this point in the history
Puppet run, they were re-created.

Restructure the code, to get rid of the bogus/broken parse_command method.
Fix the test after the updated exchange provider
  • Loading branch information
buzzdeee committed Feb 22, 2015
1 parent ed99304 commit 121771b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
32 changes: 11 additions & 21 deletions lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,28 @@ def should_vhost

def self.all_vhosts
vhosts = []
parse_command(
self.run_with_retries {
rabbitmqctl('list_vhosts')
}
).collect do |vhost|
vhosts.push(vhost)
self.run_with_retries {
rabbitmqctl('-q', 'list_vhosts')
}.split(/\n/).each do |vhost|
vhosts.push(vhost)
end
vhosts
end

def self.all_exchanges(vhost)
exchanges = []
parse_command(
self.run_with_retries {
rabbitmqctl('list_exchanges', '-p', vhost, 'name', 'type')
}
)
end

def self.parse_command(cmd_output)
# first line is:
# Listing exchanges/vhosts ...
# while the last line is
# ...done.
#
cmd_output.split(/\n/)[1..-2]
self.run_with_retries {
rabbitmqctl('-q', 'list_exchanges', '-p', vhost, 'name', 'type')
}.split(/\n/).each do |exchange|
exchanges.push(exchange)
end
exchanges
end

def self.instances
resources = []
all_vhosts.each do |vhost|
all_exchanges(vhost).collect do |line|
all_exchanges(vhost).each do |line|
name, type = line.split()
if type.nil?
# if name is empty, it will wrongly get the type's value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
end

it 'should return instances' do
provider_class.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
Listing vhosts ...
provider_class.expects(:rabbitmqctl).with('-q', 'list_vhosts').returns <<-EOT
/
...done.
EOT
provider_class.expects(:rabbitmqctl).with('list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT
Listing exchanges ...
provider_class.expects(:rabbitmqctl).with('-q', 'list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT
direct
amq.direct direct
amq.fanout fanout
Expand All @@ -29,7 +26,6 @@
amq.rabbitmq.log topic
amq.rabbitmq.trace topic
amq.topic topic
...done.
EOT
instances = provider_class.instances
instances.size.should == 8
Expand Down

0 comments on commit 121771b

Please sign in to comment.