summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-01-16 12:52:53 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-01-16 12:52:53 -0800
commit7c4670ce77cafb481477e9da75348a75b44c0393 (patch)
tree62a8d3a7ad3df821140911758d3743e98f62573f
parentdbd925b357b036447b47cf5f369792f81d69e76d (diff)
downloadchef-7c4670ce77cafb481477e9da75348a75b44c0393.tar.gz
CHEF-4777: fix for fully qualifying recipes
this makes it so that the recipes in the attribute will be fully qualified, and will avoid the problem of both "cookbook" and "cookbook::default" showing up.
-rw-r--r--lib/chef/node.rb5
-rw-r--r--lib/chef/run_context.rb2
-rw-r--r--spec/unit/cookbook_spec.rb2
-rw-r--r--spec/unit/node_spec.rb4
-rw-r--r--spec/unit/recipe_spec.rb8
-rw-r--r--spec/unit/run_context_spec.rb7
6 files changed, 15 insertions, 13 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index eaae1ee148..69e5e05b01 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -249,8 +249,9 @@ class Chef
# used by include_recipe to add recipes to the expanded run_list to be
# saved back to the node and be searchable
- def loaded_recipe(recipe_name)
- automatic_attrs[:recipes] << recipe_name unless Array(self[:recipes]).include?(recipe_name)
+ def loaded_recipe(cookbook, recipe)
+ fully_qualified_recipe = "#{cookbook}::#{recipe}"
+ automatic_attrs[:recipes] << fully_qualified_recipe unless Array(self[:recipes]).include?(fully_qualified_recipe)
end
# Returns true if this Node expects a given role, false if not.
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 97a5bce439..df188a2028 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -146,7 +146,7 @@ class Chef
false
else
loaded_recipe(cookbook_name, recipe_short_name)
- node.loaded_recipe(recipe_name)
+ node.loaded_recipe(cookbook_name, recipe_short_name)
cookbook = cookbook_collection[cookbook_name]
cookbook.load_recipe(recipe_short_name, self)
end
diff --git a/spec/unit/cookbook_spec.rb b/spec/unit/cookbook_spec.rb
index a9122bd150..ca4f4adc08 100644
--- a/spec/unit/cookbook_spec.rb
+++ b/spec/unit/cookbook_spec.rb
@@ -70,7 +70,7 @@ describe Chef::CookbookVersion do
it "should allow you to include a fully-qualified recipe using the DSL" do
# DSL method include_recipe allows multiple arguments, so extract the first
- @node.should_receive(:loaded_recipe).with("openldap::gigantor")
+ @node.should_receive(:loaded_recipe).with(:openldap, "gigantor")
recipe = @run_context.include_recipe("openldap::gigantor").first
recipe.recipe_name.should == "gigantor"
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 80d694d036..1cc40979cc 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -464,13 +464,13 @@ describe Chef::Node do
describe "loaded_recipe" do
it "should not add a recipe that is already in the recipes list" do
node.automatic_attrs[:recipes] = [ "nginx::module" ]
- node.loaded_recipe("nginx::module")
+ node.loaded_recipe(:nginx, "module")
expect(node.automatic_attrs[:recipes].length).to eq(1)
end
it "should add a recipe that is not already in the recipes list" do
node.automatic_attrs[:recipes] = [ "nginx::other_module" ]
- node.loaded_recipe("nginx::module")
+ node.loaded_recipe(:nginx, "module")
expect(node.automatic_attrs[:recipes].length).to eq(2)
expect(node.recipe?("nginx::module")).to be_true
expect(node.recipe?("nginx::other_module")).to be_true
diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb
index 16f1743c9c..3240739dd7 100644
--- a/spec/unit/recipe_spec.rb
+++ b/spec/unit/recipe_spec.rb
@@ -193,7 +193,7 @@ describe Chef::Recipe do
describe "include_recipe" do
it "should evaluate another recipe with include_recipe" do
- @node.should_receive(:loaded_recipe).with("openldap::gigantor")
+ @node.should_receive(:loaded_recipe).with(:openldap, "gigantor")
@run_context.include_recipe "openldap::gigantor"
res = @run_context.resource_collection.resources(:cat => "blanket")
res.name.should eql("blanket")
@@ -201,7 +201,7 @@ describe Chef::Recipe do
end
it "should load the default recipe for a cookbook if include_recipe is called without a ::" do
- @node.should_receive(:loaded_recipe).with("openldap")
+ @node.should_receive(:loaded_recipe).with(:openldap, "default")
@run_context.include_recipe "openldap"
res = @run_context.resource_collection.resources(:cat => "blanket")
res.name.should eql("blanket")
@@ -209,13 +209,13 @@ describe Chef::Recipe do
end
it "should store that it has seen a recipe in the run_context" do
- @node.should_receive(:loaded_recipe).with("openldap")
+ @node.should_receive(:loaded_recipe).with(:openldap, "default")
@run_context.include_recipe "openldap"
@run_context.loaded_recipe?("openldap").should be_true
end
it "should not include the same recipe twice" do
- @node.should_receive(:loaded_recipe).with("openldap").exactly(:once)
+ @node.should_receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
@cookbook_collection[:openldap].should_receive(:load_recipe).with("default", @run_context)
@recipe.include_recipe "openldap"
@cookbook_collection[:openldap].should_not_receive(:load_recipe).with("default", @run_context)
diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb
index aff1f85ead..39b8a8a50d 100644
--- a/spec/unit/run_context_spec.rb
+++ b/spec/unit/run_context_spec.rb
@@ -45,9 +45,10 @@ describe Chef::RunContext do
describe "loading cookbooks for a run list" do
before do
- @node.should_receive(:loaded_recipe).with("test")
- @node.should_receive(:loaded_recipe).with("test::one")
- @node.should_receive(:loaded_recipe).with("test::two")
+ @node.run_list << "test" << "test::one" << "test::two"
+ @node.should_receive(:loaded_recipe).with(:test, "default")
+ @node.should_receive(:loaded_recipe).with(:test, "one")
+ @node.should_receive(:loaded_recipe).with(:test, "two")
@run_context.load(@node.run_list.expand('_default'))
end