diff options
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/chef_class.rb | 5 | ||||
-rw-r--r-- | lib/chef/cookbook_site_streaming_uploader.rb | 2 | ||||
-rw-r--r-- | lib/chef/file_content_management/tempfile.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/bootstrap/templates/README.md | 7 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_create.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_download.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_install.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_site_share.rb | 12 | ||||
-rw-r--r-- | lib/chef/knife/search.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/ssh.rb | 2 | ||||
-rw-r--r-- | lib/chef/mixin/which.rb | 2 | ||||
-rw-r--r-- | lib/chef/platform/service_helpers.rb | 62 | ||||
-rw-r--r-- | lib/chef/policy_builder/expand_node_object.rb | 30 | ||||
-rw-r--r-- | lib/chef/property.rb | 11 | ||||
-rw-r--r-- | lib/chef/provider/package/rpm.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/remote_directory.rb | 2 | ||||
-rw-r--r-- | lib/chef/provider/template/content.rb | 24 | ||||
-rw-r--r-- | lib/chef/run_context.rb | 8 | ||||
-rw-r--r-- | lib/chef/run_lock.rb | 51 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 |
20 files changed, 142 insertions, 94 deletions
diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb index b18c3fbdde..6a0d09ec96 100644 --- a/lib/chef/chef_class.rb +++ b/lib/chef/chef_class.rb @@ -226,5 +226,10 @@ class Chef end end + # @api private Only for test dependency injection; not evenly implemented as yet. + def self.path_to(path) + path + end + reset! end diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index 0302a51165..2be189e942 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -26,7 +26,7 @@ require 'openssl' class Chef # == Chef::CookbookSiteStreamingUploader # A streaming multipart HTTP upload implementation. Used to upload cookbooks - # (in tarball form) to http://cookbooks.opscode.com + # (in tarball form) to https://supermarket.chef.io # # inspired by http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html class CookbookSiteStreamingUploader 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/knife/bootstrap/templates/README.md b/lib/chef/knife/bootstrap/templates/README.md index 13a0fe7ada..b5bca25d8e 100644 --- a/lib/chef/knife/bootstrap/templates/README.md +++ b/lib/chef/knife/bootstrap/templates/README.md @@ -1,12 +1,11 @@ This directory contains bootstrap templates which can be used with the -d flag to 'knife bootstrap' to install Chef in different ways. To simplify installation, and reduce the matrix of common installation patterns to support, we have -standardized on the [Omnibus](https://github.com/opscode/omnibus-ruby) built installation +standardized on the [Omnibus](https://github.com/chef/omnibus) built installation packages. The 'chef-full' template downloads a script which is used to determine the correct -Omnibus package for this system from the [Omnitruck](https://github.com/opscode/opscode-omnitruck) API. All other templates in this directory are deprecated and will be removed -in the future. +Omnibus package for this system from the [Omnitruck](https://docs.chef.io/api_omnitruck.html) API. You can still utilize custom bootstrap templates on your system if your installation -needs are unique. Additional information can be found on the [docs site](http://docs.opscode.com/knife_bootstrap.html#custom-templates).
\ No newline at end of file +needs are unique. Additional information can be found on the [docs site](https://docs.chef.io/knife_bootstrap.html#custom-templates). diff --git a/lib/chef/knife/cookbook_create.rb b/lib/chef/knife/cookbook_create.rb index e17a54079f..97f6e65d3c 100644 --- a/lib/chef/knife/cookbook_create.rb +++ b/lib/chef/knife/cookbook_create.rb @@ -48,7 +48,7 @@ class Chef option :cookbook_copyright, :short => "-C COPYRIGHT", :long => "--copyright COPYRIGHT", - :description => "Name of Copyright holder" + :description => "Name of copyright holder" option :cookbook_email, :short => "-m EMAIL", diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index c2d72ef8da..3e586e6542 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -84,7 +84,7 @@ class Chef end def download_cookbook - ui.info "Downloading #{@name_args[0]} from the cookbooks site at version #{version} to #{download_location}" + ui.info "Downloading #{@name_args[0]} from Supermarket at version #{version} to #{download_location}" noauth_rest.sign_on_redirect = false tf = noauth_rest.get_rest desired_cookbook_data["file"], true diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index d0ab6da3ef..aee8b7fa94 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -93,7 +93,7 @@ class Chef # TODO: it'd be better to store these outside the cookbook repo and # keep them around, e.g., in ~/Library/Caches on OS X. - ui.info("removing downloaded tarball") + ui.info("Removing downloaded tarball") File.unlink(upstream_file) if @repo.finalize_updates_to(@cookbook_name, downloader.version) diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index efd2e7f129..beb98b71b8 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -48,7 +48,7 @@ class Chef :short => '-n', :boolean => true, :default => false, - :description => "Don't take action, only print what files will be upload to SuperMarket." + :description => "Don't take action, only print what files will be uploaded to Supermarket." def run config[:cookbook_path] ||= Chef::Config[:cookbook_path] @@ -94,7 +94,7 @@ class Chef Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}") FileUtils.rm_rf tmp_cookbook_dir rescue => e - ui.error("Error uploading cookbook #{cookbook_name} to the Opscode Cookbook Site: #{e.message}. Increase log verbosity (-VV) for more information.") + ui.error("Error uploading cookbook #{cookbook_name} to Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") Chef::Log.debug("\n#{e.backtrace.join("\n")}") exit(1) end @@ -108,15 +108,15 @@ class Chef def get_category(cookbook_name) begin - data = noauth_rest.get_rest("http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}") + data = noauth_rest.get_rest("https://supermarket.chef.io/api/v1/cookbooks/#{@name_args[0]}") if !data["category"] && data["error_code"] - ui.fatal("Received an error from the Opscode Cookbook site: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.") + ui.fatal("Received an error from Supermarket: #{data["error_code"]}. On the first time you upload it, you are required to specify the category you want to share this cookbook to.") exit(1) else data['category'] end rescue => e - ui.fatal("Unable to reach Opscode Cookbook Site: #{e.message}. Increase log verbosity (-VV) for more information.") + ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") Chef::Log.debug("\n#{e.backtrace.join("\n")}") exit(1) end @@ -136,7 +136,7 @@ class Chef if http_resp.code.to_i != 201 if res['error_messages'] if res['error_messages'][0] =~ /Version already exists/ - ui.error "The same version of this cookbook already exists on the Opscode Cookbook Site." + ui.error "The same version of this cookbook already exists on Supermarket." exit(1) else ui.error "#{res['error_messages'][0]}" diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 2b0c79ff6c..014fc8dd87 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -136,7 +136,7 @@ class Chef def read_cli_args if config[:query] if @name_args[1] - ui.error "please specify query as an argument or an option via -q, not both" + ui.error "Please specify query as an argument or an option via -q, not both" ui.msg opt_parser exit 1 end @@ -145,7 +145,7 @@ class Chef else case name_args.size when 0 - ui.error "no query specified" + ui.error "No query specified" ui.msg opt_parser exit 1 when 1 diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index bb3d9d78bb..62af853e88 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -425,7 +425,7 @@ class Chef begin require 'appscript' rescue LoadError - STDERR.puts "you need the rb-appscript gem to use knife ssh macterm. `(sudo) gem install rb-appscript` to install" + STDERR.puts "You need the rb-appscript gem to use knife ssh macterm. `(sudo) gem install rb-appscript` to install" raise end diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index 4179c97b62..4e1c516386 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -28,7 +28,7 @@ class Chef paths = ENV['PATH'].split(File::PATH_SEPARATOR) + extra_path paths.each do |path| filename = File.join(path, cmd) - return filename if File.executable?(filename) + return filename if File.executable?(Chef.path_to(filename)) end false end diff --git a/lib/chef/platform/service_helpers.rb b/lib/chef/platform/service_helpers.rb index d50812e687..8365141c6e 100644 --- a/lib/chef/platform/service_helpers.rb +++ b/lib/chef/platform/service_helpers.rb @@ -19,6 +19,7 @@ # XXX: mixing shellout into a mixin into classes has to be code smell require 'chef/mixin/shell_out' require 'chef/mixin/which' +require 'chef/chef_class' class Chef class Platform @@ -42,56 +43,56 @@ class Chef # different services is NOT a design concern of this module. # def service_resource_providers - @service_resource_providers ||= [].tap do |service_resource_providers| + providers = [] - if ::File.exist?("/usr/sbin/update-rc.d") - service_resource_providers << :debian - end - - if ::File.exist?("/usr/sbin/invoke-rc.d") - service_resource_providers << :invokercd - end + if ::File.exist?(Chef.path_to("/usr/sbin/update-rc.d")) + providers << :debian + end - if ::File.exist?("/sbin/insserv") - service_resource_providers << :insserv - end + if ::File.exist?(Chef.path_to("/usr/sbin/invoke-rc.d")) + providers << :invokercd + end - # debian >= 6.0 has /etc/init but does not have upstart - if ::File.exist?("/etc/init") && ::File.exist?("/sbin/start") - service_resource_providers << :upstart - end + if ::File.exist?(Chef.path_to("/sbin/insserv")) + providers << :insserv + end - if ::File.exist?("/sbin/chkconfig") - service_resource_providers << :redhat - end + # debian >= 6.0 has /etc/init but does not have upstart + if ::File.exist?(Chef.path_to("/etc/init")) && ::File.exist?(Chef.path_to("/sbin/start")) + providers << :upstart + end - if systemd_sanity_check? - service_resource_providers << :systemd - end + if ::File.exist?(Chef.path_to("/sbin/chkconfig")) + providers << :redhat + end + if systemd_sanity_check? + providers << :systemd end + + providers end def config_for_service(service_name) configs = [] - if ::File.exist?("/etc/init.d/#{service_name}") + if ::File.exist?(Chef.path_to("/etc/init.d/#{service_name}")) configs << :initd end - if ::File.exist?("/etc/init/#{service_name}.conf") + if ::File.exist?(Chef.path_to("/etc/init/#{service_name}.conf")) configs << :upstart end - if ::File.exist?("/etc/xinetd.d/#{service_name}") + if ::File.exist?(Chef.path_to("/etc/xinetd.d/#{service_name}")) configs << :xinetd end - if ::File.exist?("/etc/rc.d/#{service_name}") + if ::File.exist?(Chef.path_to("/etc/rc.d/#{service_name}")) configs << :etc_rcd end - if ::File.exist?("/usr/local/etc/rc.d/#{service_name}") + if ::File.exist?(Chef.path_to("/usr/local/etc/rc.d/#{service_name}")) configs << :usr_local_etc_rcd end @@ -105,14 +106,11 @@ class Chef private def systemctl_path - if @systemctl_path.nil? - @systemctl_path = which("systemctl") - end - @systemctl_path + which("systemctl") end def systemd_sanity_check? - systemctl_path && File.exist?("/proc/1/comm") && File.open("/proc/1/comm").gets.chomp == "systemd" + systemctl_path && File.exist?(Chef.path_to("/proc/1/comm")) && File.open(Chef.path_to("/proc/1/comm")).gets.chomp == "systemd" end def extract_systemd_services(command) @@ -126,7 +124,7 @@ class Chef # this splits off the suffix after the last dot to return "sshd" services += services.select {|s| s.match(/\.service$/) }.map { |s| s.sub(/(.*)\.service$/, '\1') } rescue Mixlib::ShellOut::ShellCommandFailed - false + [] end def platform_has_systemd_unit?(service_name) 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/package/rpm.rb b/lib/chef/provider/package/rpm.rb index c5d52a8384..6ce0dd689f 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -61,7 +61,7 @@ class Chef Chef::Log.debug("#{@new_resource} checking rpm status") shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}").stdout.each_line do |line| case line - when /^([\w\d+_.-]+)\s([\w\d~_.-]+)$/ + when /^(\S+)\s(\S+)$/ @current_resource.package_name($1) @new_resource.version($2) @candidate_version = $2 @@ -78,7 +78,7 @@ class Chef @rpm_status = shell_out_with_timeout("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}") @rpm_status.stdout.each_line do |line| case line - when /^([\w\d+_.-]+)\s([\w\d~_.-]+)$/ + when /^(\S+)\s(\S+)$/ Chef::Log.debug("#{@new_resource} current version is #{$2}") @current_resource.version($2) end diff --git a/lib/chef/provider/remote_directory.rb b/lib/chef/provider/remote_directory.rb index 56c2ff0caf..3c1c50b963 100644 --- a/lib/chef/provider/remote_directory.rb +++ b/lib/chef/provider/remote_directory.rb @@ -161,7 +161,7 @@ class Chef def files_to_transfer cookbook = run_context.cookbook_collection[resource_cookbook] files = cookbook.relative_filenames_in_preferred_directory(node, :files, source) - files.sort!.reverse! + files.sort_by! { |x| x.count(::File::SEPARATOR) } end # Either the explicit cookbook that the user sets on the resource, or the implicit 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 0c8d3d1a48..b2a4b13ea4 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -522,6 +522,9 @@ ERROR_MESSAGE ChildRunContext.new(self) end + # @api private + attr_writer :resource_collection + protected attr_reader :cookbook_compiler @@ -532,11 +535,6 @@ ERROR_MESSAGE ### # These need to be settable so deploy can run a resource_collection # independent of any cookbooks via +recipe_eval+ - def resource_collection=(value) - Chef.log_deprecation("Setting run_context.resource_collection will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.") - @resource_collection = value - end - def audits=(value) Chef.log_deprecation("Setting run_context.audits will be removed in a future Chef. Use run_context.create_child to create a new RunContext instead.") @audits = value 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 # |