summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortylercloke <tyler@opscode.com>2012-07-03 16:05:17 -0700
committertylercloke <tyler@opscode.com>2012-07-03 16:05:17 -0700
commit7bd88ff70ee9cb87ed9605b75a7afdaf880cdb26 (patch)
treed6db0bdfa65ea7a432b887023885f4eb057eb515
parent40936f2ecc7ebc5a94d2db3b4a763ba12311b555 (diff)
downloadchef-OC-1880-error-reporting.tar.gz
Fixed intergration with chef_rest_named_node_run_resource.erl for error reporting to db.OC-1880-error-reporting
-rw-r--r--chef/lib/chef/formatters/base.rb3
-rw-r--r--chef/lib/chef/formatters/error_descriptor.rb2
-rw-r--r--chef/lib/chef/formatters/error_mapper.rb4
-rw-r--r--chef/lib/chef/resource_reporter.rb24
-rw-r--r--chef/spec/unit/resource_reporter_spec.rb36
5 files changed, 39 insertions, 30 deletions
diff --git a/chef/lib/chef/formatters/base.rb b/chef/lib/chef/formatters/base.rb
index 08fcbeaeda..9907caa2de 100644
--- a/chef/lib/chef/formatters/base.rb
+++ b/chef/lib/chef/formatters/base.rb
@@ -120,12 +120,15 @@ class Chef
@output.print(*args)
end
+ # Input: a Formatters::ErrorDescription object.
+ # Outputs error to SDOUT.
def display_error(description)
puts("")
description.display(output)
end
def registration_failed(node_name, exception, config)
+ #A Formatters::ErrorDescription object
description = ErrorMapper.registration_failed_helper(node_name, exception, config)
display_error(description)
end
diff --git a/chef/lib/chef/formatters/error_descriptor.rb b/chef/lib/chef/formatters/error_descriptor.rb
index 3f8d916536..abf10076be 100644
--- a/chef/lib/chef/formatters/error_descriptor.rb
+++ b/chef/lib/chef/formatters/error_descriptor.rb
@@ -19,6 +19,8 @@
class Chef
module Formatters
+ # == Formatters::ErrorDescription
+ # Class for displaying errors on STDOUT.
class ErrorDescription
attr_reader :sections
diff --git a/chef/lib/chef/formatters/error_mapper.rb b/chef/lib/chef/formatters/error_mapper.rb
index 06177bf773..a9ca5c9ae9 100644
--- a/chef/lib/chef/formatters/error_mapper.rb
+++ b/chef/lib/chef/formatters/error_mapper.rb
@@ -18,6 +18,10 @@
class Chef
module Formatters
+ # == Formatters::ErrorMapper
+ # Collection of methods for creating and returning
+ # Formatters::ErrorDescription objects based on node,
+ # exception, and configuration information.
module ErrorMapper
# Failed to register this client with the server.
diff --git a/chef/lib/chef/resource_reporter.rb b/chef/lib/chef/resource_reporter.rb
index a61ccd7837..7382edfab3 100644
--- a/chef/lib/chef/resource_reporter.rb
+++ b/chef/lib/chef/resource_reporter.rb
@@ -95,7 +95,7 @@ class Chef
@run_id = nil
@rest_client = rest_client
@node = nil
- @error_descriptions = []
+ @error_descriptions = nil
end
def node_load_completed(node, expanded_run_list_with_versions, config)
@@ -138,7 +138,7 @@ class Chef
resource_completed
end
description = Formatters::ErrorMapper.resource_failed_helper(new_resource, action, exception)
- @error_descriptions << description.for_json
+ @error_descriptions = description.for_json
end
def run_completed(node)
@@ -156,7 +156,7 @@ class Chef
def run_failed(exception)
@exception = exception
- @status = "failed"
+ @status = "failure"
end
def report(node)
@@ -167,30 +167,30 @@ class Chef
run_data["status"] = status
run_data["run_list"] = node.run_list.to_json
run_data["total_res_count"] = @total_res_count.to_s
+ run_data["data"] = {}
if exception
- run_data["exception"] = {}
- run_data["exception"]["class"] = exception.inspect
- run_data["exception"]["message"] = exception.message
- run_data["exception"]["backtrace"] = exception.backtrace
- run_data["exception"]["description"] = @error_descriptions
+ run_data["data"]["exception"] = {}
+ run_data["data"]["exception"]["class"] = exception.inspect
+ run_data["data"]["exception"]["message"] = exception.message
+ run_data["data"]["exception"]["backtrace"] = exception.backtrace
+ run_data["data"]["exception"]["description"] = @error_descriptions
end
- run_data["data"] = {}
run_data
end
def run_list_expand_failed(node, exception)
description = Formatters::ErrorMapper.run_list_expand_failed_helper(node, exception)
- @error_descriptions << description.for_json
+ @error_descriptions = description.for_json
end
def cookbook_resolution_failed(expanded_run_list, exception)
description = Formatters::ErrorMapper.cookbook_resolution_failed_helper(expanded_run_list, exception)
- @error_descriptions << description.for_json
+ @error_descriptions = description.for_json
end
def cookbook_sync_failed(cookbooks, exception)
description = Formatters::ErrorMapper.cookbook_sync_failed_helper(cookbooks, exception)
- @error_descriptions << description.for_json
+ @error_descriptions = description.for_json
end
def reporting_enabled?
diff --git a/chef/spec/unit/resource_reporter_spec.rb b/chef/spec/unit/resource_reporter_spec.rb
index b6a3c0a422..e61d3751a2 100644
--- a/chef/spec/unit/resource_reporter_spec.rb
+++ b/chef/spec/unit/resource_reporter_spec.rb
@@ -49,9 +49,9 @@ describe Chef::ResourceReporter do
end
it "should have no error_descriptions" do
- @resource_reporter.error_descriptions.should == []
- @resource_reporter.error_descriptions.should be_empty
- @resource_reporter.should have(0).error_descriptions
+ @resource_reporter.error_descriptions.should be_nil
+ # @resource_reporter.error_descriptions.should be_empty
+ # @resource_reporter.should have(0).error_descriptions
end
end
@@ -72,8 +72,8 @@ describe Chef::ResourceReporter do
@resource_reporter.run_failed(@exception)
end
- it "sets the run status to 'failed'" do
- @resource_reporter.status.should == "failed"
+ it "sets the run status to 'failure'" do
+ @resource_reporter.status.should == "failure"
end
it "keeps the exception data" do
@@ -96,8 +96,8 @@ describe Chef::ResourceReporter do
it "collects the desired state of the resource" do
update_record = @resource_reporter.updated_resources.first
update_record.new_resource.should == @new_resource
- end
+ end
end
# TODO: make sure a resource that is skipped because of `not_if` doesn't
@@ -329,6 +329,7 @@ describe Chef::ResourceReporter do
context "for an unsuccessful run" do
before do
+
@backtrace = "foo.rb:1 in `foo!'\nbar.rb:2 in `bar!\n'baz.rb:3 in `baz!'"
@node = Chef::Node.new
@node.name("spitfire")
@@ -342,28 +343,27 @@ describe Chef::ResourceReporter do
end
it "includes the exception type in the event data" do
- @report.should have_key("exception")
- @report["exception"].should have_key("class")
- @report["exception"]["class"].should == "Net::HTTPServerException"
+ @report.should have_key("data")
+ @report["data"].should have_key("exception")
+ @report["data"]["exception"].should have_key("class")
+ @report["data"]["exception"]["class"].should == "Net::HTTPServerException"
end
it "includes the exception message in the event data" do
- @report.should have_key("exception")
- @report["exception"].should have_key("message")
- @report["exception"]["message"].should == "Object not found"
+ @report["data"]["exception"].should have_key("message")
+ @report["data"]["exception"]["message"].should == "Object not found"
end
it "includes the exception trace in the event data" do
- @report.should have_key("exception")
- @report["exception"].should have_key("backtrace")
- @report["exception"]["backtrace"].should == @backtrace
+ @report["data"]["exception"].should have_key("backtrace")
+ @report["data"]["exception"]["backtrace"].should == @backtrace
end
it "includes the error inspector output in the event data" do
- @report.should have_key("exception")
- @report["exception"].should have_key("description")
- @report["exception"]["description"].should include({"title"=>"Error expanding the run_list:", "sections"=>[["Unexpected Error:", "RSpec::Mocks::Mock: Object not found"]]})
+ @report["data"]["exception"].should have_key("description")
+ @report["data"]["exception"]["description"].should include({"title"=>"Error expanding the run_list:", "sections"=>[["Unexpected Error:", "RSpec::Mocks::Mock: Object not found"]]})
end
+
end