From af395c7cea2d63c87059fb2f84120c326ae22001 Mon Sep 17 00:00:00 2001 From: mkanoor Date: Tue, 9 May 2017 10:00:54 -0400 Subject: [PATCH] Support embedded_ansible to fetch credentials from provider https://bugzilla.redhat.com/show_bug.cgi?id=1448918 If we dont find a ansible provider thru the service template and the method gets passed in a parameter embedded_ansible true we use the first Embedded Ansible Provider and collect the credentials connected to it --- .../Operations/Methods.class/__class__.yaml | 22 +++++++++++- .../__methods__/available_credentials.rb | 8 ++++- .../__methods__/available_credentials.yaml | 20 +++++++++++ ...ansible_available_machine_credentials.yaml | 2 ++ ...ansible_available_network_credentials.yaml | 2 ++ .../__methods__/available_credentials_spec.rb | 34 +++++++++++++++---- 6 files changed, 79 insertions(+), 9 deletions(-) diff --git a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__class__.yaml b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__class__.yaml index 76ce6c19b..ec2044020 100644 --- a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__class__.yaml +++ b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__class__.yaml @@ -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 diff --git a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.rb b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.rb index e10a99724..f4b17ffd6 100644 --- a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.rb +++ b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.rb @@ -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 @@ -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 diff --git a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.yaml b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.yaml index 691f548f1..28ac98c9c 100644 --- a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.yaml +++ b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials.yaml @@ -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: diff --git a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_machine_credentials.yaml b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_machine_credentials.yaml index 49a30e806..6e0f82f9c 100644 --- a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_machine_credentials.yaml +++ b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_machine_credentials.yaml @@ -10,5 +10,7 @@ object: fields: - credential_type: value: ManageIQ::Providers::EmbeddedAnsible::AutomationManager::MachineCredential + - embedded_ansible: + value: 'true' - execute: value: Available_Credentials diff --git a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_network_credentials.yaml b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_network_credentials.yaml index 871b2b012..5ff37174a 100644 --- a/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_network_credentials.yaml +++ b/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/embedded_ansible_available_network_credentials.yaml @@ -10,5 +10,7 @@ object: fields: - credential_type: value: ManageIQ::Providers::EmbeddedAnsible::AutomationManager::NetworkCredential + - embedded_ansible: + value: 'true' - execute: value: Available_Credentials diff --git a/spec/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials_spec.rb b/spec/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials_spec.rb index 044d9e6d0..15bec82ab 100644 --- a/spec/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials_spec.rb +++ b/spec/content/automate/ManageIQ/AutomationManagement/AnsibleTower/Operations/Methods.class/__methods__/available_credentials_spec.rb @@ -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} } @@ -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 @@ -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