Skip to content

Commit

Permalink
Reformat Ansible Tower error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bdunne committed Apr 17, 2017
1 parent 2983b46 commit 2f239dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def create_in_provider(manager_id, params)
task_ids.each { |tid| MiqTask.wait_for_taskid(tid) }

find_by!(:manager_id => manager.id, :manager_ref => job_template.id)
rescue AnsibleTowerClient::Error => err
begin
raise err.class, JSON.parse(err.message).values.flatten.join(", ")
rescue JSON::ParserError
raise err
end
end

def update_in_provider(manager_id, params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@

expect { described_class.create_in_provider(manager.id, params) }.to raise_error(ActiveRecord::RecordNotFound)
end

context "provider raises on create" do
it "with a hash" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(job_templates).to receive(:create!).and_raise(AnsibleTowerClient::Error, {"name"=>["Job template with this Name already exists."]}.to_json)

expect { described_class.create_in_provider(manager.id, params) }.to raise_error(AnsibleTowerClient::Error, "Job template with this Name already exists.")
end

it "with a string" do
expect(AnsibleTowerClient::Connection).to receive(:new).and_return(atc)
expect(job_templates).to receive(:create!).and_raise(AnsibleTowerClient::Error, "Job template with this Name already exists.")

expect { described_class.create_in_provider(manager.id, params) }.to raise_error(AnsibleTowerClient::Error, "Job template with this Name already exists.")
end
end
end

it ".create_in_provider_queue" do
Expand Down

0 comments on commit 2f239dc

Please sign in to comment.