summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-04-30 14:25:00 +0100
committerThom May <thom@may.lt>2015-04-30 14:25:00 +0100
commitb18b5ed8ef1360f9444649d1efd643727e5a42ed (patch)
tree2ed605d57b4c68336a5013d1eea96df0eda28988
parent77e32218bcec1a6b0934d826919b8e1ba0b6dbc0 (diff)
parent56958bd7b82dc2eff15f1d55182efd549323bbfb (diff)
downloadchef-b18b5ed8ef1360f9444649d1efd643727e5a42ed.tar.gz
Merge pull request #3207 from Igorshp/exception_handlers
patch to always run exception handlers
-rw-r--r--lib/chef/client.rb4
-rw-r--r--lib/chef/run_status.rb6
-rw-r--r--spec/unit/client_spec.rb13
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index d04a3dbbd5..0764d3f3ba 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -152,7 +152,6 @@ class Chef
def initialize(json_attribs=nil, args={})
@json_attribs = json_attribs || {}
@node = nil
- @run_status = nil
@runner = nil
@ohai = Ohai::System.new
@@ -162,6 +161,7 @@ class Chef
@events = EventDispatch::Dispatcher.new(*event_handlers)
@override_runlist = args.delete(:override_runlist)
@specific_recipes = args.delete(:specific_recipes)
+ @run_status = Chef::RunStatus.new(node, events)
if new_runlist = args.delete(:runlist)
@json_attribs["run_list"] = new_runlist
@@ -248,7 +248,7 @@ class Chef
# @return [Chef::Node] The updated node object
def build_node
policy_builder.build_node
- @run_status = Chef::RunStatus.new(node, events)
+ @run_status.node = node
node
end
diff --git a/lib/chef/run_status.rb b/lib/chef/run_status.rb
index 0f181426b0..ce8ff296f4 100644
--- a/lib/chef/run_status.rb
+++ b/lib/chef/run_status.rb
@@ -39,15 +39,13 @@ class Chef::RunStatus
attr_accessor :run_id
+ attr_accessor :node
+
def initialize(node, events)
@node = node
@events = events
end
- def node
- @node
- end
-
# sets +start_time+ to the current time.
def start_clock
@start_time = Time.now
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index fa8317744c..affbd0544d 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -819,4 +819,17 @@ describe Chef::Client do
end
end
+
+ describe "always attempt to run handlers" do
+ subject { client }
+ before do
+ # fail on the first thing in begin block
+ allow_any_instance_of(Chef::RunLock).to receive(:save_pid).and_raise(NoMethodError)
+ end
+
+ it "should run exception handlers on early fail" do
+ expect(subject).to receive(:run_failed)
+ expect { subject.run }.to raise_error(NoMethodError)
+ end
+ end
end