summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-09-29 14:46:28 -0700
committerThom May <thom@chef.io>2015-09-29 15:13:09 -0700
commit53380ccb30465f003ddc2fb3461007c135110577 (patch)
treef435d2da42949bcbfbaf2c586faf76b22e0f4166
parentbc82c3e8603f6908d80fc29beb1d0902563398e7 (diff)
downloadchef-53380ccb30465f003ddc2fb3461007c135110577.tar.gz
Ensure that our list of recipes is backwards compattm/duplicate_recipes
Prior to chef 12.2 we included unexpanded 'cookbook' names for default recipes. In 12.2, we moved to expanded ('cookbook::default') names, which broke some searches. However, some of our users have now moved to searching for expanded, so we need to cater for both. Fixes #3767
-rw-r--r--lib/chef/node.rb2
-rw-r--r--lib/chef/run_list/versioned_recipe_list.rb15
-rw-r--r--spec/unit/client_spec.rb3
-rw-r--r--spec/unit/run_list/versioned_recipe_list_spec.rb5
4 files changed, 23 insertions, 2 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 668ddbdc35..1e4a850277 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -440,7 +440,7 @@ class Chef
self.tags # make sure they're defined
- automatic_attrs[:recipes] = expansion.recipes.with_fully_qualified_names_and_version_constraints
+ automatic_attrs[:recipes] = expansion.recipes.with_duplicate_names
automatic_attrs[:expanded_run_list] = expansion.recipes.with_fully_qualified_names_and_version_constraints
automatic_attrs[:roles] = expansion.roles
diff --git a/lib/chef/run_list/versioned_recipe_list.rb b/lib/chef/run_list/versioned_recipe_list.rb
index 2824f08f31..803156aef9 100644
--- a/lib/chef/run_list/versioned_recipe_list.rb
+++ b/lib/chef/run_list/versioned_recipe_list.rb
@@ -82,6 +82,21 @@ class Chef
qualified_recipe
end
end
+
+ # Get an array of strings of both fully-qualified and unexpanded recipe names
+ # in response to chef/chef#3767
+ # Chef-13 will revert to the behaviour of just including the fully-qualified name
+ #
+ # @return [Array] Array of strings with fully-qualified and unexpanded recipe names
+ def with_duplicate_names
+ self.map do |recipe_name|
+ if recipe_name.include?('::')
+ recipe_name
+ else
+ [recipe_name, "#{recipe_name}::default"]
+ end
+ end.flatten
+ end
end
end
end
diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb
index f736c38859..8fbf56844e 100644
--- a/spec/unit/client_spec.rb
+++ b/spec/unit/client_spec.rb
@@ -375,7 +375,8 @@ describe Chef::Client do
expect(node[:roles].length).to eq(1)
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].length).to eq(2)
+ 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)
diff --git a/spec/unit/run_list/versioned_recipe_list_spec.rb b/spec/unit/run_list/versioned_recipe_list_spec.rb
index 9c3ecaa0dd..be57d6c944 100644
--- a/spec/unit/run_list/versioned_recipe_list_spec.rb
+++ b/spec/unit/run_list/versioned_recipe_list_spec.rb
@@ -187,4 +187,9 @@ describe Chef::RunList::VersionedRecipeList do
end
end
+ context "with duplicated names", :chef_gte_13_only do
+ it "should fail in Chef 13" do
+ expect(list).to_not respond_to(:with_duplicate_names)
+ end
+ end
end