-
-
Notifications
You must be signed in to change notification settings - Fork 498
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 multiple routing keys for bindings using separate parameters #504
Conversation
:destination_type => destination_type, | ||
:routing_key => routing_key, | ||
:arguments => JSON.parse(arguments), | ||
:ensure => :present, | ||
:name => "%s@%s@%s" % [source_name, destination_name, vhost], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "%s@%s@%s@%s" % [source_name, destination_name, vhost, routing_key],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In retrospect, perhaps this should just be a hash of these values to remain unique but not duplicate the information that is available in the properties when printed by puppet resource rabbitmq_binding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hunner so, like this?
hashed_name = Digest::SHA256.hexdigest "%s@%s@%s@%s" % [source_name, destination_name, vhost, routing_key
unless(source_name.empty?)
binding = {
:source => source_name,
[...]
:name => hashed_name,
}
:destination_type => destination_type, | ||
:routing_key => routing_key, | ||
:arguments => JSON.parse(arguments), | ||
:ensure => :present, | ||
:name => "%s@%s@%s" % [source_name, destination_name, vhost], | ||
} | ||
resources << new(binding) if binding[:name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs fixing
:destination_type => destination_type, | ||
:routing_key => routing_key, | ||
:arguments => JSON.parse(arguments), | ||
:ensure => :present, | ||
:name => "%s@%s@%s" % [source_name, destination_name, vhost], | ||
} | ||
resources << new(binding) if binding[:name] | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefetch should match on all 4 properties, not on .name
like
if provider = bindings.find { |route| route.source == source && route.dest == dest && ... }
lib/puppet/type/rabbitmq_binding.rb
Outdated
newparam(:vhost, :namevar => true) do | ||
desc 'vhost' | ||
newvalues(/^\S+$/) | ||
defaultto('/') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does a required (because namevar) property have a defaultto? Maybe not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: keep the default because when explicitly specifying source/dest/routing_key and not using title_pattern, then it's good to have a default.
Any progress on this one? |
1d88136
to
eb81ba8
Compare
@fatmcgav Sorry for the delayed response, and also to not having updated this PR in forever. I got some good pointers from @hunner, @bmjen, and @DavidS, but honestly haven't had the energy to jump back into this so far, hopefully soon. I still do have the use case (though would be just as happy if someone else wanted to take a stab at it). I've rebased against current master, made some of the suggested changes, and am taking a quick look to see if it works (some of the existing tests for 'name' patterns would need to be dropped, but perhaps there should be some additional tests added). I've made most of the suggestions @hunner had in the review, but I'm still not getting it to work, whether or not I try to do it in a backwards-compatible way or not, so I think there are still some bits of the ever-fun title_patterns / composite namevars that are eluding me. I know some people have said composite namevars are not necessary, but I think maybe they are? I briefly got it to work for one use case in Vagrant, but right now I'm getting stuck on:
which seems to be similar to what's described in These are my test cases:
|
eb81ba8
to
b62e944
Compare
The error is coming (presumably) from https://github.com/voxpupuli/puppet-rabbitmq/pull/504/files#diff-6848b732a3c79af87de0ad6905d8387eR73 and I don't think that can work like this. Print out what the It's been a long time since I played around with that part. |
OK, so I've been able to re-produce the failure in a unit test.
That makes it a bit easier to debug... I'll see if can spot the cause later... |
f647763
to
0272df3
Compare
0272df3
to
b799846
Compare
b799846
to
4f55649
Compare
I am curious if there's a way to validate whether we have a valid source / destination / vhost / routing_key combination in total, between defaults and splitting up the name in the legacy case, but not sure what the cleanest way to do that validation would be. |
498e3eb
to
4f55649
Compare
4f55649
to
5cd02e1
Compare
lib/puppet/type/rabbitmq_binding.rb
Outdated
isnamevar | ||
end | ||
|
||
newparam(:source) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source/destination/vhost/routing_key should be properties because they can be read from & written to the system's configuration. This will also allow them to be printed when running puppet resource rabbitmq_binding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the global validate do
block can check raise ArgumentError, "source is required" if ! self[:source] and ! self.provider.source
etc. to ensure that the values are actually passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated those, as well as a couple other things that are read from / written to the config to be properties, let me know how that looks. Will work on validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did now have to update title_patterns to match :name
where I didn't before, not sure why that is. With the a@b@c
style naming, I got a name error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[root@centos-7-x64 tmp]# puppet apply apply_manifest.pp.1fJLTF
[...]
Notice: /Stage[main]/Main/Rabbitmq_exchange[exchange1@host1]/ensure: created
Notice: /Stage[main]/Main/Rabbitmq_binding[binding 1]/ensure: created
Notice: /Stage[main]/Main/Rabbitmq_binding[binding 2]/ensure: created
Notice: Applied catalog in 4.25 seconds
[root@centos-7-x64 tmp]# puppet resource rabbitmq_binding
rabbitmq_binding { '3716cc442c568f6be3772365f29af0ca786ea852b527e3c564dcb3cd83f928a9':
ensure => 'present',
destination => 'queue1',
destination_type => 'queue',
routing_key => 'test2',
source => 'exchange1',
vhost => 'host1',
}
rabbitmq_binding { 'b0f96dde732ed9be309bb466b680faa49117a151716a524eceaeb91080a34d64':
ensure => 'present',
destination => 'queue1',
destination_type => 'queue',
routing_key => 'test1',
source => 'exchange1',
vhost => 'host1',
}
Other questions: should routing_key default to |
…ferent routing key (MODULES-3679)
aa186f2
to
b405be7
Compare
ps - I took out the default for |
lib/puppet/type/rabbitmq_binding.rb
Outdated
desc 'destination of binding' | ||
|
||
newvalues(/^\S+$/) | ||
isnamevar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed aswell as the :namevar => true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, they're redundant. Removed.
f4b0cd0
to
2e00a19
Compare
Interestingly, |
2e00a19
to
2b7e726
Compare
@hunner @fatmcgav I think this is good to go maybe!? Technically, the user / password are managed by Puppet but not this resource, so am I right in thinking they should be params not properties? A lot of the things that should have been properties were params before, here's how I have it now:
|
2b7e726
to
9897c01
Compare
Multiple routing keys for bindings using namevars
…ake2 Multiple routing keys for bindings using namevars
…ake2 Multiple routing keys for bindings using namevars
Updated: proposing this as an option instead of #375
This PR lets you specify legacy style resources (
source@destination@vhost
) and / or lets you specifysource
,destination
(and, optionally,routing_key
andvhost
) as separate parameters, with a descriptive or arbitrary name.There's still probably some room for improvement, but I've finally got this in shape where I think it could be merged.