diff options
author | Thom May <thom@may.lt> | 2015-06-09 10:28:25 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-06-09 10:28:25 +0100 |
commit | 6daea43f5578d6bf2aeb3464144dd8dbdf6bd4ef (patch) | |
tree | b3ff28173e0cf06bc99f90f74e278a2caf09bca9 | |
parent | 6b4d242607440a5e9193aa3dd02e986ab2691e83 (diff) | |
parent | a93cdc6e526735912eae6f921f1da2af8b0ef5b0 (diff) | |
download | chef-6daea43f5578d6bf2aeb3464144dd8dbdf6bd4ef.tar.gz |
Merge pull request #3497 from chef/adamedx/3485-run_context_corruption
Issue#3485: Fix corruption of run_context when guard interpreters are executed
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/chef/guard_interpreter/resource_guard_interpreter.rb | 5 | ||||
-rw-r--r-- | spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c0bbb0677..7ddb91ab3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Unreleased +* [pr#3497](https://github.com/chef/chef/pull/3497): Issue 3485: Corruption of node's run\_context when non-default guard\_interpreter is evaluated * [**Yukihiko SAWANOBORI**](https://github.com/sawanoboly): Pass name by knife cil attribute [pr#3195](https://github.com/chef/chef/pull/3195) * [**Torben Knerr**](https://github.com/tknerr): diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb index 1e2a534c18..d4b386a15a 100644 --- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb +++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb @@ -92,8 +92,11 @@ class Chef raise ArgumentError, "Specified guard interpreter class #{resource_class} must be a kind of Chef::Resource::Execute resource" end + # Duplicate the node below because the new RunContext + # overwrites the state of Node instances passed to it. + # See https://github.com/chef/chef/issues/3485. empty_events = Chef::EventDispatch::Dispatcher.new - anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events) + anonymous_run_context = Chef::RunContext.new(parent_resource.node.dup, {}, empty_events) interpreter_resource = resource_class.new('Guard resource', anonymous_run_context) interpreter_resource.is_guard_interpreter = true diff --git a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb index 02e4eb2fae..acf1b15fd8 100644 --- a/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +++ b/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb @@ -84,6 +84,14 @@ describe Chef::GuardInterpreter::ResourceGuardInterpreter do expect(guard_interpreter.evaluate).to eq(true) end + it "does not corrupt the run_context of the node" do + node_run_context_before_guard_execution = parent_resource.run_context + expect(node_run_context_before_guard_execution.object_id).to eq(parent_resource.node.run_context.object_id) + guard_interpreter.evaluate + node_run_context_after_guard_execution = parent_resource.run_context + expect(node_run_context_after_guard_execution.object_id).to eq(parent_resource.node.run_context.object_id) + end + describe "script command opts switch" do let(:command_opts) { {} } let(:guard_interpreter) { Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource, "exit 0", command_opts) } |