Skip to content

Commit

Permalink
Merge pull request #15029 from jameswnl/project-cred
Browse files Browse the repository at this point in the history
Allow Tower Project to reset credential
(cherry picked from commit 4d16248)

https://bugzilla.redhat.com/show_bug.cgi?id=1460304
  • Loading branch information
blomquisg authored and simaishi committed Jun 9, 2017
1 parent f9deb1d commit 46c6892
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Expand Up @@ -5,8 +5,10 @@ module ManageIQ::Providers::AnsibleTower::Shared::AutomationManager::Configurati

module ClassMethods
def provider_params(params)
authentication_id = params.delete(:authentication_id)
params[:credential] = Authentication.find(authentication_id).manager_ref if authentication_id
if params.keys.include?(:authentication_id)
authentication_id = params.delete(:authentication_id)
params[:credential] = authentication_id ? Authentication.find(authentication_id).manager_ref : nil
end
params
end

Expand Down
Expand Up @@ -22,9 +22,9 @@

let(:params) do
{
:description => "Description",
:name => "My Project",
:related => {}
:description => "Description",
:name => "My Project",
:related => {}
}
end

Expand Down Expand Up @@ -146,6 +146,7 @@ def store_new_project(project, manager)
let(:projects) { double("AnsibleTowerClient::Collection", :find => tower_project) }
let(:tower_project) { double("AnsibleTowerClient::Project", :update_attributes! => {}, :id => 1) }
let(:project) { described_class.create!(:manager => manager, :manager_ref => tower_project.id) }
let(:tower_cred) { FactoryGirl.create(:ansible_scm_credential, :manager_ref => '100') }
let(:expected_notify) do
{
:type => :tower_op_success,
Expand Down Expand Up @@ -173,6 +174,24 @@ def store_new_project(project, manager)
expect { project.update_in_provider({}) }.to raise_error(AnsibleTowerClient::ClientError)
end

it "#update_in_provider with credential" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(EmsRefresh).to receive(:queue_refresh_task).with(manager).and_return([finished_task])
expect(project).to receive(:refresh_in_provider)
expect(tower_project).to receive(:update_attributes!).with(:credential => tower_cred.manager_ref)
expect(Notification).to receive(:create).with(expected_notify)
expect(project.update_in_provider(:authentication_id => tower_cred.id)).to be_a(described_class)
end

it "#update_in_provider with nil credential" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(EmsRefresh).to receive(:queue_refresh_task).with(manager).and_return([finished_task])
expect(project).to receive(:refresh_in_provider)
expect(tower_project).to receive(:update_attributes!).with(:credential => nil)
expect(Notification).to receive(:create).with(expected_notify)
expect(project.update_in_provider(:authentication_id => nil)).to be_a(described_class)
end

it "#update_in_provider_queue" do
task_id = project.update_in_provider_queue({})
expect(MiqTask.find(task_id)).to have_attributes(:name => "Updating #{described_class::FRIENDLY_NAME} (Tower internal reference=#{project.manager_ref})")
Expand Down

0 comments on commit 46c6892

Please sign in to comment.