Commit 05eb8b28 authored by Lamont Granquist's avatar Lamont Granquist
Browse files

ignore 500s returned by the reporting url if the service is down.

parent 2566b021
......@@ -202,6 +202,7 @@ class Chef
color false
client_fork false
enable_reporting true
enable_reporting_url_fatals false
# Set these to enable SSL authentication / mutual-authentication
# with the server
......
......@@ -116,8 +116,16 @@ class Chef
Chef::Log.info("Chef server generated run history id: #{@run_id}")
@summary_only = server_response["summary_only"]
rescue Net::HTTPServerException => e
raise unless e.response.code.to_s == "404"
Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
if e.response.code.to_s == "404"
Chef::Log.debug("Received 404 attempting to generate run history id (URL Path: #{resource_history_url}), assuming feature is not supported.")
else
if Chef::Config[:enable_reporting_url_fatals]
Chef::Log.error("Received #{e.response.code} attempting to generate run history id (URL Path: #{resource_history_url}), and enable_reporting_url_fatals is set, aborting run.")
raise
else
Chef::Log.info("Received #{e.response.code} attempting to generate run history id (URL Path: #{resource_history_url}), disabling reporting for this run.")
end
end
@reporting_enabled = false
end
end
......
......@@ -427,6 +427,52 @@ describe Chef::ResourceReporter do
end
context "when the server returns a 500 to the client" do
before do
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
end
it "assumes the feature is not enabled" do
@resource_reporter.reporting_enabled?.should be_false
end
it "does not send a resource report to the server" do
@rest_client.should_not_receive(:post_rest)
@resource_reporter.run_completed(@node)
end
end
context "when the server returns a 500 to the client and enable_reporting_url_fatals is true" do
before do
@enable_reporting_url_fatals = Chef::Config[:enable_reporting_url_fatals]
Chef::Config[:enable_reporting_url_fatals] = true
# 500 getting the run_id
@response = Net::HTTPInternalServerError.new("a response body", "500", "Internal Server Error")
@error = Net::HTTPServerException.new("500 message", @response)
@rest_client.should_receive(:post_rest).
with("reports/nodes/spitfire/runs", {:action => :begin}).
and_raise(@error)
end
after do
Chef::Config[:enable_reporting_url_fatals] = @enable_reporting_url_fatals
end
it "fails the run" do
lambda {
@resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
}.should raise_error(Net::HTTPServerException)
end
end
context "after creating the run history document" do
before do
response = {"uri"=>"https://example.com/reports/nodes/spitfire/runs/ABC123"}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment