-
Notifications
You must be signed in to change notification settings - Fork 900
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
app/models/manageiq/providers/ansible_tower/automation_manager/machine_credential.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential < ManageIQ::Providers::AutomationManager::Authentication | ||
extend ApiCreate | ||
end |
36 changes: 36 additions & 0 deletions
36
...dels/manageiq/providers/ansible_tower/automation_manager/machine_credential/api_create.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential | ||
module ApiCreate | ||
def create_in_provider(manager_id, params) | ||
manager = ExtManagementSystem.find(manager_id) | ||
credential = manager.with_provider_connection do |connection| | ||
connection.api.credentials.create!(params) | ||
end | ||
|
||
# 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? | ||
|
||
find_by(:resource_id => manager.id, :manager_ref => credential.id) | ||
end | ||
|
||
def create_in_provider_queue(manager_id, params) | ||
task_opts = { | ||
:action => "Creating Ansible Tower MachineCredential", | ||
:userid => "system" | ||
} | ||
|
||
manager = ExtManagementSystem.find(manager_id) | ||
|
||
queue_opts = { | ||
:args => [manager_id, params], | ||
:class_name => "ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential", | ||
:method_name => "create_in_provider", | ||
:priority => MiqQueue::HIGH_PRIORITY, | ||
:role => "ems_operations", | ||
:zone => manager.my_zone | ||
} | ||
|
||
MiqTask.generic_action_with_callback(task_opts, queue_opts) | ||
end | ||
end | ||
end |
56 changes: 56 additions & 0 deletions
56
...manageiq/providers/ansible_tower/automation_manager/machine_credential/api_create_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'ansible_tower_client' | ||
|
||
describe ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential do | ||
context "::ApiCreate" do | ||
let(:provider) { FactoryGirl.create(:provider_ansible_tower, :with_authentication) } | ||
let(:manager) { provider.managers.first } | ||
let(:atc) { double("AnsibleTowerClient::Connection", :api => api) } | ||
let(:api) { double("AnsibleTowerClient::Api", :credentials => credentials) } | ||
let(:credentials) { double("AnsibleTowerClient::Collection", :create! => credential) } | ||
let(:credential) { AnsibleTowerClient::Credential.new(nil, credential_json) } | ||
|
||
let(:credential_json) do | ||
params.merge( | ||
:id => 10, | ||
).stringify_keys.to_json | ||
end | ||
|
||
let(:params) do | ||
{ | ||
:description => "Description", | ||
:name => "My Credential", | ||
:related => {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect to see |
||
} | ||
end | ||
|
||
it ".create_in_provider" do | ||
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc) | ||
expect(EmsRefresh).to receive(:queue_refresh).and_return(store_new_credential(credential, manager)) | ||
expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager) | ||
|
||
expect(described_class.create_in_provider(manager.id, params)).to be_a(described_class) | ||
end | ||
|
||
it ".create_in_provider_queue" do | ||
EvmSpecHelper.local_miq_server | ||
task_id = described_class.create_in_provider_queue(manager.id, params) | ||
expect(MiqTask.find(task_id)).to have_attributes(:name => "Creating Ansible Tower MachineCredential") | ||
expect(MiqQueue.first).to have_attributes( | ||
:args => [manager.id, params], | ||
:class_name => "ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential", | ||
:method_name => "create_in_provider", | ||
:priority => MiqQueue::HIGH_PRIORITY, | ||
:role => "ems_operations", | ||
:zone => manager.my_zone | ||
) | ||
end | ||
|
||
def store_new_credential(credential, manager) | ||
described_class.create!( | ||
:resource => manager, | ||
:manager_ref => credential.id.to_s, | ||
:name => credential.name, | ||
) | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we verify that the
kind
isssh
? Or merge that in as a default option?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 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?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.
My concern about
kind
is that this is acreate
on a particular leaf class. If you want to move this logic up to the superclass so that it is shared by allAutomationManager::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)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 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 existingAutomationManager::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?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 agree, this is Tower specific logic and should live in
ManageIQ::Providers::AnsibleTower::AutomationManager::Authentication
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.
Great. It's in now