diff options
author | lamont-granquist <lamont@scriptkiddie.org> | 2014-01-16 15:53:46 -0800 |
---|---|---|
committer | lamont-granquist <lamont@scriptkiddie.org> | 2014-01-16 15:53:46 -0800 |
commit | 2fbe2365a3d8fe28540a90773dc43cdb8124fc37 (patch) | |
tree | 1af96f9c7e3e7b14101a78b92c8de7d6b63b3b0e | |
parent | 4bffa7d9682170cd940d544ddadc485a8c90c032 (diff) | |
parent | 7c4670ce77cafb481477e9da75348a75b44c0393 (diff) | |
download | chef-2fbe2365a3d8fe28540a90773dc43cdb8124fc37.tar.gz |
Merge pull request #1128 from opscode/lcg/CHEF-4777
CHEF-4777: add include_recipes to recipes node attr
-rw-r--r-- | lib/chef/node.rb | 7 | ||||
-rw-r--r-- | lib/chef/run_context.rb | 2 | ||||
-rw-r--r-- | spec/unit/cookbook_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 16 | ||||
-rw-r--r-- | spec/unit/recipe_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/run_context_spec.rb | 4 |
6 files changed, 33 insertions, 1 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 007bd3c560..69e5e05b01 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -247,6 +247,13 @@ class Chef run_list.include?(recipe_name) || Array(self[:recipes]).include?(recipe_name) end + # 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(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. def role?(role_name) run_list.include?("role[#{role_name}]") diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 2ed29a2e34..05a954ad15 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(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 c28a5c7a2a..ca4f4adc08 100644 --- a/spec/unit/cookbook_spec.rb +++ b/spec/unit/cookbook_spec.rb @@ -70,6 +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") 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 bb567dbdf7..1cc40979cc 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -461,6 +461,22 @@ describe Chef::Node do end end + 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") + 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") + 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 + end + end + describe "when querying for recipes in the run list" do context "when a recipe is in the top level run list" do before do diff --git a/spec/unit/recipe_spec.rb b/spec/unit/recipe_spec.rb index 4615bcb4d4..3240739dd7 100644 --- a/spec/unit/recipe_spec.rb +++ b/spec/unit/recipe_spec.rb @@ -193,6 +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") @run_context.include_recipe "openldap::gigantor" res = @run_context.resource_collection.resources(:cat => "blanket") res.name.should eql("blanket") @@ -200,6 +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, "default") @run_context.include_recipe "openldap" res = @run_context.resource_collection.resources(:cat => "blanket") res.name.should eql("blanket") @@ -207,11 +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, "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, "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 8063dffc77..39b8a8a50d 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -45,6 +45,10 @@ describe Chef::RunContext do describe "loading cookbooks for a run list" do before do + @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 |