diff options
author | Lamont Granquist <lamont@opscode.com> | 2012-10-04 13:59:39 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2012-10-05 10:32:38 -0700 |
commit | 05eb8b28a338cd96488d8c56cfaa4755c52d6f3f (patch) | |
tree | 38c9ead5e1364a527cf7fc35b5c8a12be09efb34 | |
parent | 2566b021e05eb90b05de413c57ced218d896dc0f (diff) | |
download | chef-05eb8b28a338cd96488d8c56cfaa4755c52d6f3f.tar.gz |
ignore 500s returned by the reporting url if the service is down.
-rw-r--r-- | chef/lib/chef/config.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/resource_reporter.rb | 12 | ||||
-rw-r--r-- | chef/spec/unit/resource_reporter_spec.rb | 46 |
3 files changed, 57 insertions, 2 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb index 8ad0648eec..e16d301c3b 100644 --- a/chef/lib/chef/config.rb +++ b/chef/lib/chef/config.rb @@ -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 diff --git a/chef/lib/chef/resource_reporter.rb b/chef/lib/chef/resource_reporter.rb index c643729dd0..e9c7f63634 100644 --- a/chef/lib/chef/resource_reporter.rb +++ b/chef/lib/chef/resource_reporter.rb @@ -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 diff --git a/chef/spec/unit/resource_reporter_spec.rb b/chef/spec/unit/resource_reporter_spec.rb index 10d27cb627..bc8e3995f7 100644 --- a/chef/spec/unit/resource_reporter_spec.rb +++ b/chef/spec/unit/resource_reporter_spec.rb @@ -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"} |