diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-07 12:36:30 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-05-18 15:37:41 -0700 |
commit | db62393671925bd778193c3ed8b2af49ccbb63a4 (patch) | |
tree | d363d4697fcd5bf229b4ad83c49185b44e346a40 | |
parent | 05b07f669b9a06799e7e20608d1df3e5bbc2853a (diff) | |
download | chef-db62393671925bd778193c3ed8b2af49ccbb63a4.tar.gz |
add/fix node attributes
* fix node[:recipes]
* add node[:expanded_run_list]
* add node[:cookbooks]
-rw-r--r-- | lib/chef/node.rb | 13 | ||||
-rw-r--r-- | lib/chef/run_context.rb | 1 | ||||
-rw-r--r-- | lib/chef/run_list/versioned_recipe_list.rb | 18 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/policy_builder/policyfile_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/run_context_spec.rb | 31 |
6 files changed, 69 insertions, 4 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 8c41d7e10e..617d2bab2f 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -77,6 +77,15 @@ class Chef @run_state = {} end + # after the run_context has been set on the node, go through the cookbook_collection + # and setup the node[:cookbooks] attribute so that it is published in the node object + def consume_cookbook_collection + return unless run_context.cookbook_collection + run_context.cookbook_collection.each do |cookbook_name, cookbook| + automatic_attrs[:cookbooks][cookbook_name][:version] = cookbook.version + end + end + # Used by DSL def node self @@ -252,6 +261,7 @@ class Chef # 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 @@ -362,7 +372,8 @@ class Chef self.tags # make sure they're defined - automatic_attrs[:recipes] = expansion.recipes + automatic_attrs[:recipes] = expansion.recipes.with_fully_qualified_names_and_version_constraints + automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints automatic_attrs[:roles] = expansion.roles apply_expansion_attributes(expansion) diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 4f0215bfd4..98cbc1a47c 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -86,6 +86,7 @@ class Chef @reboot_info = {} @node.run_context = self + @node.consume_cookbook_collection @cookbook_compiler = nil end diff --git a/lib/chef/run_list/versioned_recipe_list.rb b/lib/chef/run_list/versioned_recipe_list.rb index 0eefded964..7cce6fa48c 100644 --- a/lib/chef/run_list/versioned_recipe_list.rb +++ b/lib/chef/run_list/versioned_recipe_list.rb @@ -63,6 +63,24 @@ class Chef end end end + + # Get an array of strings of the fully-qualified recipe names (with ::default appended) and + # with the versions in "NAME@VERSION" format. + # + # @return [Array] Array of strings with fully-qualified recipe names + def with_fully_qualified_names_and_version_constraints + self.map do |recipe_name| + ret = if recipe_name.include?('::') + recipe_name + else + "#{recipe_name}::default" + end + if @versions[recipe_name] + ret << "@#{@versions[recipe_name]}" + end + ret + end + end end end end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 4cfac35cb4..c1bde072f6 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -680,6 +680,7 @@ describe Chef::Client do # check pre-conditions. expect(node[:roles]).to be_nil expect(node[:recipes]).to be_nil + expect(node[:expanded_run_list]).to be_nil allow(client.policy_builder).to receive(:node).and_return(node) @@ -692,7 +693,10 @@ describe Chef::Client do expect(node[:roles]).to include("role_containing_cookbook1") expect(node[:recipes]).not_to be_nil expect(node[:recipes].length).to eq(1) - expect(node[:recipes]).to include("cookbook1") + expect(node[:recipes]).to include("cookbook1::default") + expect(node[:expanded_run_list]).not_to be_nil + expect(node[:expanded_run_list].length).to eq(1) + expect(node[:expanded_run_list]).to include("cookbook1::default") end it "should set the environment from the specified configuration value" do diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index e4f7388a1c..ad7c83b03b 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -389,8 +389,8 @@ describe Chef::PolicyBuilder::Policyfile do let(:example1_cookbook_data) { double("CookbookVersion Hash for example1 cookbook") } let(:example2_cookbook_data) { double("CookbookVersion Hash for example2 cookbook") } - let(:example1_cookbook_object) { double("Chef::CookbookVersion for example1 cookbook") } - let(:example2_cookbook_object) { double("Chef::CookbookVersion for example2 cookbook") } + let(:example1_cookbook_object) { double("Chef::CookbookVersion for example1 cookbook", version: "0.1.2") } + let(:example2_cookbook_object) { double("Chef::CookbookVersion for example2 cookbook", version: "1.2.3") } let(:expected_cookbook_hash) do { "example1" => example1_cookbook_object, "example2" => example2_cookbook_object } diff --git a/spec/unit/run_context_spec.rb b/spec/unit/run_context_spec.rb index d656111a7d..eac5028bc1 100644 --- a/spec/unit/run_context_spec.rb +++ b/spec/unit/run_context_spec.rb @@ -53,6 +53,37 @@ describe Chef::RunContext do expect(run_context.node).to eq(node) end + it "loads up node[:cookbooks]" do + expect(run_context.node[:cookbooks]).to eql( + { + "circular-dep1" => { + "version" => "0.0.0", + }, + "circular-dep2" => { + "version" => "0.0.0", + }, + "dependency1" => { + "version" => "0.0.0", + }, + "dependency2" => { + "version" => "0.0.0", + }, + "no-default-attr" => { + "version" => "0.0.0", + }, + "test" => { + "version" => "0.0.0", + }, + "test-with-circular-deps" => { + "version" => "0.0.0", + }, + "test-with-deps" => { + "version" => "0.0.0", + }, + } + ) + end + describe "loading cookbooks for a run list" do before do |