Skip to content

Commit 26178f4

Browse files
committed
Added guards to rabbitmq version to determine if it's running, otherwise try new options every other iteration
1 parent 989ea8d commit 26178f4

File tree

6 files changed

+27
-42
lines changed

6 files changed

+27
-42
lines changed

lib/puppet/provider/rabbitmq_cli.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ def self.run_with_retries(count = 30, step = 6, timeout = 10)
7171
output = Timeout.timeout(timeout) do
7272
yield
7373
end
74-
rescue Puppet::ExecutionFailure => e
75-
Puppet.debug "Command failed, retrying: #{e.message}"
76-
sleep step
77-
rescue Timeout::Error
74+
rescue Puppet::ExecutionFailure, Timeout::Error
7875
Puppet.debug 'Command failed, retrying'
7976
sleep step
8077
else

lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
confine feature: :posix
66

77
def self.plugin_list
8-
list = run_with_retries do
9-
# Starting in RabbitMQ 3.6.7 pass in -e to list both implicitly and explicitly enabled plugins.
8+
list_str = run_with_retries do
9+
# Pass in -e to list both implicitly and explicitly enabled plugins.
1010
# If you pass in -E instead, then only explicitly enabled plugins are listed.
1111
# Implicitly enabled plugins are those that were enabled as a dependency of another plugin/
1212
# If we do not pass in -e then the order if plugin installation matters within the puppet
@@ -15,14 +15,15 @@ def self.plugin_list
1515
# -e parameter, we won't see Plugin A as being enabled so we'll try to install it again.
1616
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
1717
# explicitly enabled.
18-
if Puppet::Util::Package.versioncmp(rabbitmq_version, '3.6.7') >= 0
19-
# also pass in -q to suppress informational messages that break our parsing
20-
rabbitmqplugins('list', '-e', '-m', '-q')
21-
else
22-
rabbitmqplugins('list', '-E', '-m')
23-
end
18+
rabbitmqplugins('list', '-e', '-m')
2419
end
25-
list.split(%r{\n})
20+
# Split by newline.
21+
lines = list_str.split(%r{\n})
22+
# Return only lines that are single words because sometimes RabbitMQ likes to output
23+
# information messages. Suppressing those messages via CLI flags is inconsistent between
24+
# versions, so this this regex removes those message without having to use painful
25+
# version switches.
26+
lines.select { |line| line =~ %r{^(\S+)$} }
2627
end
2728

2829
def self.instances

spec/acceptance/parameter_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class { 'rabbitmq':
3232
}
3333
EOS
3434

35-
apply_manifest(pp, catch_failures: true, debug: true)
36-
apply_manifest(pp, catch_changes: true, debug: true)
35+
apply_manifest(pp, catch_failures: true)
36+
apply_manifest(pp, catch_changes: true)
3737
end
3838

3939
# rubocop:disable RSpec/MultipleExpectations

spec/acceptance/rabbitmqadmin_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class { 'erlang': epel_enable => true}
1414
}
1515
EOS
1616

17-
apply_manifest(pp, catch_failures: true, debug: true)
17+
apply_manifest(pp, catch_failures: true)
1818
end
1919

2020
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
@@ -36,7 +36,7 @@ class { 'erlang': epel_enable => true}
3636
EOS
3737

3838
shell('rm -f /var/lib/rabbitmq/rabbitmqadmin')
39-
apply_manifest(pp, catch_failures: true, debug: true)
39+
apply_manifest(pp, catch_failures: true)
4040
end
4141

4242
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
@@ -73,7 +73,7 @@ class { 'erlang': epel_enable => true}
7373
EOS
7474

7575
shell('rm -f /var/lib/rabbitmq/rabbitmqadmin')
76-
apply_manifest(pp_pre, catch_failures: true, debug: true)
76+
apply_manifest(pp_pre, catch_failures: true)
7777
apply_manifest(pp, catch_failures: true)
7878
end
7979

spec/spec_helper_acceptance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@
9999
end
100100

101101
it 'applies a second time without changes' do
102-
apply_manifest(pp, catch_changes: true, debug: true)
102+
apply_manifest(pp, catch_changes: true)
103103
end
104104
end

spec/unit/puppet/provider/rabbitmq_plugin/rabbitmqctl_spec.rb

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,19 @@
4343
expect(provider_class).to respond_to :instances
4444
end
4545

46-
context 'with RabbitMQ version >=3.6.7' do
47-
it 'returns a list of plugins' do
48-
provider.class.expects(:rabbitmq_version).returns '3.6.7'
49-
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m', '-q').returns("foo\nbar\nbaz\n")
50-
expect(provider.class.plugin_list).to eq(%w[foo bar baz])
51-
end
52-
53-
it 'handles no training newline properly' do
54-
provider.class.expects(:rabbitmq_version).returns '3.6.7'
55-
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m', '-q').returns("foo\nbar")
56-
expect(provider.class.plugin_list).to eq(%w[foo bar])
57-
end
46+
it 'returns a list of plugins' do
47+
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m').returns("foo\nbar\nbaz\n")
48+
expect(provider.class.plugin_list).to eq(%w[foo bar baz])
5849
end
5950

60-
context 'with RabbitMQ version <3.6.7' do
61-
it 'returns a list of plugins' do
62-
provider.class.expects(:rabbitmq_version).returns '3.6.6'
63-
provider.class.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\nbar\nbaz\n")
64-
expect(provider.class.plugin_list).to eq(%w[foo bar baz])
65-
end
51+
it 'handles no training newline properly' do
52+
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m').returns("foo\nbar")
53+
expect(provider.class.plugin_list).to eq(%w[foo bar])
54+
end
6655

67-
it 'handles no training newline properly' do
68-
provider.class.expects(:rabbitmq_version).returns '3.6.6'
69-
provider.class.expects(:rabbitmqplugins).with('list', '-E', '-m').returns("foo\nbar")
70-
expect(provider.class.plugin_list).to eq(%w[foo bar])
71-
end
56+
it 'handles lines that are not plugins ' do
57+
provider.class.expects(:rabbitmqplugins).with('list', '-e', '-m').returns("Listing plugins with pattern \".*\" ...\nfoo\nbar")
58+
expect(provider.class.plugin_list).to eq(%w[foo bar])
7259
end
7360
end
7461

0 commit comments

Comments
 (0)