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

Tower 3.3 fix: Credential.manager_ref need to be an integer for Tower 3.3 #134

Merged
merged 1 commit into from
Nov 1, 2018
Merged

Conversation

jameswnl
Copy link
Contributor

@jameswnl jameswnl commented Oct 26, 2018

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

@miq-bot miq-bot added the wip label Oct 26, 2018
@miq-bot
Copy link
Member

miq-bot commented Oct 29, 2018

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
3 files checked, 0 offenses detected
Everything looks fine. ⭐

@jameswnl jameswnl changed the title [WIP] Tower 3.3 fix Tower 3.3 fix: Credential.manager_ref returned as integer Oct 29, 2018
@miq-bot miq-bot removed the wip label Oct 29, 2018
Copy link
Member

@gmcculloug gmcculloug left a 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
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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 ...

Copy link
Member

@agrare agrare left a 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:

  1. 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

  1. 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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bdunne overriding manager_ref which was my initial approach. See @agrare 's concern in this thread

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

@jameswnl jameswnl changed the title Tower 3.3 fix: Credential.manager_ref returned as integer Tower 3.3 fix: Credential.manager_ref need to be an integer for Tower 3.3 Oct 31, 2018
@jameswnl
Copy link
Contributor Author

jameswnl commented Nov 1, 2018

@miq-bot assign @agrare

@jameswnl
Copy link
Contributor Author

jameswnl commented Nov 1, 2018

@agrare can we merge this?

@agrare agrare merged commit 73ba300 into ManageIQ:master Nov 1, 2018
@agrare agrare added this to the Sprint 98 Ending Nov 5, 2018 milestone Nov 1, 2018
@jameswnl jameswnl deleted the tower33 branch November 1, 2018 20:32
simaishi pushed a commit that referenced this pull request Nov 2, 2018
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
@simaishi
Copy link
Contributor

simaishi commented Nov 2, 2018

Hammer backport details:

$ git log -1
commit a45325609bd2294ae3376d89f98154d757cd23e3
Author: Adam Grare <agrare@redhat.com>
Date:   Thu Nov 1 15:55:08 2018 -0400

    Merge pull request #134 from jameswnl/tower33
    
    Tower 3.3 fix: Credential.manager_ref need to be an integer for Tower 3.3
    
    (cherry picked from commit 73ba300544826bf50c8ca635c17a4b625349aeef)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1640533

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants