Skip to content

Commit

Permalink
Create/update Tower project with scm_credential
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Apr 17, 2017
1 parent 6a911ad commit f067258
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -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
Expand Down
Expand Up @@ -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) }
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f067258

Please sign in to comment.