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

Corrections for rabbitmq-server 3.4.0-1 #247

Closed
wants to merge 8 commits into from
Closed
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
11 changes: 3 additions & 8 deletions lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,19 @@ def should_vhost

def self.all_vhosts
vhosts = []
parse_command(rabbitmqctl('list_vhosts')).collect do |vhost|
parse_command(rabbitmqctl('list_vhosts','-q')).collect do |vhost|
vhosts.push(vhost)
end
vhosts
end

def self.all_exchanges(vhost)
exchanges = []
parse_command(rabbitmqctl('list_exchanges', '-p', vhost, 'name', 'type'))
parse_command(rabbitmqctl('list_exchanges', '-p', vhost, 'name', 'type', '-q'))
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]
cmd_output.split(/\n/)[0..-1]
end

def self.instances
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/rabbitmq_user/rabbitmqctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
defaultfor :feature => :posix

def self.instances
rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
rabbitmqctl('list_users','-q').split(/\n/)[0..-1].collect do |line|
if line =~ /^(\S+)(\s+\[.*?\]|)$/
new(:name => $1)
else
Expand All @@ -37,7 +37,7 @@ def destroy
end

def exists?
rabbitmqctl('list_users').split(/\n/)[1..-2].detect do |line|
rabbitmqctl('list_users','-q').split(/\n/)[0..-1].detect do |line|
line.match(/^#{Regexp.escape(resource[:name])}(\s+(\[.*?\]|\S+)|)$/)
end
end
Expand Down Expand Up @@ -90,7 +90,7 @@ def make_user_admin

private
def get_user_tags
match = rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
match = rabbitmqctl('list_users','-q').split(/\n/)[0..-1].collect do |line|
line.match(/^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]/)
end.compact.first
Set.new(match[1].split(/, /)) if match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.users(name, vhost)
@users = {} unless @users
unless @users[name]
@users[name] = {}
rabbitmqctl('list_user_permissions', name).split(/\n/)[1..-2].each do |line|
rabbitmqctl('list_user_permissions',name,'-q').split(/\n/)[0..-1].each do |line|
if line =~ /^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$/
@users[name][$1] =
{:configure => $2, :read => $4, :write => $3}
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/rabbitmq_vhost/rabbitmqctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

def self.instances
rabbitmqctl('list_vhosts').split(/\n/)[1..-2].map do |line|
rabbitmqctl('list_vhosts', '-q').split(/\n/)[0..-1].map do |line|
if line =~ /^(\S+)$/
new(:name => $1)
else
Expand All @@ -27,7 +27,7 @@ def destroy
end

def exists?
out = rabbitmqctl('list_vhosts').split(/\n/)[1..-2].detect do |line|
out = rabbitmqctl('list_vhosts', '-q').split(/\n/)[0..-1].detect do |line|
line.match(/^#{Regexp.escape(resource[:name])}$/)
end
end
Expand Down
22 changes: 9 additions & 13 deletions spec/unit/puppet/provider/rabbitmq_exchange/rabbitmqadmin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@
end

it 'should return instances' do
provider_class.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
Listing vhosts ...
provider_class.expects(:rabbitmqctl).with('list_vhosts','-q').returns <<-EOT
/
...done.
EOT
provider_class.expects(:rabbitmqctl).with('list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT
Listing exchanges ...
provider_class.expects(:rabbitmqctl).with('list_exchanges', '-p', '/', 'name', 'type','-q').returns <<-EOT
direct
amq.direct direct
amq.fanout fanout
amq.headers headers
amq.match headers
amq.rabbitmq.log topic
amq.rabbitmq.trace topic
amq.topic topic
...done.
amq.direct direct
amq.fanout fanout
amq.headers headers
amq.match headers
amq.rabbitmq.log topic
amq.rabbitmq.trace topic
amq.topic topic
EOT
instances = provider_class.instances
instances.size.should == 8
Expand Down
76 changes: 19 additions & 57 deletions spec/unit/puppet/provider/rabbitmq_user/rabbitmqctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,34 @@
@provider = provider_class.new(@resource)
end
it 'should match user names' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo
...done.
EOT
@provider.exists?.should == 'foo'
end
it 'should match user names with 2.4.1 syntax' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo bar
...done.
EOT
@provider.exists?.should == 'foo bar'
end
it 'should not match if no users on system' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
...done.
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
EOT
@provider.exists?.should be_nil
end
it 'should not match if no matching users on system' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
fooey
...done.
EOT
@provider.exists?.should be_nil
end
it 'should match user names from list' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one
two three
foo
bar
...done.
EOT
@provider.exists?.should == 'foo'
end
Expand All @@ -62,13 +52,11 @@
@resource[:password] = 'bar'
@resource[:admin] = 'true'
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
@provider.create
Expand All @@ -78,129 +66,107 @@
@provider.destroy
end
it 'should be able to retrieve admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo [administrator]
...done.
EOT
@provider.admin.should == :true
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one [administrator]
foo []
...done.
EOT
@provider.admin.should == :false
end
it 'should fail if admin value is invalid' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo fail
...done.
EOT
expect { @provider.admin }.to raise_error(Puppet::Error, /Could not match line/)
end
it 'should be able to set admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
@provider.admin=:true
end
it 'should not interfere with existing tags on the user when setting admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo [bar, baz]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz', 'administrator'].sort)
@provider.admin=:true
end
it 'should be able to unset admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo [administrator]
guest [administrator]
icinga []
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', [])
@provider.admin=:false
end
it 'should not interfere with existing tags on the user when unsetting admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo [administrator, bar, baz]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz'].sort)
@provider.admin=:false
end

it 'should clear all tags on existing user' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one [administrator]
foo [tag1,tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', [])
@provider.tags=[]
end

it 'should set multiple tags' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one [administrator]
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['tag1','tag2'])
@provider.tags=['tag1','tag2']
end

it 'should clear tags while keep admin tag' do
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one [administrator]
foo [administrator, tag1, tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"])
@provider.tags=[]
end

it 'should change tags while keep admin tag' do
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
one [administrator]
foo [administrator, tag1, tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag3","tag7"])
@provider.tags=['tag1','tag7','tag3']
Expand All @@ -210,10 +176,8 @@
@resource[:tags] = [ "tag1", "tag2" ]
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["tag1","tag2"])
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').returns <<-EOT
foo []
...done.
EOT
@provider.create
end
Expand All @@ -222,10 +186,8 @@
@resource[:tags] = [ "tag1", "tag2" ]
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('list_users').twice.returns <<-EOT
Listing users ...
@provider.expects(:rabbitmqctl).with('list_users','-q').twice.returns <<-EOT
foo []
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"])
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag2"])
Expand Down
Loading