-
Notifications
You must be signed in to change notification settings - Fork 54
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
Tower 3.3 fix: Credential.manager_ref need to be an integer for Tower 3.3 #134
Conversation
Checked commit https://github.com/jameswnl/manageiq-providers-ansible_tower/commit/14b5e83174492aa869a2b15976fc59f3bb9afc36 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
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.
One question about the potential handling of a nil value, but otherwise I think this looks good.
@agrare Can you review?
@@ -33,6 +33,10 @@ def provider_object(connection = nil) | |||
(connection || connection_source.connect).api.credentials.find(manager_ref) | |||
end | |||
|
|||
def manager_ref | |||
self[:manager_ref].to_i |
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.
We have tested with this change in a few scenarios and it resolves the reported issue. 👍
@jameswnl Is there any condition you can think of where this column could end up as nil
and we may not want to convert that to an int?
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.
nil.to_i
returns 0 and also this is implemented in Tower
subclass.
But talked to @agrare has concern on changing the type returned. So your team may have to explore performing the conversion in automate code
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.
We would have to find all the places where we do something like: https://github.com/ManageIQ/manageiq/blob/master/app/models/manageiq/providers/embedded_ansible/automation_manager/playbook.rb#L49 (There are other places that do something similar.)
Maybe the other third option is to do this at the client gem layer so the database and code can continue the same but the client knows what Tower is expecting.
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.
@gmcculloug going Tower client gem route, you mean updating https://github.com/ansible/ansible_tower_client_ruby/blob/master/lib/ansible_tower_client/base_models/job_template.rb#L12 to search/replace the options
param?
hmm.. I am not sure if this is a clean way ...
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.
So I have a few concerns, might turn out that none of them are a big issue but:
- There will be inconsistent results depending on how you ask
Authentication.pluck(:manager_ref)
<- will return all strings
Authentication.all.map { |a| a.manager_ref}
<- will return a mix of strings and ints
ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.pluck(:manager_ref)
<- will return all strings
ManageIQ::Providers::AnsibleTower::AutomationManager::Credential.all.map { |a| a.manager_ref}
<- will return all ints
This just seems like a recipe for someone doing ems.authentications.map { |auth| auth.manager_ref.split("something") }
or some string op and it'll blow up when it gets an int
- If there isn't something which is castable to an int in the manager_ref field it will always return 0
0 Could be a valid credential that isn't the one the user selected.
We could use Integer(manager_ref)
so that it would raise an exception? IDK
So high level I don't see anything explicitly wrong, just strange
@@ -33,6 +33,10 @@ def provider_object(connection = nil) | |||
(connection || connection_source.connect).api.credentials.find(manager_ref) | |||
end | |||
|
|||
def manager_ref | |||
self[:manager_ref].to_i |
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.
super.to_i
would be cleaner
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 don't have a preference but the self[:attr]
is based on https://stackoverflow.com/questions/21835116/how-can-i-overwrite-a-getter-method-in-an-activerecord-model
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.
If we want to use something like manager_ref_obj
can that be a virtual column? This would still requires us to modify all the callers.
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.
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 see. I guess my concern is that all callers need to be updated and new code needs to know about the new method.
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.
yeah, that's the drawback of creating a new method.
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.
We discussed a couple of approaches and this felt like the best options.
One was overriding manager_ref
for this sub-class to return an integer, but that would be if you loop over all instances the same property would return different object types. Some integer some string.
Also, discussed changing it down at the tower client gem, but that was James/Adam were not in favor of that either.
Key point, I'm hoping to get this resolve for the next Hammer build and Lucy is working on the corresponding changes so if we think this is going to change then let's get it addressed now. Otherwise I'd like to move forward with this approach.
app/models/manageiq/providers/ansible_tower/shared/automation_manager/credential.rb
Show resolved
Hide resolved
app/models/manageiq/providers/ansible_tower/shared/automation_manager/credential.rb
Outdated
Show resolved
Hide resolved
@agrare can we merge this? |
Tower 3.3 fix: Credential.manager_ref need to be an integer for Tower 3.3 (cherry picked from commit 73ba300) https://bugzilla.redhat.com/show_bug.cgi?id=1640533
Hammer backport details:
|
Part of the fix to https://bugzilla.redhat.com/show_bug.cgi?id=1640533
Tower 3.3 changed validation rule that now the type of reference to credentials (and others) must be an integer.
Automate code would make use of this new method
Related PR: ManageIQ/manageiq#18154