Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat Ansible Tower error messages #14777

Merged
merged 1 commit into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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