Skip to content

Commit

Permalink
Added guards to rabbitmq version to determine if it's running, otherw…
Browse files Browse the repository at this point in the history
…ise try new options every other iteration
  • Loading branch information
nmaludy committed Jun 30, 2020
1 parent 989ea8d commit 31d9ca3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
42 changes: 28 additions & 14 deletions lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb
Expand Up @@ -5,21 +5,35 @@
confine feature: :posix

def self.plugin_list
retry_iter = 0
list = run_with_retries do
# Starting in RabbitMQ 3.6.7 pass in -e to list both implicitly and explicitly enabled plugins.
# If you pass in -E instead, then only explicitly enabled plugins are listed.
# Implicitly enabled plugins are those that were enabled as a dependency of another plugin/
# If we do not pass in -e then the order if plugin installation matters within the puppet
# code. Example, if Plugin A depends on Plugin B and we install Plugin B first it will
# implicitly enable Plugin A. Then when we go to run Puppet a second time without the
# -e parameter, we won't see Plugin A as being enabled so we'll try to install it again.
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
# explicitly enabled.
if Puppet::Util::Package.versioncmp(rabbitmq_version, '3.6.7') >= 0
# also pass in -q to suppress informational messages that break our parsing
rabbitmqplugins('list', '-e', '-m', '-q')
else
rabbitmqplugins('list', '-E', '-m')
begin
# Starting in RabbitMQ 3.6.7 pass in -e to list both implicitly and explicitly enabled plugins.
# If you pass in -E instead, then only explicitly enabled plugins are listed.
# Implicitly enabled plugins are those that were enabled as a dependency of another plugin/
# If we do not pass in -e then the order if plugin installation matters within the puppet
# code. Example, if Plugin A depends on Plugin B and we install Plugin B first it will
# implicitly enable Plugin A. Then when we go to run Puppet a second time without the
# -e parameter, we won't see Plugin A as being enabled so we'll try to install it again.
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
# explicitly enabled.
#
# if we can't determine the running version of rabbitmq, then try the new options
# vs old options every other time (modulo 2)
if rabbitmq_running
if Puppet::Util::Package.versioncmp(rabbitmq_version, '3.6.7') >= 0
# also pass in -q to suppress informational messages that break our parsing
rabbitmqplugins('list', '-e', '-m', '-q')
else
rabbitmqplugins('list', '-E', '-m')
end
elsif retry_iter.modulo(2).zero?
rabbitmqplugins('list', '-e', '-m', '-q')
else
rabbitmqplugins('list', '-E', '-m')
end
ensure
retry_iter += 1
end
end
list.split(%r{\n})
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb
Expand Up @@ -45,12 +45,14 @@

context 'with RabbitMQ version >=3.6.7' do
it 'returns a list of plugins' do
provider.class.expects(:rabbitmq_running).returns true
provider.class.expects(:rabbitmq_version).returns '3.6.7'
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m', '-q').returns("foo\nbar\nbaz\n")
expect(provider.class.plugin_list).to eq(%w[foo bar baz])
end

it 'handles no training newline properly' do
provider.class.expects(:rabbitmq_running).returns true
provider.class.expects(:rabbitmq_version).returns '3.6.7'
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m', '-q').returns("foo\nbar")
expect(provider.class.plugin_list).to eq(%w[foo bar])
Expand All @@ -59,12 +61,14 @@

context 'with RabbitMQ version <3.6.7' do
it 'returns a list of plugins' do
provider.class.expects(:rabbitmq_running).returns true
provider.class.expects(:rabbitmq_version).returns '3.6.6'
provider.class.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\nbar\nbaz\n")
expect(provider.class.plugin_list).to eq(%w[foo bar baz])
end

it 'handles no training newline properly' do
provider.class.expects(:rabbitmq_running).returns true
provider.class.expects(:rabbitmq_version).returns '3.6.6'
provider.class.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\nbar")
expect(provider.class.plugin_list).to eq(%w[foo bar])
Expand Down

0 comments on commit 31d9ca3

Please sign in to comment.