summaryrefslogtreecommitdiff
path: root/lib/chef/run_context
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-05-03 12:35:02 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-05-03 12:37:14 -0700
commit1a94e1bc43aed773ef7584ea6c88af80cc884520 (patch)
treefb321770c271528e1aa750324d1f987cf72763bf /lib/chef/run_context
parent1c0a097bd1f9f55d4db199b0681afd68f52c218e (diff)
downloadchef-1a94e1bc43aed773ef7584ea6c88af80cc884520.tar.gz
Chef-15: cookbook compiler should parse only .rb fileslcg/parse-only-rb-files
Fixes #6281 which is a frequently reported issue where md files and swap files and other junk causes the cookbook compiler to barf. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/run_context')
-rw-r--r--lib/chef/run_context/cookbook_compiler.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/chef/run_context/cookbook_compiler.rb b/lib/chef/run_context/cookbook_compiler.rb
index 1bd612e721..1469462e69 100644
--- a/lib/chef/run_context/cookbook_compiler.rb
+++ b/lib/chef/run_context/cookbook_compiler.rb
@@ -206,13 +206,13 @@ class Chef
end
list_of_attr_files.each do |filename|
+ next unless File.extname(filename) == ".rb"
load_attribute_file(cookbook_name.to_s, filename)
end
end
def load_attribute_file(cookbook_name, filename)
- # FIXME(log): should be trace
- logger.debug("Node #{node.name} loading cookbook #{cookbook_name}'s attribute file #{filename}")
+ logger.trace("Node #{node.name} loading cookbook #{cookbook_name}'s attribute file #{filename}")
attr_file_basename = ::File.basename(filename, ".rb")
node.include_attribute("#{cookbook_name}::#{attr_file_basename}")
rescue Exception => e
@@ -224,8 +224,7 @@ class Chef
files_in_cookbook_by_segment(cookbook_name, :libraries).each do |filename|
next unless File.extname(filename) == ".rb"
begin
- # FIXME(log): should be trace
- logger.debug("Loading cookbook #{cookbook_name}'s library file: #{filename}")
+ logger.trace("Loading cookbook #{cookbook_name}'s library file: #{filename}")
Kernel.require(filename)
@events.library_file_loaded(filename)
rescue Exception => e
@@ -237,16 +236,17 @@ class Chef
def load_lwrps_from_cookbook(cookbook_name)
files_in_cookbook_by_segment(cookbook_name, :providers).each do |filename|
+ next unless File.extname(filename) == ".rb"
load_lwrp_provider(cookbook_name, filename)
end
files_in_cookbook_by_segment(cookbook_name, :resources).each do |filename|
+ next unless File.extname(filename) == ".rb"
load_lwrp_resource(cookbook_name, filename)
end
end
def load_lwrp_provider(cookbook_name, filename)
- # FIXME(log): should be trace
- logger.debug("Loading cookbook #{cookbook_name}'s providers from #{filename}")
+ logger.trace("Loading cookbook #{cookbook_name}'s providers from #{filename}")
Chef::Provider::LWRPBase.build_from_file(cookbook_name, filename, self)
@events.lwrp_file_loaded(filename)
rescue Exception => e
@@ -255,8 +255,7 @@ class Chef
end
def load_lwrp_resource(cookbook_name, filename)
- # FIXME(log): should be trace
- logger.debug("Loading cookbook #{cookbook_name}'s resources from #{filename}")
+ logger.trace("Loading cookbook #{cookbook_name}'s resources from #{filename}")
Chef::Resource::LWRPBase.build_from_file(cookbook_name, filename, self)
@events.lwrp_file_loaded(filename)
rescue Exception => e
@@ -269,8 +268,7 @@ class Chef
files_in_cookbook_by_segment(cookbook_name, :ohai).each do |filename|
next unless File.extname(filename) == ".rb"
- # FIXME(log): should be trace
- logger.debug "Loading Ohai plugin: #{filename} from #{cookbook_name}"
+ logger.trace "Loading Ohai plugin: #{filename} from #{cookbook_name}"
target_name = File.join(target, cookbook_name.to_s, File.basename(filename))
FileUtils.mkdir_p(File.dirname(target_name))
@@ -280,9 +278,10 @@ class Chef
def load_resource_definitions_from_cookbook(cookbook_name)
files_in_cookbook_by_segment(cookbook_name, :definitions).each do |filename|
+ next unless File.extname(filename) == ".rb"
+
begin
- # FIXME(log): should be trace
- logger.debug("Loading cookbook #{cookbook_name}'s definitions from #{filename}")
+ logger.trace("Loading cookbook #{cookbook_name}'s definitions from #{filename}")
resourcelist = Chef::ResourceDefinitionList.new
resourcelist.from_file(filename)
definitions.merge!(resourcelist.defines) do |key, oldval, newval|