From f0672587e8229f603d0945d45b214d54df9210c5 Mon Sep 17 00:00:00 2001 From: James Wong Date: Mon, 3 Apr 2017 12:28:16 -0400 Subject: [PATCH] Create/update Tower project with scm_credential https://bugzilla.redhat.com/show_bug.cgi?id=1439145 --- .../configuration_script_source.rb | 6 ++++++ .../configuration_script_source.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script_source.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script_source.rb index ac6a56589cb..66308ade050 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script_source.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script_source.rb @@ -4,6 +4,12 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::Configurati include ProviderObjectMixin module ClassMethods + def provider_params(params) + authentication_id = params.delete(:authentication_id) + params[:credential] = Authentication.find(authentication_id).manager_ref if authentication_id + params + end + def provider_collection(manager) manager.with_provider_connection do |connection| connection.api.projects diff --git a/spec/support/ansible_shared/automation_manager/configuration_script_source.rb b/spec/support/ansible_shared/automation_manager/configuration_script_source.rb index 4a9ac31d0c7..394a288db42 100644 --- a/spec/support/ansible_shared/automation_manager/configuration_script_source.rb +++ b/spec/support/ansible_shared/automation_manager/configuration_script_source.rb @@ -5,6 +5,7 @@ let(:manager) { FactoryGirl.create(:provider_ansible_tower, :with_authentication).managers.first } let(:atc) { double("AnsibleTowerClient::Connection", :api => api) } let(:api) { double("AnsibleTowerClient::Api", :projects => projects) } + let(:credential) { FactoryGirl.create(:ansible_scm_credential, :manager_ref => '1') } context "create through API" do let(:projects) { double("AnsibleTowerClient::Collection", :create! => project) } @@ -56,6 +57,20 @@ expect { described_class.create_in_provider(manager.id, params) }.to raise_error(ActiveRecord::RecordNotFound) end + it ".create_in_provider with credential" do + params[:authentication_id] = credential.id + expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc) + store_new_project(project, manager) + expect(EmsRefresh).to receive(:queue_refresh_task).and_return([finished_task]) + expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager) + expected_params = params.clone.merge(:credential => '1') + expected_params.delete(:authentication_id) + expect(projects).to receive(:create!).with(expected_params) + expected_notify[:options][:op_arg] = expected_params.to_s + expect(Notification).to receive(:create).with(expected_notify) + 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)