Skip to content

Commit

Permalink
MODULES-1856 - Fix to allow bindings and queues to be created on non-…
Browse files Browse the repository at this point in the history
…default management port

Without this fix the rabbitmq_binding & rabbitmq_queue providers are unable to work when
rabbitmq is running on a non-default management port. This fix fixes the problem by passing in
the /etc/rabbitmq/rabbitmqadmin.conf to the call to rabbitmqadmin so that the port can be read from the conf file.
  • Loading branch information
jaxim committed Mar 21, 2015
1 parent 4d4c9ef commit 01aae16
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/puppet/provider/rabbitmq_binding/rabbitmqadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def create
vhost_opt,
"--user=#{resource[:user]}",
"--password=#{resource[:password]}",
'-c',
'/etc/rabbitmq/rabbitmqadmin.conf',
"source=#{name}",
"destination=#{destination}",
"arguments=#{arguments.to_json}",
Expand All @@ -103,7 +105,7 @@ def destroy
vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
name = resource[:name].split('@').first
destination = resource[:name].split('@')[1]
rabbitmqadmin('delete', 'binding', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "source=#{name}", "destination_type=#{resource[:destination_type]}", "destination=#{destination}")
rabbitmqadmin('delete', 'binding', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "source=#{name}", "destination_type=#{resource[:destination_type]}", "destination=#{destination}")
@property_hash[:ensure] = :absent
end

Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/provider/rabbitmq_queue/rabbitmqadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def create
vhost_opt,
"--user=#{resource[:user]}",
"--password=#{resource[:password]}",
'-c',
'/etc/rabbitmq/rabbitmqadmin.conf',
"name=#{name}",
"durable=#{resource[:durable]}",
"auto_delete=#{resource[:auto_delete]}",
Expand All @@ -98,7 +100,7 @@ def create
def destroy
vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
name = resource[:name].rpartition('@').first
rabbitmqadmin('delete', 'queue', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}")
rabbitmqadmin('delete', 'queue', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf', "name=#{name}")
@property_hash[:ensure] = :absent
end

Expand Down
157 changes: 157 additions & 0 deletions spec/acceptance/queue_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
require 'spec_helper_acceptance'

describe 'rabbitmq binding:' do


context "create binding and queue resources when rabbit using default management port" do
it 'should run successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
class { '::rabbitmq':
service_manage => true,
port => '5672',
delete_guest_user => true,
admin_enable => true,
} ->
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
tags => ['monitoring', 'tag1'],
} ->
rabbitmq_user_permissions { 'dan@host1':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
}
rabbitmq_vhost { 'host1':
ensure => present,
} ->
rabbitmq_exchange { 'exchange1@host1':
user => 'dan',
password => 'bar',
type => 'topic',
ensure => present,
} ->
rabbitmq_queue { 'queue1@host1':
user => 'dan',
password => 'bar',
durable => true,
auto_delete => false,
ensure => present,
} ->
rabbitmq_binding { 'exchange1@queue1@host1':
user => 'dan',
password => 'bar',
destination_type => 'queue',
routing_key => '#',
ensure => present,
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

it 'should have the binding' do
shell('rabbitmqctl list_bindings -q -p host1') do |r|
expect(r.stdout).to match(/exchange1\sexchange\squeue1\squeue\s#/)
expect(r.exit_code).to be_zero
end
end

it 'should have the queue' do
shell('rabbitmqctl list_queues -q -p host1') do |r|
expect(r.stdout).to match(/queue1/)
expect(r.exit_code).to be_zero
end
end

end

context "create binding and queue resources when rabbit using a non-default management port" do
it 'should run successfully' do
pp = <<-EOS
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true }
Class['erlang'] -> Class['::rabbitmq']
}
class { '::rabbitmq':
service_manage => true,
port => '5672',
management_port => '11111',
delete_guest_user => true,
admin_enable => true,
} ->
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
tags => ['monitoring', 'tag1'],
} ->
rabbitmq_user_permissions { 'dan@host2':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
}
rabbitmq_vhost { 'host2':
ensure => present,
} ->
rabbitmq_exchange { 'exchange2@host2':
user => 'dan',
password => 'bar',
type => 'topic',
ensure => present,
} ->
rabbitmq_queue { 'queue2@host2':
user => 'dan',
password => 'bar',
durable => true,
auto_delete => false,
ensure => present,
} ->
rabbitmq_binding { 'exchange2@queue2@host2':
user => 'dan',
password => 'bar',
destination_type => 'queue',
routing_key => '#',
ensure => present,
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end

it 'should have the binding' do
shell('rabbitmqctl list_bindings -q -p host2') do |r|
expect(r.stdout).to match(/exchange2\sexchange\squeue2\squeue\s#/)
expect(r.exit_code).to be_zero
end
end

it 'should have the queue' do
shell('rabbitmqctl list_queues -q -p host2') do |r|
expect(r.stdout).to match(/queue2/)
expect(r.exit_code).to be_zero
end
end

end

end
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
end

it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue')
@provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=target', 'arguments={}', 'routing_key=blablub', 'destination_type=queue')
@provider.create
end

it 'should call rabbitmqadmin to destroy' do
@provider.expects(:rabbitmqadmin).with('delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', 'source=source', 'destination_type=queue', 'destination=target')
@provider.expects(:rabbitmqadmin).with('delete', 'binding', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination_type=queue', 'destination=target')
@provider.destroy
end

Expand All @@ -52,7 +52,7 @@
end

it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue')
@provider.expects(:rabbitmqadmin).with('declare', 'binding', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'source=source', 'destination=test2', 'arguments={}', 'routing_key=blablubd', 'destination_type=queue')
@provider.create
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
end

it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=guest', '--password=guest', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.create
end

it 'should call rabbitmqadmin to destroy' do
@provider.expects(:rabbitmqadmin).with('delete', 'queue', '--vhost=/', '--user=guest', '--password=guest', 'name=test')
@provider.expects(:rabbitmqadmin).with('delete', 'queue', '--vhost=/', '--user=guest', '--password=guest', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test')
@provider.destroy
end

Expand All @@ -53,7 +53,7 @@
end

it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=colin', '--password=secret', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.expects(:rabbitmqadmin).with('declare', 'queue', '--vhost=/', '--user=colin', '--password=secret', '-c', '/etc/rabbitmq/rabbitmqadmin.conf', 'name=test', 'durable=true', 'auto_delete=false', 'arguments={}')
@provider.create
end
end
Expand Down

0 comments on commit 01aae16

Please sign in to comment.