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

Support policy format change in v3.7.0 - #671 (Replaces #674) #676

Merged
merged 7 commits into from
Jan 11, 2018

Conversation

fatmcgav
Copy link
Contributor

RabbitMQ 3.7.0 seems to have changed the ordering of fields in the policies output.

Credit to @alexizmailov for the original work in #674, I just tweaked it a bit and added some tests :)

Fixes #671

alex123321-wq and others added 4 commits December 27, 2017 15:14
RMQ < 3.7.0 shows policies as:
`/ ha-all all .* {"ha-mode":"all","ha-sync-mode":"automatic"} 0`

V3.7.0 returns this:
`/ ha-all  .*  all {"ha-mode":"all","ha-sync-mode":"automatic"}  0`

```.*``` and ```all``` are swapped and regex needs to be updated.

Also corrected a typo when (vhost, name) was swapped, accidentally, I suppose.
and corresponding applyto/pattern indexes outside of policy_line.each.
Fixed tests to handle additional 'rabbitmqctl -p status' call, and add
explicit testing for >=3.7.0
it 'matches policies from list' do
provider.class.expects(:rabbitmqctl).with('-q', 'status').returns '{rabbit,"RabbitMQ","3.7.0"}'
provider.class.expects(:rabbitmqctl).with('list_policies', '-q', '-p', '/').returns <<-EOT
/ ha-all .* all {"ha-mode":"all","ha-sync-mode":"automatic"} 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly makes sense to me, just curious why there's a literal .* in the heredoc in these various examples (including in the existing code)... shouldn't the result be the literal output of running rabbitmqctl list_policies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe .* can be the output from rabbitmqctl list_polices, as it's a regex pattern that can be used within the rabbitmq policy to control what resources the policy affects.
Unless I'm missing your point :)

More details here: https://www.rabbitmq.com/parameters.html#policies

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, that makes sense then. I didn't have a rabbitmq instance handy so couldn't check the actual output, and a quick Google search failed me.

@wyardley
Copy link
Contributor

wyardley commented Jan 10, 2018

Thanks for this @fatmcgav, and thanks for preserving attribution.

I'm +1 on this, with just the open question above (maybe I'm misunderstanding how the mock works here?)

My only other question is on how reliable rabbitmq_version is, and whether it might not make sense to just try both match patterns? But since the existing code seems to already have been using it, I guess it should work.
The rubocop / Puppet 5 failures obviously would need to be resolved as well.

@fatmcgav
Copy link
Contributor Author

Yeh, I'm confused by the TravisCI failures, as those tests all pass for me locally :s

@wyardley
Copy link
Contributor

@fatmcgav did you try with PUPPET_VERSION="~> 5.0"?

@wyardley
Copy link
Contributor

I'm also not seeing the error locally, even with PUPPET_VERSION="~> 5.0".

I think the following should resolve the rubocop failures?

--- a/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb
+++ b/lib/puppet/provider/rabbitmq_policy/rabbitmqctl.rb
@@ -20,10 +20,12 @@ Puppet::Type.type(:rabbitmq_policy).provide(:rabbitmqctl, parent: Puppet::Provid
       # / ha-all .* all {"ha-mode":"all","ha-sync-mode":"automatic"} 0 << This is for RabbitMQ v >= 3.7.0
       if Puppet::Util::Package.versioncmp(rabbitmq_version, '3.7') >= 0
         regex = %r{^(\S+)\s+(\S+)\s+(\S+)\s+(all|exchanges|queues)?\s+(\S+)\s+(\d+)$}
-        applyto_index, pattern_index = 4, 3
+        applyto_index = 4
+        pattern_index = 3
       else
         regex = %r{^(\S+)\s+(\S+)\s+(all|exchanges|queues)?\s*(\S+)\s+(\S+)\s+(\d+)$}
-        applyto_index, pattern_index = 3, 4
+        applyto_index = 3
+        pattern_index = 4
       end
 
       policy_list.split(%r{\n}).each do |line|

@wyardley
Copy link
Contributor

wyardley commented Jan 11, 2018

Proposed a possible fix in
fatmcgav#1
Alternately, you could try dropping the context statements around the version-specific bits.
I could only replicate the error locally by switching to this pattern (and then only when running in parallel):

provider_class = Puppet::Type.type(:rabbitmq_policy).provider(:rabbitmqctl)
describe provider_class do
[...]
  let(:provider) { provider_class.new(resource) }

It's basically an issue with that same instance being reused in combination with the parallel tests, I think? I think voxpupuli/puppet-nodejs@6b7acb5 was a similar problem (similar error and similar cause)

Resolve test failures
@fatmcgav
Copy link
Contributor Author

@wyardley it looks like ure fix has got all the tests passing, so thanks for that... 😀

@@ -7,11 +7,10 @@
pattern: '.*',
definition: {
'ha-mode' => 'all'
},
provider: described_class.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't 100% sure about this, but seems to work without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, it does :)

@wyardley wyardley added the bug Something isn't working label Jan 11, 2018
@wyardley wyardley changed the title Support policy format change in v3.7.0 - Replaces #674 Support policy format change in v3.7.0 - #671 (Replaces #674) Jan 11, 2018
Copy link
Contributor

@wyardley wyardley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but since I've got some changes in here, hoping someone else can merge. After merge, we should cut a release.

@fatmcgav
Copy link
Contributor Author

@wyardley A new release sounds good to me :)

@bastelfreak
Copy link
Member

Thanks @fatmcgav!

@bastelfreak bastelfreak merged commit f5e1ffe into voxpupuli:master Jan 11, 2018
cegeka-jenkins pushed a commit to cegeka/puppet-rabbitmq that referenced this pull request Mar 26, 2021
Support policy format change in v3.7.0 - voxpupuli#671 (Replaces voxpupuli#674)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants