From affb2afd1b49100590be5bd75f9cb39b48b48967 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 23 Feb 2017 13:17:29 -0500 Subject: [PATCH] Allow create_in_provider to fail Credentials should already be valid at this point, if not, that is the problem of the refresh. We should raise an error if the record is not found in our database --- .../configuration_script.rb | 5 +++-- .../configuration_script_spec.rb | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script.rb b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script.rb index 4917bf7c668..c2f8bd0f778 100644 --- a/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script.rb +++ b/app/models/manageiq/providers/ansible_tower/shared/automation_manager/configuration_script.rb @@ -11,8 +11,9 @@ def create_in_provider(manager_id, params) # Get the record in our database # TODO: This needs to be targeted refresh so it doesn't take too long - EmsRefresh.queue_refresh(manager, nil, true) if !manager.missing_credentials? && manager.authentication_status_ok? - find_by(:manager_id => manager.id, :manager_ref => job_template.id) + EmsRefresh.queue_refresh(manager, nil, true) + + find_by!(:manager_id => manager.id, :manager_ref => job_template.id) end def create_in_provider_queue(manager_id, params, auth_user = nil) diff --git a/spec/models/manageiq/providers/ansible_tower/automation_manager/configuration_script_spec.rb b/spec/models/manageiq/providers/ansible_tower/automation_manager/configuration_script_spec.rb index 6b10d4e6d26..9d1fb982fb3 100644 --- a/spec/models/manageiq/providers/ansible_tower/automation_manager/configuration_script_spec.rb +++ b/spec/models/manageiq/providers/ansible_tower/automation_manager/configuration_script_spec.rb @@ -109,12 +109,22 @@ } end - it ".create_in_provider" do - expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc) - expect(EmsRefresh).to receive(:queue_refresh).and_return(store_new_job_template(job_template, manager)) - expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager) - - expect(described_class.create_in_provider(manager.id, params)).to be_a(described_class) + context ".create_in_provider" do + it "successfully created in provider" do + expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc) + expect(EmsRefresh).to receive(:queue_refresh).and_return(store_new_job_template(job_template, manager)) + expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager) + + expect(described_class.create_in_provider(manager.id, params)).to be_a(described_class) + end + + it "not found during refresh" do + expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc) + expect(EmsRefresh).to receive(:queue_refresh) + expect(ExtManagementSystem).to receive(:find).with(manager.id).and_return(manager) + + expect { described_class.create_in_provider(manager.id, params) }.to raise_error(ActiveRecord::RecordNotFound) + end end it ".create_in_provider_queue" do