summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-10 12:25:25 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-23 14:42:28 -0700
commit1f7f5577cc5cc89d210d6b3578132e2c391d1aca (patch)
treecb9bc6bdd0e887aa7546cdbb750452867934fc5c
parent54a0d0d6df9ca93eb6c0116e0d8c5865a098bfe4 (diff)
downloadchef-jk/resource_actions.tar.gz
Make load/include recipe run in child contextjk/resource_actions
-rw-r--r--lib/chef/run_context.rb6
-rw-r--r--spec/data/run_context/cookbooks/include/recipes/default.rb24
-rw-r--r--spec/data/run_context/cookbooks/include/recipes/includee.rb3
-rw-r--r--spec/unit/run_context/child_run_context_spec.rb27
-rw-r--r--spec/unit/run_context_spec.rb3
5 files changed, 60 insertions, 3 deletions
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 6aa511f30f..f55d1740b1 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -564,10 +564,7 @@ ERROR_MESSAGE
events
has_cookbook_file_in_cookbook?
has_template_in_cookbook?
- include_recipe
load
- load_recipe
- load_recipe_file
loaded_attribute
loaded_attributes
loaded_attributes_hash
@@ -606,7 +603,10 @@ ERROR_MESSAGE
immediate_notification_collection
immediate_notification_collection=
immediate_notifications
+ include_recipe
initialize_child_state
+ load_recipe
+ load_recipe_file
notifies_immediately
notifies_delayed
parent_run_context
diff --git a/spec/data/run_context/cookbooks/include/recipes/default.rb b/spec/data/run_context/cookbooks/include/recipes/default.rb
new file mode 100644
index 0000000000..8d22994252
--- /dev/null
+++ b/spec/data/run_context/cookbooks/include/recipes/default.rb
@@ -0,0 +1,24 @@
+module ::RanResources
+ def self.resources
+ @resources ||= []
+ end
+end
+class RunContextCustomResource < Chef::Resource
+ action :create do
+ ruby_block '4' do
+ block { RanResources.resources << 4 }
+ end
+ recipe_eval do
+ ruby_block '1' do
+ block { RanResources.resources << 1 }
+ end
+ include_recipe 'include::includee'
+ ruby_block '3' do
+ block { RanResources.resources << 3 }
+ end
+ end
+ ruby_block '5' do
+ block { RanResources.resources << 5 }
+ end
+ end
+end
diff --git a/spec/data/run_context/cookbooks/include/recipes/includee.rb b/spec/data/run_context/cookbooks/include/recipes/includee.rb
new file mode 100644
index 0000000000..87bb7f114e
--- /dev/null
+++ b/spec/data/run_context/cookbooks/include/recipes/includee.rb
@@ -0,0 +1,3 @@
+ruby_block '2' do
+ block { RanResources.resources << 2 }
+end
diff --git a/spec/unit/run_context/child_run_context_spec.rb b/spec/unit/run_context/child_run_context_spec.rb
index 4651bd2737..63586e459c 100644
--- a/spec/unit/run_context/child_run_context_spec.rb
+++ b/spec/unit/run_context/child_run_context_spec.rb
@@ -101,6 +101,33 @@ describe Chef::RunContext::ChildRunContext do
c = child.create_child
expect(c.parent_run_context).to eq child
end
+
+ context "after load('include::default')" do
+ before do
+ run_list = Chef::RunList.new('include::default').expand('_default')
+ # TODO not sure why we had to do this to get everything to work ...
+ node.automatic_attrs[:recipes] = []
+ child.load(run_list)
+ end
+
+ it "load_recipe loads into the child" do
+ expect(child.resource_collection).to be_empty
+ child.load_recipe("include::includee")
+ expect(child.resource_collection).not_to be_empty
+ end
+
+ it "include_recipe loads into the child" do
+ expect(child.resource_collection).to be_empty
+ child.include_recipe("include::includee")
+ expect(child.resource_collection).not_to be_empty
+ end
+
+ it "load_recipe_file loads into the child" do
+ expect(child.resource_collection).to be_empty
+ child.load_recipe_file(File.expand_path("include/recipes/includee.rb", chef_repo_path))
+ expect(child.resource_collection).not_to be_empty
+ end
+ end
end
end
end
diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb
index 857bc6b90e..99801575ef 100644
--- a/spec/unit/run_context_spec.rb
+++ b/spec/unit/run_context_spec.rb
@@ -68,6 +68,9 @@ describe Chef::RunContext do
"dependency2" => {
"version" => "0.0.0",
},
+ "include" => {
+ "version" => "0.0.0",
+ },
"no-default-attr" => {
"version" => "0.0.0",
},