diff options
author | Adam Leff <adam@leff.co> | 2016-06-22 23:14:55 -0400 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-06-24 14:48:42 -0400 |
commit | bb56a100caf7de9b7f0bbcb1377ba7f7cae05f90 (patch) | |
tree | 030b846f3032a7f77fb0e9fb0e18fa04614f0c91 /spec/unit | |
parent | 20774deff25b952ff24d6e6d100007713dcbf005 (diff) | |
download | chef-bb56a100caf7de9b7f0bbcb1377ba7f7cae05f90.tar.gz |
Expand data_collector resource list to include all resources
Historically when a Chef run fails, the event handlers only report
on resources that have been processed during the run. This change
allows the Data Collector to report those resources in the resource
collection that have not yet been processed so users can better
ascertain how much of their run was completed, and specifically
what resources were not processed as a result of the Chef failure.
Instead of building up a list of resources as they are processed,
this change instead creates a resource report for each resource+action
in the resource collection and then modifies each of those reports
once the resource is processed.
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/data_collector/messages_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/data_collector_spec.rb | 64 |
2 files changed, 43 insertions, 27 deletions
diff --git a/spec/unit/data_collector/messages_spec.rb b/spec/unit/data_collector/messages_spec.rb index dee86a3907..686e500507 100644 --- a/spec/unit/data_collector/messages_spec.rb +++ b/spec/unit/data_collector/messages_spec.rb @@ -62,12 +62,12 @@ describe Chef::DataCollector::Messages do describe '#run_end_message' do let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) } - let(:resource1) { double("resource1", for_json: "resource_data", status: "updated") } - let(:resource2) { double("resource2", for_json: "resource_data", status: "skipped") } + let(:report1) { double("report1", report_data: { "status" => "updated" }) } + let(:report2) { double("report2", report_data: { "status" => "skipped" }) } let(:reporter_data) do { run_status: run_status, - completed_resources: [resource1, resource2], + resources: [report1, report2], } end diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 78b0aaf97d..831643347b 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -20,6 +20,7 @@ require "spec_helper" require "chef/data_collector" +require "chef/resource_builder" describe Chef::DataCollector do describe ".register_reporter?" do @@ -193,10 +194,32 @@ describe Chef::DataCollector::Reporter do end end + describe '#converge_start' do + it "stashes the run_context for later use" do + reporter.converge_start("test_context") + expect(reporter.run_context).to eq("test_context") + end + end + + describe '#converge_complete' do + it "detects and processes any unprocessed resources" do + expect(reporter).to receive(:detect_unprocessed_resources) + reporter.converge_complete + end + end + + describe '#converge_failed' do + it "detects and processes any unprocessed resources" do + expect(reporter).to receive(:detect_unprocessed_resources) + reporter.converge_failed("exception") + end + end + describe '#resource_current_state_loaded' do let(:new_resource) { double("new_resource") } let(:action) { double("action") } let(:current_resource) { double("current_resource") } + let(:resource_report) { double("resource_report") } context "when resource is a nested resource" do it "does not update the resource report" do @@ -207,14 +230,12 @@ describe Chef::DataCollector::Reporter do end context "when resource is not a nested resource" do - it "updates the resource report" do + it "creates the resource report and stores it as the current one" do allow(reporter).to receive(:nested_resource?).and_return(false) - expect(Chef::DataCollector::ResourceReport).to receive(:new).with( - new_resource, - action, - current_resource) - .and_return("resource_report") - expect(reporter).to receive(:update_current_resource_report).with("resource_report") + expect(reporter).to receive(:create_resource_report) + .with(new_resource, action, current_resource) + .and_return(resource_report) + expect(reporter).to receive(:update_current_resource_report).with(resource_report) reporter.resource_current_state_loaded(new_resource, action, current_resource) end end @@ -256,7 +277,7 @@ describe Chef::DataCollector::Reporter do before do allow(reporter).to receive(:nested_resource?) - allow(reporter).to receive(:current_resource_report).and_return(resource_report) + allow(reporter).to receive(:create_resource_report).and_return(resource_report) allow(resource_report).to receive(:skipped) end @@ -269,13 +290,12 @@ describe Chef::DataCollector::Reporter do end context "when the resource is not a nested resource" do - it "updates the resource report" do + it "creates the resource report and stores it as the current one" do allow(reporter).to receive(:nested_resource?).and_return(false) - expect(Chef::DataCollector::ResourceReport).to receive(:new).with( - new_resource, - action) - .and_return("resource_report") - expect(reporter).to receive(:update_current_resource_report).with("resource_report") + expect(reporter).to receive(:create_resource_report) + .with(new_resource, action) + .and_return(resource_report) + expect(reporter).to receive(:update_current_resource_report).with(resource_report) reporter.resource_skipped(new_resource, action, conditional) end @@ -349,15 +369,16 @@ describe Chef::DataCollector::Reporter do let(:resource_report) { double("resource_report") } before do - allow(reporter).to receive(:add_completed_resource) allow(reporter).to receive(:update_current_resource_report) + allow(reporter).to receive(:add_resource_report) + allow(reporter).to receive(:current_resource_report) allow(resource_report).to receive(:finish) end context "when there is no current resource report" do - it "does not add the updated resource" do + it "does not touch the current resource report" do allow(reporter).to receive(:current_resource_report).and_return(nil) - expect(reporter).not_to receive(:add_completed_resource) + expect(reporter).not_to receive(:update_current_resource_report) reporter.resource_completed(new_resource) end end @@ -368,9 +389,9 @@ describe Chef::DataCollector::Reporter do end context "when the resource is a nested resource" do - it "does not add the updated resource" do + it "does not mark the resource as finished" do allow(reporter).to receive(:nested_resource?).with(new_resource).and_return(true) - expect(reporter).not_to receive(:add_completed_resource) + expect(resource_report).not_to receive(:finish) reporter.resource_completed(new_resource) end end @@ -385,11 +406,6 @@ describe Chef::DataCollector::Reporter do reporter.resource_completed(new_resource) end - it "adds the resource to the updated resource list" do - expect(reporter).to receive(:add_completed_resource).with(resource_report) - reporter.resource_completed(new_resource) - end - it "nils out the current resource report" do expect(reporter).to receive(:update_current_resource_report).with(nil) reporter.resource_completed(new_resource) |