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

Support embedded_ansible to fetch credentials from provider #112

Merged
merged 1 commit into from
May 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,32 @@ object:
on_error:
max_retries:
max_time:
- field:
aetype: attribute
name: embedded_ansible
display_name:
datatype: boolean
priority: 2
owner:
default_value: 'false'
substitute: true
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
- field:
aetype: method
name: execute
display_name:
datatype: string
priority: 2
priority: 3
owner:
default_value:
substitute: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module AnsibleTower
module Operations
class AvailableCredentials
AUTH_CLASS = "ManageIQ_Providers_AutomationManager_Authentication".freeze
EMBEDDED_ANSIBLE_CLASS = "ManageIQ_Providers_EmbeddedAnsible_AutomationManager".freeze
def initialize(handle = $evm)
@handle = handle
end
Expand All @@ -22,8 +23,13 @@ def main
def provider
# for provisioning we use service_template
# for reconfig and retire use service
# Or use the embedded_ansible_provider
service = @handle.root['service_template'] || @handle.root['service']
service.try(:job_template, 'Provision').try(:manager)
service.try(:job_template, 'Provision').try(:manager) || embedded_ansible_provider
end

def embedded_ansible_provider
@handle.vmdb(EMBEDDED_ANSIBLE_CLASS).first if @handle.inputs.fetch('embedded_ansible', false)
end

def credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ object:
on_error:
max_retries:
max_time:
- field:
aetype:
name: embedded_ansible
display_name:
datatype: boolean
priority: 2
owner:
default_value: 'false'
substitute: false
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ object:
fields:
- credential_type:
value: ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential
- embedded_ansible:
value: 'true'
- execute:
value: Available_Credentials
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ object:
fields:
- credential_type:
value: ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential
- embedded_ansible:
value: 'true'
- execute:
value: Available_Credentials
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
require_domain_file

describe ManageIQ::Automate::AutomationManagement::AnsibleTower::Operations::AvailableCredentials do
let(:ansible_tower_manager) { FactoryGirl.create(:automation_manager_ansible_tower) }
let(:ansible_manager) { FactoryGirl.create(:automation_manager_ansible_tower) }
let(:job_template) do
FactoryGirl.create(:ansible_configuration_script, :manager => ansible_tower_manager)
FactoryGirl.create(:ansible_configuration_script, :manager => ansible_manager)
end
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service_template' => svc_service_template)
end
let(:method_args) do
{ 'credential_type' => credential_type }
end

let(:ae_service) do
Spec::Support::MiqAeMockService.new(root_object).tap do |service|
current_object = Spec::Support::MiqAeMockObject.new
current_object.parent = root_object
service.object = current_object
service.inputs = {'credential_type' => credential_type }
service.inputs = method_args
end
end
let(:ra) { {:action => 'Provision', :configuration_template => job_template} }
Expand All @@ -27,16 +31,16 @@
MiqAeMethodService::MiqAeServiceServiceTemplate.find(svc_template.id)
end
let(:mach_cred1) do
FactoryGirl.create(:ansible_machine_credential, :resource => ansible_tower_manager)
FactoryGirl.create(:ansible_machine_credential, :resource => ansible_manager)
end
let(:mach_cred2) do
FactoryGirl.create(:ansible_machine_credential, :resource => ansible_tower_manager)
FactoryGirl.create(:ansible_machine_credential, :resource => ansible_manager)
end
let(:net_cred1) do
FactoryGirl.create(:ansible_network_credential, :resource => ansible_tower_manager)
FactoryGirl.create(:ansible_network_credential, :resource => ansible_manager)
end
let(:net_cred2) do
FactoryGirl.create(:ansible_network_credential, :resource => ansible_tower_manager)
FactoryGirl.create(:ansible_network_credential, :resource => ansible_manager)
end

shared_examples_for "#having only default value" do
Expand Down Expand Up @@ -87,6 +91,22 @@

it_behaves_like "#having specific values based on credential type"
end

context "no service template" do
let(:ansible_manager) { FactoryGirl.create(:embedded_automation_manager_ansible) }
let(:root_object) do
Spec::Support::MiqAeMockObject.new
end
let(:credential_type) do
"ManageIQ::Providers::AnsibleTower::AutomationManager::MachineCredential"
end
let(:method_args) do
{ 'credential_type' => credential_type, 'embedded_ansible' => true }
end
let(:valid_ids) { [mach_cred1.id, mach_cred2.id, nil] }

it_behaves_like "#having specific values based on credential type"
end
end

context "no credentials" do
Expand Down