Skip to content

Commit 0df8c3d

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 0df8c3d

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

lib/puppet/provider/rabbitmq_cli.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def self.run_with_retries(count = 30, step = 6, timeout = 10)
7272
yield
7373
end
7474
rescue Puppet::ExecutionFailure => e
75-
Puppet.debug "Command failed, retrying: #{e.message}"
75+
Puppet.info "Command failed, retrying: #{e.message}"
7676
sleep step
7777
rescue Timeout::Error
78-
Puppet.debug 'Command failed, retrying'
78+
Puppet.info 'Command failed, retrying'
7979
sleep step
8080
else
8181
Puppet.debug 'Command succeeded'

lib/puppet/provider/rabbitmq_plugin/rabbitmqplugins.rb

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,44 @@
55
confine feature: :posix
66

77
def self.plugin_list
8+
retry_iter = 0
89
list = run_with_retries do
9-
# Starting in RabbitMQ 3.6.7 pass in -e to list both implicitly and explicitly enabled plugins.
10-
# If you pass in -E instead, then only explicitly enabled plugins are listed.
11-
# Implicitly enabled plugins are those that were enabled as a dependency of another plugin/
12-
# If we do not pass in -e then the order if plugin installation matters within the puppet
13-
# code. Example, if Plugin A depends on Plugin B and we install Plugin B first it will
14-
# implicitly enable Plugin A. Then when we go to run Puppet a second time without the
15-
# -e parameter, we won't see Plugin A as being enabled so we'll try to install it again.
16-
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
17-
# 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')
10+
begin
11+
# Starting in RabbitMQ 3.6.7 pass in -e to list both implicitly and explicitly enabled plugins.
12+
# If you pass in -E instead, then only explicitly enabled plugins are listed.
13+
# Implicitly enabled plugins are those that were enabled as a dependency of another plugin/
14+
# If we do not pass in -e then the order if plugin installation matters within the puppet
15+
# code. Example, if Plugin A depends on Plugin B and we install Plugin B first it will
16+
# implicitly enable Plugin A. Then when we go to run Puppet a second time without the
17+
# -e parameter, we won't see Plugin A as being enabled so we'll try to install it again.
18+
# To preserve idempotency we should get all enabled plugins regardless of implicitly or
19+
# explicitly enabled.
20+
#
21+
# if we can't determine the running version of rabbitmq, then try the new options
22+
# vs old options every other time (modulo 2)
23+
if rabbitmq_running
24+
if Puppet::Util::Package.versioncmp(rabbitmq_version, '3.6.7') >= 0
25+
# also pass in -q to suppress informational messages that break our parsing
26+
Puppet.info('Running new plugins command because rabbitmq version is good')
27+
rabbitmqplugins('list', '-e', '-m', '-q')
28+
else
29+
Puppet.info('Running new plugins command because rabbitmq version is old')
30+
rabbitmqplugins('list', '-E', '-m')
31+
end
32+
elsif retry_iter.modulo(2).zero?
33+
Puppet.info('Running new plugins command because rabbitmq isnt running iter mod 0')
34+
rabbitmqplugins('list', '-e', '-m', '-q')
35+
else
36+
Puppet.info('Running new plugins command because rabbitmq isnt running iter mod 1')
37+
rabbitmqplugins('list', '-E', '-m')
38+
end
39+
ensure
40+
retry_iter += 1
2341
end
2442
end
25-
list.split(%r{\n})
43+
plugins = list.split(%r{\n})
44+
Puppet.info("Existing plugins list: #{plugins}")
45+
plugins
2646
end
2747

2848
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@
4545

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

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

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

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

0 commit comments

Comments
 (0)