summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasu1105 <vasundhara.jagdale@msystechnologies.com>2019-10-22 14:12:22 +0530
committerVasu1105 <vasundhara.jagdale@msystechnologies.com>2020-01-22 10:50:38 +0530
commit28be43bc6476e5ee7eb0a83d8cdc2e8db00489bd (patch)
tree3b5f497f04a1a94b88edb0847b42b2502a4e5bcb
parent87645e71e0141f2409a9b06513e36878ba7164ef (diff)
downloadchef-28be43bc6476e5ee7eb0a83d8cdc2e8db00489bd.tar.gz
Deprecated the load method in cookbook_version_loader and added deprecation warning for it. Updated code to raise error if cookbook repo has cookbook directory without cookbook files, this is to make sure user should fix their cookbook repo and remove any garbage from cookbook repository and then do bulk upload.
Signed-off-by: Vasu1105 <vasundhara.jagdale@msystechnologies.com>
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb28
-rw-r--r--lib/chef/cookbook_uploader.rb15
-rw-r--r--lib/chef/knife/cookbook_upload.rb3
-rw-r--r--spec/unit/cookbook/cookbook_version_loader_spec.rb15
4 files changed, 21 insertions, 40 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index 8d4c3208fd..fe3652bbdf 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -65,14 +65,6 @@ class Chef
# Load the cookbook. Raises an error if the cookbook_path given to the
# constructor doesn't point to a valid cookbook.
def load!
- # file_paths_map = load
-
- # if empty?
- # raise Exceptions::CookbookNotFoundInRepo, "The directory #{cookbook_path} does not contain a cookbook"
- # end
-
- # file_paths_map
-
metadata # force lazy evaluation to occur
# re-raise any exception that occurred when reading the metadata
@@ -83,8 +75,9 @@ class Chef
remove_ignored_files
if empty?
- Chef::Log.warn "Found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping."
+ raise Exceptions::CookbookNotFoundInRepo, "The directory #{cookbook_path} does not contain a cookbook"
end
+
cookbook_settings
end
@@ -92,23 +85,10 @@ class Chef
# directory as the cookbook_path. This behavior is provided for
# compatibility, it is recommended to use #load! instead.
def load
- Chef::Log.warn "This method is deprecated. Use load! instead"
- # metadata # force lazy evaluation to occur
-
- # re-raise any exception that occurred when reading the metadata
- # raise_metadata_error!
-
- # load_all_files
-
- # remove_ignored_files
-
- # if empty?
- # Chef::Log.warn "Found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping."
- # end
- # cookbook_settings
+ Chef::Log.warn "load method is deprecated. Use load! instead"
end
- alias :load_cookbooks :load
+ alias :load_cookbooks :load!
def cookbook_version
return nil if empty?
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index 91c7e49c5e..042100bab7 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -139,14 +139,13 @@ class Chef
def validate_cookbooks
cookbooks.each do |cb|
- unless cb.nil?
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.root_dir)
- Chef::Log.info("Validating ruby files")
- exit(1) unless syntax_checker.validate_ruby_files
- Chef::Log.info("Validating templates")
- exit(1) unless syntax_checker.validate_templates
- Chef::Log.info("Syntax OK")
- end
+ next if cb.nil?
+ syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.root_dir)
+ Chef::Log.info("Validating ruby files")
+ exit(1) unless syntax_checker.validate_ruby_files
+ Chef::Log.info("Validating templates")
+ exit(1) unless syntax_checker.validate_templates
+ Chef::Log.info("Syntax OK")
end
end
diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb
index 7605366718..7bda2815e7 100644
--- a/lib/chef/knife/cookbook_upload.rb
+++ b/lib/chef/knife/cookbook_upload.rb
@@ -167,7 +167,6 @@ class Chef
exit 1
end
end
-
unless version_constraints_to_update.empty?
update_version_constraints(version_constraints_to_update) if config[:environment]
end
@@ -192,7 +191,7 @@ class Chef
end
end
rescue Exceptions::CookbookNotFoundInRepo => e
- ui.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
+ ui.error(e.message)
Log.debug(e)
end
end
diff --git a/spec/unit/cookbook/cookbook_version_loader_spec.rb b/spec/unit/cookbook/cookbook_version_loader_spec.rb
index 2cd86877cb..fd7a3ef8c9 100644
--- a/spec/unit/cookbook/cookbook_version_loader_spec.rb
+++ b/spec/unit/cookbook/cookbook_version_loader_spec.rb
@@ -124,8 +124,9 @@ describe Chef::Cookbook::CookbookVersionLoader do
expect { cookbook_loader.load! }.to raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
end
- it "skips the cookbook when called with #load" do
- expect { cookbook_loader.load }.to_not raise_error
+ it "gives deprecation warning called with #load" do
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
+ cookbook_loader.load
end
end
@@ -148,8 +149,9 @@ describe Chef::Cookbook::CookbookVersionLoader do
expect { cookbook_loader.load! }.to raise_error("THIS METADATA HAS A BUG")
end
- it "raises an error when called with #load" do
- expect { cookbook_loader.load }.to raise_error("THIS METADATA HAS A BUG")
+ it "gives deprecation warning to us load! when called with #load" do
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
+ cookbook_loader.load
end
it "doesn't raise an error when determining the cookbook name" do
@@ -180,8 +182,9 @@ describe Chef::Cookbook::CookbookVersionLoader do
expect { cookbook_loader.load! }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message)
end
- it "raises an error when called with #load" do
- expect { cookbook_loader.load }.to raise_error(Chef::Exceptions::MetadataNotValid, error_message)
+ it "gives deprecation warning to use load! method when called with #load" do
+ expect(Chef::Log).to receive(:warn).with(/load method is deprecated. Use load! instead/)
+ cookbook_loader.load
end
it "uses the inferred cookbook name [CHEF-2923]" do