summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/file_content_management/tempfile.rb2
-rw-r--r--lib/chef/policy_builder/expand_node_object.rb30
-rw-r--r--lib/chef/property.rb11
-rw-r--r--lib/chef/provider.rb2
-rw-r--r--lib/chef/provider/powershell_script.rb8
-rw-r--r--lib/chef/provider/template/content.rb24
-rw-r--r--lib/chef/run_context.rb6
-rw-r--r--lib/chef/run_lock.rb51
-rw-r--r--lib/chef/version.rb2
9 files changed, 95 insertions, 41 deletions
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb
index 2dde0ce21b..6e1624f9a4 100644
--- a/lib/chef/file_content_management/tempfile.rb
+++ b/lib/chef/file_content_management/tempfile.rb
@@ -49,7 +49,7 @@ class Chef
end
end
- raise Chef::Exceptions::FileContentStagingError(errors) if tf.nil?
+ raise Chef::Exceptions::FileContentStagingError, errors if tf.nil?
# We always process the tempfile in binmode so that we
# preserve the line endings of the content.
diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb
index 26b98afa52..933960a429 100644
--- a/lib/chef/policy_builder/expand_node_object.rb
+++ b/lib/chef/policy_builder/expand_node_object.rb
@@ -33,6 +33,9 @@ class Chef
# expands the run_list on a node object and then queries the chef-server
# to find the correct set of cookbooks, given version constraints of the
# node's environment.
+ #
+ # Note that this class should only be used via PolicyBuilder::Dynamic and
+ # not instantiated directly.
class ExpandNodeObject
attr_reader :events
@@ -94,6 +97,33 @@ class Chef
run_context
end
+ # DEPRECATED: As of Chef 12.5, chef selects either policyfile mode or
+ # "expand node" mode dynamically, based on the content of the node
+ # object, first boot JSON, and config. This happens in
+ # PolicyBuilder::Dynamic, which selects the implementation during
+ # #load_node and then delegates to either ExpandNodeObject or Policyfile
+ # implementations as appropriate. Tools authors should update their code
+ # to create a PolicyBuilder::Dynamc policy builder and allow it to select
+ # the proper implementation.
+ def load_node
+ Chef.log_deprecation("ExpandNodeObject#load_node is deprecated. Please use Chef::PolicyBuilder::Dynamic instead of using ExpandNodeObject directly")
+
+ events.node_load_start(node_name, config)
+ Chef::Log.debug("Building node object for #{node_name}")
+
+ @node =
+ if Chef::Config[:solo]
+ Chef::Node.build(node_name)
+ else
+ Chef::Node.find_or_create(node_name)
+ end
+ finish_load_node(node)
+ node
+ rescue Exception => e
+ events.node_load_failed(node_name, e, config)
+ raise
+ end
+
def finish_load_node(node)
@node = node
end
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 2b151b350a..c1207d9132 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -422,7 +422,16 @@ class Chef
# @return [Property] The new property type.
#
def derive(**modified_options)
- Property.new(**options.merge(**modified_options))
+ # Since name_property, name_attribute and default override each other,
+ # if you specify one of them in modified_options it overrides anything in
+ # the original options.
+ options = self.options
+ if modified_options.has_key?(:name_property) ||
+ modified_options.has_key?(:name_attribute) ||
+ modified_options.has_key?(:default)
+ options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default }
+ end
+ Property.new(options.merge(modified_options))
end
#
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 3138704a55..e22f11d9be 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -265,7 +265,7 @@ class Chef
provider_class = self
@included_resource_dsl_module = Module.new do
extend Forwardable
- define_singleton_method(:to_s) { "#{resource_class} forwarder module" }
+ define_singleton_method(:to_s) { "forwarder module for #{provider_class}" }
define_singleton_method(:inspect) { to_s }
# Add a delegator for each explicit property that will get the *current* value
# of the property by default instead of the *actual* value.
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index b876b6d8ee..91ce11c337 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -16,6 +16,7 @@
# limitations under the License.
#
+require 'chef/platform/query_helpers'
require 'chef/provider/windows_script'
class Chef
@@ -49,7 +50,10 @@ class Chef
# code -- otherwise, powershell.exe does not propagate the
# error status of a failed Windows process that ran at the
# end of the script, it gets changed to '1'.
- interpreter_flags = [default_interpreter_flags, '-File'].join(' ')
+ #
+ # Nano only supports -Command
+ file_or_command = Chef::Platform.windows_nano_server? ? '-Command' : '-File'
+ interpreter_flags = [*default_interpreter_flags, file_or_command].join(' ')
if ! (@new_resource.flags.nil?)
interpreter_flags = [@new_resource.flags, interpreter_flags].join(' ')
@@ -107,6 +111,8 @@ EOH
end
def default_interpreter_flags
+ return [] if Chef::Platform.windows_nano_server?
+
# Execution policy 'Bypass' is preferable since it doesn't require
# user input confirmation for files such as PowerShell modules
# downloaded from the Internet. However, 'Bypass' is not supported
diff --git a/lib/chef/provider/template/content.rb b/lib/chef/provider/template/content.rb
index a231bd509e..693b19a8c6 100644
--- a/lib/chef/provider/template/content.rb
+++ b/lib/chef/provider/template/content.rb
@@ -29,30 +29,30 @@ class Chef
def template_location
@template_file_cache_location ||= begin
- template_finder.find(@new_resource.source, :local => @new_resource.local, :cookbook => @new_resource.cookbook)
+ template_finder.find(new_resource.source, :local => new_resource.local, :cookbook => new_resource.cookbook)
end
end
private
def file_for_provider
- context = TemplateContext.new(@new_resource.variables)
- context[:node] = @run_context.node
+ context = TemplateContext.new(new_resource.variables)
+ context[:node] = run_context.node
context[:template_finder] = template_finder
# helper variables
- context[:cookbook_name] = @new_resource.cookbook_name unless context.keys.include?(:coookbook_name)
- context[:recipe_name] = @new_resource.recipe_name unless context.keys.include?(:recipe_name)
- context[:recipe_line_string] = @new_resource.source_line unless context.keys.include?(:recipe_line_string)
- context[:recipe_path] = @new_resource.source_line_file unless context.keys.include?(:recipe_path)
- context[:recipe_line] = @new_resource.source_line_number unless context.keys.include?(:recipe_line)
- context[:template_name] = @new_resource.source unless context.keys.include?(:template_name)
+ context[:cookbook_name] = new_resource.cookbook_name unless context.keys.include?(:coookbook_name)
+ context[:recipe_name] = new_resource.recipe_name unless context.keys.include?(:recipe_name)
+ context[:recipe_line_string] = new_resource.source_line unless context.keys.include?(:recipe_line_string)
+ context[:recipe_path] = new_resource.source_line_file unless context.keys.include?(:recipe_path)
+ context[:recipe_line] = new_resource.source_line_number unless context.keys.include?(:recipe_line)
+ context[:template_name] = new_resource.source unless context.keys.include?(:template_name)
context[:template_path] = template_location unless context.keys.include?(:template_path)
- context._extend_modules(@new_resource.helper_modules)
+ context._extend_modules(new_resource.helper_modules)
output = context.render_template(template_location)
- tempfile = Tempfile.open("chef-rendered-template")
+ tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
tempfile.binmode
tempfile.write(output)
tempfile.close
@@ -61,7 +61,7 @@ class Chef
def template_finder
@template_finder ||= begin
- TemplateFinder.new(run_context, @new_resource.cookbook_name, @run_context.node)
+ TemplateFinder.new(run_context, new_resource.cookbook_name, run_context.node)
end
end
end
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 205bb47448..b2a4b13ea4 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -522,15 +522,15 @@ ERROR_MESSAGE
ChildRunContext.new(self)
end
+ # @api private
+ attr_writer :resource_collection
+
protected
attr_reader :cookbook_compiler
attr_reader :loaded_attributes_hash
attr_reader :loaded_recipes_hash
- # @api private
- attr_writer :resource_collection
-
module Deprecated
###
# These need to be settable so deploy can run a resource_collection
diff --git a/lib/chef/run_lock.rb b/lib/chef/run_lock.rb
index cefe637db6..9e0952bdcb 100644
--- a/lib/chef/run_lock.rb
+++ b/lib/chef/run_lock.rb
@@ -87,27 +87,8 @@ class Chef
# Either acquire() or test() methods should be called in order to
# get the ownership of run_lock.
def test
- # ensure the runlock_file path exists
- create_path(File.dirname(runlock_file))
- @runlock = File.open(runlock_file,'a+')
-
- if Chef::Platform.windows?
- acquire_win32_mutex
- else
- # If we support FD_CLOEXEC, then use it.
- # NB: ruby-2.0.0-p195 sets FD_CLOEXEC by default, but not
- # ruby-1.8.7/1.9.3
- if Fcntl.const_defined?('F_SETFD') && Fcntl.const_defined?('FD_CLOEXEC')
- runlock.fcntl(Fcntl::F_SETFD, runlock.fcntl(Fcntl::F_GETFD, 0) | Fcntl::FD_CLOEXEC)
- end
- # Flock will return 0 if it can acquire the lock otherwise it
- # will return false
- if runlock.flock(File::LOCK_NB|File::LOCK_EX) == 0
- true
- else
- false
- end
- end
+ create_lock
+ acquire_lock
end
#
@@ -147,6 +128,34 @@ class Chef
end
end
+ # @api private solely for race condition tests
+ def create_lock
+ # ensure the runlock_file path exists
+ create_path(File.dirname(runlock_file))
+ @runlock = File.open(runlock_file,'a+')
+ end
+
+ # @api private solely for race condition tests
+ def acquire_lock
+ if Chef::Platform.windows?
+ acquire_win32_mutex
+ else
+ # If we support FD_CLOEXEC, then use it.
+ # NB: ruby-2.0.0-p195 sets FD_CLOEXEC by default, but not
+ # ruby-1.8.7/1.9.3
+ if Fcntl.const_defined?('F_SETFD') && Fcntl.const_defined?('FD_CLOEXEC')
+ runlock.fcntl(Fcntl::F_SETFD, runlock.fcntl(Fcntl::F_GETFD, 0) | Fcntl::FD_CLOEXEC)
+ end
+ # Flock will return 0 if it can acquire the lock otherwise it
+ # will return false
+ if runlock.flock(File::LOCK_NB|File::LOCK_EX) == 0
+ true
+ else
+ false
+ end
+ end
+ end
+
private
def reset
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index faa61aee54..c0ff754873 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -21,7 +21,7 @@
class Chef
CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
- VERSION = '12.5.0.current.0'
+ VERSION = '12.5.0'
end
#