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

Model change for Ansible Tower Credential #13773

Merged
merged 3 commits into from
Feb 16, 2017

Conversation

jameswnl
Copy link
Contributor

@jameswnl jameswnl commented Feb 6, 2017

We're duplicating this api_creat code. We need to refactor this (next round)

@jameswnl jameswnl changed the title Allow MachineCredential to create in Tower [WIP] Allow MachineCredential to create in Tower Feb 6, 2017
@jameswnl
Copy link
Contributor Author

jameswnl commented Feb 6, 2017

@miq-bot add_labels wip, enhancement, providers/ansible_tower

@jameswnl jameswnl force-pushed the credential-crud branch 2 times, most recently from 91984ac to bdedab2 Compare February 6, 2017 20:51
@jameswnl jameswnl changed the title [WIP] Allow MachineCredential to create in Tower Allow MachineCredential to create in Tower Feb 6, 2017
@jameswnl
Copy link
Contributor Author

jameswnl commented Feb 6, 2017

@miq-bot remove_label wip

@Fryguy
Copy link
Member

Fryguy commented Feb 7, 2017

@bdunne Please review.

def create_in_provider(manager_id, params)
manager = ExtManagementSystem.find(manager_id)
credential = manager.with_provider_connection do |connection|
connection.api.credentials.create!(params)
Copy link
Member

Choose a reason for hiding this comment

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

Should we verify that the kind is ssh? Or merge that in as a default option?

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 was the same thing I am not sure about. Actually not just kind, my question is do we want to validate the input? and how much we want to validate? Or let Tower's validation does its work?

Copy link
Member

Choose a reason for hiding this comment

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

My concern about kind is that this is a create on a particular leaf class. If you want to move this logic up to the superclass so that it is shared by all AutomationManager::Authentications, then I would be okay with letting Tower do all of the data validation. Is there a reason for this method to be on the leaf class rather than the superclass? (I don't think there's anything specific to this leaf class here)

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 don't like this at all and that's why I have only done this to MachineCredential. I prefer this to be done at a higher level class. The existing AutomationManager::Authentication is not the right place because this particular behavior is Tower specific.
We need to insert another Authentication in the name space of Tower. Are you onboard with that?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, this is Tower specific logic and should live in ManageIQ::Providers::AnsibleTower::AutomationManager::Authentication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. It's in now

{
:description => "Description",
:name => "My Credential",
:related => {}
Copy link
Member

Choose a reason for hiding this comment

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

I would expect to see :username here and maybe some other fields too.

@jameswnl jameswnl force-pushed the credential-crud branch 3 times, most recently from 31bb1db to d330632 Compare February 8, 2017 18:56
@jameswnl jameswnl changed the title Allow MachineCredential to create in Tower Allow Ansible Tower Credential to create in Tower Feb 8, 2017
@blomquisg
Copy link
Member

Holding off merging this until #13879 is merged. I believe that #13879 is adding many of the automate models added here, too.

# TODO: This needs to be targeted refresh so it doesn't take too long
EmsRefresh.queue_refresh(manager, nil, true) if !manager.missing_credentials? && manager.authentication_status_ok?

find_by(:resource_id => manager.id, :manager_ref => credential.id)
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this line. You shouldn't query against the resource_id as it's part of a polymorphic pair. You have to query with:

find_by(:resource => manager, :manager_ref => credential.id)


# Get the record in our database
# TODO: This needs to be targeted refresh so it doesn't take too long
EmsRefresh.queue_refresh(manager, nil, true) if !manager.missing_credentials? && manager.authentication_status_ok?
Copy link
Member

@Fryguy Fryguy Feb 15, 2017

Choose a reason for hiding this comment

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

I really don't like this blocking call, but it is what it is for the existing pattern. cc @bdunne @agrare

Copy link
Member

Choose a reason for hiding this comment

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

Typically CRUD of native is done inside of a state machine like how provisioning does it where there is a step to create natively, poke the refresh asynchronously, then transition to a state where you can check asynchronously. All of these seems to be happening directly in this method, which means a worker is going to be completely locked waiting for refresh to complete.

I feel like a better approach for ANY CRUD of native objects is to use some sort of MiqTask, but not as it's done here. This task should call a method that natively creates the object, then pokes the refresh and then immediately returns. The MiqTask is then responsible for the next step of seeing if the refresh has completed. Once the MiqTask completes, it can use UI Notifications to tell the user that the object is ready.

So, for the use case of creating a credential and then using it during creating a repository, I would see:

  • User creates the credential
  • Creation request put in queue via a task and user is notified that "Request to create credential has started"
  • Queue picks up the message, executes the native create, pokes the EmsRefresh
  • Task then puts polling on the queue until the expected object is in the database.
  • Task then notifies via UI notification, and marks itself as done.
  • The User will then see the notification and can go create his repository. If he tries any earlier, the new cred just won't appear.

Copy link
Member

Choose a reason for hiding this comment

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

Or perhaps a ::Job is a better choice and create a "real" state machine

Copy link
Member

Choose a reason for hiding this comment

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

Another option is doing what's similar to the rhev create_vm event where we inject ourselves to create the object on the fly without impacting the EMS Refresh. cc @agrare

Copy link
Member

Choose a reason for hiding this comment

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

The api_create method that this is based on is changing too, I agree with splitting the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is following the pattern established in #13495. And API create is the key goal of this PR. The modeling code will need refresh once GregB's new models PR is merged.

I can close this for now and re-create once the new pattern is established -- @bdunne is there a PR for the new changes?

Copy link
Member

Choose a reason for hiding this comment

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

If you have to return the id of the object that is created (and looks like you are) then the rhev refresh new vm is probably the right approach, just create the basic object kick off a refresh and return the new id.

Otherwise I'd love to put anything waiting for a refresh in a Task/Job state machine.

Copy link
Member

Choose a reason for hiding this comment

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

We just have to weigh time to implement versus current implementation. If we already do this "wait for refresh" elsewhere, we can continue that for now, with the plan to get away from it.

@jameswnl No need to close, just split the PR. This PR can just be the new models, and ApiCreate can be split out.

@Fryguy
Copy link
Member

Fryguy commented Feb 15, 2017

@jameswnl If you split the modeling from the ApiCreate stuff, then I can merge that independent. They are not related in this PR.

@blomquisg
Copy link
Member

So, this PR is

  1. APICreate, and
  2. Some model hierarchy cleanup and adding some automate models.

For #1 we want to hold off and talk about the APICreate approach.

For #2, those models are part of #13879.

So, for now, I guess this PR can just be closed until we figure out the right approach for APICreate.

Thoughts? @jameswnl @Fryguy @bdunne

@jameswnl
Copy link
Contributor Author

@blomquisg yes, that's what I think too. closing it.

@jameswnl jameswnl closed this Feb 16, 2017
@jameswnl jameswnl reopened this Feb 16, 2017
@jameswnl jameswnl changed the title Allow Ansible Tower Credential to create in Tower Model change for Ansible Tower Credential Feb 16, 2017
@miq-bot
Copy link
Member

miq-bot commented Feb 16, 2017

Checked commits jameswnl/manageiq@fe4fd78~...c8e2fe2 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
9 files checked, 1 offense detected

spec/lib/miq_automation_engine/service_models/miq_ae_service_manageiq-providers-ansible_tower-automation_manager-credential_spec.rb

  • ❗ - Line 1, Col 1 - Style/FileName - The name of this source file (miq_ae_service_manageiq-providers-ansible_tower-automation_manager-credential_spec.rb) should use snake_case.

@Fryguy Fryguy merged commit 7034341 into ManageIQ:master Feb 16, 2017
@Fryguy Fryguy added this to the Sprint 55 Ending Feb 27, 2017 milestone Feb 16, 2017
@jameswnl jameswnl deleted the credential-crud branch February 16, 2017 20:00
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.

6 participants