diff options
54 files changed, 378 insertions, 247 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3115a8a48e..6e306e05f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,30 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 14.0.210 --> -## [v14.0.210](https://github.com/chef/chef/tree/v14.0.210) (2018-04-23) +<!-- latest_release 14.0.217 --> +## [v14.0.217](https://github.com/chef/chef/tree/v14.0.217) (2018-05-02) #### Merged Pull Requests -- whitespace fix to make expeditor run [#7179](https://github.com/chef/chef/pull/7179) ([lamont-granquist](https://github.com/lamont-granquist)) +- Allow specifying `ignore_failure :quiet` to disable the error spew [#7194](https://github.com/chef/chef/pull/7194) ([coderanger](https://github.com/coderanger)) <!-- latest_release --> <!-- release_rollup since=14.0.202 --> ### Changes since 14.0.202 release #### Merged Pull Requests -- whitespace fix to make expeditor run [#7179](https://github.com/chef/chef/pull/7179) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.210 --> +- Allow specifying `ignore_failure :quiet` to disable the error spew [#7194](https://github.com/chef/chef/pull/7194) ([coderanger](https://github.com/coderanger)) <!-- 14.0.217 --> +- Don't always request lazy files [#7208](https://github.com/chef/chef/pull/7208) ([thommay](https://github.com/thommay)) <!-- 14.0.216 --> +- Convert some of remote_directory to use properties [#7204](https://github.com/chef/chef/pull/7204) ([tas50](https://github.com/tas50)) <!-- 14.0.215 --> +- Convert properties in subversion to use property [#7200](https://github.com/chef/chef/pull/7200) ([tas50](https://github.com/tas50)) +- Convert :key property in registry_key to use property [#7199](https://github.com/chef/chef/pull/7199) ([tas50](https://github.com/tas50)) +- Set desired_state: false on several properties [#7201](https://github.com/chef/chef/pull/7201) ([tas50](https://github.com/tas50)) +- Fix regression where owner was removed from link resource [#7206](https://github.com/chef/chef/pull/7206) ([tas50](https://github.com/tas50)) +- Add descriptions to more resources [#7195](https://github.com/chef/chef/pull/7195) ([tas50](https://github.com/tas50)) +- Allow build_essential resource to be used without setting a name [#7197](https://github.com/chef/chef/pull/7197) ([tas50](https://github.com/tas50)) +- rhsm_register: skip the registration check if force is specified [#7193](https://github.com/chef/chef/pull/7193) ([tas50](https://github.com/tas50)) +- Whitelist some additional Hash/Array methods [#7198](https://github.com/chef/chef/pull/7198) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 14.0.214 --> +- sysctl: Fix ignore_error being ignored [#7192](https://github.com/chef/chef/pull/7192) ([tas50](https://github.com/tas50)) +- prune remotes with git fetch, fixes #3929 [#7129](https://github.com/chef/chef/pull/7129) ([rmoriz](https://github.com/rmoriz)) +- Fix NoMethodError when (un)locking single packages in apt and zypper [#7138](https://github.com/chef/chef/pull/7138) ([RoboticCheese](https://github.com/RoboticCheese)) <!-- 14.0.213 --> +- CLI help text now includes :trace log level [#7186](https://github.com/chef/chef/pull/7186) ([stuartpreston](https://github.com/stuartpreston)) <!-- 14.0.212 --> - Ubuntu 1804 - passing tests and fixed ifconfig provider [#7174](https://github.com/chef/chef/pull/7174) ([thommay](https://github.com/thommay)) <!-- 14.0.208 --> - Avoid conflict with build_powershell_command from powershell_out mixin [#7173](https://github.com/chef/chef/pull/7173) ([stuartpreston](https://github.com/stuartpreston)) <!-- 14.0.207 --> - Some options, i.e. metric, require specifying dev [#7162](https://github.com/chef/chef/pull/7162) ([tomdoherty](https://github.com/tomdoherty)) <!-- 14.0.206 --> diff --git a/Gemfile.lock b/Gemfile.lock index 854d91aabb..b39f410d3e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,13 +15,14 @@ GIT PATH remote: . specs: - chef (14.0.210) + chef (14.0.217) addressable bundler (>= 1.10) - chef-config (= 14.0.210) + chef-config (= 14.0.217) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) + ffi (< 1.9.22) ffi-yajl (~> 2.2) highline (~> 1.6, >= 1.6.9) iniparse (~> 1.4) @@ -45,14 +46,14 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (14.0.210-universal-mingw32) + chef (14.0.217-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 14.0.210) + chef-config (= 14.0.217) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) - ffi (~> 1.9) + ffi (< 1.9.22) ffi-yajl (~> 2.2) highline (~> 1.6, >= 1.6.9) iniparse (~> 1.4) @@ -91,7 +92,7 @@ PATH PATH remote: chef-config specs: - chef-config (14.0.210) + chef-config (14.0.217) addressable fuzzyurl mixlib-config (~> 2.0) @@ -106,29 +107,29 @@ GEM mixlib-cli (~> 1.4) mixlib-shellout (~> 2.0) ast (2.4.0) - aws-sdk (2.11.33) - aws-sdk-resources (= 2.11.33) - aws-sdk-core (2.11.33) + aws-sdk (2.11.39) + aws-sdk-resources (= 2.11.39) + aws-sdk-core (2.11.39) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.33) - aws-sdk-core (= 2.11.33) + aws-sdk-resources (2.11.39) + aws-sdk-core (= 2.11.39) aws-sigv4 (1.0.2) azure_mgmt_resources (0.16.0) ms_rest_azure (~> 0.10.0) - backports (3.11.2) + backports (3.11.3) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) builder (3.2.3) byebug (10.0.2) chef-vault (3.3.0) - chef-zero (14.0.1) + chef-zero (14.0.6) ffi-yajl (~> 2.2) hashie (>= 2.0, < 4.0) - mixlib-log (~> 2) + mixlib-log (~> 2.0) rack (~> 2.0) uuidtools (~> 2.1) - cheffish (14.0.0) + cheffish (14.0.1) chef-zero (~> 14.0) net-ssh coderay (1.1.2) @@ -141,22 +142,22 @@ GEM docker-api (1.34.2) excon (>= 0.47.0) multi_json - domain_name (0.5.20170404) + domain_name (0.5.20180417) unf (>= 0.0.5, < 1.0.0) erubis (2.7.0) ethon (0.11.0) ffi (>= 1.3.0) excon (0.62.0) - faraday (0.14.0) + faraday (0.15.0) multipart-post (>= 1.2, < 3) faraday-cookie_jar (0.0.6) faraday (>= 0.7.4) http-cookie (~> 1.0.0) faraday_middleware (0.12.2) faraday (>= 0.7.4, < 1.0) - ffi (1.9.23) - ffi (1.9.23-x64-mingw32) - ffi (1.9.23-x86-mingw32) + ffi (1.9.21) + ffi (1.9.21-x64-mingw32) + ffi (1.9.21-x86-mingw32) ffi-win32-extensions (1.0.3) ffi ffi-yajl (2.3.1) @@ -182,7 +183,7 @@ GEM httpclient (2.8.3) inifile (3.0.0) iniparse (1.4.4) - inspec (2.1.30) + inspec (2.1.59) addressable (~> 2.4) faraday (>= 0.9.0) hashie (~> 3.4) @@ -200,7 +201,7 @@ GEM sslshake (~> 1.2) thor (~> 0.20) tomlrb (~> 1.2) - train (~> 1.3) + train (~> 1.4) ipaddress (0.8.3) iso8601 (0.9.1) jmespath (1.4.0) @@ -213,7 +214,7 @@ GEM little-plugger (~> 1.1) multi_json (~> 1.10) method_source (0.9.0) - mixlib-archive (0.4.1) + mixlib-archive (0.4.2) mixlib-log mixlib-authentication (2.0.0) mixlib-cli (1.7.0) @@ -228,7 +229,7 @@ GEM concurrent-ruby (~> 1.0) faraday (~> 0.9) timeliness (~> 0.3) - ms_rest_azure (0.10.4) + ms_rest_azure (0.10.6) concurrent-ruby (~> 1.0) faraday (~> 0.9) faraday-cookie_jar (~> 0.0.6) @@ -350,7 +351,7 @@ GEM thor (0.20.0) timeliness (0.3.8) tomlrb (1.2.6) - train (1.3.0) + train (1.4.2) aws-sdk (~> 2) azure_mgmt_resources (~> 0.15) docker-api (~> 1.26) @@ -374,7 +375,7 @@ GEM ethon (>= 0.8.0) unf (0.1.4) unf_ext - unicode-display_width (1.3.0) + unicode-display_width (1.3.2) uuidtools (2.1.5) webmock (3.3.0) addressable (>= 2.3.6) @@ -1 +1 @@ -14.0.210
\ No newline at end of file +14.0.217
\ No newline at end of file diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index d1f33d3400..ef792b2db7 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -322,6 +322,7 @@ module ChefConfig default :umask, 0022 # Valid log_levels are: + # * :trace # * :debug # * :info # * :warn diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index c8500ff6ea..9432970e58 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "14.0.210" + VERSION = "14.0.217" end # diff --git a/chef-universal-mingw32.gemspec b/chef-universal-mingw32.gemspec index ea65edbbd6..a4949db712 100644 --- a/chef-universal-mingw32.gemspec +++ b/chef-universal-mingw32.gemspec @@ -2,7 +2,6 @@ gemspec = eval(IO.read(File.expand_path("../chef.gemspec", __FILE__))) gemspec.platform = Gem::Platform.new(%w{universal mingw32}) -gemspec.add_dependency "ffi", "~> 1.9" gemspec.add_dependency "win32-api", "~> 1.5.3" gemspec.add_dependency "win32-dir", "~> 0.5.0" gemspec.add_dependency "win32-event", "~> 0.6.1" diff --git a/chef.gemspec b/chef.gemspec index b829d96e22..63e4192652 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -24,6 +24,8 @@ Gem::Specification.new do |s| s.add_dependency "mixlib-archive", "~> 0.4" s.add_dependency "ohai", "~> 14.0" + # ffi 1.9.22+1.9.23 are buggy in our spec/unit/application/client_spec.rb tests on el6/el7 + s.add_dependency "ffi", "< 1.9.22" s.add_dependency "ffi-yajl", "~> 2.2" s.add_dependency "net-ssh", "~> 4.2" s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1" diff --git a/kitchen-tests/cookbooks/base/recipes/default.rb b/kitchen-tests/cookbooks/base/recipes/default.rb index dac989cc81..ea0215ca96 100644 --- a/kitchen-tests/cookbooks/base/recipes/default.rb +++ b/kitchen-tests/cookbooks/base/recipes/default.rb @@ -25,7 +25,7 @@ yum_repository "epel" do only_if { platform_family?("rhel") } end -build_essential "install compilation tools" +build_essential include_recipe "::packages" diff --git a/lib/chef/application/apply.rb b/lib/chef/application/apply.rb index d7f2359b02..ec627ada2e 100644 --- a/lib/chef/application/apply.rb +++ b/lib/chef/application/apply.rb @@ -70,7 +70,7 @@ class Chef::Application::Apply < Chef::Application option :log_level, :short => "-l LEVEL", :long => "--log_level LEVEL", - :description => "Set the log level (debug, info, warn, error, fatal)", + :description => "Set the log level (trace, debug, info, warn, error, fatal)", :proc => lambda { |l| l.to_sym } option :help, diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 5ee1d1a4ec..28de71fa71 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -82,7 +82,7 @@ class Chef::Application::Client < Chef::Application option :log_level, :short => "-l LEVEL", :long => "--log_level LEVEL", - :description => "Set the log level (auto, debug, info, warn, error, fatal)", + :description => "Set the log level (auto, trace, debug, info, warn, error, fatal)", :proc => lambda { |l| l.to_sym } option :log_location, diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index 2294d63c21..646d68182c 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -81,7 +81,7 @@ class Chef::Application::Solo < Chef::Application option :log_level, :short => "-l LEVEL", :long => "--log_level LEVEL", - :description => "Set the log level (debug, info, warn, error, fatal)", + :description => "Set the log level (trace, debug, info, warn, error, fatal)", :proc => lambda { |l| l.to_sym } option :log_location, diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index 3f73c1cca6..7db0cb8686 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -62,7 +62,7 @@ class Chef # If the checksums are different between on-disk (current) and on-server # (remote, per manifest), do the update. This will also execute if there # is no current checksum. - if found_manifest_record[:lazy] || current_checksum != found_manifest_record["checksum"] + if current_checksum != found_manifest_record["checksum"] raw_file = @rest.streaming_request(found_manifest_record[:url]) Chef::Log.trace("Storing updated #{cache_filename} in the cache.") diff --git a/lib/chef/formatters/base.rb b/lib/chef/formatters/base.rb index 2fbe00862c..0b27b55048 100644 --- a/lib/chef/formatters/base.rb +++ b/lib/chef/formatters/base.rb @@ -137,7 +137,7 @@ class Chef def resource_failed(resource, action, exception) description = ErrorMapper.resource_failed(resource, action, exception) - display_error(description) + display_error(description) unless resource.ignore_failure && resource.ignore_failure.to_s == "quiet" end # Generic callback for any attribute/library/lwrp/recipe file in a diff --git a/lib/chef/node/mixin/immutablize_array.rb b/lib/chef/node/mixin/immutablize_array.rb index 88c7e6ffa9..ba59385d68 100644 --- a/lib/chef/node/mixin/immutablize_array.rb +++ b/lib/chef/node/mixin/immutablize_array.rb @@ -112,6 +112,7 @@ class Chef :take_while, :to_a, :to_ary, + :to_csv, :to_h, :to_plist, :to_set, diff --git a/lib/chef/node/mixin/immutablize_hash.rb b/lib/chef/node/mixin/immutablize_hash.rb index cd2bbf7bf6..71d2f754a4 100644 --- a/lib/chef/node/mixin/immutablize_hash.rb +++ b/lib/chef/node/mixin/immutablize_hash.rb @@ -88,6 +88,7 @@ class Chef :minmax, :minmax_by, :none?, + :normalize_param, :one?, :partition, :rassoc, @@ -112,6 +113,7 @@ class Chef :to_plist, :to_proc, :to_set, + :to_xml_attributes, :transform_keys, :transform_values, :uniq, diff --git a/lib/chef/null_logger.rb b/lib/chef/null_logger.rb index 927cfc0c08..5781d8e055 100644 --- a/lib/chef/null_logger.rb +++ b/lib/chef/null_logger.rb @@ -42,6 +42,9 @@ class Chef def debug(message, &block) end + def trace(message, &block) + end + def add(severity, message = nil, progname = nil) end @@ -68,5 +71,9 @@ class Chef false end + def trace? + false + end + end end diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index 302404e293..a14711e2b6 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -194,8 +194,8 @@ class Chef converge_by("fetch updates for #{new_resource.remote}") do # since we're in a local branch already, just reset to specified revision rather than merge logger.trace "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}" - git("fetch", new_resource.remote, cwd: cwd) - git("fetch", new_resource.remote, "--tags", cwd: cwd) + git("fetch", "--prune", new_resource.remote, cwd: cwd) + git("fetch", "--prune-tags", new_resource.remote, "--tags", cwd: cwd) git("reset", "--hard", target_revision, cwd: cwd) end end diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index 2692ec9f15..798abf4680 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -70,12 +70,22 @@ class Chef @candidate_version ||= get_candidate_versions end - def package_locked(name, version) - locked = shell_out_compact_timeout!("apt-mark", "showhold") - locked_packages = locked.stdout.each_line.map do |line| - line.strip - end - name.all? { |n| locked_packages.include? n } + def packages_all_locked?(names, versions) + names.all? { |n| locked_packages.include? n } + end + + def packages_all_unlocked?(names, versions) + names.all? { |n| !locked_packages.include? n } + end + + def locked_packages + @locked_packages ||= + begin + locked = shell_out_compact_timeout!("apt-mark", "showhold") + locked.stdout.each_line.map do |line| + line.strip + end + end end def install_package(name, version) diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb index 7d97bf310d..c2638fbfc1 100644 --- a/lib/chef/provider/package/zypper.rb +++ b/lib/chef/provider/package/zypper.rb @@ -75,12 +75,22 @@ class Chef end end - def package_locked(name, version) - locked = shell_out_compact_timeout!("zypper", "locks") - locked_packages = locked.stdout.each_line.map do |line| - line.split("|").shift(2).last.strip - end - name.all? { |n| locked_packages.include? n } + def packages_all_locked?(names, versions) + names.all? { |n| locked_packages.include? n } + end + + def packages_all_unlocked?(names, versions) + names.all? { |n| !locked_packages.include? n } + end + + def locked_packages + @locked_packages ||= + begin + locked = shell_out_compact_timeout!("zypper", "locks") + locked.stdout.each_line.map do |line| + line.split("|").shift(2).last.strip + end + end end def load_current_resource diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 7cfb907795..05349b80e7 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -515,15 +515,16 @@ class Chef # # Whether to ignore failures. If set to `true`, and this resource when an # action is run, the resource will be marked as failed but no exception will - # be thrown (and no error will be output). Defaults to `false`. + # be thrown (and no error will be output). Defaults to `false`. If set to + # `:quiet` or `'quiet'`, the normal error trace will be suppressed. # # TODO ignore_failure and retries seem to be mutually exclusive; I doubt # that was intended. # - # @param arg [Boolean] Whether to ignore failures. + # @param arg [Boolean, String, Symbol] Whether to ignore failures. # @return Whether this resource will ignore failures. # - property :ignore_failure, [ TrueClass, FalseClass ], default: false, desired_state: false + property :ignore_failure, [ true, false, :quiet, "quiet" ], default: false, desired_state: false # # Make this resource into an exact (shallow) copy of the other resource. diff --git a/lib/chef/resource/apt_preference.rb b/lib/chef/resource/apt_preference.rb index e546a54225..0169fb73c2 100644 --- a/lib/chef/resource/apt_preference.rb +++ b/lib/chef/resource/apt_preference.rb @@ -25,9 +25,7 @@ class Chef resource_name :apt_preference provides(:apt_preference) { true } - description "The apt_preference resource allows for the creation of APT preference"\ - " files. Preference files are used to control which package versions and"\ - " sources are prioritized during installation." + description "The apt_preference resource allows for the creation of APT preference files. Preference files are used to control which package versions and sources are prioritized during installation." introduced "13.3" property :package_name, String, diff --git a/lib/chef/resource/apt_repository.rb b/lib/chef/resource/apt_repository.rb index 236e9477e0..0ed38e61d3 100644 --- a/lib/chef/resource/apt_repository.rb +++ b/lib/chef/resource/apt_repository.rb @@ -24,8 +24,7 @@ class Chef resource_name :apt_repository provides(:apt_repository) { true } - description "Use the apt_repository resource to specify additional APT repositories."\ - " Adding a new repository will update APT package cache immediately." + description "Use the apt_repository resource to specify additional APT repositories. Adding a new repository will update the APT package cache immediately." introduced "12.9" # There's a pile of [ String, nil, FalseClass ] types in these properties. @@ -35,22 +34,50 @@ class Chef # to allow that so don't refactor this however tempting it is property :repo_name, String, regex: [/^[^\/]+$/], + description: "The name of the repository to configure, if it differs from the name of the resource block. The value of this setting must not contain spaces.", validation_message: "repo_name property cannot contain a forward slash '/'", name_property: true - property :uri, String - property :distribution, [ String, nil, FalseClass ], default: lazy { node["lsb"]["codename"] } - property :components, Array, default: lazy { [] } - property :arch, [String, nil, FalseClass] - property :trusted, [TrueClass, FalseClass], default: false - # whether or not to add the repository as a source repo, too - property :deb_src, [TrueClass, FalseClass], default: false - property :keyserver, [String, nil, FalseClass], default: "keyserver.ubuntu.com" - property :key, [String, Array, nil, FalseClass], default: lazy { [] }, coerce: proc { |x| x ? Array(x) : x } - property :key_proxy, [String, nil, FalseClass] - - property :cookbook, [String, nil, FalseClass], desired_state: false - property :cache_rebuild, [TrueClass, FalseClass], default: true, desired_state: false + property :uri, String, + description: "The base of the Debian distribution." + + property :distribution, [ String, nil, FalseClass ], + description: "Usually a distribution’s codename, such as trusty, xenial or bionic. Default value: the codename of the node’s distro.", + default: lazy { node["lsb"]["codename"] } + + property :components, Array, + description: "Package groupings, such as ‘main’ and ‘stable’.", + default: lazy { [] } + + property :arch, [String, nil, FalseClass], + description: "Constrain packages to a particular CPU architecture such as 'i386' or 'amd64'." + + property :trusted, [TrueClass, FalseClass], + description: "Determines whether you should treat all packages from this repository as authenticated regardless of signature.", + default: false + + property :deb_src, [TrueClass, FalseClass], + description: "Determines whether or not to add the repository as a source repo as well.", + default: false + + property :keyserver, [String, nil, FalseClass], + description: "The GPG keyserver where the key for the repo should be retrieved.", + default: "keyserver.ubuntu.com" + + property :key, [String, Array, nil, FalseClass], + description: "If a keyserver is provided, this is assumed to be the fingerprint; otherwise it can be either the URI of GPG key for the repo, or a cookbook_file.", + default: lazy { [] }, coerce: proc { |x| x ? Array(x) : x } + + property :key_proxy, [String, nil, FalseClass], + description: "If set, a specified proxy is passed to GPG via http-proxy=." + + property :cookbook, [String, nil, FalseClass], + description: "If key should be a cookbook_file, specify a cookbook where the key is located for files/default. Default value is nil, so it will use the cookbook where the resource is used.", + desired_state: false + + property :cache_rebuild, [TrueClass, FalseClass], + description: "Determines whether to rebuild the APT package cache.", + default: true, desired_state: false default_action :add allowed_actions :add, :remove diff --git a/lib/chef/resource/apt_update.rb b/lib/chef/resource/apt_update.rb index a302ff252b..04a9407813 100644 --- a/lib/chef/resource/apt_update.rb +++ b/lib/chef/resource/apt_update.rb @@ -29,7 +29,9 @@ class Chef # allow bare apt_update with no name property :name, String, default: "" - property :frequency, Integer, default: 86_400 + property :frequency, Integer, + description: "Determines how frequently (in seconds) APT repository updates are made. Use this property when the :periodic action is specified.", + default: 86_400 default_action :periodic allowed_actions :update, :periodic diff --git a/lib/chef/resource/bash.rb b/lib/chef/resource/bash.rb index 03fdd0e396..22a84f4134 100644 --- a/lib/chef/resource/bash.rb +++ b/lib/chef/resource/bash.rb @@ -22,12 +22,7 @@ require "chef/provider/script" class Chef class Resource class Bash < Chef::Resource::Script - description "Use the bash resource to execute scripts using the Bash interpreter."\ - " This resource may also use any of the actions and properties that are"\ - " available to the execute resource. Commands that are executed with this"\ - " resource are (by their nature) not idempotent, as they are typically"\ - " unique to the environment in which they are run. Use not_if and only_if"\ - " to guard this resource for idempotence." + description "Use the bash resource to execute scripts using the Bash interpreter. This resource may also use any of the actions and properties that are available to the execute resource. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for idempotence." def initialize(name, run_context = nil) super diff --git a/lib/chef/resource/batch.rb b/lib/chef/resource/batch.rb index 4e6d67aa2d..e3bff8145c 100644 --- a/lib/chef/resource/batch.rb +++ b/lib/chef/resource/batch.rb @@ -23,13 +23,7 @@ class Chef class Batch < Chef::Resource::WindowsScript provides :batch - description "Use the batch resource to execute a batch script using the cmd.exe"\ - " interpreter on Windows. The batch resource creates and executes a"\ - " temporary file (similar to how the script resource behaves), rather"\ - " than running the command inline. Commands that are executed with this"\ - " resource are (by their nature) not idempotent, as they are typically"\ - " unique to the environment in which they are run. Use not_if and only_if"\ - " to guard this resource for idempotence." + description "Use the batch resource to execute a batch script using the cmd.exe interpreter on Windows. The batch resource creates and executes a temporary file (similar to how the script resource behaves), rather than running the command inline. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use not_if and only_if to guard this resource for idempotence." def initialize(name, run_context = nil) super(name, run_context, nil, "cmd.exe") diff --git a/lib/chef/resource/bff_package.rb b/lib/chef/resource/bff_package.rb index 62838cfd60..8750cb0b2b 100644 --- a/lib/chef/resource/bff_package.rb +++ b/lib/chef/resource/bff_package.rb @@ -24,10 +24,7 @@ class Chef resource_name :bff_package provides :bff_package - description "Use the bff_package resource to manage packages for the AIX platform"\ - " using the installp utility. When a package is installed from a local"\ - " file, it must be added to the node using the remote_file or cookbook_file"\ - " resources." + description "Use the bff_package resource to manage packages for the AIX platform using the installp utility. When a package is installed from a local file, it must be added to the node using the remote_file or cookbook_file resources." introduced "12.0" end end diff --git a/lib/chef/resource/breakpoint.rb b/lib/chef/resource/breakpoint.rb index 1ccc4311b3..8af3edbe22 100644 --- a/lib/chef/resource/breakpoint.rb +++ b/lib/chef/resource/breakpoint.rb @@ -24,13 +24,7 @@ class Chef provides :breakpoint resource_name :breakpoint - description "Use the breakpoint resource to add breakpoints to recipes. Run the"\ - " chef-shell in chef-client mode, and then use those breakpoints to debug"\ - " recipes. Breakpoints are ignored by the chef-client during an actual"\ - " chef-client run. That said, breakpoints are typically used to debug"\ - " recipes only when running them in a non-production environment, after"\ - " which they are removed from those recipes before the parent cookbook is"\ - " uploaded to the Chef server." + description "Use the breakpoint resource to add breakpoints to recipes. Run the chef-shell in chef-client mode, and then use those breakpoints to debug recipes. Breakpoints are ignored by the chef-client during an actual chef-client run. That said, breakpoints are typically used to debug recipes only when running them in a non-production environment, after which they are removed from those recipes before the parent cookbook is uploaded to the Chef server." introduced "12.0" default_action :break diff --git a/lib/chef/resource/build_essential.rb b/lib/chef/resource/build_essential.rb index 8d32af9684..7c549fb236 100644 --- a/lib/chef/resource/build_essential.rb +++ b/lib/chef/resource/build_essential.rb @@ -22,9 +22,12 @@ class Chef resource_name :build_essential provides(:build_essential) { true } - description "Use the build_essential resource to install packages required for compiling C software from source" + description "Use the build_essential resource to install packages required for compiling C software from source." introduced "14.0" + # this allows us to use build_essential without setting a name + property :name, String, default: "" + property :compile_time, [TrueClass, FalseClass], description: "Install build essential packages at compile time.", default: false diff --git a/lib/chef/resource/cab_package.rb b/lib/chef/resource/cab_package.rb index 7c5da016c9..a90ddc6891 100644 --- a/lib/chef/resource/cab_package.rb +++ b/lib/chef/resource/cab_package.rb @@ -27,13 +27,13 @@ class Chef resource_name :cab_package provides :cab_package - description "Use the cab_package resource to install or remove Microsoft Windows"\ - " cabinet (.cab) packages." + description "Use the cab_package resource to install or remove Microsoft Windows cabinet (.cab) packages." introduced "12.15" allowed_actions :install, :remove property :source, String, + description: "The local file path or URL for the CAB package.", coerce: (proc do |s| unless s.nil? uri_scheme?(s) ? s : Chef::Util::PathHelper.canonical_path(s, false) diff --git a/lib/chef/resource/chocolatey_package.rb b/lib/chef/resource/chocolatey_package.rb index cf8e67d708..5f63f4b5b5 100644 --- a/lib/chef/resource/chocolatey_package.rb +++ b/lib/chef/resource/chocolatey_package.rb @@ -24,18 +24,26 @@ class Chef resource_name :chocolatey_package provides :chocolatey_package - description "Use the chocolatey_package resource to manage packages using Chocolatey"\ - " on the Microsoft Windows platform." + description "Use the chocolatey_package resource to manage packages using Chocolatey on the Microsoft Windows platform." introduced "12.7" allowed_actions :install, :upgrade, :remove, :purge, :reconfig # windows can't take Array options yet - property :options, String + property :options, String, + description: "One (or more) additional options that are passed to the command." - property :package_name, [String, Array], coerce: proc { |x| [x].flatten } - property :version, [String, Array], coerce: proc { |x| [x].flatten } - property :returns, [Integer, Array], default: [ 0 ], desired_state: false + property :package_name, [String, Array], + description: "The name of the package. Default value: the name of the resource block See “Syntax” section above for more information.", + coerce: proc { |x| [x].flatten } + + property :version, [String, Array], + description: "The version of a package to be installed or upgraded.", + coerce: proc { |x| [x].flatten } + + property :returns, [Integer, Array], + description: "The exit code(s) returned a chocolatey package that indicate success.", + default: [ 0 ], desired_state: false end end end diff --git a/lib/chef/resource/cookbook_file.rb b/lib/chef/resource/cookbook_file.rb index 593cb5e137..0caa9d0553 100644 --- a/lib/chef/resource/cookbook_file.rb +++ b/lib/chef/resource/cookbook_file.rb @@ -29,20 +29,14 @@ class Chef resource_name :cookbook_file - description "Use the cookbook_file resource to transfer files from a sub-directory"\ - " of COOKBOOK_NAME/files/ to a specified path located on a host that is"\ - " running the chef-client. The file is selected according to file specificity,"\ - " which allows different source files to be used based on the hostname, host"\ - " platform (operating system, distro, or as appropriate), or platform version."\ - " Files that are located in the COOKBOOK_NAME/files/default sub-directory may be"\ - " used on any platform.\n\n"\ - "During a chef-client run, the checksum for each local file is calculated and then"\ - " compared against the checksum for the same file as it currently exists in the"\ - " cookbook on the Chef server. A file is not transferred when the checksums match."\ - " Only files that require an update are transferred from the Chef server to a node." + description "Use the cookbook_file resource to transfer files from a sub-directory of COOKBOOK_NAME/files/ to a specified path located on a host that is running the chef-client. The file is selected according to file specificity, which allows different source files to be used based on the hostname, host platform (operating system, distro, or as appropriate), or platform version. Files that are located in the COOKBOOK_NAME/files/default sub-directory may be used on any platform.\n\nDuring a chef-client run, the checksum for each local file is calculated and then compared against the checksum for the same file as it currently exists in the cookbook on the Chef server. A file is not transferred when the checksums match. Only files that require an update are transferred from the Chef server to a node." - property :source, [ String, Array ], default: lazy { ::File.basename(name) } - property :cookbook, String + property :source, [ String, Array ], + description: "The name of the file in COOKBOOK_NAME/files/default or the path to a file located in COOKBOOK_NAME/files. The path must include the file name and its extension. This can be used to distribute specific files depending upon the platform used.", + default: lazy { ::File.basename(name) } + + property :cookbook, String, + description: "The cookbook in which a file is located (if it is not located in the current cookbook)." default_action :create end diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb index 3c11d83d9a..ea6d692709 100644 --- a/lib/chef/resource/cron.rb +++ b/lib/chef/resource/cron.rb @@ -26,9 +26,7 @@ class Chef resource_name :cron provides :cron - description "Use the cron resource to manage cron entries for time-based job scheduling."\ - " Properties for a schedule will default to * if not provided. The cron resource"\ - " requires access to a crontab program, typically cron." + description "Use the cron resource to manage cron entries for time-based job scheduling. Properties for a schedule will default to * if not provided. The cron resource requires access to a crontab program, typically cron." state_attrs :minute, :hour, :day, :month, :weekday, :user diff --git a/lib/chef/resource/launchd.rb b/lib/chef/resource/launchd.rb index 1addffe404..9161efa6ea 100644 --- a/lib/chef/resource/launchd.rb +++ b/lib/chef/resource/launchd.rb @@ -31,8 +31,8 @@ class Chef allowed_actions :create, :create_if_missing, :delete, :enable, :disable, :restart property :label, String, identity: true, name_property: true - property :backup, [Integer, FalseClass] - property :cookbook, String + property :backup, [Integer, FalseClass], desired_state: false + property :cookbook, String, desired_state: false property :group, [String, Integer] property :plist_hash, Hash property :mode, [String, Integer] diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb index c4ab1e0a75..487befde2e 100644 --- a/lib/chef/resource/link.rb +++ b/lib/chef/resource/link.rb @@ -47,11 +47,25 @@ class Chef super end - property :target_file, String, name_property: true, identity: true - property :to, String - property :link_type, [String, Symbol], coerce: proc { |arg| arg.kind_of?(String) ? arg.to_sym : arg }, equal_to: [ :symbolic, :hard ], default: :symbolic - property :group, [String, Integer], regex: [Chef::Config[:group_valid_regex]] - property :user, [String, Integer], regex: [Chef::Config[:user_valid_regex]] + property :target_file, String, + description: "The name of the link. Default value: the name of the resource block See “Syntax” section above for more information.", + name_property: true, identity: true + + property :to, String, + description: "The actual file to which the link is to be created." + + property :link_type, [String, Symbol], + description: "The type of link: :symbolic or :hard.", + coerce: proc { |arg| arg.kind_of?(String) ? arg.to_sym : arg }, + equal_to: [ :symbolic, :hard ], default: :symbolic + + property :group, [String, Integer], + description: "A string or ID that identifies the group associated with a symbolic link.", + regex: [Chef::Config[:group_valid_regex]] + + property :owner, [String, Integer], + description: "The owner associated with a symbolic link.", + regex: [Chef::Config[:user_valid_regex]] # make link quack like a file (XXX: not for public consumption) def path diff --git a/lib/chef/resource/ohai_hint.rb b/lib/chef/resource/ohai_hint.rb index 3b9f49385d..6eb36aea13 100644 --- a/lib/chef/resource/ohai_hint.rb +++ b/lib/chef/resource/ohai_hint.rb @@ -33,7 +33,7 @@ class Chef property :compile_time, [TrueClass, FalseClass], description: "Should the resource execute during the compile time phase", - default: true + default: true, desired_state: false action :create do description "Create an Ohai hint file" diff --git a/lib/chef/resource/openssl_rsa_private_key.rb b/lib/chef/resource/openssl_rsa_private_key.rb index 968eeded4c..be4c85bcbb 100644 --- a/lib/chef/resource/openssl_rsa_private_key.rb +++ b/lib/chef/resource/openssl_rsa_private_key.rb @@ -65,7 +65,7 @@ class Chef property :force, [TrueClass, FalseClass], description: "Force creating the key even if the existing key exists.", - default: false + default: false, desired_state: false action :create do return if new_resource.force || priv_key_file_valid?(new_resource.path, new_resource.key_pass) diff --git a/lib/chef/resource/registry_key.rb b/lib/chef/resource/registry_key.rb index 1ae3f81492..84abb98699 100644 --- a/lib/chef/resource/registry_key.rb +++ b/lib/chef/resource/registry_key.rb @@ -28,7 +28,6 @@ class Chef description "Use the registry_key resource to create and delete registry keys in Microsoft Windows." introduced "11.0" - identity_attr :key state_attrs :values default_action :create @@ -67,17 +66,10 @@ class Chef def initialize(name, run_context = nil) super - @key = name @values, @unscrubbed_values = [], [] end - def key(arg = nil) - set_or_return( - :key, - arg, - :kind_of => String - ) - end + property :key, String, name_property: true, identity: true def values(arg = nil) if not arg.nil? diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb index 677f358cc2..14e4f4a497 100644 --- a/lib/chef/resource/remote_directory.rb +++ b/lib/chef/resource/remote_directory.rb @@ -41,16 +41,11 @@ class Chef def initialize(name, run_context = nil) super @path = name - @source = ::File.basename(name) @delete = false @recursive = true - @purge = false - @files_backup = 5 @files_owner = nil @files_group = nil @files_mode = 0644 unless Chef::Platform.windows? - @overwrite = true - @cookbook = nil end if Chef::Platform.windows? @@ -58,29 +53,11 @@ class Chef rights_attribute(:files_rights) end - def source(args = nil) - set_or_return( - :source, - args, - :kind_of => String - ) - end - - def files_backup(arg = nil) - set_or_return( - :files_backup, - arg, - :kind_of => [ Integer, FalseClass ] - ) - end - - def purge(arg = nil) - set_or_return( - :purge, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end + property :source, String, default: lazy { ::File.basename(path) } + property :files_backup, [ Integer, FalseClass ], default: 5, desired_state: false + property :purge, [ TrueClass, FalseClass ], default: false, desired_state: false + property :overwrite, [ TrueClass, FalseClass ], default: false + property :cookbook, String def files_group(arg = nil) set_or_return( @@ -105,23 +82,6 @@ class Chef :regex => Chef::Config[:user_valid_regex] ) end - - def overwrite(arg = nil) - set_or_return( - :overwrite, - arg, - :kind_of => [ TrueClass, FalseClass ] - ) - end - - def cookbook(args = nil) - set_or_return( - :cookbook, - args, - :kind_of => String - ) - end - end end end diff --git a/lib/chef/resource/rhsm_register.rb b/lib/chef/resource/rhsm_register.rb index 05e748e98d..0e478eff38 100644 --- a/lib/chef/resource/rhsm_register.rb +++ b/lib/chef/resource/rhsm_register.rb @@ -58,7 +58,7 @@ class Chef property :force, [TrueClass, FalseClass], description: "If true, the system will be registered even if it is already registered. Normally, any register operations will fail if the machine is has already registered.", - default: false + default: false, desired_state: false action :register do description "Register the node with RHSM" @@ -88,7 +88,7 @@ class Chef sensitive new_resource.sensitive command register_command action :run - not_if { registered_with_rhsm? } + not_if { registered_with_rhsm? } unless new_resource.force end yum_package "katello-agent" do diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb index 2fef1a1466..d8b4dd304a 100644 --- a/lib/chef/resource/scm.rb +++ b/lib/chef/resource/scm.rb @@ -36,8 +36,8 @@ class Chef property :enable_submodules, [TrueClass, FalseClass], default: false property :enable_checkout, [TrueClass, FalseClass], default: true property :remote, String, default: "origin" - property :ssh_wrapper, String - property :timeout, Integer + property :ssh_wrapper, String, desired_state: false + property :timeout, Integer, desired_state: false property :checkout_branch, String, default: "deploy" property :environment, [Hash, nil], default: nil diff --git a/lib/chef/resource/subversion.rb b/lib/chef/resource/subversion.rb index 02b9da0a42..d67fd22834 100644 --- a/lib/chef/resource/subversion.rb +++ b/lib/chef/resource/subversion.rb @@ -22,40 +22,27 @@ require "chef/resource/scm" class Chef class Resource class Subversion < Chef::Resource::Scm - description "Use the subversion resource to manage source control resources that"\ - " exist in a Subversion repository." + description "Use the subversion resource to manage source control resources that exist in a Subversion repository." allowed_actions :force_export - def initialize(name, run_context = nil) - super - @svn_arguments = "--no-auth-cache" - @svn_info_args = "--no-auth-cache" - end + property :svn_arguments, [String, nil, FalseClass], + description: "The extra arguments that are passed to the Subversion command.", + coerce: proc { |v| v == false ? nil : v }, # coerce false to nil + default: "--no-auth-cache" + + property :svn_info_args, [String, nil, FalseClass], + description: "Use when the svn info command is used by the chef-client and arguments need to be passed. The svn_arguments command does not work when the svn info command is used.", + coerce: proc { |v| v == false ? nil : v }, # coerce false to nil + default: "--no-auth-cache" + + property :svn_binary, String, + description: "The location of the svn binary." # Override exception to strip password if any, so it won't appear in logs and different Chef notifications def custom_exception_message(e) "#{self} (#{defined_at}) had an error: #{e.class.name}: #{svn_password ? e.message.gsub(svn_password, "[hidden_password]") : e.message}" end - - def svn_arguments(arg = nil) - @svn_arguments, arg = nil, nil if arg == false - set_or_return( - :svn_arguments, - arg, - :kind_of => String - ) - end - - def svn_info_args(arg = nil) - @svn_info_args, arg = nil, nil if arg == false - set_or_return( - :svn_info_args, - arg, - :kind_of => String) - end - - property :svn_binary, String end end end diff --git a/lib/chef/resource/sysctl.rb b/lib/chef/resource/sysctl.rb index bf6864db31..aab1c055c1 100644 --- a/lib/chef/resource/sysctl.rb +++ b/lib/chef/resource/sysctl.rb @@ -38,7 +38,7 @@ class Chef property :ignore_error, [TrueClass, FalseClass], description: "Ignore any errors when setting the value on the command line.", - default: false + default: false, desired_state: false property :value, [Array, String, Integer, Float], description: "The value to set.", @@ -63,14 +63,12 @@ class Chef end end - def get_sysctl_value(key) - o = shell_out("sysctl -n -e #{key}") - raise "Unknown sysctl key #{key}!" if o.error? - o.stdout.to_s.tr("\t", " ").strip - end - + # shellout to systctl to get the current value + # ignore missing keys by using '-e' + # convert tabs to spaces since systctl tab deliminates multivalue parameters + # strip the newline off the end of the output as well load_current_value do - value get_sysctl_value(key) + value shell_out!("sysctl -n -e #{key}").stdout.tr("\t", " ").strip end action :apply do @@ -84,7 +82,10 @@ class Chef content "#{new_resource.key} = #{new_resource.value}" end - execute "sysctl -p" + execute "Load sysctl values" do + command "sysctl #{'-e ' if new_resource.ignore_error}-p" + action :run + end end end @@ -96,7 +97,10 @@ class Chef action :delete end - execute "sysctl -p" + execute "Load sysctl values" do + command "sysctl -p" + action :run + end end end end diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 637fbc08a9..adb6557fd5 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require "chef/version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("14.0.210") + VERSION = Chef::VersionString.new("14.0.217") end # diff --git a/spec/support/shared/examples/client.rb b/spec/support/shared/examples/client.rb index 8ad9f6189a..6479c9d582 100644 --- a/spec/support/shared/examples/client.rb +++ b/spec/support/shared/examples/client.rb @@ -23,6 +23,7 @@ shared_examples "a completed run" do let(:file) { instance_double(File) } before do + allow(File).to receive(:read).and_call_original Chef::Config[:chef_guid_path] = chef_guid_path Chef::Config[:chef_guid] = nil end diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 0cd3cb3995..de6972b625 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -447,6 +447,7 @@ describe Chef::Application::Client, "configure_chef" do before do @original_argv = ARGV.dup ARGV.clear + allow(::File).to receive(:read).and_call_original allow(::File).to receive(:read).with(Chef::Config.platform_specific_path("/etc/chef/client.rb")).and_return("") app.configure_chef end diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 273f605905..76be387c22 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -101,6 +101,7 @@ describe Chef::Application do @app = Chef::Application.new allow(@app).to receive(:parse_options).and_return(true) + allow(::File).to receive(:read).with("/proc/sys/crypto/fips_enabled").and_call_original expect(Chef::Config).to receive(:export_proxies).and_return(true) end diff --git a/spec/unit/formatters/base_spec.rb b/spec/unit/formatters/base_spec.rb index 30c7757e5a..19182554f9 100644 --- a/spec/unit/formatters/base_spec.rb +++ b/spec/unit/formatters/base_spec.rb @@ -23,6 +23,14 @@ describe Chef::Formatters::Base do let(:out) { StringIO.new } let(:err) { StringIO.new } let(:formatter) { Chef::Formatters::Base.new(out, err) } + let(:exception) do + # An exception with a real backtrace. + begin + raise EOFError + rescue EOFError => exc + end + exc + end it "starts with an indentation of zero" do expect(formatter.output.indent).to eql(0) @@ -45,27 +53,48 @@ describe Chef::Formatters::Base do end it "humanizes EOFError exceptions for #registration_failed" do - formatter.registration_failed("foo.example.com", EOFError.new, double("Chef::Config")) + formatter.registration_failed("foo.example.com", exception, double("Chef::Config")) expect(out.string).to match(/Received an EOF on transport socket/) end it "humanizes EOFError exceptions for #node_load_failed" do - formatter.node_load_failed("foo.example.com", EOFError.new, double("Chef::Config")) + formatter.node_load_failed("foo.example.com", exception, double("Chef::Config")) expect(out.string).to match(/Received an EOF on transport socket/) end it "humanizes EOFError exceptions for #run_list_expand_failed" do - formatter.run_list_expand_failed(double("Chef::Node"), EOFError.new) + formatter.run_list_expand_failed(double("Chef::Node"), exception) expect(out.string).to match(/Received an EOF on transport socket/) end it "humanizes EOFError exceptions for #cookbook_resolution_failed" do - formatter.run_list_expand_failed(double("Expanded Run List"), EOFError.new) + formatter.run_list_expand_failed(double("Expanded Run List"), exception) expect(out.string).to match(/Received an EOF on transport socket/) end it "humanizes EOFError exceptions for #cookbook_sync_failed" do - formatter.cookbook_sync_failed("foo.example.com", EOFError.new) + formatter.cookbook_sync_failed("foo.example.com", exception) expect(out.string).to match(/Received an EOF on transport socket/) end + + it "outputs error information for failed resources with ignore_failure true" do + resource = Chef::Resource::RubyBlock.new("test") + resource.ignore_failure(true) + formatter.resource_failed(resource, :run, exception) + expect(out.string).to match(/Error executing action `run` on resource 'ruby_block\[test\]'/) + end + + it "does not output error information for failed resources with ignore_failure :quiet" do + resource = Chef::Resource::RubyBlock.new("test") + resource.ignore_failure(:quiet) + formatter.resource_failed(resource, :run, exception) + expect(out.string).to eq("") + end + + it "does not output error information for failed resources with ignore_failure 'quiet'" do + resource = Chef::Resource::RubyBlock.new("test") + resource.ignore_failure("quiet") + formatter.resource_failed(resource, :run, exception) + expect(out.string).to eq("") + end end diff --git a/spec/unit/provider/git_spec.rb b/spec/unit/provider/git_spec.rb index cacee0baaa..c32c2ee146 100644 --- a/spec/unit/provider/git_spec.rb +++ b/spec/unit/provider/git_spec.rb @@ -425,9 +425,9 @@ SHAS it "runs a sync command with default options" do expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - expected_cmd1 = "git fetch origin" + expected_cmd1 = "git fetch --prune origin" expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") - expected_cmd2 = "git fetch origin --tags" + expected_cmd2 = "git fetch --prune-tags origin --tags" expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") expected_cmd3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" expect(@provider).to receive(:shell_out!).with(expected_cmd3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @@ -440,12 +440,12 @@ SHAS @resource.group("thisis") expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - expected_cmd1 = "git fetch origin" + expected_cmd1 = "git fetch --prune origin" expect(@provider).to receive(:shell_out!).with(expected_cmd1, :cwd => "/my/deploy/dir", :user => "whois", :group => "thisis", :log_tag => "git[web2.0 app]", :environment => { "HOME" => "/home/whois" }) - expected_cmd2 = "git fetch origin --tags" + expected_cmd2 = "git fetch --prune-tags origin --tags" expect(@provider).to receive(:shell_out!).with(expected_cmd2, :cwd => "/my/deploy/dir", :user => "whois", :group => "thisis", :log_tag => "git[web2.0 app]", @@ -461,9 +461,9 @@ SHAS it "configures remote tracking branches when remote is ``origin''" do @resource.remote "origin" expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - fetch_command1 = "git fetch origin" + fetch_command1 = "git fetch --prune origin" expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") - fetch_command2 = "git fetch origin --tags" + fetch_command2 = "git fetch --prune-tags origin --tags" expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") @@ -473,9 +473,9 @@ SHAS it "configures remote tracking branches when remote is not ``origin''" do @resource.remote "opscode" expect(@provider).to receive(:setup_remote_tracking_branches).with(@resource.remote, @resource.repository) - fetch_command1 = "git fetch opscode" + fetch_command1 = "git fetch --prune opscode" expect(@provider).to receive(:shell_out!).with(fetch_command1, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") - fetch_command2 = "git fetch opscode --tags" + fetch_command2 = "git fetch --prune-tags opscode --tags" expect(@provider).to receive(:shell_out!).with(fetch_command2, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") fetch_command3 = "git reset --hard d35af14d41ae22b19da05d7d03a0bafc321b244c" expect(@provider).to receive(:shell_out!).with(fetch_command3, :cwd => "/my/deploy/dir", :log_tag => "git[web2.0 app]") diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index 78c517b9a0..0700f69eb4 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -422,7 +422,6 @@ mpg123 1.12.1-0ubuntu1 ) expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked") - @provider.new_resource.package_name = ["irssi"] @provider.action_lock end end @@ -444,7 +443,6 @@ mpg123 1.12.1-0ubuntu1 ) expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked") - @provider.new_resource.package_name = ["irssi"] @provider.action_unlock end end diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb index 3f172dc370..819278a795 100644 --- a/spec/unit/provider/package/zypper_spec.rb +++ b/spec/unit/provider/package/zypper_spec.rb @@ -267,6 +267,40 @@ describe Chef::Provider::Package::Zypper do end end + describe "action_lock" do + it "should lock if the package is not already locked" do + prov = provider + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "--non-interactive", "info", new_resource.package_name + ).and_return(status) + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "locks" + ).and_return(instance_double( + Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)" + )) + expect(prov).to receive(:lock_package).with(["cups"], [nil]) + + prov.load_current_resource + prov.action_lock + end + + it "should not lock if the package is already locked" do + prov = provider + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "--non-interactive", "info", new_resource.package_name + ).and_return(status) + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "locks" + ).and_return(instance_double( + Mixlib::ShellOut, stdout: "1 | cups | package | (any)" + )) + expect(prov).to_not receive(:lock_package) + + prov.load_current_resource + prov.action_lock + end + end + describe "lock_package" do it "should run zypper addlock with the package name" do shell_out_expectation!( @@ -290,6 +324,39 @@ describe Chef::Provider::Package::Zypper do end end + describe "action_unlock" do + it "should unlock if the package is not already unlocked" do + prov = provider + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "--non-interactive", "info", new_resource.package_name + ).and_return(status) + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "locks" + ).and_return(instance_double( + Mixlib::ShellOut, stdout: "1 | cups | package | (any)" + )) + expect(prov).to receive(:unlock_package).with(["cups"], [nil]) + + prov.load_current_resource + provider.action_unlock + end + it "should not unlock if the package is already unlocked" do + prov = provider + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "--non-interactive", "info", new_resource.package_name + ).and_return(status) + allow(prov).to receive(:shell_out_compact_timeout!).with( + "zypper", "locks" + ).and_return(instance_double( + Mixlib::ShellOut, stdout: "1 | somethingelse | package | (any)" + )) + expect(prov).to_not receive(:unlock_package) + + prov.load_current_resource + provider.action_unlock + end + end + describe "unlock_package" do it "should run zypper removelock with the package name" do shell_out_expectation!( diff --git a/spec/unit/resource/build_essential_spec.rb b/spec/unit/resource/build_essential_spec.rb index dff94e6bdc..5c25d3e961 100644 --- a/spec/unit/resource/build_essential_spec.rb +++ b/spec/unit/resource/build_essential_spec.rb @@ -28,4 +28,12 @@ describe Chef::Resource::BuildEssential do it "has a default action of install" do expect(resource.action).to eql([:install]) end + + context "when not settting a resource name" do + let(:resource) { Chef::Resource::BuildEssential.new(nil) } + + it "the name defaults to an empty string" do + expect(resource.name).to eql("") + end + end end diff --git a/spec/unit/resource/registry_key_spec.rb b/spec/unit/resource/registry_key_spec.rb index d8eea74ed4..1f32a00210 100644 --- a/spec/unit/resource/registry_key_spec.rb +++ b/spec/unit/resource/registry_key_spec.rb @@ -195,6 +195,6 @@ describe Chef::Resource::RegistryKey, "state" do it "returns scrubbed values" do resource.values([ { :name => "poosh", :type => :binary, :data => 255.chr * 1 } ]) - expect(resource.state_for_resource_reporter).to eql( { :values => [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] } ) + expect(resource.state_for_resource_reporter[:values]).to eql( [{ :name => "poosh", :type => :binary, :data => "a8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89" }] ) end end diff --git a/spec/unit/resource/remote_directory_spec.rb b/spec/unit/resource/remote_directory_spec.rb index c016213c4a..8ec2d80bc8 100644 --- a/spec/unit/resource/remote_directory_spec.rb +++ b/spec/unit/resource/remote_directory_spec.rb @@ -22,7 +22,7 @@ describe Chef::Resource::RemoteDirectory do let(:resource) { Chef::Resource::RemoteDirectory.new("/etc/dunk") } - it "sets the path to the first argument to new" do + it "path is the name property" do expect(resource.path).to eql("/etc/dunk") end @@ -32,7 +32,8 @@ describe Chef::Resource::RemoteDirectory do end it "has the basename of the remote directory resource as the default source" do - expect(resource.source).to eql("dunk") + resource.path "/foo/bar" + expect(resource.source).to eql("bar") end it "accepts a number for the remote files backup" do @@ -45,7 +46,7 @@ describe Chef::Resource::RemoteDirectory do expect(resource.files_backup).to eql(false) end - it "accepts 3 or 4 digets for the files_mode" do + it "accepts 3 or 4 digits for the files_mode" do resource.files_mode 100 expect(resource.files_mode).to eql(100) resource.files_mode 1000 diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index fe853922a1..523f9f7365 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -555,6 +555,16 @@ end resource.ignore_failure(true) expect(resource.ignore_failure).to eq(true) end + + it "should allow you to set quiet ignore_failure as a symbol" do + resource.ignore_failure(:quiet) + expect(resource.ignore_failure).to eq(:quiet) + end + + it "should allow you to set quiet ignore_failure as a string" do + resource.ignore_failure("quiet") + expect(resource.ignore_failure).to eq("quiet") + end end describe "retries" do |