diff options
221 files changed, 1076 insertions, 903 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 44951bb0e3..86518b5ced 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,20 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 14.0.163 --> -## [v14.0.163](https://github.com/chef/chef/tree/v14.0.163) (2018-03-24) +<!-- latest_release 14.0.166 --> +## [v14.0.166](https://github.com/chef/chef/tree/v14.0.166) (2018-03-26) #### Merged Pull Requests -- Add swap_file resource from the swap cookbook [#6990](https://github.com/chef/chef/pull/6990) ([tas50](https://github.com/tas50)) +- RFC-102: Deprecation warning in resources [#7050](https://github.com/chef/chef/pull/7050) ([thommay](https://github.com/thommay)) <!-- latest_release --> -<!-- release_rollup since=13.7.16 --> -### Changes since 13.7.16 release +<!-- release_rollup since=13.8.5 --> +### Changes since 13.8.5 release #### Merged Pull Requests +- RFC-102: Deprecation warning in resources [#7050](https://github.com/chef/chef/pull/7050) ([thommay](https://github.com/thommay)) <!-- 14.0.166 --> +- Ensure that we pass the correct options to mount [#7030](https://github.com/chef/chef/pull/7030) ([thommay](https://github.com/thommay)) <!-- 14.0.165 --> +- Parser 2.5.0.4 was yanked [#7055](https://github.com/chef/chef/pull/7055) ([tas50](https://github.com/tas50)) <!-- 14.0.164 --> +- Switch chef debug logging to trace [#7039](https://github.com/chef/chef/pull/7039) ([thommay](https://github.com/thommay)) +- Remove path helpers from window_pagefile [#7048](https://github.com/chef/chef/pull/7048) ([tas50](https://github.com/tas50)) - Add swap_file resource from the swap cookbook [#6990](https://github.com/chef/chef/pull/6990) ([tas50](https://github.com/tas50)) <!-- 14.0.163 --> - Revert "Upgrade to openssl 1.1" [#7045](https://github.com/chef/chef/pull/7045) ([tas50](https://github.com/tas50)) <!-- 14.0.162 --> - Upgrade to openssl 1.1 [#7044](https://github.com/chef/chef/pull/7044) ([tas50](https://github.com/tas50)) <!-- 14.0.161 --> @@ -173,6 +178,36 @@ <!-- release_rollup --> <!-- latest_stable_release --> +## [v13.8.5](https://github.com/chef/chef/tree/v13.8.5) (2018-03-07) + +#### Merged Pull Requests +- [knife] Don't crash when a deprecated cookbook has no replacement (#6853) [#6936](https://github.com/chef/chef/pull/6936) ([tas50](https://github.com/tas50)) +- lock ffi at 1.9.21 [#6960](https://github.com/chef/chef/pull/6960) ([thommay](https://github.com/thommay)) +<!-- latest_stable_release --> + +## [v13.8.3](https://github.com/chef/chef/tree/v13.8.3) (2018-03-05) + +#### Merged Pull Requests +- Link to the knife.rb docs when the knife.rb file is missing [#6892](https://github.com/chef/chef/pull/6892) ([tas50](https://github.com/tas50)) +- Revert "Revert "fixup some unit tests"" [#6912](https://github.com/chef/chef/pull/6912) ([lamont-granquist](https://github.com/lamont-granquist)) +- Bump depenencies to pull in Ohai 13.8 / InSpec 1.51.21 [#6934](https://github.com/chef/chef/pull/6934) ([tas50](https://github.com/tas50)) + +## [v13.8.0](https://github.com/chef/chef/tree/v13.8.0) (2018-02-27) + +#### Merged Pull Requests +- Fix regression where message isn't an identity property in log resource [#6780](https://github.com/chef/chef/pull/6780) ([tas50](https://github.com/tas50)) +- fix node assignment of ImmutableArrays to VividMashes/AttrArrays (Chef-13 backport) [#6791](https://github.com/chef/chef/pull/6791) ([lamont-granquist](https://github.com/lamont-granquist)) +- Ensure that we create a docker compatible ca-certs symlink [#6799](https://github.com/chef/chef/pull/6799) ([thommay](https://github.com/thommay)) +- Backport the powershell spec fix to get Appveyor green again [#6813](https://github.com/chef/chef/pull/6813) ([tas50](https://github.com/tas50)) +- Use the version of LicenseScout that comes with the Omnibus gem. [#6841](https://github.com/chef/chef/pull/6841) ([tduffield](https://github.com/tduffield)) +- RemoteFile: unlink tempfile when using cache control shows unchanged (Chef-13 backport) [#6849](https://github.com/chef/chef/pull/6849) ([lamont-granquist](https://github.com/lamont-granquist)) +- add Chef::NodeMap#delete_class API (Chef 13 backport) [#6848](https://github.com/chef/chef/pull/6848) ([lamont-granquist](https://github.com/lamont-granquist)) +- Fix windows_task idle_time validation [#6856](https://github.com/chef/chef/pull/6856) ([tas50](https://github.com/tas50)) +- Update libxml2 to 2.9.7 [#6886](https://github.com/chef/chef/pull/6886) ([tas50](https://github.com/tas50)) +- use a stricter comparison so knife ssh only fails if --exit-on-error [#6894](https://github.com/chef/chef/pull/6894) ([tas50](https://github.com/tas50)) +- Prevent knife search --id-only from outputting IDs in the same format as an empty hash [#6893](https://github.com/chef/chef/pull/6893) ([tas50](https://github.com/tas50)) +- Chef-13 revert lazy attributes [#6898](https://github.com/chef/chef/pull/6898) ([lamont-granquist](https://github.com/lamont-granquist)) + ## [v13.7.16](https://github.com/chef/chef/tree/v13.7.16) (2018-01-23) #### Merged Pull Requests diff --git a/Gemfile.lock b/Gemfile.lock index 7960939704..0955923e14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,10 +15,10 @@ GIT PATH remote: . specs: - chef (14.0.163) + chef (14.0.166) addressable bundler (>= 1.10) - chef-config (= 14.0.163) + chef-config (= 14.0.166) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -29,7 +29,7 @@ PATH mixlib-archive (~> 0.4) mixlib-authentication (~> 1.4) mixlib-cli (~> 1.7) - mixlib-log (~> 2.0) + mixlib-log (~> 2.0, >= 2.0.3) mixlib-shellout (~> 2.0) net-sftp (~> 2.1, >= 2.1.2) net-ssh (~> 4.2) @@ -45,10 +45,10 @@ PATH specinfra (~> 2.10) syslog-logger (~> 1.6) uuidtools (~> 2.1.5) - chef (14.0.163-universal-mingw32) + chef (14.0.166-universal-mingw32) addressable bundler (>= 1.10) - chef-config (= 14.0.163) + chef-config (= 14.0.166) chef-zero (>= 13.0) diff-lcs (~> 1.2, >= 1.2.4) erubis (~> 2.7) @@ -60,7 +60,7 @@ PATH mixlib-archive (~> 0.4) mixlib-authentication (~> 1.4) mixlib-cli (~> 1.7) - mixlib-log (~> 2.0) + mixlib-log (~> 2.0, >= 2.0.3) mixlib-shellout (~> 2.0) net-sftp (~> 2.1, >= 2.1.2) net-ssh (~> 4.2) @@ -90,7 +90,7 @@ PATH PATH remote: chef-config specs: - chef-config (14.0.163) + chef-config (14.0.166) addressable fuzzyurl mixlib-config (~> 2.0) @@ -1 +1 @@ -14.0.163
\ No newline at end of file +14.0.166
\ 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 c467d88f80..ad4ef0574d 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -1060,9 +1060,9 @@ module ChefConfig end rescue if ChefConfig.windows? - ChefConfig.logger.debug "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else." + ChefConfig.logger.trace "Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else." else - ChefConfig.logger.debug "No usable locale -a command found, assuming you have en_US.UTF-8 installed." + ChefConfig.logger.trace "No usable locale -a command found, assuming you have en_US.UTF-8 installed." end "en_US.UTF-8" end diff --git a/chef-config/lib/chef-config/logger.rb b/chef-config/lib/chef-config/logger.rb index d239e85f43..69d7889f88 100644 --- a/chef-config/lib/chef-config/logger.rb +++ b/chef-config/lib/chef-config/logger.rb @@ -27,6 +27,9 @@ module ChefConfig def add(_severity, _message = nil, _progname = nil) end + def trace(_progname = nil, &block) + end + def debug(_progname = nil, &block) end diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb index c011c4f18a..6341ffe4e6 100644 --- a/chef-config/lib/chef-config/path_helper.rb +++ b/chef-config/lib/chef-config/path_helper.rb @@ -79,7 +79,7 @@ module ChefConfig end if windows_max_length_exceeded?(path) - ChefConfig.logger.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'") + ChefConfig.logger.trace("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'") path.insert(0, "\\\\?\\") end end diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index ee9786c18f..af2b000d99 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.163" + VERSION = "14.0.166" end # diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 41b4382cf0..71ea158840 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -767,8 +767,8 @@ RSpec.describe ChefConfig::Config do shared_examples_for "a suitable locale" do it "returns an English UTF-8 locale" do expect(ChefConfig.logger).to_not receive(:warn).with(/Please install an English UTF-8 locale for Chef to use/) - expect(ChefConfig.logger).to_not receive(:debug).with(/Defaulting to locale en_US.UTF-8 on Windows/) - expect(ChefConfig.logger).to_not receive(:debug).with(/No usable locale -a command found/) + expect(ChefConfig.logger).to_not receive(:trace).with(/Defaulting to locale en_US.UTF-8 on Windows/) + expect(ChefConfig.logger).to_not receive(:trace).with(/No usable locale -a command found/) expect(ChefConfig::Config.guess_internal_locale).to eq expected_locale end end @@ -837,9 +837,9 @@ RSpec.describe ChefConfig::Config do it "should default to 'en_US.UTF-8'" do if is_windows - expect(ChefConfig.logger).to receive(:debug).with("Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else.") + expect(ChefConfig.logger).to receive(:trace).with("Defaulting to locale en_US.UTF-8 on Windows, until it matters that we do something else.") else - expect(ChefConfig.logger).to receive(:debug).with("No usable locale -a command found, assuming you have en_US.UTF-8 installed.") + expect(ChefConfig.logger).to receive(:trace).with("No usable locale -a command found, assuming you have en_US.UTF-8 installed.") end expect(ChefConfig::Config.guess_internal_locale).to eq "en_US.UTF-8" end diff --git a/chef.gemspec b/chef.gemspec index 02815a6d56..5f99dd72fb 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| s.add_dependency "chef-config", "= #{Chef::VERSION}" s.add_dependency "mixlib-cli", "~> 1.7" - s.add_dependency "mixlib-log", "~> 2.0" + s.add_dependency "mixlib-log", "~> 2.0", ">= 2.0.3" s.add_dependency "mixlib-authentication", "~> 1.4" s.add_dependency "mixlib-shellout", "~> 2.0" s.add_dependency "mixlib-archive", "~> 0.4" diff --git a/data_collection.json b/data_collection.json deleted file mode 100644 index 139597f9cb..0000000000 --- a/data_collection.json +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/lib/chef/application.rb b/lib/chef/application.rb index b8acf41557..069d840813 100644 --- a/lib/chef/application.rb +++ b/lib/chef/application.rb @@ -315,7 +315,7 @@ class Chef client_solo = chef_config[:solo] ? "chef-solo" : "chef-client" $0 = "#{client_solo} worker: ppid=#{Process.ppid};start=#{Time.new.strftime("%R:%S")};" begin - logger.debug "Forked instance now converging" + logger.trace "Forked instance now converging" @chef_client.run rescue Exception => e logger.error(e.to_s) @@ -324,10 +324,10 @@ class Chef exit 0 end end - logger.debug "Fork successful. Waiting for new chef pid: #{pid}" + logger.trace "Fork successful. Waiting for new chef pid: #{pid}" result = Process.waitpid2(pid) handle_child_exit(result) - logger.debug "Forked instance successfully reaped (pid: #{pid})" + logger.trace "Forked instance successfully reaped (pid: #{pid})" true end diff --git a/lib/chef/application/client.rb b/lib/chef/application/client.rb index 706ba93ca0..5ee1d1a4ec 100644 --- a/lib/chef/application/client.rb +++ b/lib/chef/application/client.rb @@ -336,10 +336,10 @@ class Chef::Application::Client < Chef::Application Chef::Application.fatal!("chef-client recipe-url can be used only in local-mode") else if Chef::Config[:delete_entire_chef_repo] - Chef::Log.debug "Cleanup path #{Chef::Config.chef_repo_path} before extract recipes into it" + Chef::Log.trace "Cleanup path #{Chef::Config.chef_repo_path} before extract recipes into it" FileUtils.rm_rf(recipes_path, :secure => true) end - Chef::Log.debug "Creating path #{Chef::Config.chef_repo_path} to extract recipes into" + Chef::Log.trace "Creating path #{Chef::Config.chef_repo_path} to extract recipes into" FileUtils.mkdir_p(Chef::Config.chef_repo_path) tarball_path = File.join(Chef::Config.chef_repo_path, "recipes.tgz") fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path) @@ -467,7 +467,7 @@ class Chef::Application::Client < Chef::Application end def sleep_then_run_chef_client(sleep_sec) - Chef::Log.debug("Sleeping for #{sleep_sec} seconds") + Chef::Log.trace("Sleeping for #{sleep_sec} seconds") # interval_sleep will return early if we received a signal (unless on windows) interval_sleep(sleep_sec) @@ -480,7 +480,7 @@ class Chef::Application::Client < Chef::Application rescue Exception => e if Chef::Config[:interval] Chef::Log.error("#{e.class}: #{e}") - Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}") + Chef::Log.trace("#{e.class}: #{e}\n#{e.backtrace.join("\n")}") retry end @@ -533,7 +533,7 @@ class Chef::Application::Client < Chef::Application end def fetch_recipe_tarball(url, path) - Chef::Log.debug("Download recipes tarball from #{url} to #{path}") + Chef::Log.trace("Download recipes tarball from #{url} to #{path}") File.open(path, "wb") do |f| open(url) do |r| f.write(r.read) diff --git a/lib/chef/application/solo.rb b/lib/chef/application/solo.rb index f8502edc38..2294d63c21 100644 --- a/lib/chef/application/solo.rb +++ b/lib/chef/application/solo.rb @@ -242,7 +242,7 @@ class Chef::Application::Solo < Chef::Application ARGV.delete("--ez") # For back compat reasons, we need to ensure that we try and use the cache_path as a repo first - Chef::Log.debug "Current chef_repo_path is #{Chef::Config.chef_repo_path}" + Chef::Log.trace "Current chef_repo_path is #{Chef::Config.chef_repo_path}" if !Chef::Config.has_key?(:cookbook_path) && !Chef::Config.has_key?(:chef_repo_path) Chef::Config.chef_repo_path = Chef::Config.find_chef_repo_path(Chef::Config[:cache_path]) @@ -272,10 +272,10 @@ class Chef::Application::Solo < Chef::Application recipes_path = File.expand_path(File.join(cookbooks_path, "..")) if Chef::Config[:delete_entire_chef_repo] - Chef::Log.debug "Cleanup path #{recipes_path} before extract recipes into it" + Chef::Log.trace "Cleanup path #{recipes_path} before extract recipes into it" FileUtils.rm_rf(recipes_path, :secure => true) end - Chef::Log.debug "Creating path #{recipes_path} to extract recipes into" + Chef::Log.trace "Creating path #{recipes_path} to extract recipes into" FileUtils.mkdir_p(recipes_path) tarball_path = File.join(recipes_path, "recipes.tgz") fetch_recipe_tarball(Chef::Config[:recipe_url], tarball_path) @@ -336,7 +336,7 @@ EOH sleep_sec += rand(Chef::Config[:splay]) if Chef::Config[:splay] sleep_sec += Chef::Config[:interval] if Chef::Config[:interval] if sleep_sec != 0 - Chef::Log.debug("Sleeping for #{sleep_sec} seconds") + Chef::Log.trace("Sleeping for #{sleep_sec} seconds") sleep(sleep_sec) end @@ -349,7 +349,7 @@ EOH rescue Exception => e if Chef::Config[:interval] Chef::Log.error("#{e.class}: #{e}") - Chef::Log.debug("#{e.class}: #{e}\n#{e.backtrace.join("\n")}") + Chef::Log.trace("#{e.class}: #{e}\n#{e.backtrace.join("\n")}") retry else Chef::Application.fatal!("#{e.class}: #{e.message}", e) @@ -359,7 +359,7 @@ EOH end def fetch_recipe_tarball(url, path) - Chef::Log.debug("Download recipes tarball from #{url} to #{path}") + Chef::Log.trace("Download recipes tarball from #{url} to #{path}") File.open(path, "wb") do |f| open(url) do |r| f.write(r.read) diff --git a/lib/chef/application/windows_service.rb b/lib/chef/application/windows_service.rb index fa4b3fd27e..41dcc55d70 100644 --- a/lib/chef/application/windows_service.rb +++ b/lib/chef/application/windows_service.rb @@ -109,9 +109,9 @@ class Chef # Daemon class needs to have all the signal callbacks return # before service_main returns. - Chef::Log.debug("Giving signal callbacks some time to exit...") + Chef::Log.trace("Giving signal callbacks some time to exit...") sleep 1 - Chef::Log.debug("Exiting service...") + Chef::Log.trace("Exiting service...") end ################################################################################ @@ -135,7 +135,7 @@ class Chef run_warning_displayed = true end - Chef::Log.debug("Waiting for chef-client run...") + Chef::Log.trace("Waiting for chef-client run...") sleep 1 end end @@ -200,8 +200,8 @@ class Chef :timeout => Chef::Config[:windows_service][:watchdog_timeout], :logger => Chef::Log ) - Chef::Log.debug "#{result.stdout}" - Chef::Log.debug "#{result.stderr}" + Chef::Log.trace "#{result.stdout}" + Chef::Log.trace "#{result.stderr}" rescue Mixlib::ShellOut::CommandTimeout => e Chef::Log.error "chef-client timed out\n(#{e})" Chef::Log.error(<<-EOF) diff --git a/lib/chef/audit/audit_event_proxy.rb b/lib/chef/audit/audit_event_proxy.rb index 25ff31ecb1..e2e6ab1ede 100644 --- a/lib/chef/audit/audit_event_proxy.rb +++ b/lib/chef/audit/audit_event_proxy.rb @@ -37,7 +37,7 @@ class Chef if notification.group.parent_groups.size == 1 # top level `control_group` block desc = notification.group.description - Chef::Log.debug("Entered `control_group` block named #{desc}") + Chef::Log.trace("Entered `control_group` block named #{desc}") events.control_group_started(desc) end end diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index 80ae3a8dd4..bb5537b97b 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -42,13 +42,13 @@ class Chef end def audit_phase_start(run_status) - Chef::Log.debug("Audit Reporter starting") + Chef::Log.trace("Audit Reporter starting") @audit_data = AuditData.new(run_status.node.name, run_status.run_id) @run_status = run_status end def audit_phase_complete(audit_output) - Chef::Log.debug("Audit Reporter completed successfully without errors.") + Chef::Log.trace("Audit Reporter completed successfully without errors.") ordered_control_groups.each_value do |control_group| audit_data.add_control_group(control_group) end @@ -61,7 +61,7 @@ class Chef def audit_phase_failed(error, audit_output) # The stacktrace information has already been logged elsewhere @audit_phase_error = error - Chef::Log.debug("Audit Reporter failed.") + Chef::Log.trace("Audit Reporter failed.") ordered_control_groups.each_value do |control_group| audit_data.add_control_group(control_group) end @@ -104,12 +104,12 @@ class Chef def post_auditing_data unless auditing_enabled? - Chef::Log.debug("Audit Reports are disabled. Skipping sending reports.") + Chef::Log.trace("Audit Reports are disabled. Skipping sending reports.") return end unless run_status - Chef::Log.debug("Run failed before audit mode was initialized, not sending audit report to server") + Chef::Log.trace("Run failed before audit mode was initialized, not sending audit report to server") return end @@ -117,7 +117,7 @@ class Chef audit_data.end_time = iso8601ify(run_status.end_time) audit_history_url = "controls" - Chef::Log.debug("Sending audit report (run-id: #{audit_data.run_id})") + Chef::Log.trace("Sending audit report (run-id: #{audit_data.run_id})") run_data = audit_data.to_hash if @audit_phase_error @@ -126,7 +126,7 @@ class Chef run_data[:error] = error_info end - Chef::Log.debug "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}" + Chef::Log.trace "Audit Report:\n#{Chef::JSONCompat.to_json_pretty(run_data)}" begin rest_client.post(audit_history_url, run_data, headers) rescue StandardError => e @@ -134,14 +134,14 @@ class Chef # 404 error code is OK. This means the version of server we're running against doesn't support # audit reporting. Don't alarm failure in this case. if e.response.code == "404" - Chef::Log.debug("Server doesn't support audit reporting. Skipping report.") + Chef::Log.trace("Server doesn't support audit reporting. Skipping report.") return else # Save the audit report to local disk error_file = "failed-audit-data.json" Chef::FileCache.store(error_file, Chef::JSONCompat.to_json_pretty(run_data), 0640) if Chef::Config.chef_zero.enabled - Chef::Log.debug("Saving audit report to #{Chef::FileCache.load(error_file, false)}") + Chef::Log.trace("Saving audit report to #{Chef::FileCache.load(error_file, false)}") else Chef::Log.error("Failed to post audit report to server. Saving report to #{Chef::FileCache.load(error_file, false)}") end diff --git a/lib/chef/chef_fs/file_system/multiplexed_dir.rb b/lib/chef/chef_fs/file_system/multiplexed_dir.rb index cf1fb34345..969a579532 100644 --- a/lib/chef/chef_fs/file_system/multiplexed_dir.rb +++ b/lib/chef/chef_fs/file_system/multiplexed_dir.rb @@ -39,7 +39,7 @@ class Chef child_entry = dir.child(name) if child_entry.exists? if result - Chef::Log.debug("Child with name '#{child_entry.name}' found in multiple directories: #{result.parent.path_for_printing} and #{child_entry.parent.path_for_printing}") + Chef::Log.trace("Child with name '#{child_entry.name}' found in multiple directories: #{result.parent.path_for_printing} and #{child_entry.parent.path_for_printing}") else result = child_entry end diff --git a/lib/chef/chef_fs/file_system/repository/base_file.rb b/lib/chef/chef_fs/file_system/repository/base_file.rb index 3e1edc8d62..76d242eee5 100644 --- a/lib/chef/chef_fs/file_system/repository/base_file.rb +++ b/lib/chef/chef_fs/file_system/repository/base_file.rb @@ -43,12 +43,12 @@ class Chef file_path = "#{parent.file_path}/#{name}" - Chef::Log.debug "BaseFile: Detecting file extension for #{name}" + Chef::Log.trace "BaseFile: Detecting file extension for #{name}" ext = File.exist?(file_path + ".rb") ? ".rb" : ".json" name += ext file_path += ext - Chef::Log.debug "BaseFile: got a file path of #{file_path} for #{name}" + Chef::Log.trace "BaseFile: got a file path of #{file_path} for #{name}" @name = name @path = Chef::ChefFS::PathUtils.join(parent.path, name) @file_path = file_path diff --git a/lib/chef/chef_fs/file_system_cache.rb b/lib/chef/chef_fs/file_system_cache.rb index a9d8d8bfe4..7b6c4c148f 100644 --- a/lib/chef/chef_fs/file_system_cache.rb +++ b/lib/chef/chef_fs/file_system_cache.rb @@ -51,7 +51,7 @@ class Chef def delete!(path) parent = _get_parent(path) - Chef::Log.debug("Deleting parent #{parent} and #{path} from FileSystemCache") + Chef::Log.trace("Deleting parent #{parent} and #{path} from FileSystemCache") if @cache.key?(path) @cache.delete(path) end diff --git a/lib/chef/cookbook/chefignore.rb b/lib/chef/cookbook/chefignore.rb index d905e027d6..00dc7c0939 100644 --- a/lib/chef/cookbook/chefignore.rb +++ b/lib/chef/cookbook/chefignore.rb @@ -56,7 +56,7 @@ class Chef ignore_globs << line.strip unless line =~ COMMENTS_AND_WHITESPACE end else - Chef::Log.debug("No chefignore file found at #{@ignore_file} no files will be ignored") + Chef::Log.trace("No chefignore file found at #{@ignore_file} no files will be ignored") end ignore_globs end diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb index 0b64d3354f..deac48ff78 100644 --- a/lib/chef/cookbook/gem_installer.rb +++ b/lib/chef/cookbook/gem_installer.rb @@ -57,8 +57,8 @@ class Chef tf.puts "gem(*#{([gem_name] + args).inspect})" end tf.close - Chef::Log.debug("generated Gemfile contents:") - Chef::Log.debug(IO.read(tf.path)) + Chef::Log.trace("generated Gemfile contents:") + Chef::Log.trace(IO.read(tf.path)) so = shell_out!("bundle install", cwd: dir, env: { "PATH" => path_with_prepended_ruby_bin }) Chef::Log.info(so.stdout) end diff --git a/lib/chef/cookbook/manifest_v2.rb b/lib/chef/cookbook/manifest_v2.rb index 59b5c9afb0..2a5f1fb5e6 100644 --- a/lib/chef/cookbook/manifest_v2.rb +++ b/lib/chef/cookbook/manifest_v2.rb @@ -24,7 +24,7 @@ class Chef minimum_api_version 2 def self.from_hash(hash) - Chef::Log.debug "processing manifest: #{hash}" + Chef::Log.trace "processing manifest: #{hash}" Mash.new hash end diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 22f006640d..c378cb75b6 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -616,7 +616,7 @@ class Chef if block_given? super else - Chef::Log.debug "ignoring method #{method} on cookbook with name #{name}, possible typo or the ghosts of metadata past or future?" + Chef::Log.trace "ignoring method #{method} on cookbook with name #{name}, possible typo or the ghosts of metadata past or future?" end end diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb index 668d74c9ce..3f73c1cca6 100644 --- a/lib/chef/cookbook/remote_file_vendor.rb +++ b/lib/chef/cookbook/remote_file_vendor.rb @@ -65,11 +65,11 @@ class Chef if found_manifest_record[:lazy] || current_checksum != found_manifest_record["checksum"] raw_file = @rest.streaming_request(found_manifest_record[:url]) - Chef::Log.debug("Storing updated #{cache_filename} in the cache.") + Chef::Log.trace("Storing updated #{cache_filename} in the cache.") Chef::FileCache.move_to(raw_file.path, cache_filename) else - Chef::Log.debug("Not fetching #{cache_filename}, as the cache is up to date.") - Chef::Log.debug("Current checksum: #{current_checksum}; manifest checksum: #{found_manifest_record['checksum']})") + Chef::Log.trace("Not fetching #{cache_filename}, as the cache is up to date.") + Chef::Log.trace("Current checksum: #{current_checksum}; manifest checksum: #{found_manifest_record['checksum']})") end full_path_cache_filename = Chef::FileCache.load(cache_filename, false) diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb index 991e418f99..6df39fece3 100644 --- a/lib/chef/cookbook/synchronizer.rb +++ b/lib/chef/cookbook/synchronizer.rb @@ -148,7 +148,7 @@ class Chef # true:: Always returns true def sync_cookbooks Chef::Log.info("Loading cookbooks [#{cookbooks.map { |ckbk| ckbk.name + '@' + ckbk.version }.join(', ')}]") - Chef::Log.debug("Cookbooks detail: #{cookbooks.inspect}") + Chef::Log.trace("Cookbooks detail: #{cookbooks.inspect}") clear_obsoleted_cookbooks @@ -272,7 +272,7 @@ class Chef download_file(file.manifest_record["url"], cache_filename) @events.updated_cookbook_file(file.cookbook.name, cache_filename) else - Chef::Log.debug("Not storing #{cache_filename}, as the cache is up to date.") + Chef::Log.trace("Not storing #{cache_filename}, as the cache is up to date.") end # Load the file in the cache and return the full file path to the loaded file diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index 8d0d636bd2..b94b14fe6a 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -124,7 +124,7 @@ class Chef def untested_ruby_files ruby_files.reject do |file| if validated?(file) - Chef::Log.debug("Ruby file #{file} is unchanged, skipping syntax check") + Chef::Log.trace("Ruby file #{file} is unchanged, skipping syntax check") true else false @@ -139,7 +139,7 @@ class Chef def untested_template_files template_files.reject do |file| if validated?(file) - Chef::Log.debug("Template #{file} is unchanged, skipping syntax check") + Chef::Log.trace("Template #{file} is unchanged, skipping syntax check") true else false @@ -170,12 +170,12 @@ class Chef end def validate_template(erb_file) - Chef::Log.debug("Testing template #{erb_file} for syntax errors...") + Chef::Log.trace("Testing template #{erb_file} for syntax errors...") validate_erb_file_inline(erb_file) end def validate_ruby_file(ruby_file) - Chef::Log.debug("Testing #{ruby_file} for syntax errors...") + Chef::Log.trace("Testing #{ruby_file} for syntax errors...") validate_ruby_file_inline(ruby_file) end diff --git a/lib/chef/cookbook_site_streaming_uploader.rb b/lib/chef/cookbook_site_streaming_uploader.rb index c082710da3..e4b45532f0 100644 --- a/lib/chef/cookbook_site_streaming_uploader.rb +++ b/lib/chef/cookbook_site_streaming_uploader.rb @@ -41,19 +41,19 @@ class Chef tmp_cookbook_dir = tmp_cookbook_path.path File.unlink(tmp_cookbook_dir) FileUtils.mkdir_p(tmp_cookbook_dir) - Chef::Log.debug("Staging at #{tmp_cookbook_dir}") + Chef::Log.trace("Staging at #{tmp_cookbook_dir}") checksums_to_on_disk_paths = cookbook.checksums cookbook.each_file do |manifest_record| path_in_cookbook = manifest_record[:path] on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]] dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook) FileUtils.mkdir_p(File.dirname(dest)) - Chef::Log.debug("Staging #{on_disk_path} to #{dest}") + Chef::Log.trace("Staging #{on_disk_path} to #{dest}") FileUtils.cp(on_disk_path, dest) end # First, generate metadata - Chef::Log.debug("Generating metadata") + Chef::Log.trace("Generating metadata") kcm = Chef::Knife::CookbookMetadata.new kcm.config[:cookbook_path] = [ tmp_cookbook_dir ] kcm.name_args = [ cookbook.name.to_s ] diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb index 470d7be5b6..e79a7774eb 100644 --- a/lib/chef/cookbook_uploader.rb +++ b/lib/chef/cookbook_uploader.rb @@ -71,14 +71,14 @@ class Chef Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}") queue << uploader_function_for(checksum_files[checksum], checksum, info["url"], checksums_to_upload) else - Chef::Log.debug("#{checksum_files[checksum]} has not changed") + Chef::Log.trace("#{checksum_files[checksum]} has not changed") end end queue.process(@concurrency) sandbox_url = new_sandbox["uri"] - Chef::Log.debug("Committing sandbox") + Chef::Log.trace("Committing sandbox") # Retry if S3 is claims a checksum doesn't exist (the eventual # in eventual consistency) retries = 0 diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 99438ade82..7bb3f3385f 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -79,7 +79,7 @@ class Chef def self.checksum_cookbook_file(filepath) Chef::Digester.generate_md5_checksum_for_file(filepath) rescue Errno::ENOENT - Chef::Log.debug("File #{filepath} does not exist, so there is no checksum to generate") + Chef::Log.trace("File #{filepath} does not exist, so there is no checksum to generate") nil end @@ -188,7 +188,7 @@ class Chef raise Chef::Exceptions::RecipeNotFound, "could not find recipe #{recipe_name} for cookbook #{name}" end - Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{name}") + Chef::Log.trace("Found recipe #{recipe_name} in cookbook #{name}") recipe = Chef::Recipe.new(name, recipe_name, run_context) recipe_filename = recipe_filenames_by_name[recipe_name] diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index bee2e88543..5cc92a34e4 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -42,20 +42,20 @@ class Chef # falsey value def self.register_reporter? if why_run? - Chef::Log.debug("data collector is disabled for why run mode") + Chef::Log.trace("data collector is disabled for why run mode") return false end unless reporter_enabled_for_current_mode? - Chef::Log.debug("data collector is configured to only run in " \ + Chef::Log.trace("data collector is configured to only run in " \ "#{Chef::Config[:data_collector][:mode].inspect} modes, disabling it") return false end unless data_collector_url_configured? || data_collector_output_locations_configured? - Chef::Log.debug("Neither data collector URL or output locations have been configured, disabling data collector") + Chef::Log.trace("Neither data collector URL or output locations have been configured, disabling data collector") return false end if solo? && !token_auth_configured? - Chef::Log.debug("Data collector token must be configured to use Chef Automate data collector with Chef Solo") + Chef::Log.trace("Data collector token must be configured to use Chef Automate data collector with Chef Solo") end if !solo? && token_auth_configured? Chef::Log.warn("Data collector token authentication is not recommended for client-server mode" \ @@ -368,7 +368,7 @@ class Chef def send_to_http_location(http_url, message) @http_output_locations[http_url].post(nil, message, headers) if @http_output_locations[http_url] rescue - Chef::Log.debug("Data collector failed to send to URL location #{http_url}. Please check your configured data_collector.output_locations") + Chef::Log.trace("Data collector failed to send to URL location #{http_url}. Please check your configured data_collector.output_locations") end # diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb index ac4440f6db..792df69f71 100644 --- a/lib/chef/deprecated.rb +++ b/lib/chef/deprecated.rb @@ -280,6 +280,13 @@ class Chef # id 3694 was deleted + # Returned when using the deprecated option on a property + class Property < Base + def inspect + "#{message}\n#{location}" + end + end + class Generic < Base def url "https://docs.chef.io/chef_deprecations_client.html" diff --git a/lib/chef/dsl/include_attribute.rb b/lib/chef/dsl/include_attribute.rb index 9f73143722..c81b37a963 100644 --- a/lib/chef/dsl/include_attribute.rb +++ b/lib/chef/dsl/include_attribute.rb @@ -31,9 +31,9 @@ class Chef attr_file_specs.flatten.each do |attr_file_spec| cookbook_name, attr_file = parse_attribute_file_spec(attr_file_spec) if run_context.loaded_fully_qualified_attribute?(cookbook_name, attr_file) - Chef::Log.debug("I am not loading attribute file #{cookbook_name}::#{attr_file}, because I have already seen it.") + Chef::Log.trace("I am not loading attribute file #{cookbook_name}::#{attr_file}, because I have already seen it.") else - Chef::Log.debug("Loading Attribute #{cookbook_name}::#{attr_file}") + Chef::Log.trace("Loading Attribute #{cookbook_name}::#{attr_file}") run_context.loaded_attribute(cookbook_name, attr_file) attr_file_path = run_context.resolve_attribute(cookbook_name, attr_file) node.from_file(attr_file_path) diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb index 734ed40691..ac36dbd1dd 100644 --- a/lib/chef/dsl/platform_introspection.rb +++ b/lib/chef/dsl/platform_introspection.rb @@ -79,8 +79,8 @@ class Chef key_matches << k end rescue Chef::Exceptions::InvalidVersionConstraint => e - Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform." - Chef::Log.debug(e) + Chef::Log.trace "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform." + Chef::Log.trace(e) end end return @values[platform][version] if key_matches.include?(version) @@ -94,12 +94,12 @@ class Chef end rescue Chef::Exceptions::InvalidCookbookVersion => e # Lets not break because someone passes a weird string like 'default' :) - Chef::Log.debug(e) - Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint" + Chef::Log.trace(e) + Chef::Log.trace "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint" nil rescue Chef::Exceptions::InvalidPlatformVersion => e - Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format" - Chef::Log.debug(e) + Chef::Log.trace "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format" + Chef::Log.trace(e) nil end diff --git a/lib/chef/event_dispatch/dsl.rb b/lib/chef/event_dispatch/dsl.rb index 999d536fbe..0a9c082fc1 100644 --- a/lib/chef/event_dispatch/dsl.rb +++ b/lib/chef/event_dispatch/dsl.rb @@ -35,10 +35,10 @@ class Chef # and associated event dispatcher is set, else fallback to # Chef::Config[:event_handlers] if Chef.run_context && Chef.run_context.events - Chef::Log.debug("Registering handler '#{name}' using events api") + Chef::Log.trace("Registering handler '#{name}' using events api") Chef.run_context.events.register(handler) else - Chef::Log.debug("Registering handler '#{name}' using global config") + Chef::Log.trace("Registering handler '#{name}' using global config") Chef::Config[:event_handlers] << handler end end diff --git a/lib/chef/file_access_control/unix.rb b/lib/chef/file_access_control/unix.rb index ee96bf5045..5d674c2c32 100644 --- a/lib/chef/file_access_control/unix.rb +++ b/lib/chef/file_access_control/unix.rb @@ -79,18 +79,18 @@ class Chef def should_update_owner? if target_uid.nil? # the user has not specified a permission on the new resource, so we never manage it with FAC - Chef::Log.debug("Found target_uid == nil, so no owner was specified on resource, not managing owner") + Chef::Log.trace("Found target_uid == nil, so no owner was specified on resource, not managing owner") false elsif current_uid.nil? # the user has specified a permission, and we are creating a file, so always enforce permissions - Chef::Log.debug("Found current_uid == nil, so we are creating a new file, updating owner") + Chef::Log.trace("Found current_uid == nil, so we are creating a new file, updating owner") true elsif target_uid != current_uid # the user has specified a permission, and it does not match the file, so fix the permission - Chef::Log.debug("Found target_uid != current_uid, updating owner") + Chef::Log.trace("Found target_uid != current_uid, updating owner") true else - Chef::Log.debug("Found target_uid == current_uid, not updating owner") + Chef::Log.trace("Found target_uid == current_uid, not updating owner") # the user has specified a permission, but it matches the file, so behave idempotently false end @@ -138,18 +138,18 @@ class Chef def should_update_group? if target_gid.nil? # the user has not specified a permission on the new resource, so we never manage it with FAC - Chef::Log.debug("Found target_gid == nil, so no group was specified on resource, not managing group") + Chef::Log.trace("Found target_gid == nil, so no group was specified on resource, not managing group") false elsif current_gid.nil? # the user has specified a permission, and we are creating a file, so always enforce permissions - Chef::Log.debug("Found current_gid == nil, so we are creating a new file, updating group") + Chef::Log.trace("Found current_gid == nil, so we are creating a new file, updating group") true elsif target_gid != current_gid # the user has specified a permission, and it does not match the file, so fix the permission - Chef::Log.debug("Found target_gid != current_gid, updating group") + Chef::Log.trace("Found target_gid != current_gid, updating group") true else - Chef::Log.debug("Found target_gid == current_gid, not updating group") + Chef::Log.trace("Found target_gid == current_gid, not updating group") # the user has specified a permission, but it matches the file, so behave idempotently false end @@ -187,20 +187,20 @@ class Chef def should_update_mode? if target_mode.nil? # the user has not specified a permission on the new resource, so we never manage it with FAC - Chef::Log.debug("Found target_mode == nil, so no mode was specified on resource, not managing mode") + Chef::Log.trace("Found target_mode == nil, so no mode was specified on resource, not managing mode") false elsif current_mode.nil? # the user has specified a permission, and we are creating a file, so always enforce permissions - Chef::Log.debug("Found current_mode == nil, so we are creating a new file, updating mode") + Chef::Log.trace("Found current_mode == nil, so we are creating a new file, updating mode") true elsif target_mode != current_mode # the user has specified a permission, and it does not match the file, so fix the permission - Chef::Log.debug("Found target_mode != current_mode, updating mode") + Chef::Log.trace("Found target_mode != current_mode, updating mode") true elsif suid_bit_set? && (should_update_group? || should_update_owner?) true else - Chef::Log.debug("Found target_mode == current_mode, not updating mode") + Chef::Log.trace("Found target_mode == current_mode, not updating mode") # the user has specified a permission, but it matches the file, so behave idempotently false end diff --git a/lib/chef/file_content_management/content_base.rb b/lib/chef/file_content_management/content_base.rb index 6080e37180..d5593579b0 100644 --- a/lib/chef/file_content_management/content_base.rb +++ b/lib/chef/file_content_management/content_base.rb @@ -23,12 +23,14 @@ class Chef attr_reader :run_context attr_reader :new_resource attr_reader :current_resource + attr_reader :logger - def initialize(new_resource, current_resource, run_context) + def initialize(new_resource, current_resource, run_context, logger = Chef::Log.with_child) @new_resource = new_resource @current_resource = current_resource @run_context = run_context @tempfile_loaded = false + @logger = logger end def tempfile diff --git a/lib/chef/file_content_management/deploy/cp.rb b/lib/chef/file_content_management/deploy/cp.rb index 14dde85d13..8d804e7493 100644 --- a/lib/chef/file_content_management/deploy/cp.rb +++ b/lib/chef/file_content_management/deploy/cp.rb @@ -34,12 +34,12 @@ class Chef # class Cp def create(file) - Chef::Log.debug("Touching #{file} to create it") + Chef::Log.trace("Touching #{file} to create it") FileUtils.touch(file) end def deploy(src, dst) - Chef::Log.debug("Copying temporary file #{src} into place at #{dst}") + Chef::Log.trace("Copying temporary file #{src} into place at #{dst}") FileUtils.cp(src, dst) end end diff --git a/lib/chef/file_content_management/deploy/mv_unix.rb b/lib/chef/file_content_management/deploy/mv_unix.rb index 3805b3bef3..cbc9b903a8 100644 --- a/lib/chef/file_content_management/deploy/mv_unix.rb +++ b/lib/chef/file_content_management/deploy/mv_unix.rb @@ -30,19 +30,19 @@ class Chef def create(file) # this is very simple, but it ensures that ownership and file modes take # good defaults, in particular mode needs to obey umask on create - Chef::Log.debug("Touching #{file} to create it") + Chef::Log.trace("Touching #{file} to create it") FileUtils.touch(file) end def deploy(src, dst) # we are only responsible for content so restore the dst files perms - Chef::Log.debug("Reading modes from #{dst} file") + Chef::Log.trace("Reading modes from #{dst} file") stat = ::File.stat(dst) mode = stat.mode & 07777 uid = stat.uid gid = stat.gid - Chef::Log.debug("Applying mode = #{mode.to_s(8)}, uid = #{uid}, gid = #{gid} to #{src}") + Chef::Log.trace("Applying mode = #{mode.to_s(8)}, uid = #{uid}, gid = #{gid} to #{src}") # i own the inode, so should be able to at least chmod it ::File.chmod(mode, src) @@ -67,7 +67,7 @@ class Chef Chef::Log.warn("Could not set gid = #{gid} on #{src}, file modes not preserved") end - Chef::Log.debug("Moving temporary file #{src} into place at #{dst}") + Chef::Log.trace("Moving temporary file #{src} into place at #{dst}") FileUtils.mv(src, dst) end end diff --git a/lib/chef/file_content_management/deploy/mv_windows.rb b/lib/chef/file_content_management/deploy/mv_windows.rb index 0e6e6cd76f..210400bc08 100644 --- a/lib/chef/file_content_management/deploy/mv_windows.rb +++ b/lib/chef/file_content_management/deploy/mv_windows.rb @@ -35,7 +35,7 @@ class Chef ACL = Security::ACL def create(file) - Chef::Log.debug("Touching #{file} to create it") + Chef::Log.trace("Touching #{file} to create it") FileUtils.touch(file) end diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index cf59a87996..9d8a7ea882 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -45,7 +45,7 @@ class Chef break rescue SystemCallError => e message = "Creating temp file under '#{tempfile_dirname}' failed with: '#{e.message}'" - Chef::Log.debug(message) + Chef::Log.trace(message) errors << message end end diff --git a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb index d5ed69a83d..ea423a2f97 100644 --- a/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +++ b/lib/chef/formatters/error_inspectors/compile_error_inspector.rb @@ -108,7 +108,7 @@ class Chef def culprit_backtrace_entry @culprit_backtrace_entry ||= begin bt_entry = filtered_bt.first - Chef::Log.debug("Backtrace entry for compile error: '#{bt_entry}'") + Chef::Log.trace("Backtrace entry for compile error: '#{bt_entry}'") bt_entry end end @@ -116,7 +116,7 @@ class Chef def culprit_line @culprit_line ||= begin line_number = culprit_backtrace_entry[/^(?:.\:)?[^:]+:([\d]+)/, 1].to_i - Chef::Log.debug("Line number of compile error: '#{line_number}'") + Chef::Log.trace("Line number of compile error: '#{line_number}'") line_number end end @@ -138,7 +138,7 @@ class Chef begin filters = Array(Chef::Config.cookbook_path).map { |p| /^#{Regexp.escape(p)}/i } r = exception.backtrace.select { |line| filters.any? { |filter| line =~ filter } } - Chef::Log.debug("Filtered backtrace of compile error: #{r.join(",")}") + Chef::Log.trace("Filtered backtrace of compile error: #{r.join(",")}") r end end diff --git a/lib/chef/http.rb b/lib/chef/http.rb index 241806da4e..edcd6eed3d 100644 --- a/lib/chef/http.rb +++ b/lib/chef/http.rb @@ -54,7 +54,7 @@ class Chef # stream handlers handle responses so must be applied in reverse order # (same as #apply_stream_complete_middleware or #apply_response_midddleware) @stream_handlers.reverse.inject(next_chunk) do |chunk, handler| - Chef::Log.debug("Chef::HTTP::StreamHandler calling #{handler.class}#handle_chunk") + Chef::Log.trace("Chef::HTTP::StreamHandler calling #{handler.class}#handle_chunk") handler.handle_chunk(chunk) end end @@ -156,7 +156,7 @@ class Chef http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 - Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") + Chef::Log.trace("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") retry else raise @@ -194,7 +194,7 @@ class Chef http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 - Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") + Chef::Log.trace("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") retry else raise @@ -249,7 +249,7 @@ class Chef http_attempts += 1 response = e.response if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0 - Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") + Chef::Log.trace("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}") retry else raise @@ -324,7 +324,7 @@ class Chef # @api private def apply_request_middleware(method, url, headers, data) middlewares.inject([method, url, headers, data]) do |req_data, middleware| - Chef::Log.debug("Chef::HTTP calling #{middleware.class}#handle_request") + Chef::Log.trace("Chef::HTTP calling #{middleware.class}#handle_request") middleware.handle_request(*req_data) end end @@ -332,7 +332,7 @@ class Chef # @api private def apply_response_middleware(response, rest_request, return_value) middlewares.reverse.inject([response, rest_request, return_value]) do |res_data, middleware| - Chef::Log.debug("Chef::HTTP calling #{middleware.class}#handle_response") + Chef::Log.trace("Chef::HTTP calling #{middleware.class}#handle_response") middleware.handle_response(*res_data) end end @@ -340,7 +340,7 @@ class Chef # @api private def apply_stream_complete_middleware(response, rest_request, return_value) middlewares.reverse.inject([response, rest_request, return_value]) do |res_data, middleware| - Chef::Log.debug("Chef::HTTP calling #{middleware.class}#handle_stream_complete") + Chef::Log.trace("Chef::HTTP calling #{middleware.class}#handle_stream_complete") middleware.handle_stream_complete(*res_data) end end @@ -468,7 +468,7 @@ class Chef def follow_redirect raise Chef::Exceptions::RedirectLimitExceeded if @redirects_followed >= redirect_limit @redirects_followed += 1 - Chef::Log.debug("Following redirect #{@redirects_followed}/#{redirect_limit}") + Chef::Log.trace("Following redirect #{@redirects_followed}/#{redirect_limit}") yield ensure @@ -506,7 +506,7 @@ class Chef tf.binmode # required for binary files on Windows platforms end end - Chef::Log.debug("Streaming download from #{url} to tempfile #{tf.path}") + Chef::Log.trace("Streaming download from #{url} to tempfile #{tf.path}") # Stolen from http://www.ruby-forum.com/topic/166423 # Kudos to _why! diff --git a/lib/chef/http/auth_credentials.rb b/lib/chef/http/auth_credentials.rb index 053b2c938e..e2494c9405 100644 --- a/lib/chef/http/auth_credentials.rb +++ b/lib/chef/http/auth_credentials.rb @@ -38,7 +38,7 @@ class Chef def signature_headers(request_params = {}) raise ArgumentError, "Cannot sign the request without a client name, check that :node_name is assigned" if client_name.nil? - Chef::Log.debug("Signing the request as #{client_name}") + Chef::Log.trace("Signing the request as #{client_name}") # params_in = {:http_method => :GET, :path => "/clients", :body => "", :host => "localhost"} request_params = request_params.dup diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb index 1539770aa8..54da722b3d 100644 --- a/lib/chef/http/basic_client.rb +++ b/lib/chef/http/basic_client.rb @@ -60,32 +60,32 @@ class Chef def request(method, url, req_body, base_headers = {}) http_request = HTTPRequest.new(method, url, req_body, base_headers).http_request - Chef::Log.debug("Initiating #{method} to #{url}") - Chef::Log.debug("---- HTTP Request Header Data: ----") + Chef::Log.trace("Initiating #{method} to #{url}") + Chef::Log.trace("---- HTTP Request Header Data: ----") base_headers.each do |name, value| - Chef::Log.debug("#{name}: #{value}") + Chef::Log.trace("#{name}: #{value}") end - Chef::Log.debug("---- End HTTP Request Header Data ----") + Chef::Log.trace("---- End HTTP Request Header Data ----") http_client.request(http_request) do |response| - Chef::Log.debug("---- HTTP Status and Header Data: ----") - Chef::Log.debug("HTTP #{response.http_version} #{response.code} #{response.msg}") + Chef::Log.trace("---- HTTP Status and Header Data: ----") + Chef::Log.trace("HTTP #{response.http_version} #{response.code} #{response.msg}") response.each do |header, value| - Chef::Log.debug("#{header}: #{value}") + Chef::Log.trace("#{header}: #{value}") end - Chef::Log.debug("---- End HTTP Status/Header Data ----") + Chef::Log.trace("---- End HTTP Status/Header Data ----") # For non-400's, log the request and response bodies if !response.code || !response.code.start_with?("2") if response.body - Chef::Log.debug("---- HTTP Response Body ----") - Chef::Log.debug(response.body) - Chef::Log.debug("---- End HTTP Response Body -----") + Chef::Log.trace("---- HTTP Response Body ----") + Chef::Log.trace(response.body) + Chef::Log.trace("---- End HTTP Response Body -----") end if req_body - Chef::Log.debug("---- HTTP Request Body ----") - Chef::Log.debug(req_body) - Chef::Log.debug("---- End HTTP Request Body ----") + Chef::Log.trace("---- HTTP Request Body ----") + Chef::Log.trace(req_body) + Chef::Log.trace("---- End HTTP Request Body ----") end end @@ -133,7 +133,7 @@ class Chef if proxy_uri.nil? Net::HTTP else - Chef::Log.debug("Using #{proxy_uri.host}:#{proxy_uri.port} for proxy") + Chef::Log.trace("Using #{proxy_uri.host}:#{proxy_uri.port} for proxy") Net::HTTP.Proxy(proxy_uri.host, proxy_uri.port, http_proxy_user(proxy_uri), http_proxy_pass(proxy_uri)) end diff --git a/lib/chef/http/decompressor.rb b/lib/chef/http/decompressor.rb index 1bba4cc492..cf4a4bc593 100644 --- a/lib/chef/http/decompressor.rb +++ b/lib/chef/http/decompressor.rb @@ -79,10 +79,10 @@ class Chef else case response[CONTENT_ENCODING] when GZIP - Chef::Log.debug "Decompressing gzip response" + Chef::Log.trace "Decompressing gzip response" Zlib::Inflate.new(Zlib::MAX_WBITS + 16).inflate(response.body) when DEFLATE - Chef::Log.debug "Decompressing deflate response" + Chef::Log.trace "Decompressing deflate response" Zlib::Inflate.inflate(response.body) else response.body @@ -94,20 +94,20 @@ class Chef # object you can use to unzip/inflate a streaming response. def stream_response_handler(response) if gzip_disabled? - Chef::Log.debug "disable_gzip is set. \ + Chef::Log.trace "disable_gzip is set. \ Not using #{response[CONTENT_ENCODING]} \ and initializing noop stream deflator." NoopInflater.new else case response[CONTENT_ENCODING] when GZIP - Chef::Log.debug "Initializing gzip stream deflator" + Chef::Log.trace "Initializing gzip stream deflator" GzipInflater.new when DEFLATE - Chef::Log.debug "Initializing deflate stream deflator" + Chef::Log.trace "Initializing deflate stream deflator" DeflateInflater.new else - Chef::Log.debug "content_encoding = '#{response[CONTENT_ENCODING]}' \ + Chef::Log.trace "content_encoding = '#{response[CONTENT_ENCODING]}' \ initializing noop stream deflator." NoopInflater.new end diff --git a/lib/chef/http/http_request.rb b/lib/chef/http/http_request.rb index bd999d8f86..de589e429e 100644 --- a/lib/chef/http/http_request.rb +++ b/lib/chef/http/http_request.rb @@ -127,9 +127,9 @@ class Chef # http://redmine.ruby-lang.org/issues/show/2708 # http://redmine.ruby-lang.org/issues/show/2758 if e.to_s =~ /#{Regexp.escape(%q{undefined method `closed?' for nil:NilClass})}/ - Chef::Log.debug("Rescued error in http connect, re-raising as Errno::ECONNREFUSED to hide bug in net/http") - Chef::Log.debug("#{e.class.name}: #{e}") - Chef::Log.debug(e.backtrace.join("\n")) + Chef::Log.trace("Rescued error in http connect, re-raising as Errno::ECONNREFUSED to hide bug in net/http") + Chef::Log.trace("#{e.class.name}: #{e}") + Chef::Log.trace(e.backtrace.join("\n")) raise Errno::ECONNREFUSED, "Connection refused attempting to contact #{url.scheme}://#{host}:#{port}" else raise diff --git a/lib/chef/http/json_output.rb b/lib/chef/http/json_output.rb index dc363cdc54..25f1380ceb 100644 --- a/lib/chef/http/json_output.rb +++ b/lib/chef/http/json_output.rb @@ -60,9 +60,9 @@ class Chef end [http_response, rest_request, return_value] else - Chef::Log.debug("Expected JSON response, but got content-type '#{http_response['content-type']}'") + Chef::Log.trace("Expected JSON response, but got content-type '#{http_response['content-type']}'") if http_response.body - Chef::Log.debug("Response body contains:\n#{http_response.body.length < 256 ? http_response.body : http_response.body[0..256] + " [...truncated...]"}") + Chef::Log.trace("Response body contains:\n#{http_response.body.length < 256 ? http_response.body : http_response.body[0..256] + " [...truncated...]"}") end return [http_response, rest_request, http_response.body.to_s] end diff --git a/lib/chef/http/validate_content_length.rb b/lib/chef/http/validate_content_length.rb index 3a8d3bda2b..c8e8ac53ad 100644 --- a/lib/chef/http/validate_content_length.rb +++ b/lib/chef/http/validate_content_length.rb @@ -55,7 +55,7 @@ class Chef def handle_stream_complete(http_response, rest_request, return_value) if @content_length_counter.nil? - Chef::Log.debug("No content-length information collected for the streamed download, cannot identify streamed download.") + Chef::Log.trace("No content-length information collected for the streamed download, cannot identify streamed download.") else validate(http_response, @content_length_counter.content_length) end @@ -86,19 +86,19 @@ class Chef transfer_encoding = http_response["transfer-encoding"] if content_length.nil? - Chef::Log.debug "HTTP server did not include a Content-Length header in response, cannot identify truncated downloads." + Chef::Log.trace "HTTP server did not include a Content-Length header in response, cannot identify truncated downloads." return true end if content_length < 0 - Chef::Log.debug "HTTP server responded with a negative Content-Length header (#{content_length}), cannot identify truncated downloads." + Chef::Log.trace "HTTP server responded with a negative Content-Length header (#{content_length}), cannot identify truncated downloads." return true end # if Transfer-Encoding is set the RFC states that we must ignore the Content-Length field # CHEF-5041: some proxies uncompress gzip content, leave the incorrect content-length, but set the transfer-encoding field unless transfer_encoding.nil? - Chef::Log.debug "Transfer-Encoding header is set, skipping Content-Length check." + Chef::Log.trace "Transfer-Encoding header is set, skipping Content-Length check." return true end @@ -106,7 +106,7 @@ class Chef raise Chef::Exceptions::ContentLengthMismatch.new(response_length, content_length) end - Chef::Log.debug "Content-Length validated correctly." + Chef::Log.trace "Content-Length validated correctly." true end end diff --git a/lib/chef/knife/bootstrap.rb b/lib/chef/knife/bootstrap.rb index 2a9fd2da69..15d0f1be18 100644 --- a/lib/chef/knife/bootstrap.rb +++ b/lib/chef/knife/bootstrap.rb @@ -303,7 +303,7 @@ class Chef # Use the template directly if it's a path to an actual file if File.exists?(template) - Chef::Log.debug("Using the specified bootstrap template: #{File.dirname(template)}") + Chef::Log.trace("Using the specified bootstrap template: #{File.dirname(template)}") return template end @@ -316,7 +316,7 @@ class Chef bootstrap_files.flatten! template_file = Array(bootstrap_files).find do |bootstrap_template| - Chef::Log.debug("Looking for bootstrap template in #{File.dirname(bootstrap_template)}") + Chef::Log.trace("Looking for bootstrap template in #{File.dirname(bootstrap_template)}") File.exists?(bootstrap_template) end @@ -325,7 +325,7 @@ class Chef raise Errno::ENOENT end - Chef::Log.debug("Found bootstrap template in #{File.dirname(template_file)}") + Chef::Log.trace("Found bootstrap template in #{File.dirname(template_file)}") template_file end diff --git a/lib/chef/knife/client_reregister.rb b/lib/chef/knife/client_reregister.rb index 5d9b2c0962..cc2b218e87 100644 --- a/lib/chef/knife/client_reregister.rb +++ b/lib/chef/knife/client_reregister.rb @@ -44,7 +44,7 @@ class Chef end client = Chef::ApiClientV1.reregister(@client_name) - Chef::Log.debug("Updated client data: #{client.inspect}") + Chef::Log.trace("Updated client data: #{client.inspect}") key = client.private_key if config[:file] File.open(config[:file], "w") do |f| diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb index b745e77f27..77e7aa0d09 100644 --- a/lib/chef/knife/cookbook_download.rb +++ b/lib/chef/knife/cookbook_download.rb @@ -75,7 +75,7 @@ class Chef basedir = File.join(config[:download_directory], "#{@cookbook_name}-#{cookbook.version}") if File.exists?(basedir) if config[:force] - Chef::Log.debug("Deleting #{basedir}") + Chef::Log.trace("Deleting #{basedir}") FileUtils.rm_rf(basedir) else ui.fatal("Directory #{basedir} exists, use --force to overwrite") @@ -87,7 +87,7 @@ class Chef ui.info("Downloading #{segment}") files.each do |segment_file| dest = File.join(basedir, segment_file["path"].gsub("/", File::SEPARATOR)) - Chef::Log.debug("Downloading #{segment_file['path']} to #{dest}") + Chef::Log.trace("Downloading #{segment_file['path']} to #{dest}") FileUtils.mkdir_p(File.dirname(dest)) tempfile = rest.streaming_request(segment_file["url"]) FileUtils.mv(tempfile.path, dest) diff --git a/lib/chef/knife/cookbook_metadata.rb b/lib/chef/knife/cookbook_metadata.rb index e089c4b777..6f8f6db996 100644 --- a/lib/chef/knife/cookbook_metadata.rb +++ b/lib/chef/knife/cookbook_metadata.rb @@ -80,7 +80,7 @@ class Chef File.open(json_file, "w") do |f| f.write(Chef::JSONCompat.to_json_pretty(md)) end - Chef::Log.debug("Generated #{json_file}") + Chef::Log.trace("Generated #{json_file}") rescue Exceptions::ObsoleteDependencySyntax, Exceptions::InvalidVersionConstraint => e ui.stderr.puts "ERROR: The cookbook '#{cookbook}' contains invalid or obsolete metadata syntax." ui.stderr.puts "in #{file}:" diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index d55d6c123a..e4d55276da 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -78,12 +78,12 @@ class Chef Chef::CookbookUploader.new(cookbook).validate_cookbooks tmp_cookbook_dir = Chef::CookbookSiteStreamingUploader.create_build_dir(cookbook) begin - Chef::Log.debug("Temp cookbook directory is #{tmp_cookbook_dir.inspect}") + Chef::Log.trace("Temp cookbook directory is #{tmp_cookbook_dir.inspect}") ui.info("Making tarball #{cookbook_name}.tgz") shell_out!("#{tar_cmd} -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir) rescue => e ui.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Increase log verbosity (-VV) for more information.") - Chef::Log.debug("\n#{e.backtrace.join("\n")}") + Chef::Log.trace("\n#{e.backtrace.join("\n")}") exit(1) end @@ -98,11 +98,11 @@ class Chef begin do_upload("#{tmp_cookbook_dir}/#{cookbook_name}.tgz", category, Chef::Config[:node_name], Chef::Config[:client_key]) ui.info("Upload complete") - Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}") + Chef::Log.trace("Removing local staging directory at #{tmp_cookbook_dir}") FileUtils.rm_rf tmp_cookbook_dir rescue => e 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")}") + Chef::Log.trace("\n#{e.backtrace.join("\n")}") exit(1) end @@ -118,7 +118,7 @@ class Chef rescue => e return "Other" if e.kind_of?(Net::HTTPServerException) && e.response.code == "404" ui.fatal("Unable to reach Supermarket: #{e.message}. Increase log verbosity (-VV) for more information.") - Chef::Log.debug("\n#{e.backtrace.join("\n")}") + Chef::Log.trace("\n#{e.backtrace.join("\n")}") exit(1) end diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 14b6479b53..026967d6ec 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -46,7 +46,7 @@ class Chef # or directly instantiate the appropriate subclass def self.for_config(chef_config_dir) if autogenerated_manifest? - Chef::Log.debug("Using autogenerated hashed command manifest #{plugin_manifest_path}") + Chef::Log.trace("Using autogenerated hashed command manifest #{plugin_manifest_path}") Knife::SubcommandLoader::HashedCommandLoader.new(chef_config_dir, plugin_manifest) else Knife::SubcommandLoader::GemGlobLoader.new(chef_config_dir) diff --git a/lib/chef/knife/exec.rb b/lib/chef/knife/exec.rb index 0aa8ea2ba8..7b27a51b85 100644 --- a/lib/chef/knife/exec.rb +++ b/lib/chef/knife/exec.rb @@ -68,15 +68,15 @@ class Chef::Knife::Exec < Chef::Knife # Failing that, try searching the script path. If we can't find # anything, fail gracefully. - Chef::Log.debug("Searching script_path: #{config[:script_path].inspect}") + Chef::Log.trace("Searching script_path: #{config[:script_path].inspect}") config[:script_path].each do |path| path = File.expand_path(path) test = File.join(path, x) - Chef::Log.debug("Testing: #{test}") + Chef::Log.trace("Testing: #{test}") if File.exists?(test) script = test - Chef::Log.debug("Found: #{test}") + Chef::Log.trace("Found: #{test}") return script end end diff --git a/lib/chef/knife/osc_user_reregister.rb b/lib/chef/knife/osc_user_reregister.rb index b513f31328..dee1cf41b1 100644 --- a/lib/chef/knife/osc_user_reregister.rb +++ b/lib/chef/knife/osc_user_reregister.rb @@ -49,7 +49,7 @@ class Chef end user = Chef::User.load(@user_name).reregister - Chef::Log.debug("Updated user data: #{user.inspect}") + Chef::Log.trace("Updated user data: #{user.inspect}") key = user.private_key if config[:file] File.open(config[:file], "w") do |f| diff --git a/lib/chef/knife/ssl_check.rb b/lib/chef/knife/ssl_check.rb index b3374e0999..c864ef52ec 100644 --- a/lib/chef/knife/ssl_check.rb +++ b/lib/chef/knife/ssl_check.rb @@ -44,7 +44,7 @@ class Chef def uri @uri ||= begin - Chef::Log.debug("Checking SSL cert on #{given_uri}") + Chef::Log.trace("Checking SSL cert on #{given_uri}") URI.parse(given_uri) end end @@ -131,7 +131,7 @@ class Chef true rescue OpenSSL::SSL::SSLError => e ui.error "The SSL certificate of #{host} could not be verified" - Chef::Log.debug e.message + Chef::Log.trace e.message debug_invalid_cert false end @@ -141,7 +141,7 @@ class Chef true rescue OpenSSL::SSL::SSLError => e ui.error "The SSL cert is signed by a trusted authority but is not valid for the given hostname" - Chef::Log.debug(e) + Chef::Log.trace(e) debug_invalid_host false end diff --git a/lib/chef/knife/ssl_fetch.rb b/lib/chef/knife/ssl_fetch.rb index 238796c804..98c98d06ae 100644 --- a/lib/chef/knife/ssl_fetch.rb +++ b/lib/chef/knife/ssl_fetch.rb @@ -41,7 +41,7 @@ class Chef def uri @uri ||= begin - Chef::Log.debug("Checking SSL cert on #{given_uri}") + Chef::Log.trace("Checking SSL cert on #{given_uri}") URI.parse(given_uri) end end diff --git a/lib/chef/knife/user_reregister.rb b/lib/chef/knife/user_reregister.rb index 172629faea..fec6792134 100644 --- a/lib/chef/knife/user_reregister.rb +++ b/lib/chef/knife/user_reregister.rb @@ -75,7 +75,7 @@ EOF run_osc_11_user_reregister else # EC / CS 12 case user.reregister - Chef::Log.debug("Updated user data: #{user.inspect}") + Chef::Log.trace("Updated user data: #{user.inspect}") key = user.private_key if config[:file] File.open(config[:file], "w") do |f| diff --git a/lib/chef/mixin/create_path.rb b/lib/chef/mixin/create_path.rb index 21a945d2ae..455110b1a2 100644 --- a/lib/chef/mixin/create_path.rb +++ b/lib/chef/mixin/create_path.rb @@ -61,7 +61,7 @@ class Chef # File.directory?(create_path) <- false # Dir.mkdir(create_path) # Dir.mkdir(create_path) <- raises Errno::EEXIST - Chef::Log.debug("Creating directory #{path}") + Chef::Log.trace("Creating directory #{path}") Dir.mkdir(path) rescue Errno::EEXIST end diff --git a/lib/chef/mixin/get_source_from_package.rb b/lib/chef/mixin/get_source_from_package.rb index 96cef058ed..832f96064d 100644 --- a/lib/chef/mixin/get_source_from_package.rb +++ b/lib/chef/mixin/get_source_from_package.rb @@ -18,7 +18,7 @@ # # mixin to make this syntax work without specifying a source: # -# gem_pacakge "/tmp/foo-x.y.z.gem" +# gem_package "/tmp/foo-x.y.z.gem" # rpm_package "/tmp/foo-x.y-z.rpm" # dpkg_package "/tmp/foo-x.y.z.deb" # @@ -38,7 +38,7 @@ class Chef # if we're passed something that looks like a filesystem path, with no source, use it # - require at least one '/' in the path to avoid gem_package "foo" breaking if a file named 'foo' exists in the cwd if new_resource.source.nil? && new_resource.package_name.match(/#{::File::SEPARATOR}/) && ::File.exist?(new_resource.package_name) - Chef::Log.debug("No package source specified, but #{new_resource.package_name} exists on the filesystem, copying to package source") + Chef::Log.trace("No package source specified, but #{new_resource.package_name} exists on the filesystem, copying to package source") new_resource.source(new_resource.package_name) end end diff --git a/lib/chef/mixin/properties.rb b/lib/chef/mixin/properties.rb index 6b95b87063..fb765fbb3a 100644 --- a/lib/chef/mixin/properties.rb +++ b/lib/chef/mixin/properties.rb @@ -149,6 +149,10 @@ class Chef Property.derive(**options) end + def deprecated_property_alias(from, to, message) + Property.emit_deprecated_alias(from, to, message, self) + end + # # Create a lazy value for assignment to a default value. # diff --git a/lib/chef/policy_builder/dynamic.rb b/lib/chef/policy_builder/dynamic.rb index 5b6bc40f9e..84021ea611 100644 --- a/lib/chef/policy_builder/dynamic.rb +++ b/lib/chef/policy_builder/dynamic.rb @@ -63,7 +63,7 @@ class Chef # @return [Chef::Node] the loaded node. def load_node events.node_load_start(node_name, config) - Chef::Log.debug("Building node object for #{node_name}") + Chef::Log.trace("Building node object for #{node_name}") @node = if Chef::Config[:solo_legacy_mode] diff --git a/lib/chef/policy_builder/expand_node_object.rb b/lib/chef/policy_builder/expand_node_object.rb index 26f39e8b73..b390042ea7 100644 --- a/lib/chef/policy_builder/expand_node_object.rb +++ b/lib/chef/policy_builder/expand_node_object.rb @@ -170,7 +170,7 @@ class Chef # === Returns # Hash:: The hash of cookbooks with download URLs as given by the server def sync_cookbooks - Chef::Log.debug("Synchronizing cookbooks") + Chef::Log.trace("Synchronizing cookbooks") begin events.cookbook_resolution_start(@expanded_run_list_with_versions) diff --git a/lib/chef/policy_builder/policyfile.rb b/lib/chef/policy_builder/policyfile.rb index d479808b4a..80ecda1850 100644 --- a/lib/chef/policy_builder/policyfile.rb +++ b/lib/chef/policy_builder/policyfile.rb @@ -216,7 +216,7 @@ class Chef # @return [Hash{String => Chef::CookbookManifest}] A map of # CookbookManifest objects by cookbook name. def sync_cookbooks - Chef::Log.debug("Synchronizing cookbooks") + Chef::Log.trace("Synchronizing cookbooks") synchronizer = Chef::CookbookSynchronizer.new(cookbooks_to_sync, events) synchronizer.sync_cookbooks @@ -275,7 +275,7 @@ class Chef # # Hoists attributes from role_X[policy_group] up to the equivalent role_X level def hoist_policyfile_attributes(policy_group) - Chef::Log.debug("Running attribute Hoist for group #{policy_group}") + Chef::Log.trace("Running attribute Hoist for group #{policy_group}") Chef::Mixin::DeepMerge.hash_only_merge!(node.role_default, node.role_default[policy_group]) if node.role_default.include?(policy_group) Chef::Mixin::DeepMerge.hash_only_merge!(node.role_override, node.role_override[policy_group]) if node.role_override.include?(policy_group) end diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 942fff0ee9..b38ec24de6 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -51,6 +51,27 @@ class Chef new(**options) end + # This is to support #deprecated_property_alias, by emitting an alias and a + # deprecatation warning when called. + # + # @param from [String] Name of the deprecated property + # @param to [String] Name of the correct property + # @param message [String] Deprecation message to show to the cookbook author + # @param declared_in [Class] Class this property comes from + # + def self.emit_deprecated_alias(from, to, message, declared_in) + declared_in.class_eval <<-EOM, __FILE__, __LINE__ + 1 + def #{from}(value=NOT_PASSED) + Chef.deprecated(:property, "#{message}") + #{to}(value) + end + def #{from}=(value) + Chef.deprecated(:property, "#{message}") + #{to} = value + end + EOM + end + # # Create a new property. # @@ -90,6 +111,8 @@ class Chef # @option options [Boolean] :required `true` if this property # must be present; `false` otherwise. This is checked after the resource # is fully initialized. + # @option options [String] :deprecated If set, this property is deprecated and + # will create a deprecation warning. # def initialize(**options) options = options.inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo } @@ -272,7 +295,7 @@ class Chef # def validation_options @validation_options ||= options.reject do |k, v| - [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable, :sensitive, :description, :introduced].include?(k) + [:declared_in, :name, :instance_variable_name, :desired_state, :identity, :default, :name_property, :coerce, :required, :nillable, :sensitive, :description, :introduced, :deprecated].include?(k) end end @@ -380,6 +403,10 @@ class Chef def set(resource, value) value = set_value(resource, input_to_stored_value(resource, value)) + if options.has_key?(:deprecated) + Chef.deprecated(:property, options[:deprecated]) + end + if value.nil? && required? raise Chef::Exceptions::ValidationFailed, "#{name} is a required property" else diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb index 6971465b0a..58659c4e95 100644 --- a/lib/chef/provider.rb +++ b/lib/chef/provider.rb @@ -38,6 +38,7 @@ class Chef attr_accessor :run_context attr_reader :recipe_name + attr_reader :logger include Chef::Mixin::WhyRun extend Chef::Mixin::Provides @@ -90,6 +91,12 @@ class Chef @run_context = run_context @converge_actions = nil + @logger = if run_context + run_context.logger.with_child({ resource: new_resource.name, cookbook: cookbook_name, recipe: recipe_name }) + else + Chef::Log.with_child({ resource: new_resource.name, cookbook: cookbook_name, recipe: recipe_name }) + end + @recipe_name = nil @cookbook_name = nil self.class.include_resource_dsl_module(new_resource) @@ -130,7 +137,7 @@ class Chef end def action_nothing - Chef::Log.debug("Doing nothing for #{@new_resource}") + logger.trace("Doing nothing for #{@new_resource}") true end @@ -271,7 +278,7 @@ class Chef end end.join(", ") end - Chef::Log.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.") + logger.debug("Skipping update of #{new_resource}: has not changed any of the specified properties #{properties_str}.") return false end diff --git a/lib/chef/provider/apt_preference.rb b/lib/chef/provider/apt_preference.rb index 59c6fc7f6d..416a1c0d1d 100644 --- a/lib/chef/provider/apt_preference.rb +++ b/lib/chef/provider/apt_preference.rb @@ -47,7 +47,7 @@ class Chef # cleanup any existing pref files w/o the sanitized name (created by old apt cookbook) if (sanitized_prefname != new_resource.package_name) && ::File.exist?("#{APT_PREFERENCE_DIR}/#{new_resource.package_name}.pref") - Chef::Log.warn "Replacing legacy #{new_resource.package_name}.pref with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}" + logger.warn "Replacing legacy #{new_resource.package_name}.pref with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}" declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{new_resource.package_name}.pref") do action :delete end @@ -55,7 +55,7 @@ class Chef # cleanup any existing pref files without the .pref extension (created by old apt cookbook) if ::File.exist?("#{APT_PREFERENCE_DIR}/#{new_resource.package_name}") - Chef::Log.warn "Replacing legacy #{new_resource.package_name} with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}" + logger.warn "Replacing legacy #{new_resource.package_name} with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}" declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{new_resource.package_name}") do action :delete end @@ -72,7 +72,7 @@ class Chef sanitized_prefname = safe_name(new_resource.package_name) if ::File.exist?("#{APT_PREFERENCE_DIR}/#{sanitized_prefname}.pref") - Chef::Log.info "Un-pinning #{sanitized_prefname} from #{APT_PREFERENCE_DIR}" + logger.info "Un-pinning #{sanitized_prefname} from #{APT_PREFERENCE_DIR}" declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{sanitized_prefname}.pref") do action :delete end diff --git a/lib/chef/provider/apt_repository.rb b/lib/chef/provider/apt_repository.rb index 31dfc5c5d4..91292929e6 100644 --- a/lib/chef/provider/apt_repository.rb +++ b/lib/chef/provider/apt_repository.rb @@ -36,7 +36,7 @@ class Chef action :add do if new_resource.key.nil? - Chef::Log.debug "No 'key' property specified skipping key import" + logger.debug "No 'key' property specified skipping key import" else new_resource.key.each do |k| if is_key_id?(k) && !has_cookbook_file?(k) @@ -93,7 +93,7 @@ class Chef end end else - Chef::Log.debug("/etc/apt/sources.list.d/#{new_resource.name}.list does not exist. Nothing to do") + logger.trace("/etc/apt/sources.list.d/#{new_resource.name}.list does not exist. Nothing to do") end end @@ -129,13 +129,13 @@ class Chef so = shell_out("apt-key list") so.stdout.split(/\n/).map do |t| if t =~ %r{^\/#{key}.*\[expired: .*\]$} - Chef::Log.debug "Found expired key: #{t}" + logger.debug "Found expired key: #{t}" valid = false break end end - Chef::Log.debug "key #{key} #{valid ? "is valid" : "is not valid"}" + logger.debug "key #{key} #{valid ? "is valid" : "is not valid"}" valid end diff --git a/lib/chef/provider/cookbook_file/content.rb b/lib/chef/provider/cookbook_file/content.rb index 1d24dee3e7..82e2cf4390 100644 --- a/lib/chef/provider/cookbook_file/content.rb +++ b/lib/chef/provider/cookbook_file/content.rb @@ -34,7 +34,7 @@ class Chef else tempfile = Chef::FileContentManagement::Tempfile.new(@new_resource).tempfile tempfile.close - Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}") + logger.trace("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}") FileUtils.cp(file_cache_location, tempfile.path) tempfile end diff --git a/lib/chef/provider/cron.rb b/lib/chef/provider/cron.rb index 2e702d4376..70edd89636 100644 --- a/lib/chef/provider/cron.rb +++ b/lib/chef/provider/cron.rb @@ -50,7 +50,7 @@ class Chef crontab.each_line do |line| case line.chomp when "# Chef Name: #{new_resource.name}" - Chef::Log.debug("Found cron '#{new_resource.name}'") + logger.trace("Found cron '#{new_resource.name}'") cron_found = true @cron_exists = true next @@ -79,9 +79,9 @@ class Chef next end end - Chef::Log.debug("Cron '#{new_resource.name}' not found") unless @cron_exists + logger.trace("Cron '#{new_resource.name}' not found") unless @cron_exists else - Chef::Log.debug("Cron empty for '#{new_resource.user}'") + logger.trace("Cron empty for '#{new_resource.user}'") @cron_empty = true end @@ -103,7 +103,7 @@ class Chef if @cron_exists unless cron_different? - Chef::Log.debug("Skipping existing cron entry '#{new_resource.name}'") + logger.trace("Skipping existing cron entry '#{new_resource.name}'") return end read_crontab.each_line do |line| @@ -140,7 +140,7 @@ class Chef converge_by("update crontab entry for #{new_resource}") do write_crontab crontab - Chef::Log.info("#{new_resource} updated crontab entry") + logger.info("#{new_resource} updated crontab entry") end else @@ -149,7 +149,7 @@ class Chef converge_by("add crontab entry for #{new_resource}") do write_crontab crontab - Chef::Log.info("#{new_resource} added crontab entry") + logger.info("#{new_resource} added crontab entry") end end end @@ -184,7 +184,7 @@ class Chef description = cron_found ? "remove #{new_resource.name} from crontab" : "save unmodified crontab" converge_by(description) do write_crontab crontab - Chef::Log.info("#{new_resource} deleted crontab entry") + logger.info("#{new_resource} deleted crontab entry") end end end diff --git a/lib/chef/provider/cron/unix.rb b/lib/chef/provider/cron/unix.rb index 108e73c9d3..15195dbb88 100644 --- a/lib/chef/provider/cron/unix.rb +++ b/lib/chef/provider/cron/unix.rb @@ -36,7 +36,7 @@ class Chef crontab = shell_out("/usr/bin/crontab -l", :user => @new_resource.user) status = crontab.status.exitstatus - Chef::Log.debug crontab.format_for_exception if status > 0 + logger.trace crontab.format_for_exception if status > 0 if status > 1 raise Chef::Exceptions::Cron, "Error determining state of #{@new_resource.name}, exit: #{status}" @@ -62,12 +62,12 @@ class Chef exit_status = 1 end rescue Chef::Exceptions::Exec => e - Chef::Log.debug(e.message) + logger.trace(e.message) exit_status = 1 error_message = e.message rescue ArgumentError => e # usually raised on invalid user. - Chef::Log.debug(e.message) + logger.trace(e.message) exit_status = 1 error_message = e.message end diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb index a176230bba..3e816d5a06 100644 --- a/lib/chef/provider/directory.rb +++ b/lib/chef/provider/directory.rb @@ -129,7 +129,7 @@ class Chef else ::Dir.mkdir(new_resource.path) end - Chef::Log.info("#{new_resource} created directory #{new_resource.path}") + logger.info("#{new_resource} created directory #{new_resource.path}") end end do_acl_changes @@ -144,10 +144,10 @@ class Chef # we don't use rm_rf here because it masks all errors, including # IO errors or permission errors that would prvent the deletion FileUtils.rm_r(new_resource.path) - Chef::Log.info("#{new_resource} deleted #{new_resource.path} recursively") + logger.info("#{new_resource} deleted #{new_resource.path} recursively") else ::Dir.delete(new_resource.path) - Chef::Log.info("#{new_resource} deleted #{new_resource.path}") + logger.info("#{new_resource} deleted #{new_resource.path}") end end end diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index f16c91640b..9c147cb634 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -196,10 +196,10 @@ class Chef unless @reboot_resource.nil? case reboot_action when :nothing - Chef::Log.debug("A reboot was requested by the DSC resource, but reboot_action is :nothing.") - Chef::Log.debug("This dsc_resource will not reboot the node.") + logger.trace("A reboot was requested by the DSC resource, but reboot_action is :nothing.") + logger.trace("This dsc_resource will not reboot the node.") else - Chef::Log.debug("Requesting node reboot with #{reboot_action}.") + logger.trace("Requesting node reboot with #{reboot_action}.") @reboot_resource.run_action(reboot_action) end end diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb index b568a3bab9..7a101fa68b 100644 --- a/lib/chef/provider/dsc_script.rb +++ b/lib/chef/provider/dsc_script.rb @@ -44,7 +44,7 @@ class Chef if ! @resource_converged converge_by(generate_description) do run_configuration(:set) - Chef::Log.info("DSC resource configuration completed successfully") + logger.info("DSC resource configuration completed successfully") end end end @@ -95,7 +95,7 @@ class Chef configuration_document = generate_configuration_document(config_directory, configuration_flags) @operations[operation].call(config_manager, configuration_document, shellout_flags) rescue Exception => e - Chef::Log.error("DSC operation failed: #{e.message}") + logger.error("DSC operation failed: #{e.message}") raise e ensure ::FileUtils.rm_rf(config_directory) @@ -124,7 +124,7 @@ class Chef generator.configuration_document_from_script_path(@dsc_resource.command, configuration_name, configuration_flags, shellout_flags) else # If code is also not provided, we mimic what the other script resources do (execute nothing) - Chef::Log.warn("Neither code or command were provided for dsc_resource[#{@dsc_resource.name}].") unless @dsc_resource.code + logger.warn("Neither code or command were provided for dsc_resource[#{@dsc_resource.name}].") unless @dsc_resource.code generator.configuration_document_from_script_code(@dsc_resource.code || "", configuration_flags, @dsc_resource.imports, shellout_flags) end end diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb index 0e9acb4028..6872e2d67d 100644 --- a/lib/chef/provider/execute.rb +++ b/lib/chef/provider/execute.rb @@ -49,7 +49,7 @@ class Chef def action_run if creates && sentinel_file.exist? - Chef::Log.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do") + logger.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do") return false end @@ -68,7 +68,7 @@ class Chef raise end end - Chef::Log.info("#{new_resource} ran successfully") + logger.info("#{new_resource} ran successfully") end end @@ -99,7 +99,7 @@ class Chef opts[:umask] = umask if umask opts[:log_level] = :info opts[:log_tag] = new_resource.to_s - if (Chef::Log.info? || live_stream?) && !sensitive? + if (logger.info? || live_stream?) && !sensitive? if run_context.events.formatter? opts[:live_stream] = Chef::EventDispatch::EventsOutputStream.new(run_context.events, :name => :execute) elsif stream_to_stdout? diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb index 86e7e5a5c4..05522f1eb8 100644 --- a/lib/chef/provider/file.rb +++ b/lib/chef/provider/file.rb @@ -92,7 +92,7 @@ class Chef if !needs_creating? # we are updating an existing file if managing_content? - Chef::Log.debug("#{new_resource} checksumming file at #{new_resource.path}.") + logger.trace("#{new_resource} checksumming file at #{new_resource.path}.") current_resource.checksum(checksum(current_resource.path)) else # if the file does not exist or is not a file, then the checksum is invalid/pointless @@ -151,7 +151,7 @@ class Chef unless ::File.exist?(new_resource.path) action_create else - Chef::Log.debug("#{new_resource} exists at #{new_resource.path} taking no action.") + logger.trace("#{new_resource} exists at #{new_resource.path} taking no action.") end end @@ -160,7 +160,7 @@ class Chef converge_by("delete file #{new_resource.path}") do do_backup unless file_class.symlink?(new_resource.path) ::File.delete(new_resource.path) - Chef::Log.info("#{new_resource} deleted file at #{new_resource.path}") + logger.info("#{new_resource} deleted file at #{new_resource.path}") end end end @@ -170,7 +170,7 @@ class Chef converge_by("update utime on file #{new_resource.path}") do time = Time.now ::File.utime(time, time, new_resource.path) - Chef::Log.info("#{new_resource} updated atime and mtime to #{time}") + logger.info("#{new_resource} updated atime and mtime to #{time}") end end @@ -227,9 +227,9 @@ class Chef elsif file_class.symlink?(path) && new_resource.manage_symlink_source verify_symlink_sanity(path) elsif file_class.symlink?(new_resource.path) && new_resource.manage_symlink_source.nil? - Chef::Log.warn("File #{path} managed by #{new_resource} is really a symlink. Managing the source file instead.") - Chef::Log.warn("Disable this warning by setting `manage_symlink_source true` on the resource") - Chef::Log.warn("In a future Chef release, 'manage_symlink_source' will not be enabled by default") + logger.warn("File #{path} managed by #{new_resource} is really a symlink. Managing the source file instead.") + logger.warn("Disable this warning by setting `manage_symlink_source true` on the resource") + logger.warn("In a future Chef release, 'manage_symlink_source' will not be enabled by default") verify_symlink_sanity(path) elsif new_resource.force_unlink [nil, nil, nil] @@ -273,7 +273,7 @@ class Chef def content @content ||= begin load_current_resource if current_resource.nil? - @content_class.new(new_resource, current_resource, @run_context) + @content_class.new(new_resource, current_resource, @run_context, logger) end end @@ -361,7 +361,7 @@ class Chef if needs_creating? converge_by("create new file #{new_resource.path}") do deployment_strategy.create(new_resource.path) - Chef::Log.info("#{new_resource} created file #{new_resource.path}") + logger.info("#{new_resource} created file #{new_resource.path}") end end end @@ -377,7 +377,7 @@ class Chef def update_file_contents do_backup unless needs_creating? deployment_strategy.deploy(tempfile.path, ::File.realpath(new_resource.path)) - Chef::Log.info("#{new_resource} updated file contents #{new_resource.path}") + logger.info("#{new_resource} updated file contents #{new_resource.path}") if managing_content? # save final checksum for reporting. new_resource.final_checksum = checksum(new_resource.path) @@ -428,7 +428,7 @@ class Chef restore_security_context(::File.realpath(new_resource.path), recursive) end else - Chef::Log.debug "selinux utilities can not be found. Skipping selinux permission fixup." + logger.trace "selinux utilities can not be found. Skipping selinux permission fixup." end end end @@ -442,7 +442,7 @@ class Chef end def contents_changed? - Chef::Log.debug "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}" + logger.trace "calculating checksum of #{tempfile.path} to compare with #{current_resource.checksum}" tempfile_checksum != current_resource.checksum end diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb index bdbeca5941..302404e293 100644 --- a/lib/chef/provider/git.rb +++ b/lib/chef/provider/git.rb @@ -80,7 +80,7 @@ class Chef enable_submodules add_remotes else - Chef::Log.debug "#{new_resource} checkout destination #{cwd} already exists or is a non-empty directory" + logger.trace "#{new_resource} checkout destination #{cwd} already exists or is a non-empty directory" end end @@ -93,11 +93,11 @@ class Chef def action_sync if existing_git_clone? - Chef::Log.debug "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}" + logger.trace "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}" unless current_revision_matches_target_revision? fetch_updates enable_submodules - Chef::Log.info "#{new_resource} updated to revision #{target_revision}" + logger.info "#{new_resource} updated to revision #{target_revision}" end add_remotes else @@ -116,7 +116,7 @@ class Chef if match @git_gem_version = Gem::Version.new(match[1]) else - Chef::Log.warn "Unable to parse git version from '#{output}'" + logger.warn "Unable to parse git version from '#{output}'" @git_gem_version = nil end @git_gem_version @@ -131,7 +131,7 @@ class Chef end def find_current_revision - Chef::Log.debug("#{new_resource} finding current git revision") + logger.trace("#{new_resource} finding current git revision") if ::File.exist?(::File.join(cwd, ".git")) # 128 is returned when we're not in a git repo. this is fine result = git("rev-parse", "HEAD", cwd: cwd, returns: [0, 128]).stdout.strip @@ -143,7 +143,7 @@ class Chef if new_resource.additional_remotes.length > 0 new_resource.additional_remotes.each_pair do |remote_name, remote_url| converge_by("add remote #{remote_name} from #{remote_url}") do - Chef::Log.info "#{new_resource} adding git remote #{remote_name} = #{remote_url}" + logger.info "#{new_resource} adding git remote #{remote_name} = #{remote_url}" setup_remote_tracking_branches(remote_name, remote_url) end end @@ -161,7 +161,7 @@ class Chef clone_cmd << "\"#{new_resource.repository}\"" clone_cmd << "\"#{cwd}\"" - Chef::Log.info "#{new_resource} cloning repo #{new_resource.repository} to #{cwd}" + logger.info "#{new_resource} cloning repo #{new_resource.repository} to #{cwd}" git clone_cmd end end @@ -173,16 +173,16 @@ class Chef # checkout into a local branch rather than a detached HEAD git("branch", "-f", new_resource.checkout_branch, sha_ref, cwd: cwd) git("checkout", new_resource.checkout_branch, cwd: cwd) - Chef::Log.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{sha_ref}" + logger.info "#{new_resource} checked out branch: #{new_resource.revision} onto: #{new_resource.checkout_branch} reference: #{sha_ref}" end end def enable_submodules if new_resource.enable_submodules converge_by("enable git submodules for #{new_resource}") do - Chef::Log.info "#{new_resource} synchronizing git submodules" + logger.info "#{new_resource} synchronizing git submodules" git("submodule", "sync", cwd: cwd) - Chef::Log.info "#{new_resource} enabling git submodules" + logger.info "#{new_resource} enabling git submodules" # the --recursive flag means we require git 1.6.5+ now, see CHEF-1827 git("submodule", "update", "--init", "--recursive", cwd: cwd) end @@ -193,7 +193,7 @@ class Chef setup_remote_tracking_branches(new_resource.remote, new_resource.repository) 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 - Chef::Log.debug "Fetching updates from #{new_resource.remote} and resetting to revision #{target_revision}" + 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("reset", "--hard", target_revision, cwd: cwd) @@ -202,7 +202,7 @@ class Chef def setup_remote_tracking_branches(remote_name, remote_url) converge_by("set up remote tracking branches for #{remote_url} at #{remote_name}") do - Chef::Log.debug "#{new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}" + logger.trace "#{new_resource} configuring remote tracking branches for repository #{remote_url} " + "at remote #{remote_name}" check_remote_command = ["config", "--get", "remote.#{remote_name}.url"] remote_status = git(check_remote_command, cwd: cwd, returns: [0, 1, 2]) case remote_status.exitstatus @@ -246,7 +246,7 @@ class Chef alias :revision_slug :target_revision def remote_resolve_reference - Chef::Log.debug("#{new_resource} resolving remote reference") + logger.trace("#{new_resource} resolving remote reference") # The sha pointed to by an annotated tag is identified by the # '^{}' suffix appended to the tag. In order to resolve # annotated tags, we have to search for "revision*" and @@ -334,7 +334,7 @@ class Chef def git(*args, **run_opts) git_command = ["git", args].compact.join(" ") - Chef::Log.debug "running #{git_command}" + logger.trace "running #{git_command}" shell_out!(git_command, run_options(run_opts)) end diff --git a/lib/chef/provider/group.rb b/lib/chef/provider/group.rb index ce20a2b5e5..51e4f280fe 100644 --- a/lib/chef/provider/group.rb +++ b/lib/chef/provider/group.rb @@ -41,7 +41,7 @@ class Chef group_info = Etc.getgrnam(new_resource.group_name) rescue ArgumentError @group_exists = false - Chef::Log.debug("#{new_resource} group does not exist") + logger.trace("#{new_resource} group does not exist") end if group_info @@ -126,13 +126,13 @@ class Chef when false converge_by("create group #{new_resource.group_name}") do create_group - Chef::Log.info("#{new_resource} created") + logger.info("#{new_resource} created") end else if compare_group converge_by(["alter group #{new_resource.group_name}"] + change_desc) do manage_group - Chef::Log.info("#{new_resource} altered") + logger.info("#{new_resource} altered") end end end @@ -142,7 +142,7 @@ class Chef return unless @group_exists converge_by("remove group #{new_resource.group_name}") do remove_group - Chef::Log.info("#{new_resource} removed") + logger.info("#{new_resource} removed") end end @@ -150,7 +150,7 @@ class Chef return unless @group_exists && compare_group converge_by(["manage group #{new_resource.group_name}"] + change_desc) do manage_group - Chef::Log.info("#{new_resource} managed") + logger.info("#{new_resource} managed") end end @@ -158,7 +158,7 @@ class Chef return unless compare_group converge_by(["modify group #{new_resource.group_name}"] + change_desc) do manage_group - Chef::Log.info("#{new_resource} modified") + logger.info("#{new_resource} modified") end end diff --git a/lib/chef/provider/group/aix.rb b/lib/chef/provider/group/aix.rb index 405e43cff2..5c500e2753 100644 --- a/lib/chef/provider/group/aix.rb +++ b/lib/chef/provider/group/aix.rb @@ -66,7 +66,7 @@ class Chef { gid: "id" }.sort_by { |a| a[0] }.each do |field, option| next unless current_resource.send(field) != new_resource.send(field) if new_resource.send(field) - Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field)}") + logger.trace("#{new_resource} setting #{field} to #{new_resource.send(field)}") opts << "#{option}=#{new_resource.send(field)}" end end diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb index fe152eda33..81c7d66aa8 100644 --- a/lib/chef/provider/group/dscl.rb +++ b/lib/chef/provider/group/dscl.rb @@ -51,7 +51,7 @@ class Chef group_info = safe_dscl("read", "/Groups/#{new_resource.group_name}") rescue Chef::Exceptions::Group @group_exists = false - Chef::Log.debug("#{new_resource} group does not exist") + logger.trace("#{new_resource} group does not exist") end if group_info @@ -105,7 +105,7 @@ class Chef def set_members # First reset the memberships if the append is not set unless new_resource.append - Chef::Log.debug("#{new_resource} removing group members #{current_resource.members.join(' ')}") unless current_resource.members.empty? + logger.trace("#{new_resource} removing group members #{current_resource.members.join(' ')}") unless current_resource.members.empty? safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembers", "") # clear guid list safe_dscl("create", "/Groups/#{new_resource.group_name}", "GroupMembership", "") # clear user list current_resource.members([ ]) @@ -118,7 +118,7 @@ class Chef members_to_be_added << member unless current_resource.members.include?(member) end unless members_to_be_added.empty? - Chef::Log.debug("#{new_resource} setting group members #{members_to_be_added.join(', ')}") + logger.trace("#{new_resource} setting group members #{members_to_be_added.join(', ')}") safe_dscl("append", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_added) end end @@ -130,7 +130,7 @@ class Chef members_to_be_removed << member if current_resource.members.include?(member) end unless members_to_be_removed.empty? - Chef::Log.debug("#{new_resource} removing group members #{members_to_be_removed.join(', ')}") + logger.trace("#{new_resource} removing group members #{members_to_be_removed.join(', ')}") safe_dscl("delete", "/Groups/#{new_resource.group_name}", "GroupMembership", *members_to_be_removed) end end diff --git a/lib/chef/provider/group/groupadd.rb b/lib/chef/provider/group/groupadd.rb index 7826078e55..7d7fac146c 100644 --- a/lib/chef/provider/group/groupadd.rb +++ b/lib/chef/provider/group/groupadd.rb @@ -67,7 +67,7 @@ class Chef members_to_be_added << member unless current_resource.members.include?(member) end members_to_be_added.each do |member| - Chef::Log.debug("#{new_resource} appending member #{member} to group #{new_resource.group_name}") + logger.trace("#{new_resource} appending member #{member} to group #{new_resource.group_name}") add_member(member) end end @@ -79,13 +79,13 @@ class Chef end members_to_be_removed.each do |member| - Chef::Log.debug("#{new_resource} removing member #{member} from group #{new_resource.group_name}") + logger.trace("#{new_resource} removing member #{member} from group #{new_resource.group_name}") remove_member(member) end end else members_description = new_resource.members.empty? ? "none" : new_resource.members.join(", ") - Chef::Log.debug("#{new_resource} setting group members to: #{members_description}") + logger.trace("#{new_resource} setting group members to: #{members_description}") set_members(new_resource.members) end end @@ -113,7 +113,7 @@ class Chef next unless new_resource.send(field) opts << option opts << new_resource.send(field) - Chef::Log.debug("#{new_resource} set #{field} to #{new_resource.send(field)}") + logger.trace("#{new_resource} set #{field} to #{new_resource.send(field)}") end opts << new_resource.group_name opts diff --git a/lib/chef/provider/group/groupmod.rb b/lib/chef/provider/group/groupmod.rb index 01581e4863..13f83db4c4 100644 --- a/lib/chef/provider/group/groupmod.rb +++ b/lib/chef/provider/group/groupmod.rb @@ -66,13 +66,13 @@ class Chef end end - Chef::Log.debug("#{new_resource} not changing group members, the group has no members to add") if members_to_be_added.empty? + logger.trace("#{new_resource} not changing group members, the group has no members to add") if members_to_be_added.empty? add_group_members(members_to_be_added) else # We are resetting the members of a group so use the same trick reset_group_membership - Chef::Log.debug("#{new_resource} setting group members to: none") if new_resource.members.empty? + logger.trace("#{new_resource} setting group members to: none") if new_resource.members.empty? add_group_members(new_resource.members) end end @@ -84,7 +84,7 @@ class Chef # Adds a list of usernames to the group using `user mod` def add_group_members(members) - Chef::Log.debug("#{new_resource} adding members #{members.join(', ')}") unless members.empty? + logger.trace("#{new_resource} adding members #{members.join(', ')}") unless members.empty? members.each do |user| shell_out_compact!("user", "mod", "-G", new_resource.group_name, user) end diff --git a/lib/chef/provider/group/pw.rb b/lib/chef/provider/group/pw.rb index 115ccf3714..b0393a147e 100644 --- a/lib/chef/provider/group/pw.rb +++ b/lib/chef/provider/group/pw.rb @@ -44,7 +44,7 @@ class Chef # new or existing group. Because pw groupadd does not support the -m # and -d options used by manage_group, we treat group creation as a # special case and use -M. - Chef::Log.debug("#{new_resource} setting group members: #{new_resource.members.join(',')}") + logger.trace("#{new_resource} setting group members: #{new_resource.members.join(',')}") command += [ "-M", new_resource.members.join(",") ] end @@ -75,7 +75,7 @@ class Chef def set_options opts = [ new_resource.group_name ] if new_resource.gid && (current_resource.gid != new_resource.gid) - Chef::Log.debug("#{new_resource}: current gid (#{current_resource.gid}) doesnt match target gid (#{new_resource.gid}), changing it") + logger.trace("#{new_resource}: current gid (#{current_resource.gid}) doesnt match target gid (#{new_resource.gid}), changing it") opts << "-g" opts << new_resource.gid end @@ -119,12 +119,12 @@ class Chef end unless members_to_be_added.empty? - Chef::Log.debug("#{new_resource} adding group members: #{members_to_be_added.join(',')}") + logger.trace("#{new_resource} adding group members: #{members_to_be_added.join(',')}") opts << [ "-m", members_to_be_added.join(",") ] end unless members_to_be_removed.empty? - Chef::Log.debug("#{new_resource} removing group members: #{members_to_be_removed.join(',')}") + logger.trace("#{new_resource} removing group members: #{members_to_be_removed.join(',')}") opts << [ "-d", members_to_be_removed.join(",") ] end diff --git a/lib/chef/provider/group/windows.rb b/lib/chef/provider/group/windows.rb index c0026bf368..e0cb3b804b 100644 --- a/lib/chef/provider/group/windows.rb +++ b/lib/chef/provider/group/windows.rb @@ -42,7 +42,7 @@ class Chef members = @net_group.local_get_members rescue @group_exists = false - Chef::Log.debug("#{new_resource} group does not exist") + logger.trace("#{new_resource} group does not exist") end if members @@ -99,7 +99,7 @@ class Chef def lookup_account_name(account_name) Chef::ReservedNames::Win32::Security.lookup_account_name(locally_qualified_name(account_name))[1].to_s rescue Chef::Exceptions::Win32APIError - Chef::Log.warn("SID for '#{locally_qualified_name(account_name)}' could not be found") + logger.warn("SID for '#{locally_qualified_name(account_name)}' could not be found") "" end diff --git a/lib/chef/provider/http_request.rb b/lib/chef/provider/http_request.rb index cafdc1e007..885d473a7a 100644 --- a/lib/chef/provider/http_request.rb +++ b/lib/chef/provider/http_request.rb @@ -40,8 +40,8 @@ class Chef "#{new_resource.url}", new_resource.headers ) - Chef::Log.info("#{new_resource} HEAD to #{new_resource.url} successful") - Chef::Log.debug("#{new_resource} HEAD request response: #{modified}") + logger.info("#{new_resource} HEAD to #{new_resource.url} successful") + logger.trace("#{new_resource} HEAD request response: #{modified}") # :head is usually used to trigger notifications, which converge_by now does if modified != false converge_by("#{new_resource} HEAD to #{new_resource.url} returned modified, trigger notifications") {} @@ -57,8 +57,8 @@ class Chef "#{new_resource.url}", new_resource.headers ) - Chef::Log.info("#{new_resource} GET to #{new_resource.url} successful") - Chef::Log.debug("#{new_resource} GET request response: #{body}") + logger.info("#{new_resource} GET to #{new_resource.url} successful") + logger.trace("#{new_resource} GET request response: #{body}") end end @@ -71,8 +71,8 @@ class Chef message, new_resource.headers ) - Chef::Log.info("#{new_resource} PATCH to #{new_resource.url} successful") - Chef::Log.debug("#{new_resource} PATCH request response: #{body}") + logger.info("#{new_resource} PATCH to #{new_resource.url} successful") + logger.trace("#{new_resource} PATCH request response: #{body}") end end @@ -85,8 +85,8 @@ class Chef message, new_resource.headers ) - Chef::Log.info("#{new_resource} PUT to #{new_resource.url} successful") - Chef::Log.debug("#{new_resource} PUT request response: #{body}") + logger.info("#{new_resource} PUT to #{new_resource.url} successful") + logger.trace("#{new_resource} PUT request response: #{body}") end end @@ -99,8 +99,8 @@ class Chef message, new_resource.headers ) - Chef::Log.info("#{new_resource} POST to #{new_resource.url} message: #{message.inspect} successful") - Chef::Log.debug("#{new_resource} POST request response: #{body}") + logger.info("#{new_resource} POST to #{new_resource.url} message: #{message.inspect} successful") + logger.trace("#{new_resource} POST request response: #{body}") end end @@ -112,8 +112,8 @@ class Chef new_resource.headers ) new_resource.updated_by_last_action(true) - Chef::Log.info("#{new_resource} DELETE to #{new_resource.url} successful") - Chef::Log.debug("#{new_resource} DELETE request response: #{body}") + logger.info("#{new_resource} DELETE to #{new_resource.url} successful") + logger.trace("#{new_resource} DELETE request response: #{body}") end end diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index c8da5e255f..243c8ee9c3 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -164,7 +164,7 @@ class Chef command = add_command converge_by("run #{command.join(' ')} to add #{new_resource}") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} added") + logger.info("#{new_resource} added") end end end @@ -180,7 +180,7 @@ class Chef command = enable_command converge_by("run #{command.join(' ')} to enable #{new_resource}") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} enabled") + logger.info("#{new_resource} enabled") end end @@ -190,10 +190,10 @@ class Chef command = delete_command converge_by("run #{command.join(' ')} to delete #{new_resource}") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} deleted") + logger.info("#{new_resource} deleted") end else - Chef::Log.debug("#{new_resource} does not exist - nothing to do") + logger.trace("#{new_resource} does not exist - nothing to do") end delete_config end @@ -205,10 +205,10 @@ class Chef command = disable_command converge_by("run #{command.join(' ')} to disable #{new_resource}") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} disabled") + logger.info("#{new_resource} disabled") end else - Chef::Log.debug("#{new_resource} does not exist - nothing to do") + logger.trace("#{new_resource} does not exist - nothing to do") end end diff --git a/lib/chef/provider/launchd.rb b/lib/chef/provider/launchd.rb index 8d868784dd..0bac995247 100644 --- a/lib/chef/provider/launchd.rb +++ b/lib/chef/provider/launchd.rb @@ -119,7 +119,7 @@ class Chef end invalid_type = lltstype != "LoginWindow" if root && agent && invalid_action && invalid_type - Chef::Log.debug("#{label}: Aqua LaunchAgents shouldn't be loaded as root") + logger.trace("#{label}: Aqua LaunchAgents shouldn't be loaded as root") return false end true diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb index 94f9120582..783d52d09a 100644 --- a/lib/chef/provider/link.rb +++ b/lib/chef/provider/link.rb @@ -115,8 +115,8 @@ class Chef if new_resource.link_type == :symbolic converge_by("create symlink at #{new_resource.target_file} to #{new_resource.to}") do file_class.symlink(canonicalize(new_resource.to), new_resource.target_file) - Chef::Log.debug("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}") - Chef::Log.info("#{new_resource} created") + logger.trace("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}") + logger.info("#{new_resource} created") # file_class.symlink will create the link with default access controls. # This means that the access controls of the file could be different # than those captured during the initial evaluation of current_resource. @@ -127,8 +127,8 @@ class Chef elsif new_resource.link_type == :hard converge_by("create hard link at #{new_resource.target_file} to #{new_resource.to}") do file_class.link(new_resource.to, new_resource.target_file) - Chef::Log.debug("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}") - Chef::Log.info("#{new_resource} created") + logger.trace("#{new_resource} created #{new_resource.link_type} link from #{new_resource.target_file} -> #{new_resource.to}") + logger.info("#{new_resource} created") end end end @@ -146,12 +146,12 @@ class Chef if Chef::Platform.windows? && ::File.directory?(current_resource.target_file) converge_by("delete link to dir at #{new_resource.target_file}") do ::Dir.delete(new_resource.target_file) - Chef::Log.info("#{new_resource} deleted") + logger.info("#{new_resource} deleted") end else converge_by("delete link to file at #{new_resource.target_file}") do ::File.delete(new_resource.target_file) - Chef::Log.info("#{new_resource} deleted") + logger.info("#{new_resource} deleted") end end end diff --git a/lib/chef/provider/log.rb b/lib/chef/provider/log.rb index 214f284fbb..8d15883ff6 100644 --- a/lib/chef/provider/log.rb +++ b/lib/chef/provider/log.rb @@ -34,7 +34,7 @@ class Chef # # @return [true] Always returns true def action_write - Chef::Log.send(new_resource.level, new_resource.message) + logger.send(new_resource.level, new_resource.message) new_resource.updated_by_last_action(true) if Chef::Config[:count_log_resource_updates] end end diff --git a/lib/chef/provider/lwrp_base.rb b/lib/chef/provider/lwrp_base.rb index 09f90b7403..70f2af6539 100644 --- a/lib/chef/provider/lwrp_base.rb +++ b/lib/chef/provider/lwrp_base.rb @@ -52,7 +52,7 @@ class Chef def build_from_file(cookbook_name, filename, run_context) if LWRPBase.loaded_lwrps[filename] - Chef::Log.debug("LWRP provider #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.") + Chef::Log.trace("LWRP provider #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.") return loaded_lwrps[filename] end @@ -71,7 +71,7 @@ class Chef define_singleton_method(:inspect) { to_s } end - Chef::Log.debug("Loaded contents of #{filename} into provider #{resource_name} (#{provider_class})") + Chef::Log.trace("Loaded contents of #{filename} into provider #{resource_name} (#{provider_class})") LWRPBase.loaded_lwrps[filename] = true diff --git a/lib/chef/provider/mdadm.rb b/lib/chef/provider/mdadm.rb index 7d7b26acfa..c5f15a851a 100644 --- a/lib/chef/provider/mdadm.rb +++ b/lib/chef/provider/mdadm.rb @@ -28,7 +28,7 @@ class Chef def load_current_resource @current_resource = Chef::Resource::Mdadm.new(new_resource.name) current_resource.raid_device(new_resource.raid_device) - Chef::Log.debug("#{new_resource} checking for software raid device #{current_resource.raid_device}") + logger.trace("#{new_resource} checking for software raid device #{current_resource.raid_device}") device_not_found = 4 mdadm = shell_out!("mdadm --detail --test #{new_resource.raid_device}", :returns => [0, device_not_found]) @@ -45,12 +45,12 @@ class Chef command << " --bitmap=#{new_resource.bitmap}" if new_resource.bitmap command << " --layout=#{new_resource.layout}" if new_resource.layout command << " --raid-devices #{new_resource.devices.length} #{new_resource.devices.join(" ")}" - Chef::Log.debug("#{new_resource} mdadm command: #{command}") + logger.trace("#{new_resource} mdadm command: #{command}") shell_out!(command) - Chef::Log.info("#{new_resource} created raid device (#{new_resource.raid_device})") + logger.info("#{new_resource} created raid device (#{new_resource.raid_device})") end else - Chef::Log.debug("#{new_resource} raid device already exists, skipping create (#{new_resource.raid_device})") + logger.trace("#{new_resource} raid device already exists, skipping create (#{new_resource.raid_device})") end end @@ -58,12 +58,12 @@ class Chef unless current_resource.exists converge_by("assemble RAID device #{new_resource.raid_device}") do command = "yes | mdadm --assemble #{new_resource.raid_device} #{new_resource.devices.join(" ")}" - Chef::Log.debug("#{new_resource} mdadm command: #{command}") + logger.trace("#{new_resource} mdadm command: #{command}") shell_out!(command) - Chef::Log.info("#{new_resource} assembled raid device (#{new_resource.raid_device})") + logger.info("#{new_resource} assembled raid device (#{new_resource.raid_device})") end else - Chef::Log.debug("#{new_resource} raid device already exists, skipping assemble (#{new_resource.raid_device})") + logger.trace("#{new_resource} raid device already exists, skipping assemble (#{new_resource.raid_device})") end end @@ -71,12 +71,12 @@ class Chef if current_resource.exists converge_by("stop RAID device #{new_resource.raid_device}") do command = "yes | mdadm --stop #{new_resource.raid_device}" - Chef::Log.debug("#{new_resource} mdadm command: #{command}") + logger.trace("#{new_resource} mdadm command: #{command}") shell_out!(command) - Chef::Log.info("#{new_resource} stopped raid device (#{new_resource.raid_device})") + logger.info("#{new_resource} stopped raid device (#{new_resource.raid_device})") end else - Chef::Log.debug("#{new_resource} raid device doesn't exist (#{new_resource.raid_device}) - not stopping") + logger.trace("#{new_resource} raid device doesn't exist (#{new_resource.raid_device}) - not stopping") end end diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb index 533dd2514b..994d67939b 100644 --- a/lib/chef/provider/mount.rb +++ b/lib/chef/provider/mount.rb @@ -41,10 +41,10 @@ class Chef unless current_resource.mounted converge_by("mount #{current_resource.device} to #{current_resource.mount_point}") do mount_fs - Chef::Log.info("#{new_resource} mounted") + logger.info("#{new_resource} mounted") end else - Chef::Log.debug("#{new_resource} is already mounted") + logger.trace("#{new_resource} is already mounted") end end @@ -52,10 +52,10 @@ class Chef if current_resource.mounted converge_by("unmount #{current_resource.device}") do umount_fs - Chef::Log.info("#{new_resource} unmounted") + logger.info("#{new_resource} unmounted") end else - Chef::Log.debug("#{new_resource} is already unmounted") + logger.trace("#{new_resource} is already unmounted") end end @@ -64,21 +64,21 @@ class Chef if new_resource.supports[:remount] converge_by("remount #{current_resource.device}") do remount_fs - Chef::Log.info("#{new_resource} remounted") + logger.info("#{new_resource} remounted") end else converge_by("unmount #{current_resource.device}") do umount_fs - Chef::Log.info("#{new_resource} unmounted") + logger.info("#{new_resource} unmounted") end wait_until_unmounted(unmount_retries) converge_by("mount #{current_resource.device}") do mount_fs - Chef::Log.info("#{new_resource} mounted") + logger.info("#{new_resource} mounted") end end else - Chef::Log.debug("#{new_resource} not mounted, nothing to remount") + logger.trace("#{new_resource} not mounted, nothing to remount") end end @@ -86,10 +86,10 @@ class Chef unless current_resource.enabled && mount_options_unchanged? && device_unchanged? converge_by("enable #{current_resource.device}") do enable_fs - Chef::Log.info("#{new_resource} enabled") + logger.info("#{new_resource} enabled") end else - Chef::Log.debug("#{new_resource} already enabled") + logger.trace("#{new_resource} already enabled") end end @@ -97,10 +97,10 @@ class Chef if current_resource.enabled converge_by("disable #{current_resource.device}") do disable_fs - Chef::Log.info("#{new_resource} disabled") + logger.info("#{new_resource} disabled") end else - Chef::Log.debug("#{new_resource} already disabled") + logger.trace("#{new_resource} already disabled") end end diff --git a/lib/chef/provider/mount/aix.rb b/lib/chef/provider/mount/aix.rb index 4b60a4295d..c1ed499957 100644 --- a/lib/chef/provider/mount/aix.rb +++ b/lib/chef/provider/mount/aix.rb @@ -57,7 +57,7 @@ class Chef enabled = true @current_resource.fstype($1) @current_resource.options($4) - Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") next when /^#{Regexp.escape(@new_resource.mount_point)}:#{nodename}:(\S+)::(\S+)?:(\S+):(\S+):(\S+):(\S+)/ # mount point entry with hostname or ipv4 address @@ -65,7 +65,7 @@ class Chef @current_resource.fstype($1) @current_resource.options($4) @current_resource.device("") - Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") next when /^#{Regexp.escape(@new_resource.mount_point)}:(\S+)?:(\S+):#{devicename}:(\S+)?:(\S+):(\S+):(\S+):(\S+)/ # mount point entry with hostname or ipv4 address @@ -73,7 +73,7 @@ class Chef @current_resource.fstype($2) @current_resource.options($5) @current_resource.device(devicename + "/") - Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") next when /^#{Regexp.escape(@new_resource.mount_point)}:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)/ if $3.split("=")[0] == "LABEL" || $1.split("=")[0] == "LABEL" @@ -86,10 +86,10 @@ class Chef if @current_resource.device_type != @new_resource.device_type enabled = true - Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + logger.trace("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") else enabled = false - Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/filesystems") + logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/filesystems") end end @@ -109,10 +109,10 @@ class Chef case line when /#{search_device}\s+#{Regexp.escape(@new_resource.mount_point)}/ mounted = true - Chef::Log.debug("Special device #{device_logstring} mounted as #{@new_resource.mount_point}") + logger.trace("Special device #{device_logstring} mounted as #{@new_resource.mount_point}") when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ mounted = false - Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") + logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end end @current_resource.mounted(mounted) @@ -137,9 +137,9 @@ class Chef end command << " #{@new_resource.mount_point}" shell_out!(command) - Chef::Log.debug("#{@new_resource} is mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}") else - Chef::Log.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is already mounted at #{@new_resource.mount_point}") end end @@ -153,7 +153,7 @@ class Chef def enable_fs if @current_resource.enabled && mount_options_unchanged? - Chef::Log.debug("#{@new_resource} is already enabled - nothing to do") + logger.trace("#{@new_resource} is already enabled - nothing to do") return nil end @@ -174,7 +174,7 @@ class Chef fstab.puts("\tvfs\t\t= #{@new_resource.fstype}") fstab.puts("\tmount\t\t= false") fstab.puts "\toptions\t\t= #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty? - Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end @@ -210,7 +210,7 @@ class Chef contents.each { |line| fstab.puts line } end else - Chef::Log.debug("#{@new_resource} is not enabled - nothing to do") + logger.trace("#{@new_resource} is not enabled - nothing to do") end end diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index dd35a84186..d0da30a30a 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -64,11 +64,11 @@ class Chef @current_resource.options($3) @current_resource.dump($4.to_i) @current_resource.pass($5.to_i) - Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab") + logger.trace("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/fstab") next when /^[\/\w]+\s+#{Regexp.escape(@new_resource.mount_point)}\s+/ enabled = false - Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") + logger.trace("Found conflicting mount point #{@new_resource.mount_point} in /etc/fstab") end end @current_resource.enabled(enabled) @@ -90,10 +90,10 @@ class Chef case line when /^#{device_mount_regex}\s+on\s+#{Regexp.escape(real_mount_point)}\s/ mounted = true - Chef::Log.debug("Special device #{device_logstring} mounted as #{real_mount_point}") + logger.trace("Special device #{device_logstring} mounted as #{real_mount_point}") when /^([\/\w])+\son\s#{Regexp.escape(real_mount_point)}\s+/ mounted = false - Chef::Log.debug("Special device #{$~[1]} mounted as #{real_mount_point}") + logger.trace("Special device #{$~[1]} mounted as #{real_mount_point}") end end @current_resource.mounted(mounted) @@ -114,18 +114,18 @@ class Chef end command << " #{@new_resource.mount_point}" shell_out!(command) - Chef::Log.debug("#{@new_resource} is mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}") else - Chef::Log.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is already mounted at #{@new_resource.mount_point}") end end def umount_fs if @current_resource.mounted shell_out!("umount #{@new_resource.mount_point}") - Chef::Log.debug("#{@new_resource} is no longer mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is no longer mounted at #{@new_resource.mount_point}") else - Chef::Log.debug("#{@new_resource} is not mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is not mounted at #{@new_resource.mount_point}") end end @@ -137,13 +137,13 @@ class Chef if @current_resource.mounted && @new_resource.supports[:remount] shell_out!(remount_command) @new_resource.updated_by_last_action(true) - Chef::Log.debug("#{@new_resource} is remounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is remounted at #{@new_resource.mount_point}") elsif @current_resource.mounted umount_fs sleep 1 mount_fs else - Chef::Log.debug("#{@new_resource} is not mounted at #{@new_resource.mount_point} - nothing to do") + logger.trace("#{@new_resource} is not mounted at #{@new_resource.mount_point} - nothing to do") end end @@ -154,7 +154,7 @@ class Chef def enable_fs if @current_resource.enabled && mount_options_unchanged? && device_unchanged? - Chef::Log.debug("#{@new_resource} is already enabled - nothing to do") + logger.trace("#{@new_resource} is already enabled - nothing to do") return nil end @@ -165,7 +165,7 @@ class Chef end ::File.open("/etc/fstab", "a") do |fstab| fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? default_mount_options : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") - Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end @@ -177,7 +177,7 @@ class Chef ::File.readlines("/etc/fstab").reverse_each do |line| if !found && line =~ /^#{device_fstab_regex}\s+#{Regexp.escape(@new_resource.mount_point)}\s/ found = true - Chef::Log.debug("#{@new_resource} is removed from fstab") + logger.trace("#{@new_resource} is removed from fstab") next else contents << line @@ -188,7 +188,7 @@ class Chef contents.reverse_each { |line| fstab.puts line } end else - Chef::Log.debug("#{@new_resource} is not enabled - nothing to do") + logger.trace("#{@new_resource} is not enabled - nothing to do") end end diff --git a/lib/chef/provider/mount/solaris.rb b/lib/chef/provider/mount/solaris.rb index f59a2d2c6a..095c07432a 100644 --- a/lib/chef/provider/mount/solaris.rb +++ b/lib/chef/provider/mount/solaris.rb @@ -74,8 +74,8 @@ class Chef end def mount_fs - actual_options = options || [] - actual_options.delete("noauto") + actual_options = native_options(options) + actual_options.delete("-") command = "mount -F #{fstype}" command << " -o #{actual_options.join(',')}" unless actual_options.empty? command << " #{device} #{mount_point}" @@ -88,8 +88,8 @@ class Chef def remount_fs # FIXME: Should remount always do the remount or only if the options change? - actual_options = options || [] - actual_options.delete("noauto") + actual_options = native_options(options) + actual_options.delete("-") mount_options = actual_options.empty? ? "" : ",#{actual_options.join(',')}" shell_out!("mount -o remount#{mount_options} #{mount_point}") end @@ -112,7 +112,7 @@ class Chef else # this is likely some kind of internal error, since we should only call disable_fs when there # the filesystem we want to disable is enabled. - Chef::Log.warn("#{new_resource} did not find the mountpoint to disable in the vfstab") + logger.warn("#{new_resource} did not find the mountpoint to disable in the vfstab") end end @@ -153,10 +153,10 @@ class Chef shell_out!("mount -v").stdout.each_line do |line| case line when /^#{device_regex}\s+on\s+#{Regexp.escape(mount_point)}\s+/ - Chef::Log.debug("Special device #{device} is mounted as #{mount_point}") + logger.trace("Special device #{device} is mounted as #{mount_point}") mounted = true when /^([\/\w]+)\son\s#{Regexp.escape(mount_point)}\s+/ - Chef::Log.debug("Special device #{Regexp.last_match[1]} is mounted as #{mount_point}") + logger.trace("Special device #{Regexp.last_match[1]} is mounted as #{mount_point}") mounted = false end end @@ -191,12 +191,12 @@ class Chef end end pass = (Regexp.last_match[2] == "-") ? 0 : Regexp.last_match[2].to_i - Chef::Log.debug("Found mount #{device} to #{mount_point} in #{VFSTAB}") + logger.trace("Found mount #{device} to #{mount_point} in #{VFSTAB}") next when /^[-\/\w]+\s+[-\/\w]+\s+#{Regexp.escape(mount_point)}\s+/ # if we find a mountpoint on top of our mountpoint, then we are not enabled enabled = false - Chef::Log.debug("Found conflicting mount point #{mount_point} in #{VFSTAB}") + logger.trace("Found conflicting mount point #{mount_point} in #{VFSTAB}") end end [enabled, fstype, options, pass] @@ -234,7 +234,7 @@ class Chef ::File.readlines(VFSTAB).reverse_each do |line| if !found && line =~ /^#{device_regex}\s+\S+\s+#{Regexp.escape(mount_point)}/ found = true - Chef::Log.debug("#{new_resource} is removed from vfstab") + logger.trace("#{new_resource} is removed from vfstab") next end contents << line diff --git a/lib/chef/provider/mount/windows.rb b/lib/chef/provider/mount/windows.rb index 0fb5aa7645..1bd932729d 100644 --- a/lib/chef/provider/mount/windows.rb +++ b/lib/chef/provider/mount/windows.rb @@ -47,15 +47,15 @@ class Chef @current_resource = Chef::Resource::Mount.new(@new_resource.name) @current_resource.mount_point(@new_resource.mount_point) - Chef::Log.debug("Checking for mount point #{@current_resource.mount_point}") + logger.trace("Checking for mount point #{@current_resource.mount_point}") begin @current_resource.device(@mount.device) - Chef::Log.debug("#{@current_resource.device} mounted on #{@new_resource.mount_point}") + logger.trace("#{@current_resource.device} mounted on #{@new_resource.mount_point}") @current_resource.mounted(true) rescue ArgumentError => e @current_resource.mounted(false) - Chef::Log.debug("#{@new_resource.mount_point} is not mounted: #{e.message}") + logger.trace("#{@new_resource.mount_point} is not mounted: #{e.message}") end end @@ -65,18 +65,18 @@ class Chef :username => @new_resource.username, :domainname => @new_resource.domain, :password => @new_resource.password) - Chef::Log.debug("#{@new_resource} is mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is mounted at #{@new_resource.mount_point}") else - Chef::Log.debug("#{@new_resource} is already mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is already mounted at #{@new_resource.mount_point}") end end def umount_fs if @current_resource.mounted @mount.delete - Chef::Log.debug("#{@new_resource} is no longer mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is no longer mounted at #{@new_resource.mount_point}") else - Chef::Log.debug("#{@new_resource} is not mounted at #{@new_resource.mount_point}") + logger.trace("#{@new_resource} is not mounted at #{@new_resource.mount_point}") end end diff --git a/lib/chef/provider/noop.rb b/lib/chef/provider/noop.rb index ca8f7324f7..077da3f0b4 100644 --- a/lib/chef/provider/noop.rb +++ b/lib/chef/provider/noop.rb @@ -27,7 +27,7 @@ class Chef def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^action_/ - Chef::Log.debug("NoOp-ing for #{method_sym}") + logger.trace("NoOp-ing for #{method_sym}") else super end diff --git a/lib/chef/provider/ohai.rb b/lib/chef/provider/ohai.rb index 42fc450271..0b65a1d28a 100644 --- a/lib/chef/provider/ohai.rb +++ b/lib/chef/provider/ohai.rb @@ -37,7 +37,7 @@ class Chef # the path are picked up by ohai. ohai.all_plugins new_resource.plugin node.automatic_attrs.merge! ohai.data - Chef::Log.info("#{new_resource} reloaded") + logger.info("#{new_resource} reloaded") end end end diff --git a/lib/chef/provider/osx_profile.rb b/lib/chef/provider/osx_profile.rb index 326534c4bd..e753f84d86 100644 --- a/lib/chef/provider/osx_profile.rb +++ b/lib/chef/provider/osx_profile.rb @@ -189,14 +189,14 @@ class Chef def install_profile(profile_path) cmd = "profiles -I -F '#{profile_path}'" - Chef::Log.debug("cmd: #{cmd}") + logger.trace("cmd: #{cmd}") shellout_results = shell_out(cmd) shellout_results.exitstatus end def remove_profile cmd = "profiles -R -p '#{@new_profile_identifier}'" - Chef::Log.debug("cmd: #{cmd}") + logger.trace("cmd: #{cmd}") shellout_results = shell_out(cmd) shellout_results.exitstatus end @@ -214,7 +214,7 @@ class Chef tempfile = generate_tempfile write_installed_profiles(tempfile) installed_profiles = read_plist(tempfile) - Chef::Log.debug("Saved profiles to run_state") + logger.trace("Saved profiles to run_state") # Clean up the temp file as we do not need it anymore ::File.unlink(tempfile) installed_profiles diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 70483f9124..133f87dad9 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -84,7 +84,7 @@ class Chef action :install do unless target_version_array.any? - Chef::Log.debug("#{new_resource} is already installed - nothing to do") + logger.trace("#{new_resource} is already installed - nothing to do") return end @@ -101,7 +101,7 @@ class Chef multipackage_api_adapter(package_names_for_targets, versions_for_targets) do |name, version| install_package(name, version) end - Chef::Log.info("#{new_resource} installed #{package_names_for_targets} at #{versions_for_targets}") + logger.info("#{new_resource} installed #{package_names_for_targets} at #{versions_for_targets}") end end @@ -119,7 +119,7 @@ class Chef action :upgrade do unless target_version_array.any? - Chef::Log.debug("#{new_resource} no versions to upgrade - nothing to do") + logger.trace("#{new_resource} no versions to upgrade - nothing to do") return end @@ -128,7 +128,7 @@ class Chef upgrade_package(name, version) end log_allow_downgrade = allow_downgrade ? "(allow_downgrade)" : "" - Chef::Log.info("#{new_resource} upgraded#{log_allow_downgrade} #{package_names_for_targets} to #{versions_for_targets}") + logger.info("#{new_resource} upgraded#{log_allow_downgrade} #{package_names_for_targets} to #{versions_for_targets}") end end @@ -154,10 +154,10 @@ class Chef multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version| remove_package(name, version) end - Chef::Log.info("#{new_resource} removed") + logger.info("#{new_resource} removed") end else - Chef::Log.debug("#{new_resource} package does not exist - nothing to do") + logger.trace("#{new_resource} package does not exist - nothing to do") end end @@ -189,19 +189,19 @@ class Chef multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version| purge_package(name, version) end - Chef::Log.info("#{new_resource} purged") + logger.info("#{new_resource} purged") end end end action :reconfig do if current_resource.version.nil? - Chef::Log.debug("#{new_resource} is NOT installed - nothing to do") + logger.trace("#{new_resource} is NOT installed - nothing to do") return end unless new_resource.response_file - Chef::Log.debug("#{new_resource} no response_file provided - nothing to do") + logger.trace("#{new_resource} no response_file provided - nothing to do") return end @@ -212,10 +212,10 @@ class Chef reconfig_package(name, version) end - Chef::Log.info("#{new_resource} reconfigured") + logger.info("#{new_resource} reconfigured") end else - Chef::Log.debug("#{new_resource} preseeding has not changed - nothing to do") + logger.trace("#{new_resource} preseeding has not changed - nothing to do") end end @@ -230,11 +230,11 @@ class Chef converge_by("lock #{description}package #{current_resource.package_name}") do multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version| lock_package(name, version) - Chef::Log.info("#{new_resource} locked") + logger.info("#{new_resource} locked") end end else - Chef::Log.debug("#{new_resource} is already locked") + logger.trace("#{new_resource} is already locked") end end @@ -249,11 +249,11 @@ class Chef converge_by("unlock #{description}package #{current_resource.package_name}") do multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version| unlock_package(name, version) - Chef::Log.info("#{new_resource} unlocked") + logger.info("#{new_resource} unlocked") end end else - Chef::Log.debug("#{new_resource} is already unlocked") + logger.trace("#{new_resource} is already unlocked") end end @@ -383,7 +383,7 @@ class Chef def get_preseed_file(name, version) resource = preseed_resource(name, version) resource.run_action(:create) - Chef::Log.debug("#{new_resource} fetched preseed file to #{resource.path}") + logger.trace("#{new_resource} fetched preseed file to #{resource.path}") if resource.updated_by_last_action? resource.path @@ -399,14 +399,14 @@ class Chef # The full path where the preseed file will be stored cache_seed_to = "#{file_cache_dir}/#{name}-#{version}.seed" - Chef::Log.debug("#{new_resource} fetching preseed file to #{cache_seed_to}") + logger.trace("#{new_resource} fetching preseed file to #{cache_seed_to}") if template_available?(new_resource.response_file) - Chef::Log.debug("#{new_resource} fetching preseed file via Template") + logger.trace("#{new_resource} fetching preseed file via Template") remote_file = Chef::Resource::Template.new(cache_seed_to, run_context) remote_file.variables(new_resource.response_file_variables) elsif cookbook_file_available?(new_resource.response_file) - Chef::Log.debug("#{new_resource} fetching preseed file via cookbook_file") + logger.trace("#{new_resource} fetching preseed file via cookbook_file") remote_file = Chef::Resource::CookbookFile.new(cache_seed_to, run_context) else message = "No template or cookbook file found for response file #{new_resource.response_file}" @@ -480,22 +480,22 @@ class Chef when :upgrade if version_equals?(current_version, new_version) # this is an odd use case - Chef::Log.debug("#{new_resource} #{package_name} #{new_version} is already installed -- you are equality pinning with an :upgrade action, this may be deprecated in the future") + logger.trace("#{new_resource} #{package_name} #{new_version} is already installed -- you are equality pinning with an :upgrade action, this may be deprecated in the future") target_version_array.push(nil) elsif version_equals?(current_version, candidate_version) - Chef::Log.debug("#{new_resource} #{package_name} #{candidate_version} is already installed") + logger.trace("#{new_resource} #{package_name} #{candidate_version} is already installed") target_version_array.push(nil) elsif candidate_version.nil? - Chef::Log.debug("#{new_resource} #{package_name} has no candidate_version to upgrade to") + logger.trace("#{new_resource} #{package_name} has no candidate_version to upgrade to") target_version_array.push(nil) elsif current_version.nil? - Chef::Log.debug("#{new_resource} has no existing installed version. Installing install #{candidate_version}") + logger.trace("#{new_resource} has no existing installed version. Installing install #{candidate_version}") target_version_array.push(candidate_version) elsif version_compare(current_version, candidate_version) == 1 && !allow_downgrade - Chef::Log.debug("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)") + logger.trace("#{new_resource} #{package_name} has installed version #{current_version}, which is newer than available version #{candidate_version}. Skipping...)") target_version_array.push(nil) else - Chef::Log.debug("#{new_resource} #{package_name} is out of date, will upgrade to #{candidate_version}") + logger.trace("#{new_resource} #{package_name} is out of date, will upgrade to #{candidate_version}") target_version_array.push(candidate_version) end @@ -503,17 +503,17 @@ class Chef if new_version if version_requirement_satisfied?(current_version, new_version) - Chef::Log.debug("#{new_resource} #{package_name} #{current_version} satisifies #{new_version} requirement") + logger.trace("#{new_resource} #{package_name} #{current_version} satisifies #{new_version} requirement") target_version_array.push(nil) else - Chef::Log.debug("#{new_resource} #{package_name} #{current_version} needs updating to #{new_version}") + logger.trace("#{new_resource} #{package_name} #{current_version} needs updating to #{new_version}") target_version_array.push(new_version) end elsif current_version.nil? - Chef::Log.debug("#{new_resource} #{package_name} not installed, installing #{candidate_version}") + logger.trace("#{new_resource} #{package_name} not installed, installing #{candidate_version}") target_version_array.push(candidate_version) else - Chef::Log.debug("#{new_resource} #{package_name} #{current_version} already installed") + logger.trace("#{new_resource} #{package_name} #{current_version} already installed") target_version_array.push(nil) end @@ -641,7 +641,7 @@ class Chef package_name = package_name_array[i] # we require at least one '/' in the package_name to avoid [XXX_]package 'foo' breaking due to a random 'foo' file in cwd if use_package_name_for_source? && source.nil? && package_name.match(/#{::File::SEPARATOR}/) && ::File.exist?(package_name) - Chef::Log.debug("No package source specified, but #{package_name} exists on filesystem, using #{package_name} as source.") + logger.trace("No package source specified, but #{package_name} exists on filesystem, using #{package_name} as source.") package_name else source diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index 38dd7398c9..2692ec9f15 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -104,12 +104,12 @@ class Chef end def preseed_package(preseed_file) - Chef::Log.info("#{new_resource} pre-seeding package installation instructions") + logger.info("#{new_resource} pre-seeding package installation instructions") run_noninteractive("debconf-set-selections", preseed_file) end def reconfig_package(name, version) - Chef::Log.info("#{new_resource} reconfiguring") + logger.info("#{new_resource} reconfiguring") run_noninteractive("dpkg-reconfigure", name) end @@ -174,10 +174,10 @@ class Chef case line when /^\s{2}Installed: (.+)$/ current_version = ( $1 != "(none)" ) ? $1 : nil - Chef::Log.debug("#{new_resource} installed version for #{pkg} is #{$1}") + logger.trace("#{new_resource} installed version for #{pkg} is #{$1}") when /^\s{2}Candidate: (.+)$/ candidate_version = ( $1 != "(none)" ) ? $1 : nil - Chef::Log.debug("#{new_resource} candidate version for #{pkg} is #{$1}") + logger.trace("#{new_resource} candidate version for #{pkg} is #{$1}") end end [ current_version, candidate_version ] @@ -209,7 +209,7 @@ class Chef if newpkg virtual = true - Chef::Log.info("#{new_resource} is a virtual package, actually acting on package[#{newpkg}]") + logger.info("#{new_resource} is a virtual package, actually acting on package[#{newpkg}]") current_version, candidate_version = resolve_package_versions(newpkg) end end diff --git a/lib/chef/provider/package/bff.rb b/lib/chef/provider/package/bff.rb index 9a2ccd25b4..44fadd92df 100644 --- a/lib/chef/provider/package/bff.rb +++ b/lib/chef/provider/package/bff.rb @@ -48,7 +48,7 @@ class Chef current_resource.package_name(new_resource.package_name) if package_source_found? - Chef::Log.debug("#{new_resource} checking pkg status") + logger.trace("#{new_resource} checking pkg status") ret = shell_out_compact_timeout("installp", "-L", "-d", new_resource.source) ret.stdout.each_line do |line| case line @@ -56,7 +56,7 @@ class Chef fields = line.split(":") new_resource.version(fields[2]) when /^#{new_resource.package_name}:/ - Chef::Log.warn("You are installing a bff package by product name. For idempotent installs, please install individual filesets") + logger.warn("You are installing a bff package by product name. For idempotent installs, please install individual filesets") fields = line.split(":") new_resource.version(fields[2]) end @@ -64,13 +64,13 @@ class Chef raise Chef::Exceptions::Package, "package source #{new_resource.source} does not provide package #{new_resource.package_name}" unless new_resource.version end - Chef::Log.debug("#{new_resource} checking install state") + logger.trace("#{new_resource} checking install state") ret = shell_out_compact_timeout("lslpp", "-lcq", current_resource.package_name) ret.stdout.each_line do |line| case line when /#{current_resource.package_name}/ fields = line.split(":") - Chef::Log.debug("#{new_resource} version #{fields[2]} is already installed") + logger.trace("#{new_resource} version #{fields[2]} is already installed") current_resource.version(fields[2]) end end @@ -92,7 +92,7 @@ class Chef fields = line.split(":") @candidate_version = fields[2] new_resource.version(fields[2]) - Chef::Log.debug("#{new_resource} setting install candidate version to #{@candidate_version}") + logger.trace("#{new_resource} setting install candidate version to #{@candidate_version}") end end unless ret.exitstatus == 0 @@ -110,13 +110,13 @@ class Chef # So far, the code has been tested only with standalone packages. # def install_package(name, version) - Chef::Log.debug("#{new_resource} package install options: #{options}") + logger.trace("#{new_resource} package install options: #{options}") if options.nil? shell_out_compact_timeout!("installp", "-aYF", "-d", new_resource.source, new_resource.package_name) - Chef::Log.debug("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") + logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") else shell_out_compact_timeout!("installp", "-aYF", options, "-d", new_resource.source, new_resource.package_name) - Chef::Log.debug("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") + logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") end end @@ -125,10 +125,10 @@ class Chef def remove_package(name, version) if options.nil? shell_out_compact_timeout!("installp", "-u", name) - Chef::Log.debug("#{new_resource} removed version #{new_resource.version}") + logger.trace("#{new_resource} removed version #{new_resource.version}") else shell_out_compact_timeout!("installp", "-u", options, name) - Chef::Log.debug("#{new_resource} removed version #{new_resource.version}") + logger.trace("#{new_resource} removed version #{new_resource.version}") end end diff --git a/lib/chef/provider/package/cab.rb b/lib/chef/provider/package/cab.rb index 21ea95b85e..79292293d2 100644 --- a/lib/chef/provider/package/cab.rb +++ b/lib/chef/provider/package/cab.rb @@ -46,7 +46,7 @@ class Chef def download_source_file source_resource.run_action(:create) - Chef::Log.debug("#{new_resource} fetched source file to #{source_resource.path}") + logger.trace("#{new_resource} fetched source file to #{source_resource.path}") source_resource.path end @@ -84,7 +84,7 @@ class Chef # e.g. Package_for_KB2975719~31bf3856ad364e35~amd64~~6.3.1.8 package = new_cab_identity # Search for just the package name to catch a different version being installed - Chef::Log.debug("#{new_resource} searching for installed package #{package['name']}") + logger.trace("#{new_resource} searching for installed package #{package['name']}") existing_package_identities = installed_packages.map do |p| split_package_identity(p["package_identity"]) end @@ -108,7 +108,7 @@ class Chef end def new_cab_identity - Chef::Log.debug("#{new_resource} getting product version for package at #{cab_file_source}") + logger.trace("#{new_resource} getting product version for package at #{cab_file_source}") @new_cab_identity ||= cab_identity_from_cab_file end diff --git a/lib/chef/provider/package/dnf/python_helper.rb b/lib/chef/provider/package/dnf/python_helper.rb index 1801caa1c1..5524740fc4 100644 --- a/lib/chef/provider/package/dnf/python_helper.rb +++ b/lib/chef/provider/package/dnf/python_helper.rb @@ -64,7 +64,7 @@ class Chef def compare_versions(version1, version2) with_helper do json = build_version_query("versioncompare", [version1, version2]) - Chef::Log.debug "sending '#{json}' to python helper" + Chef::Log.trace "sending '#{json}' to python helper" stdin.syswrite json + "\n" stdout.sysread(4096).chomp.to_i end @@ -74,12 +74,12 @@ class Chef def query(action, provides, version = nil, arch = nil) with_helper do json = build_query(action, provides, version, arch) - Chef::Log.debug "sending '#{json}' to python helper" + Chef::Log.trace "sending '#{json}' to python helper" stdin.syswrite json + "\n" output = stdout.sysread(4096).chomp - Chef::Log.debug "got '#{output}' from python helper" + Chef::Log.trace "got '#{output}' from python helper" version = parse_response(output) - Chef::Log.debug "parsed #{version} from python helper" + Chef::Log.trace "parsed #{version} from python helper" version end end @@ -149,14 +149,14 @@ class Chef end output = drain_stderr unless output.empty? - Chef::Log.debug "discarding output on stderr from python helper: #{output}" + Chef::Log.trace "discarding output on stderr from python helper: #{output}" end ret rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e output = drain_stderr if ( max_retries -= 1 ) > 0 unless output.empty? - Chef::Log.debug "discarding output on stderr from python helper: #{output}" + Chef::Log.trace "discarding output on stderr from python helper: #{output}" end restart retry diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb index cc79f9fc3a..aa53f6145f 100644 --- a/lib/chef/provider/package/dpkg.rb +++ b/lib/chef/provider/package/dpkg.rb @@ -73,17 +73,17 @@ class Chef def install_package(name, version) sources = name.map { |n| name_sources[n] } - Chef::Log.info("#{new_resource} installing package(s): #{name.join(' ')}") + logger.info("#{new_resource} installing package(s): #{name.join(' ')}") run_noninteractive("dpkg", "-i", *options, *sources) end def remove_package(name, version) - Chef::Log.info("#{new_resource} removing package(s): #{name.join(' ')}") + logger.info("#{new_resource} removing package(s): #{name.join(' ')}") run_noninteractive("dpkg", "-r", *options, *name) end def purge_package(name, version) - Chef::Log.info("#{new_resource} purging packages(s): #{name.join(' ')}") + logger.info("#{new_resource} purging packages(s): #{name.join(' ')}") run_noninteractive("dpkg", "-P", *options, *name) end @@ -92,12 +92,12 @@ class Chef end def preseed_package(preseed_file) - Chef::Log.info("#{new_resource} pre-seeding package installation instructions") + logger.info("#{new_resource} pre-seeding package installation instructions") run_noninteractive("debconf-set-selections", *preseed_file) end def reconfig_package(name, version) - Chef::Log.info("#{new_resource} reconfiguring") + logger.info("#{new_resource} reconfiguring") run_noninteractive("dpkg-reconfigure", *name) end @@ -123,7 +123,7 @@ class Chef end def read_current_version_of_package(package_name) - Chef::Log.debug("#{new_resource} checking install state of #{package_name}") + logger.trace("#{new_resource} checking install state of #{package_name}") status = shell_out_compact_timeout!("dpkg", "-s", package_name, returns: [0, 1]) package_installed = false status.stdout.each_line do |line| @@ -135,7 +135,7 @@ class Chef package_installed = true when DPKG_VERSION if package_installed - Chef::Log.debug("#{new_resource} current version is #{$1}") + logger.trace("#{new_resource} current version is #{$1}") return $1 end end @@ -191,7 +191,7 @@ class Chef @name_pkginfo ||= begin pkginfos = resolved_source_array.map do |src| - Chef::Log.debug("#{new_resource} checking #{src} dpkg status") + logger.trace("#{new_resource} checking #{src} dpkg status") status = shell_out_compact_timeout!("dpkg-deb", "-W", src) status.stdout end diff --git a/lib/chef/provider/package/freebsd/base.rb b/lib/chef/provider/package/freebsd/base.rb index 64efe61bfb..fc62fa7cc0 100644 --- a/lib/chef/provider/package/freebsd/base.rb +++ b/lib/chef/provider/package/freebsd/base.rb @@ -74,10 +74,10 @@ class Chef current_resource.package_name(new_resource.package_name) current_resource.version(current_installed_version) - Chef::Log.debug("#{new_resource} current version is #{current_resource.version}") if current_resource.version + logger.trace("#{new_resource} current version is #{current_resource.version}") if current_resource.version @candidate_version = candidate_version - Chef::Log.debug("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version + logger.trace("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version current_resource end diff --git a/lib/chef/provider/package/freebsd/pkg.rb b/lib/chef/provider/package/freebsd/pkg.rb index 1d66d29be6..04e6e5c427 100644 --- a/lib/chef/provider/package/freebsd/pkg.rb +++ b/lib/chef/provider/package/freebsd/pkg.rb @@ -38,11 +38,11 @@ class Chef else shell_out_compact_timeout!("pkg_add", "-r", package_name, env: { "PACKAGEROOT" => new_resource.source, "LC_ALL" => nil }).status end - Chef::Log.debug("#{new_resource} installed from: #{new_resource.source}") + logger.trace("#{new_resource} installed from: #{new_resource.source}") when /^\// shell_out_compact_timeout!("pkg_add", file_candidate_version_path, env: { "PKG_PATH" => new_resource.source, "LC_ALL" => nil }).status - Chef::Log.debug("#{new_resource} installed from: #{new_resource.source}") + logger.trace("#{new_resource} installed from: #{new_resource.source}") else shell_out_compact_timeout!("pkg_add", "-r", latest_link_name, env: nil).status diff --git a/lib/chef/provider/package/freebsd/pkgng.rb b/lib/chef/provider/package/freebsd/pkgng.rb index 9a5f0e9472..c9c0947f9b 100644 --- a/lib/chef/provider/package/freebsd/pkgng.rb +++ b/lib/chef/provider/package/freebsd/pkgng.rb @@ -29,7 +29,7 @@ class Chef case new_resource.source when /^(http|ftp|\/)/ shell_out_compact_timeout!("pkg", "add", options, new_resource.source, env: { "LC_ALL" => nil }).status - Chef::Log.debug("#{new_resource} installed from: #{new_resource.source}") + logger.trace("#{new_resource} installed from: #{new_resource.source}") else shell_out_compact_timeout!("pkg", "install", "-y", options, name, env: { "LC_ALL" => nil }).status end diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index f4e19bc857..643faf23c6 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -35,11 +35,11 @@ class Chef self.current_resource = Chef::Resource::HomebrewPackage.new(new_resource.name) current_resource.package_name(new_resource.package_name) current_resource.version(current_installed_version) - Chef::Log.debug("#{new_resource} current version is #{current_resource.version}") if current_resource.version + logger.trace("#{new_resource} current version is #{current_resource.version}") if current_resource.version @candidate_version = candidate_version - Chef::Log.debug("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version + logger.trace("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version current_resource end @@ -126,7 +126,7 @@ class Chef homebrew_uid = find_homebrew_uid(new_resource.respond_to?(:homebrew_user) && new_resource.homebrew_user) homebrew_user = Etc.getpwuid(homebrew_uid) - Chef::Log.debug "Executing '#{command.join(' ')}' as user '#{homebrew_user.name}'" + logger.trace "Executing '#{command.join(' ')}' as user '#{homebrew_user.name}'" # FIXME: this 1800 second default timeout should be deprecated output = shell_out_compact_timeout!(*command, timeout: 1800, user: homebrew_uid, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil }) output.stdout.chomp diff --git a/lib/chef/provider/package/ips.rb b/lib/chef/provider/package/ips.rb index 255a4a2508..cabc7fc68b 100644 --- a/lib/chef/provider/package/ips.rb +++ b/lib/chef/provider/package/ips.rb @@ -58,7 +58,7 @@ class Chef def load_current_resource @current_resource = Chef::Resource::IpsPackage.new(new_resource.name) current_resource.package_name(new_resource.package_name) - Chef::Log.debug("Checking package status for #{new_resource.name}") + logger.trace("Checking package status for #{new_resource.name}") current_resource.version(get_current_version) @candidate_version = get_candidate_version current_resource diff --git a/lib/chef/provider/package/macports.rb b/lib/chef/provider/package/macports.rb index 514f3580d4..ddaf19a76f 100644 --- a/lib/chef/provider/package/macports.rb +++ b/lib/chef/provider/package/macports.rb @@ -11,7 +11,7 @@ class Chef current_resource.package_name(new_resource.package_name) current_resource.version(current_installed_version) - Chef::Log.debug("#{new_resource} current version is #{current_resource.version}") if current_resource.version + logger.trace("#{new_resource} current version is #{current_resource.version}") if current_resource.version @candidate_version = macports_candidate_version @@ -19,7 +19,7 @@ class Chef raise Chef::Exceptions::Package, "Could not get a candidate version for this package -- #{new_resource.name} does not seem to be a valid package!" end - Chef::Log.debug("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version + logger.trace("#{new_resource} candidate version is #{@candidate_version}") if @candidate_version current_resource end diff --git a/lib/chef/provider/package/msu.rb b/lib/chef/provider/package/msu.rb index 8e00a10169..c4e53a0fdf 100644 --- a/lib/chef/provider/package/msu.rb +++ b/lib/chef/provider/package/msu.rb @@ -83,7 +83,7 @@ class Chef def download_source_file source_resource.run_action(:create) - Chef::Log.debug("#{new_resource} fetched source file to #{source_resource.path}") + logger.trace("#{new_resource} fetched source file to #{source_resource.path}") source_resource.path end diff --git a/lib/chef/provider/package/openbsd.rb b/lib/chef/provider/package/openbsd.rb index 2614683fba..f528c48f08 100644 --- a/lib/chef/provider/package/openbsd.rb +++ b/lib/chef/provider/package/openbsd.rb @@ -73,7 +73,7 @@ class Chef name = parts[1] end shell_out_compact_timeout!("pkg_add", "-r", package_string(name, version), env: { "PKG_PATH" => pkg_path }).status - Chef::Log.debug("#{new_resource.package_name} installed") + logger.trace("#{new_resource.package_name} installed") end end @@ -94,7 +94,7 @@ class Chef end pkg_info = shell_out_compact_timeout!("pkg_info", "-e", "#{name}->0", env: nil, returns: [0, 1]) result = pkg_info.stdout[/^inst:#{Regexp.escape(name)}-(.+?)\s/, 1] - Chef::Log.debug("installed_version of '#{new_resource.package_name}' is '#{result}'") + logger.trace("installed_version of '#{new_resource.package_name}' is '#{result}'") result end @@ -109,7 +109,7 @@ class Chef end end results = results.reject(&:nil?) - Chef::Log.debug("Candidate versions of '#{new_resource.package_name}' are '#{results}'") + logger.trace("Candidate versions of '#{new_resource.package_name}' are '#{results}'") case results.length when 0 [] diff --git a/lib/chef/provider/package/pacman.rb b/lib/chef/provider/package/pacman.rb index 62460d6869..f6dde66219 100644 --- a/lib/chef/provider/package/pacman.rb +++ b/lib/chef/provider/package/pacman.rb @@ -31,12 +31,12 @@ class Chef @current_resource = Chef::Resource::Package.new(new_resource.name) current_resource.package_name(new_resource.package_name) - Chef::Log.debug("#{new_resource} checking pacman for #{new_resource.package_name}") + logger.trace("#{new_resource} checking pacman for #{new_resource.package_name}") status = shell_out_compact_timeout("pacman", "-Qi", new_resource.package_name) status.stdout.each_line do |line| case line when /^Version(\s?)*: (.+)$/ - Chef::Log.debug("#{new_resource} current version is #{$2}") + logger.trace("#{new_resource} current version is #{$2}") current_resource.version($2) end end diff --git a/lib/chef/provider/package/paludis.rb b/lib/chef/provider/package/paludis.rb index 092c7a0d00..f6274d7553 100644 --- a/lib/chef/provider/package/paludis.rb +++ b/lib/chef/provider/package/paludis.rb @@ -31,7 +31,7 @@ class Chef @current_resource = Chef::Resource::Package.new(new_resource.package_name) current_resource.package_name(new_resource.package_name) - Chef::Log.debug("Checking package status for #{new_resource.package_name}") + logger.trace("Checking package status for #{new_resource.package_name}") installed = false re = Regexp.new("(.*)[[:blank:]](.*)[[:blank:]](.*)$") diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb index e43e71f210..016008c339 100644 --- a/lib/chef/provider/package/portage.rb +++ b/lib/chef/provider/package/portage.rb @@ -53,7 +53,7 @@ class Chef end elsif versions.size == 1 current_resource.version(versions.first.last) - Chef::Log.debug("#{new_resource} current version #{$1}") + logger.trace("#{new_resource} current version #{$1}") end current_resource diff --git a/lib/chef/provider/package/powershell.rb b/lib/chef/provider/package/powershell.rb index 02ae114f55..87af7f61d8 100644 --- a/lib/chef/provider/package/powershell.rb +++ b/lib/chef/provider/package/powershell.rb @@ -67,7 +67,7 @@ class Chef until version.empty? version = powershell_out(build_powershell_command("Uninstall-Package '#{name}'"), timeout: new_resource.timeout).stdout.strip unless version.empty? - Chef::Log.info("Removed package '#{name}' with version #{version}") + logger.info("Removed package '#{name}' with version #{version}") end end end diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb index 3061ffccc5..9d4f2f3c23 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -56,7 +56,7 @@ class Chef return end - Chef::Log.debug("#{new_resource} checking rpm status") + logger.trace("#{new_resource} checking rpm status") shell_out_compact_timeout!("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", new_resource.source).stdout.each_line do |line| case line when /^(\S+)\s(\S+)$/ @@ -72,12 +72,12 @@ class Chef end end - Chef::Log.debug("#{new_resource} checking install state") + logger.trace("#{new_resource} checking install state") @rpm_status = shell_out_compact_timeout("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", current_resource.package_name) @rpm_status.stdout.each_line do |line| case line when /^(\S+)\s(\S+)$/ - Chef::Log.debug("#{new_resource} current version is #{$2}") + logger.trace("#{new_resource} current version is #{$2}") current_resource.version($2) end end diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb index 22a687779a..6b04af547b 100644 --- a/lib/chef/provider/package/rubygems.rb +++ b/lib/chef/provider/package/rubygems.rb @@ -148,7 +148,7 @@ class Chef def candidate_version_from_file(gem_dependency, source) spec = spec_from_file(source) if spec.satisfies_requirement?(gem_dependency) - logger.debug { "found candidate gem version #{spec.version} from local gem package #{source}" } + logger.trace { "found candidate gem version #{spec.version} from local gem package #{source}" } spec.version else # This is probably going to end badly... @@ -193,7 +193,7 @@ class Chef version = spec && spec.version if version - logger.debug { "found gem #{spec.name} version #{version} for platform #{spec.platform} from #{source}" } + logger.trace { "found gem #{spec.name} version #{version} for platform #{spec.platform} from #{source}" } version else source_list = sources.compact.empty? ? "[#{Gem.sources.to_a.join(', ')}]" : "[#{sources.join(', ')}]" @@ -232,7 +232,7 @@ class Chef # Set rubygems' user interaction to ConsoleUI or SilentUI depending # on our current debug level def with_correct_verbosity - Gem::DefaultUserInteraction.ui = Chef::Log.debug? ? Gem::ConsoleUI.new : Gem::SilentUI.new + Gem::DefaultUserInteraction.ui = logger.trace? ? Gem::ConsoleUI.new : Gem::SilentUI.new yield end @@ -247,7 +247,7 @@ class Chef private def logger - Chef::Log.logger + Chef::Log.with_child({ subsytem: "gem_installer_environment" }) end end @@ -367,10 +367,6 @@ class Chef attr_reader :gem_env attr_reader :cleanup_gem_env - def logger - Chef::Log.logger - end - provides :chef_gem provides :gem_package @@ -387,7 +383,7 @@ class Chef raise ArgumentError, msg end @gem_env = AlternateGemEnvironment.new(new_resource.gem_binary) - Chef::Log.debug("#{new_resource} using gem '#{new_resource.gem_binary}'") + logger.trace("#{new_resource} using gem '#{new_resource.gem_binary}'") elsif is_omnibus? && (!new_resource.instance_of? Chef::Resource::ChefGem) # Opscode Omnibus - The ruby that ships inside omnibus is only used for Chef # Default to installing somewhere more functional @@ -404,21 +400,21 @@ class Chef gem_location = find_gem_by_path new_resource.gem_binary gem_location @gem_env = AlternateGemEnvironment.new(gem_location) - Chef::Log.debug("#{new_resource} using gem '#{gem_location}'") + logger.trace("#{new_resource} using gem '#{gem_location}'") else @gem_env = CurrentGemEnvironment.new @cleanup_gem_env = false - Chef::Log.debug("#{new_resource} using gem from running ruby environment") + logger.trace("#{new_resource} using gem from running ruby environment") end end def is_omnibus? if RbConfig::CONFIG["bindir"] =~ %r{/(opscode|chef|chefdk)/embedded/bin} - Chef::Log.debug("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}") + logger.trace("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}") # Omnibus installs to a static path because of linking on unix, find it. true elsif RbConfig::CONFIG["bindir"].sub(/^[\w]:/, "") == "/opscode/chef/embedded/bin" - Chef::Log.debug("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}") + logger.trace("#{new_resource} detected omnibus installation in #{RbConfig::CONFIG['bindir']}") # windows, with the drive letter removed true else @@ -442,7 +438,7 @@ class Chef scheme = nil if scheme =~ /^[a-z]$/ %w{http https}.include?(scheme) rescue URI::InvalidURIError - Chef::Log.debug("#{new_resource} failed to parse source '#{new_resource.source}' as a URI, assuming a local path") + logger.trace("#{new_resource} failed to parse source '#{new_resource.source}' as a URI, assuming a local path") false end @@ -451,16 +447,16 @@ class Chef # is the current version if !matching_installed_versions.empty? gemspec = matching_installed_versions.max_by(&:version) - logger.debug { "#{new_resource} found installed gem #{gemspec.name} version #{gemspec.version} matching #{gem_dependency}" } + logger.trace { "#{new_resource} found installed gem #{gemspec.name} version #{gemspec.version} matching #{gem_dependency}" } gemspec # If no version matching the requirements exists, the latest installed # version is the current version. elsif !all_installed_versions.empty? gemspec = all_installed_versions.max_by(&:version) - logger.debug { "#{new_resource} newest installed version of gem #{gemspec.name} is #{gemspec.version}" } + logger.trace { "#{new_resource} newest installed version of gem #{gemspec.name} is #{gemspec.version}" } gemspec else - logger.debug { "#{new_resource} no installed version found for #{gem_dependency}" } + logger.trace { "#{new_resource} no installed version found for #{gem_dependency}" } nil end end @@ -492,7 +488,7 @@ class Chef def cleanup_after_converge if @cleanup_gem_env - logger.debug { "#{new_resource} resetting gem environment to default" } + logger.trace { "#{new_resource} resetting gem environment to default" } Gem.clear_paths end end diff --git a/lib/chef/provider/package/smartos.rb b/lib/chef/provider/package/smartos.rb index f18dc1e1e5..5c637814a6 100644 --- a/lib/chef/provider/package/smartos.rb +++ b/lib/chef/provider/package/smartos.rb @@ -33,7 +33,7 @@ class Chef provides :smartos_package def load_current_resource - Chef::Log.debug("#{new_resource} loading current resource") + logger.trace("#{new_resource} loading current resource") @current_resource = Chef::Resource::Package.new(new_resource.name) current_resource.package_name(new_resource.package_name) check_package_state(new_resource.package_name) @@ -41,7 +41,7 @@ class Chef end def check_package_state(name) - Chef::Log.debug("#{new_resource} checking package #{name}") + logger.trace("#{new_resource} checking package #{name}") version = nil info = shell_out_compact_timeout!("/opt/local/sbin/pkg_info", "-E", "#{name}*", env: nil, returns: [0, 1]) @@ -70,18 +70,18 @@ class Chef end def install_package(name, version) - Chef::Log.debug("#{new_resource} installing package #{name} version #{version}") + logger.trace("#{new_resource} installing package #{name} version #{version}") package = "#{name}-#{version}" out = shell_out_compact_timeout!("/opt/local/bin/pkgin", "-y", "install", package, env: nil) end def upgrade_package(name, version) - Chef::Log.debug("#{new_resource} upgrading package #{name} version #{version}") + logger.trace("#{new_resource} upgrading package #{name} version #{version}") install_package(name, version) end def remove_package(name, version) - Chef::Log.debug("#{new_resource} removing package #{name} version #{version}") + logger.trace("#{new_resource} removing package #{name} version #{version}") package = name.to_s out = shell_out_compact_timeout!("/opt/local/bin/pkgin", "-y", "remove", package, env: nil) end diff --git a/lib/chef/provider/package/solaris.rb b/lib/chef/provider/package/solaris.rb index 86197023e0..9c75c76929 100644 --- a/lib/chef/provider/package/solaris.rb +++ b/lib/chef/provider/package/solaris.rb @@ -54,7 +54,7 @@ class Chef if new_resource.source @package_source_found = ::File.exist?(new_resource.source) if @package_source_found - Chef::Log.debug("#{new_resource} checking pkg status") + logger.trace("#{new_resource} checking pkg status") shell_out_compact_timeout("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name).stdout.each_line do |line| case line when /VERSION:\s+(.+)/ @@ -64,12 +64,12 @@ class Chef end end - Chef::Log.debug("#{new_resource} checking install state") + logger.trace("#{new_resource} checking install state") status = shell_out_compact_timeout("pkginfo", "-l", current_resource.package_name) status.stdout.each_line do |line| case line when /VERSION:\s+(.+)/ - Chef::Log.debug("#{new_resource} version #{$1} is already installed") + logger.trace("#{new_resource} version #{$1} is already installed") current_resource.version($1) end end @@ -89,7 +89,7 @@ class Chef when /VERSION:\s+(.+)/ @candidate_version = $1 new_resource.version($1) - Chef::Log.debug("#{new_resource} setting install candidate version to #{@candidate_version}") + logger.trace("#{new_resource} setting install candidate version to #{@candidate_version}") end end unless status.exitstatus == 0 @@ -99,7 +99,7 @@ class Chef end def install_package(name, version) - Chef::Log.debug("#{new_resource} package install options: #{options}") + logger.trace("#{new_resource} package install options: #{options}") if options.nil? command = if ::File.directory?(new_resource.source) # CHEF-4469 [ "pkgadd", "-n", "-d", new_resource.source, new_resource.package_name ] @@ -107,7 +107,7 @@ class Chef [ "pkgadd", "-n", "-d", new_resource.source, "all" ] end shell_out_compact_timeout!(command) - Chef::Log.debug("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") + logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") else command = if ::File.directory?(new_resource.source) # CHEF-4469 [ "pkgadd", "-n", options, "-d", new_resource.source, new_resource.package_name ] @@ -115,7 +115,7 @@ class Chef [ "pkgadd", "-n", options, "-d", new_resource.source, "all" ] end shell_out_compact_timeout!(*command) - Chef::Log.debug("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") + logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") end end @@ -124,10 +124,10 @@ class Chef def remove_package(name, version) if options.nil? shell_out_compact_timeout!( "pkgrm", "-n", name ) - Chef::Log.debug("#{new_resource} removed version #{new_resource.version}") + logger.trace("#{new_resource} removed version #{new_resource.version}") else shell_out_compact_timeout!( "pkgrm", "-n", options, name ) - Chef::Log.debug("#{new_resource} removed version #{new_resource.version}") + logger.trace("#{new_resource} removed version #{new_resource.version}") end end diff --git a/lib/chef/provider/package/windows.rb b/lib/chef/provider/package/windows.rb index 28ab31c5a1..0fea32dcf3 100644 --- a/lib/chef/provider/package/windows.rb +++ b/lib/chef/provider/package/windows.rb @@ -45,7 +45,7 @@ class Chef def load_current_resource @current_resource = Chef::Resource::WindowsPackage.new(new_resource.name) if downloadable_file_missing? - Chef::Log.debug("We do not know the version of #{new_resource.source} because the file is not downloaded") + logger.trace("We do not know the version of #{new_resource.source} because the file is not downloaded") current_resource.version(:unknown.to_s) else current_resource.version(package_provider.installed_version) @@ -59,11 +59,11 @@ class Chef @package_provider ||= begin case installer_type when :msi - Chef::Log.debug("#{new_resource} is MSI") + logger.trace("#{new_resource} is MSI") require "chef/provider/package/windows/msi" Chef::Provider::Package::Windows::MSI.new(resource_for_provider, uninstall_registry_entries) else - Chef::Log.debug("#{new_resource} is EXE with type '#{installer_type}'") + logger.trace("#{new_resource} is EXE with type '#{installer_type}'") require "chef/provider/package/windows/exe" Chef::Provider::Package::Windows::Exe.new(resource_for_provider, installer_type, uninstall_registry_entries) end @@ -169,7 +169,7 @@ class Chef end def version_equals?(current_version, new_version) - Chef::Log.debug("Checking if #{new_resource} version '#{new_version}' is already installed. #{current_version} is currently installed") + logger.trace("Checking if #{new_resource} version '#{new_version}' is already installed. #{current_version} is currently installed") if current_version.is_a?(Array) current_version.include?(new_version) else @@ -226,7 +226,7 @@ class Chef def download_source_file source_resource.run_action(:create) - Chef::Log.debug("#{new_resource} fetched source file to #{source_resource.path}") + logger.trace("#{new_resource} fetched source file to #{source_resource.path}") end def source_resource diff --git a/lib/chef/provider/package/windows/exe.rb b/lib/chef/provider/package/windows/exe.rb index 0baea6bccd..6499d0cfeb 100644 --- a/lib/chef/provider/package/windows/exe.rb +++ b/lib/chef/provider/package/windows/exe.rb @@ -28,11 +28,13 @@ class Chef def initialize(resource, installer_type, uninstall_entries) @new_resource = resource + @logger = new_resource.logger @installer_type = installer_type @uninstall_entries = uninstall_entries end attr_reader :new_resource + attr_reader :logger attr_reader :installer_type attr_reader :uninstall_entries @@ -43,7 +45,7 @@ class Chef # Returns a version if the package is installed or nil if it is not. def installed_version - Chef::Log.debug("#{new_resource} checking package version") + logger.trace("#{new_resource} checking package version") current_installed_version end @@ -52,7 +54,7 @@ class Chef end def install_package - Chef::Log.debug("#{new_resource} installing #{new_resource.installer_type} package '#{new_resource.source}'") + logger.trace("#{new_resource} installing #{new_resource.installer_type} package '#{new_resource.source}'") shell_out!( [ "start", @@ -70,7 +72,7 @@ class Chef uninstall_version = new_resource.version || current_installed_version uninstall_entries.select { |entry| [uninstall_version].flatten.include?(entry.display_version) } .map(&:uninstall_string).uniq.each do |uninstall_string| - Chef::Log.debug("Registry provided uninstall string for #{new_resource} is '#{uninstall_string}'") + logger.trace("Registry provided uninstall string for #{new_resource} is '#{uninstall_string}'") shell_out!(uninstall_command(uninstall_string), timeout: new_resource.timeout, returns: new_resource.returns) end end diff --git a/lib/chef/provider/package/windows/msi.rb b/lib/chef/provider/package/windows/msi.rb index ef8b674b60..51afcab2a2 100644 --- a/lib/chef/provider/package/windows/msi.rb +++ b/lib/chef/provider/package/windows/msi.rb @@ -31,10 +31,12 @@ class Chef def initialize(resource, uninstall_entries) @new_resource = resource + @logger = new_resource.logger @uninstall_entries = uninstall_entries end attr_reader :new_resource + attr_reader :logger attr_reader :uninstall_entries # From Chef::Provider::Package @@ -45,9 +47,9 @@ class Chef # Returns a version if the package is installed or nil if it is not. def installed_version if !new_resource.source.nil? && ::File.exist?(new_resource.source) - Chef::Log.debug("#{new_resource} getting product code for package at #{new_resource.source}") + logger.trace("#{new_resource} getting product code for package at #{new_resource.source}") product_code = get_product_property(new_resource.source, "ProductCode") - Chef::Log.debug("#{new_resource} checking package status and version for #{product_code}") + logger.trace("#{new_resource} checking package status and version for #{product_code}") get_installed_version(product_code) else if uninstall_entries.count != 0 @@ -59,21 +61,21 @@ class Chef def package_version return new_resource.version if new_resource.version if !new_resource.source.nil? && ::File.exist?(new_resource.source) - Chef::Log.debug("#{new_resource} getting product version for package at #{new_resource.source}") + logger.trace("#{new_resource} getting product version for package at #{new_resource.source}") get_product_property(new_resource.source, "ProductVersion") end end def install_package # We could use MsiConfigureProduct here, but we'll start off with msiexec - Chef::Log.debug("#{new_resource} installing MSI package '#{new_resource.source}'") + logger.trace("#{new_resource} installing MSI package '#{new_resource.source}'") shell_out!("msiexec /qn /i \"#{new_resource.source}\" #{expand_options(new_resource.options)}", timeout: new_resource.timeout, returns: new_resource.returns) end def remove_package # We could use MsiConfigureProduct here, but we'll start off with msiexec if !new_resource.source.nil? && ::File.exist?(new_resource.source) - Chef::Log.debug("#{new_resource} removing MSI package '#{new_resource.source}'") + logger.trace("#{new_resource} removing MSI package '#{new_resource.source}'") shell_out!("msiexec /qn /x \"#{new_resource.source}\" #{expand_options(new_resource.options)}", timeout: new_resource.timeout, returns: new_resource.returns) else uninstall_version = new_resource.version || installed_version @@ -82,7 +84,7 @@ class Chef uninstall_string = "msiexec /x #{uninstall_string.match(/{.*}/)}" uninstall_string += expand_options(new_resource.options) uninstall_string += " /q" unless uninstall_string.downcase =~ / \/q/ - Chef::Log.debug("#{new_resource} removing MSI package version using '#{uninstall_string}'") + logger.trace("#{new_resource} removing MSI package version using '#{uninstall_string}'") shell_out!(uninstall_string, timeout: new_resource.timeout, returns: new_resource.returns) end end diff --git a/lib/chef/provider/package/windows/registry_uninstall_entry.rb b/lib/chef/provider/package/windows/registry_uninstall_entry.rb index 64889e1649..d57f700799 100644 --- a/lib/chef/provider/package/windows/registry_uninstall_entry.rb +++ b/lib/chef/provider/package/windows/registry_uninstall_entry.rb @@ -26,7 +26,7 @@ class Chef class RegistryUninstallEntry def self.find_entries(package_name) - Chef::Log.debug("Finding uninstall entries for #{package_name}") + logger.trace("Finding uninstall entries for #{package_name}") entries = [] [ [::Win32::Registry::HKEY_LOCAL_MACHINE, (::Win32::Registry::Constants::KEY_READ | 0x0100)], @@ -45,12 +45,12 @@ class Chef entries.push(quiet_uninstall_string_key?(quiet_uninstall_string, hkey, key, entry)) end rescue ::Win32::Registry::Error => ex - Chef::Log.debug("Registry error opening key '#{key}' on node #{desired}: #{ex}") + logger.trace("Registry error opening key '#{key}' on node #{desired}: #{ex}") end end end rescue ::Win32::Registry::Error => ex - Chef::Log.debug("Registry error opening hive '#{hkey[0]}' :: #{desired}: #{ex}") + logger.trace("Registry error opening hive '#{hkey[0]}' :: #{desired}: #{ex}") end end entries @@ -63,13 +63,18 @@ class Chef def self.read_registry_property(data, property) data[property] - rescue ::Win32::Registry::Error => ex - Chef::Log.debug("Failure to read property '#{property}'") + rescue ::Win32::Registry::Error + logger.trace("Failure to read property '#{property}'") nil end + def self.logger + Chef::Log + end + def initialize(hive, key, registry_data, uninstall_key = "UninstallString") - Chef::Log.debug("Creating uninstall entry for #{hive}::#{key}") + @logger = Chef::Log.with_child({ subsystem: "registry_uninstall_entry" }) + logger.trace("Creating uninstall entry for #{hive}::#{key}") @hive = hive @key = key @data = registry_data @@ -84,6 +89,7 @@ class Chef attr_reader :display_version attr_reader :uninstall_string attr_reader :data + attr_reader :logger UNINSTALL_SUBKEY = 'Software\Microsoft\Windows\CurrentVersion\Uninstall'.freeze end diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index 8fac97577b..df21a9f091 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -114,7 +114,7 @@ class Chef parameters.merge!(repo_opts) query_output = query(action, parameters) version = parse_response(query_output.lines.last) - Chef::Log.debug "parsed #{version} from python helper" + Chef::Log.trace "parsed #{version} from python helper" # XXX: for now we restart after every query with an enablerepo/disablerepo to clean the helpers internal state restart unless repo_opts.empty? version @@ -149,10 +149,10 @@ class Chef def query(action, parameters) with_helper do json = build_query(action, parameters) - Chef::Log.debug "sending '#{json}' to python helper" + Chef::Log.trace "sending '#{json}' to python helper" outpipe.syswrite json + "\n" output = inpipe.sysread(4096).chomp - Chef::Log.debug "got '#{output}' from python helper" + Chef::Log.trace "got '#{output}' from python helper" return output end end @@ -198,14 +198,14 @@ class Chef end output = drain_fds unless output.empty? - Chef::Log.debug "discarding output on stderr/stdout from python helper: #{output}" + Chef::Log.trace "discarding output on stderr/stdout from python helper: #{output}" end ret rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e output = drain_fds if ( max_retries -= 1 ) > 0 unless output.empty? - Chef::Log.debug "discarding output on stderr/stdout from python helper: #{output}" + Chef::Log.trace "discarding output on stderr/stdout from python helper: #{output}" end restart retry diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb index 59604c5a33..7d97bf310d 100644 --- a/lib/chef/provider/package/zypper.rb +++ b/lib/chef/provider/package/zypper.rb @@ -34,19 +34,19 @@ class Chef def get_versions(package_name) candidate_version = current_version = nil is_installed = false - Chef::Log.debug("#{new_resource} checking zypper") + logger.trace("#{new_resource} checking zypper") status = shell_out_compact_timeout!("zypper", "--non-interactive", "info", package_name) status.stdout.each_line do |line| case line when /^Version *: (.+) *$/ candidate_version = $1.strip - Chef::Log.debug("#{new_resource} version #{candidate_version}") + logger.trace("#{new_resource} version #{candidate_version}") when /^Installed *: Yes.*$/ # http://rubular.com/r/9StcAMjOn6 is_installed = true - Chef::Log.debug("#{new_resource} is installed") + logger.trace("#{new_resource} is installed") when /^Status *: out-of-date \(version (.+) installed\) *$/ current_version = $1.strip - Chef::Log.debug("#{new_resource} out of date version #{current_version}") + logger.trace("#{new_resource} out of date version #{current_version}") end end current_version = candidate_version if is_installed diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb index ae14738bdf..5af73b8b69 100644 --- a/lib/chef/provider/powershell_script.rb +++ b/lib/chef/provider/powershell_script.rb @@ -73,8 +73,8 @@ class Chef # special handling to cover common use cases. def add_exit_status_wrapper self.code = wrapper_script - Chef::Log.debug("powershell_script provider called with script code:\n\n#{new_resource.code}\n") - Chef::Log.debug("powershell_script provider will execute transformed code:\n\n#{code}\n") + logger.trace("powershell_script provider called with script code:\n\n#{new_resource.code}\n") + logger.trace("powershell_script provider will execute transformed code:\n\n#{code}\n") end def validate_script_syntax! diff --git a/lib/chef/provider/reboot.rb b/lib/chef/provider/reboot.rb index c09fbaa2c0..f054af0567 100644 --- a/lib/chef/provider/reboot.rb +++ b/lib/chef/provider/reboot.rb @@ -54,14 +54,14 @@ class Chef def action_request_reboot converge_by("request a system reboot to occur if the run succeeds") do - Chef::Log.warn "Reboot requested:'#{new_resource.name}'" + logger.warn "Reboot requested:'#{new_resource.name}'" request_reboot end end def action_reboot_now converge_by("rebooting the system immediately") do - Chef::Log.warn "Rebooting system immediately, requested by '#{new_resource.name}'" + logger.warn "Rebooting system immediately, requested by '#{new_resource.name}'" request_reboot throw :end_client_run_early end @@ -69,7 +69,7 @@ class Chef def action_cancel converge_by("cancel any existing end-of-run reboot request") do - Chef::Log.warn "Reboot canceled: '#{new_resource.name}'" + logger.warn "Reboot canceled: '#{new_resource.name}'" node.run_context.cancel_reboot end end diff --git a/lib/chef/provider/remote_file/cache_control_data.rb b/lib/chef/provider/remote_file/cache_control_data.rb index 8d7de5c370..32c1542d57 100644 --- a/lib/chef/provider/remote_file/cache_control_data.rb +++ b/lib/chef/provider/remote_file/cache_control_data.rb @@ -153,7 +153,7 @@ class Chef if Chef::FileCache.has_key?(old_path) # We found an old cache control data file. We started using sha256 instead of md5 # to name these. Upgrade the file to the new name. - Chef::Log.debug("Found old cache control data file at #{old_path}. Moving to #{path}.") + Chef::Log.trace("Found old cache control data file at #{old_path}. Moving to #{path}.") Chef::FileCache.load(old_path).tap do |data| Chef::FileCache.store(path, data) Chef::FileCache.delete(old_path) diff --git a/lib/chef/provider/remote_file/content.rb b/lib/chef/provider/remote_file/content.rb index 983285307a..4cf2c32287 100644 --- a/lib/chef/provider/remote_file/content.rb +++ b/lib/chef/provider/remote_file/content.rb @@ -32,10 +32,10 @@ class Chef include Chef::Mixin::Uris def file_for_provider - Chef::Log.debug("#{@new_resource} checking for changes") + logger.trace("#{@new_resource} checking for changes") if current_resource_matches_target_checksum? - Chef::Log.debug("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating") + logger.trace("#{@new_resource} checksum matches target checksum (#{@new_resource.checksum}) - not updating") else sources = @new_resource.source raw_file = try_multiple_sources(sources) @@ -55,9 +55,9 @@ class Chef end raw_file = grab_file_from_uri(uri) rescue SocketError, Errno::ECONNREFUSED, Errno::ENOENT, Errno::EACCES, Timeout::Error, Net::HTTPServerException, Net::HTTPFatalError, Net::FTPError, Errno::ETIMEDOUT => e - Chef::Log.warn("#{@new_resource} cannot be downloaded from #{source}: #{e}") + logger.warn("#{@new_resource} cannot be downloaded from #{source}: #{e}") if source = sources.shift - Chef::Log.info("#{@new_resource} trying to download from another mirror") + logger.info("#{@new_resource} trying to download from another mirror") retry else raise e diff --git a/lib/chef/provider/remote_file/http.rb b/lib/chef/provider/remote_file/http.rb index 8dfa84ee2a..2122142608 100644 --- a/lib/chef/provider/remote_file/http.rb +++ b/lib/chef/provider/remote_file/http.rb @@ -31,12 +31,14 @@ class Chef attr_reader :uri attr_reader :new_resource attr_reader :current_resource + attr_reader :logger # Parse the uri into instance variables - def initialize(uri, new_resource, current_resource) + def initialize(uri, new_resource, current_resource, logger = Chef::Log.with_child) @uri = uri @new_resource = new_resource @current_resource = current_resource + @logger = logger end def events @@ -55,7 +57,7 @@ class Chef if (etag = cache_control_data.etag) && want_etag_cache_control? cache_control_headers["if-none-match"] = etag end - Chef::Log.debug("Cache control headers: #{cache_control_headers.inspect}") + logger.trace("Cache control headers: #{cache_control_headers.inspect}") cache_control_headers end @@ -129,7 +131,7 @@ class Chef # case you'd end up with a tar archive (no gzip) named, e.g., foo.tgz, # which is not what you wanted. if uri.to_s =~ /gz$/ - Chef::Log.debug("Turning gzip compression off due to filename ending in gz") + logger.trace("Turning gzip compression off due to filename ending in gz") opts[:disable_gzip] = true end opts diff --git a/lib/chef/provider/remote_file/local_file.rb b/lib/chef/provider/remote_file/local_file.rb index 613db02337..0719e5dbf7 100644 --- a/lib/chef/provider/remote_file/local_file.rb +++ b/lib/chef/provider/remote_file/local_file.rb @@ -48,7 +48,7 @@ class Chef # Fetches the file at uri, returning a Tempfile-like File handle def fetch tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile - Chef::Log.debug("#{new_resource} staging #{source_path} to #{tempfile.path}") + Chef::Log.trace("#{new_resource} staging #{source_path} to #{tempfile.path}") FileUtils.cp(source_path, tempfile.path) tempfile.close if tempfile tempfile diff --git a/lib/chef/provider/remote_file/network_file.rb b/lib/chef/provider/remote_file/network_file.rb index f9dc7b0e7b..ffd2d0bbce 100644 --- a/lib/chef/provider/remote_file/network_file.rb +++ b/lib/chef/provider/remote_file/network_file.rb @@ -41,7 +41,7 @@ class Chef def fetch begin tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile - Chef::Log.debug("#{new_resource} staging #{@source} to #{tempfile.path}") + Chef::Log.trace("#{new_resource} staging #{@source} to #{tempfile.path}") with_user_context(new_resource.remote_user, new_resource.remote_password, new_resource.remote_domain, new_resource.authentication) do ::File.open(@source, "rb") do |remote_file| diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb index 16e06f470b..c00d6a1932 100644 --- a/lib/chef/provider/route.rb +++ b/lib/chef/provider/route.rb @@ -77,7 +77,7 @@ class Chef begin IPAddr.new(ip, Socket::AF_INET).to_s rescue ArgumentError - Chef::Log.debug("Invalid IP address data: hex=#{hex_ip}, ip=#{ip}") + logger.trace("Invalid IP address data: hex=#{hex_ip}, ip=#{ip}") return nil end end @@ -111,7 +111,7 @@ class Chef # Skip formatting lines (header, etc) next unless destination && gateway && mask - Chef::Log.debug("#{new_resource} system has route: dest=#{destination} mask=#{mask} gw=#{gateway}") + logger.trace("#{new_resource} system has route: dest=#{destination} mask=#{mask} gw=#{gateway}") # check if what were trying to configure is already there # use an ipaddr object with ip/mask this way we can have @@ -119,7 +119,7 @@ class Chef # expanding bitmask by hand. # running_ip = IPAddr.new("#{destination}/#{mask}") - Chef::Log.debug("#{new_resource} new ip: #{new_ip.inspect} running ip: #{running_ip.inspect}") + logger.trace("#{new_resource} new ip: #{new_ip.inspect} running ip: #{running_ip.inspect}") self.is_running = true if running_ip == new_ip && gateway == new_resource.gateway end @@ -129,12 +129,12 @@ class Chef def action_add # check to see if load_current_resource found the route if is_running - Chef::Log.debug("#{new_resource} route already active - nothing to do") + logger.trace("#{new_resource} route already active - nothing to do") else command = generate_command(:add) converge_by("run #{command.join(' ')} to add route") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} added") + logger.info("#{new_resource} added") end end @@ -147,10 +147,10 @@ class Chef command = generate_command(:delete) converge_by("run #{command.join(' ')} to delete route ") do shell_out_compact!(command) - Chef::Log.info("#{new_resource} removed") + logger.info("#{new_resource} removed") end else - Chef::Log.debug("#{new_resource} route does not exist - nothing to do") + logger.trace("#{new_resource} route does not exist - nothing to do") end # for now we always write the file (ugly but its what it is) @@ -185,7 +185,7 @@ class Chef if new_resource.target == "default" network_file_name = "/etc/sysconfig/network" converge_by("write route default route to #{network_file_name}") do - Chef::Log.debug("#{new_resource} writing default route #{new_resource.gateway} to #{network_file_name}") + logger.trace("#{new_resource} writing default route #{new_resource.gateway} to #{network_file_name}") if ::File.exist?(network_file_name) network_file = ::Chef::Util::FileEdit.new(network_file_name) network_file.search_file_replace_line /^GATEWAY=/, "GATEWAY=#{new_resource.gateway}" @@ -202,7 +202,7 @@ class Chef converge_by("write route route.#{k}\n#{conf[k]} to #{network_file_name}") do network_file = ::File.new(network_file_name, "w") network_file.puts(conf[k]) - Chef::Log.debug("#{new_resource} writing route.#{k}\n#{conf[k]}") + logger.trace("#{new_resource} writing route.#{k}\n#{conf[k]}") network_file.close end end diff --git a/lib/chef/provider/ruby_block.rb b/lib/chef/provider/ruby_block.rb index 878b7b52d3..01f041ca3b 100644 --- a/lib/chef/provider/ruby_block.rb +++ b/lib/chef/provider/ruby_block.rb @@ -29,7 +29,7 @@ class Chef def action_run converge_by("execute the ruby block #{new_resource.name}") do new_resource.block.call - Chef::Log.info("#{new_resource} called") + logger.info("#{new_resource} called") end end diff --git a/lib/chef/provider/script.rb b/lib/chef/provider/script.rb index 4046b7c0dd..c5966370f7 100644 --- a/lib/chef/provider/script.rb +++ b/lib/chef/provider/script.rb @@ -51,7 +51,7 @@ class Chef super # @todo Chef-13: change this to an exception if code.nil? - Chef::Log.warn "#{new_resource}: No code attribute was given, resource does nothing, this behavior is deprecated and will be removed in Chef-13" + logger.warn "#{new_resource}: No code attribute was given, resource does nothing, this behavior is deprecated and will be removed in Chef-13" end end diff --git a/lib/chef/provider/service.rb b/lib/chef/provider/service.rb index 34ecf2f0bc..c116d321f1 100644 --- a/lib/chef/provider/service.rb +++ b/lib/chef/provider/service.rb @@ -79,11 +79,11 @@ class Chef def action_enable if current_resource.enabled - Chef::Log.debug("#{new_resource} already enabled - nothing to do") + logger.trace("#{new_resource} already enabled - nothing to do") else converge_by("enable service #{new_resource}") do enable_service - Chef::Log.info("#{new_resource} enabled") + logger.info("#{new_resource} enabled") end end load_new_resource_state @@ -94,10 +94,10 @@ class Chef if current_resource.enabled converge_by("disable service #{new_resource}") do disable_service - Chef::Log.info("#{new_resource} disabled") + logger.info("#{new_resource} disabled") end else - Chef::Log.debug("#{new_resource} already disabled - nothing to do") + logger.trace("#{new_resource} already disabled - nothing to do") end load_new_resource_state new_resource.enabled(false) @@ -105,11 +105,11 @@ class Chef def action_mask if current_resource.masked - Chef::Log.debug("#{new_resource} already masked - nothing to do") + logger.trace("#{new_resource} already masked - nothing to do") else converge_by("mask service #{new_resource}") do mask_service - Chef::Log.info("#{new_resource} masked") + logger.info("#{new_resource} masked") end end load_new_resource_state @@ -120,10 +120,10 @@ class Chef if current_resource.masked converge_by("unmask service #{new_resource}") do unmask_service - Chef::Log.info("#{new_resource} unmasked") + logger.info("#{new_resource} unmasked") end else - Chef::Log.debug("#{new_resource} already unmasked - nothing to do") + logger.trace("#{new_resource} already unmasked - nothing to do") end load_new_resource_state new_resource.masked(false) @@ -133,10 +133,10 @@ class Chef unless current_resource.running converge_by("start service #{new_resource}") do start_service - Chef::Log.info("#{new_resource} started") + logger.info("#{new_resource} started") end else - Chef::Log.debug("#{new_resource} already running - nothing to do") + logger.trace("#{new_resource} already running - nothing to do") end load_new_resource_state new_resource.running(true) @@ -146,10 +146,10 @@ class Chef if current_resource.running converge_by("stop service #{new_resource}") do stop_service - Chef::Log.info("#{new_resource} stopped") + logger.info("#{new_resource} stopped") end else - Chef::Log.debug("#{new_resource} already stopped - nothing to do") + logger.trace("#{new_resource} already stopped - nothing to do") end load_new_resource_state new_resource.running(false) @@ -158,7 +158,7 @@ class Chef def action_restart converge_by("restart service #{new_resource}") do restart_service - Chef::Log.info("#{new_resource} restarted") + logger.info("#{new_resource} restarted") end load_new_resource_state new_resource.running(true) @@ -168,7 +168,7 @@ class Chef if current_resource.running converge_by("reload service #{new_resource}") do reload_service - Chef::Log.info("#{new_resource} reloaded") + logger.info("#{new_resource} reloaded") end end load_new_resource_state diff --git a/lib/chef/provider/service/aix.rb b/lib/chef/provider/service/aix.rb index dd74caf6ae..10ea06152b 100644 --- a/lib/chef/provider/service/aix.rb +++ b/lib/chef/provider/service/aix.rb @@ -88,7 +88,7 @@ class Chef protected def determine_current_status! - Chef::Log.debug "#{@new_resource} using lssrc to check the status" + logger.trace "#{@new_resource} using lssrc to check the status" begin if is_resource_group? # Groups as a whole have no notion of whether they're running @@ -101,7 +101,7 @@ class Chef @current_resource.running false end end - Chef::Log.debug "#{@new_resource} running: #{@current_resource.running}" + logger.trace "#{@new_resource} running: #{@current_resource.running}" # ShellOut sometimes throws different types of Exceptions than ShellCommandFailed. # Temporarily catching different types of exceptions here until we get Shellout fixed. # TODO: Remove the line before one we get the ShellOut fix. @@ -115,7 +115,7 @@ class Chef def is_resource_group? so = shell_out("lssrc -g #{@new_resource.service_name}") if so.exitstatus == 0 - Chef::Log.debug("#{@new_resource.service_name} is a group") + logger.trace("#{@new_resource.service_name} is a group") @is_resource_group = true end end diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb index 73c5e07715..dd8514cf20 100644 --- a/lib/chef/provider/service/aixinit.rb +++ b/lib/chef/provider/service/aixinit.rb @@ -45,11 +45,11 @@ class Chef priority_ok = @current_resource.priority == @new_resource.priority end if @current_resource.enabled && priority_ok - Chef::Log.debug("#{@new_resource} already enabled - nothing to do") + logger.trace("#{@new_resource} already enabled - nothing to do") else converge_by("enable service #{@new_resource}") do enable_service - Chef::Log.info("#{@new_resource} enabled") + logger.info("#{@new_resource} enabled") end end load_new_resource_state diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index fcfa34ddf9..01a1ed3ad9 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -101,7 +101,7 @@ class Chef def service_currently_enabled?(priority) enabled = false priority.each do |runlevel, arguments| - Chef::Log.debug("#{new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}") + logger.trace("#{new_resource} runlevel #{runlevel}, action #{arguments[0]}, priority #{arguments[1]}") # if we are in a update-rc.d default startup runlevel && we start in this runlevel if %w{ 1 2 3 4 5 S }.include?(runlevel) && arguments[0] == :start enabled = true @@ -119,11 +119,11 @@ class Chef priority_ok = @current_resource.priority == new_resource.priority end if current_resource.enabled && priority_ok - Chef::Log.debug("#{new_resource} already enabled - nothing to do") + logger.trace("#{new_resource} already enabled - nothing to do") else converge_by("enable service #{new_resource}") do enable_service - Chef::Log.info("#{new_resource} enabled") + logger.info("#{new_resource} enabled") end end load_new_resource_state diff --git a/lib/chef/provider/service/freebsd.rb b/lib/chef/provider/service/freebsd.rb index c1e315afee..68de39fd0f 100644 --- a/lib/chef/provider/service/freebsd.rb +++ b/lib/chef/provider/service/freebsd.rb @@ -47,7 +47,7 @@ class Chef return current_resource unless init_command - Chef::Log.debug("#{current_resource} found at #{init_command}") + logger.trace("#{current_resource} found at #{init_command}") @status_load_success = true determine_current_status! # see Chef::Provider::Service::Simple @@ -145,7 +145,7 @@ class Chef end # some scripts support multiple instances through symlinks such as openvpn. # We should get the service name from rcvar. - Chef::Log.debug("name=\"service\" not found at #{init_command}. falling back to rcvar") + logger.trace("name=\"service\" not found at #{init_command}. falling back to rcvar") shell_out!("#{init_command} rcvar").stdout[/(\w+_enable)=/, 1] else # for why-run mode when the rcd_script is not there yet @@ -171,7 +171,7 @@ class Chef end if current_resource.enabled.nil? - Chef::Log.debug("#{new_resource.name} enable/disable state unknown") + logger.trace("#{new_resource.name} enable/disable state unknown") current_resource.enabled false end end diff --git a/lib/chef/provider/service/gentoo.rb b/lib/chef/provider/service/gentoo.rb index 0ac74649b6..69b3d20a3f 100644 --- a/lib/chef/provider/service/gentoo.rb +++ b/lib/chef/provider/service/gentoo.rb @@ -36,11 +36,11 @@ class Chef::Provider::Service::Gentoo < Chef::Provider::Service::Init @found_script = true exists = ::File.exists? file readable = ::File.readable? file - Chef::Log.debug "#{@new_resource} exists: #{exists}, readable: #{readable}" + logger.trace "#{@new_resource} exists: #{exists}, readable: #{readable}" exists && readable end ) - Chef::Log.debug "#{@new_resource} enabled: #{@current_resource.enabled}" + logger.trace "#{@new_resource} enabled: #{@current_resource.enabled}" @current_resource end diff --git a/lib/chef/provider/service/macosx.rb b/lib/chef/provider/service/macosx.rb index a0ae03a717..40021f9ba6 100644 --- a/lib/chef/provider/service/macosx.rb +++ b/lib/chef/provider/service/macosx.rb @@ -58,7 +58,7 @@ class Chef if @console_user @console_user = Etc.getpwuid(::File.stat("/dev/console").uid).name - Chef::Log.debug("#{new_resource} console_user: '#{@console_user}'") + logger.trace("#{new_resource} console_user: '#{@console_user}'") cmd = "su " param = this_version_or_newer?("10.10") ? "" : "-l " param = "-l " if this_version_or_newer?("10.12") @@ -67,7 +67,7 @@ class Chef @session_type = "Aqua" if @session_type.nil? end - Chef::Log.debug("#{new_resource} Plist: '#{@plist}' service_label: '#{@service_label}'") + logger.trace("#{new_resource} Plist: '#{@plist}' service_label: '#{@service_label}'") set_service_status @current_resource @@ -108,7 +108,7 @@ class Chef def start_service if @current_resource.running - Chef::Log.debug("#{@new_resource} already running, not starting") + logger.trace("#{@new_resource} already running, not starting") else if @new_resource.start_command super @@ -120,7 +120,7 @@ class Chef def stop_service unless @current_resource.running - Chef::Log.debug("#{@new_resource} not running, not stopping") + logger.trace("#{@new_resource} not running, not stopping") else if @new_resource.stop_command super @@ -147,7 +147,7 @@ class Chef # supervisor that will restart daemons that are crashing, etc. def enable_service if @current_resource.enabled - Chef::Log.debug("#{@new_resource} already enabled, not enabling") + logger.trace("#{@new_resource} already enabled, not enabling") else load_service end @@ -155,7 +155,7 @@ class Chef def disable_service unless @current_resource.enabled - Chef::Log.debug("#{@new_resource} not enabled, not disabling") + logger.trace("#{@new_resource} not enabled, not disabling") else unload_service end @@ -199,7 +199,7 @@ class Chef when /\s+\"pid\"\s+=\s+(\d+).*/ pid = $1 @current_resource.running(pid.to_i != 0) - Chef::Log.debug("Current PID for #{@service_label} is #{pid}") + logger.trace("Current PID for #{@service_label} is #{pid}") end end else diff --git a/lib/chef/provider/service/openbsd.rb b/lib/chef/provider/service/openbsd.rb index f839d54780..552173fbee 100644 --- a/lib/chef/provider/service/openbsd.rb +++ b/lib/chef/provider/service/openbsd.rb @@ -48,7 +48,7 @@ class Chef @current_resource = Chef::Resource::Service.new(new_resource.name) current_resource.service_name(new_resource.service_name) - Chef::Log.debug("#{current_resource} found at #{init_command}") + logger.trace("#{current_resource} found at #{init_command}") determine_current_status! determine_enabled_status! diff --git a/lib/chef/provider/service/simple.rb b/lib/chef/provider/service/simple.rb index 81ac970b87..7b5f75c4b3 100644 --- a/lib/chef/provider/service/simple.rb +++ b/lib/chef/provider/service/simple.rb @@ -108,12 +108,12 @@ class Chef def determine_current_status! if @new_resource.status_command - Chef::Log.debug("#{@new_resource} you have specified a status command, running..") + logger.trace("#{@new_resource} you have specified a status command, running..") begin if shell_out(@new_resource.status_command).exitstatus == 0 @current_resource.running true - Chef::Log.debug("#{@new_resource} is running") + logger.trace("#{@new_resource} is running") end rescue Mixlib::ShellOut::ShellCommandFailed, SystemCallError # ShellOut sometimes throws different types of Exceptions than ShellCommandFailed. @@ -125,11 +125,11 @@ class Chef end elsif supports[:status] - Chef::Log.debug("#{@new_resource} supports status, running") + logger.trace("#{@new_resource} supports status, running") begin if shell_out("#{default_init_command} status").exitstatus == 0 @current_resource.running true - Chef::Log.debug("#{@new_resource} is running") + logger.trace("#{@new_resource} is running") end # ShellOut sometimes throws different types of Exceptions than ShellCommandFailed. # Temporarily catching different types of exceptions here until we get Shellout fixed. @@ -140,9 +140,9 @@ class Chef nil end else - Chef::Log.debug "#{@new_resource} falling back to process table inspection" + logger.trace "#{@new_resource} falling back to process table inspection" r = Regexp.new(@new_resource.pattern) - Chef::Log.debug "#{@new_resource} attempting to match '#{@new_resource.pattern}' (#{r.inspect}) against process list" + logger.trace "#{@new_resource} attempting to match '#{@new_resource.pattern}' (#{r.inspect}) against process list" begin shell_out!(ps_cmd).stdout.each_line do |line| if r.match(line) @@ -152,7 +152,7 @@ class Chef end @current_resource.running false unless @current_resource.running - Chef::Log.debug "#{@new_resource} running: #{@current_resource.running}" + logger.trace "#{@new_resource} running: #{@current_resource.running}" # ShellOut sometimes throws different types of Exceptions than ShellCommandFailed. # Temporarily catching different types of exceptions here until we get Shellout fixed. # TODO: Remove the line before one we get the ShellOut fix. diff --git a/lib/chef/provider/service/systemd.rb b/lib/chef/provider/service/systemd.rb index fa9d381267..1bcc2f3a00 100644 --- a/lib/chef/provider/service/systemd.rb +++ b/lib/chef/provider/service/systemd.rb @@ -42,7 +42,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple @status_check_success = true if new_resource.status_command - Chef::Log.debug("#{new_resource} you have specified a status command, running..") + logger.trace("#{new_resource} you have specified a status command, running..") unless shell_out(new_resource.status_command).error? current_resource.running(true) @@ -95,7 +95,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple def start_service if current_resource.running - Chef::Log.debug("#{new_resource} already running, not starting") + logger.trace("#{new_resource} already running, not starting") else if new_resource.start_command super @@ -108,7 +108,7 @@ class Chef::Provider::Service::Systemd < Chef::Provider::Service::Simple def stop_service unless current_resource.running - Chef::Log.debug("#{new_resource} not running, not stopping") + logger.trace("#{new_resource} not running, not stopping") else if new_resource.stop_command super diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index 2ff7de1138..810d9eabb7 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -109,7 +109,7 @@ class Chef # We do not support searching for a service via ps when using upstart since status is a native # upstart function. We will however support status_command in case someone wants to do something special. if @new_resource.status_command - Chef::Log.debug("#{@new_resource} you have specified a status command, running..") + logger.trace("#{@new_resource} you have specified a status command, running..") begin if shell_out!(@new_resource.status_command).exitstatus == 0 @@ -135,16 +135,16 @@ class Chef end # Get enabled/disabled state by reading job configuration file if ::File.exists?("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") - Chef::Log.debug("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") + logger.trace("#{@new_resource} found #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") ::File.open("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}", "r") do |file| while line = file.gets case line when /^start on/ - Chef::Log.debug("#{@new_resource} enabled: #{line.chomp}") + logger.trace("#{@new_resource} enabled: #{line.chomp}") @current_resource.enabled true break when /^#start on/ - Chef::Log.debug("#{@new_resource} disabled: #{line.chomp}") + logger.trace("#{@new_resource} disabled: #{line.chomp}") @current_resource.enabled false break end @@ -152,7 +152,7 @@ class Chef end else @config_file_found = false - Chef::Log.debug("#{@new_resource} did not find #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") + logger.trace("#{@new_resource} did not find #{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") @current_resource.enabled false end @@ -164,7 +164,7 @@ class Chef # Calling start on a service that is already started will return 1 # Our 'goal' when we call start is to ensure the service is started if @upstart_service_running - Chef::Log.debug("#{@new_resource} already running, not starting") + logger.trace("#{@new_resource} already running, not starting") else if @new_resource.start_command super @@ -180,7 +180,7 @@ class Chef # Calling stop on a service that is already stopped will return 1 # Our 'goal' when we call stop is to ensure the service is stopped unless @upstart_service_running - Chef::Log.debug("#{@new_resource} not running, not stopping") + logger.trace("#{@new_resource} not running, not stopping") else if @new_resource.stop_command super @@ -226,14 +226,14 @@ class Chef # https://bugs.launchpad.net/upstart/+bug/94065 def enable_service - Chef::Log.debug("#{@new_resource} upstart lacks inherent support for enabling services, editing job config file") + logger.trace("#{@new_resource} upstart lacks inherent support for enabling services, editing job config file") conf = Chef::Util::FileEdit.new("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") conf.search_file_replace(/^#start on/, "start on") conf.write_file end def disable_service - Chef::Log.debug("#{@new_resource} upstart lacks inherent support for disabling services, editing job config file") + logger.trace("#{@new_resource} upstart lacks inherent support for disabling services, editing job config file") conf = Chef::Util::FileEdit.new("#{@upstart_job_dir}/#{@new_resource.service_name}#{@upstart_conf_suffix}") conf.search_file_replace(/^start on/, "#start on") conf.write_file diff --git a/lib/chef/provider/service/windows.rb b/lib/chef/provider/service/windows.rb index ce84f7c4ee..cba626145a 100644 --- a/lib/chef/provider/service/windows.rb +++ b/lib/chef/provider/service/windows.rb @@ -57,14 +57,14 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service if Win32::Service.exists?(current_resource.service_name) current_resource.running(current_state == RUNNING) - Chef::Log.debug "#{new_resource} running: #{current_resource.running}" + logger.trace "#{new_resource} running: #{current_resource.running}" case current_startup_type when :automatic current_resource.enabled(true) when :disabled current_resource.enabled(false) end - Chef::Log.debug "#{new_resource} enabled: #{current_resource.enabled}" + logger.trace "#{new_resource} enabled: #{current_resource.enabled}" config_info = Win32::Service.config_info(current_resource.service_name) current_resource.service_type(get_service_type(config_info.service_type)) if config_info.service_type @@ -91,7 +91,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service }.reject { |k, v| v.nil? || v.length == 0 } Win32::Service.configure(new_config) - Chef::Log.info "#{@new_resource} configured with #{new_config.inspect}" + logger.info "#{@new_resource} configured with #{new_config.inspect}" if new_config.has_key?(:service_start_name) unless Chef::ReservedNames::Win32::Security.get_account_right(canonicalize_username(new_config[:service_start_name])).include?(SERVICE_RIGHT) @@ -101,13 +101,13 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service state = current_state if state == RUNNING - Chef::Log.debug "#{@new_resource} already started - nothing to do" + logger.trace "#{@new_resource} already started - nothing to do" elsif state == START_PENDING - Chef::Log.debug "#{@new_resource} already sent start signal - waiting for start" + logger.trace "#{@new_resource} already sent start signal - waiting for start" wait_for_state(RUNNING) elsif state == STOPPED if @new_resource.start_command - Chef::Log.debug "#{@new_resource} starting service using the given start_command" + logger.trace "#{@new_resource} starting service using the given start_command" shell_out!(@new_resource.start_command) else spawn_command_thread do @@ -115,7 +115,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service Win32::Service.start(@new_resource.service_name) rescue SystemCallError => ex if ex.errno == ERROR_SERVICE_LOGON_FAILED - Chef::Log.error ex.message + logger.error ex.message raise Chef::Exceptions::Service, "Service #{@new_resource} did not start due to a logon failure (error #{ERROR_SERVICE_LOGON_FAILED}): possibly the specified user '#{@new_resource.run_as_user}' does not have the 'log on as a service' privilege, or the password is incorrect." else @@ -130,7 +130,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service raise Chef::Exceptions::Service, "Service #{@new_resource} can't be started from state [#{state}]" end else - Chef::Log.debug "#{@new_resource} does not exist - nothing to do" + logger.trace "#{@new_resource} does not exist - nothing to do" end end @@ -139,7 +139,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service state = current_state if state == RUNNING if @new_resource.stop_command - Chef::Log.debug "#{@new_resource} stopping service using the given stop_command" + logger.trace "#{@new_resource} stopping service using the given stop_command" shell_out!(@new_resource.stop_command) else spawn_command_thread do @@ -149,22 +149,22 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service end @new_resource.updated_by_last_action(true) elsif state == STOPPED - Chef::Log.debug "#{@new_resource} already stopped - nothing to do" + logger.trace "#{@new_resource} already stopped - nothing to do" elsif state == STOP_PENDING - Chef::Log.debug "#{@new_resource} already sent stop signal - waiting for stop" + logger.trace "#{@new_resource} already sent stop signal - waiting for stop" wait_for_state(STOPPED) else raise Chef::Exceptions::Service, "Service #{@new_resource} can't be stopped from state [#{state}]" end else - Chef::Log.debug "#{@new_resource} does not exist - nothing to do" + logger.trace "#{@new_resource} does not exist - nothing to do" end end def restart_service if Win32::Service.exists?(@new_resource.service_name) if @new_resource.restart_command - Chef::Log.debug "#{@new_resource} restarting service using the given restart_command" + logger.trace "#{@new_resource} restarting service using the given restart_command" shell_out!(@new_resource.restart_command) else stop_service @@ -172,7 +172,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service end @new_resource.updated_by_last_action(true) else - Chef::Log.debug "#{@new_resource} does not exist - nothing to do" + logger.trace "#{@new_resource} does not exist - nothing to do" end end @@ -180,7 +180,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service if Win32::Service.exists?(@new_resource.service_name) set_startup_type(:automatic) else - Chef::Log.debug "#{@new_resource} does not exist - nothing to do" + logger.trace "#{@new_resource} does not exist - nothing to do" end end @@ -188,13 +188,13 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service if Win32::Service.exists?(@new_resource.service_name) set_startup_type(:disabled) else - Chef::Log.debug "#{@new_resource} does not exist - nothing to do" + logger.trace "#{@new_resource} does not exist - nothing to do" end end action :create do if Win32::Service.exists?(new_resource.service_name) - Chef::Log.debug "#{new_resource} already exists - nothing to do" + logger.trace "#{new_resource} already exists - nothing to do" return end @@ -207,7 +207,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service action :delete do unless Win32::Service.exists?(new_resource.service_name) - Chef::Log.debug "#{new_resource} does not exist - nothing to do" + logger.trace "#{new_resource} does not exist - nothing to do" return end @@ -218,7 +218,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service action :configure do unless Win32::Service.exists?(new_resource.service_name) - Chef::Log.warn "#{new_resource} does not exist. Maybe you need to prepend action :create" + logger.warn "#{new_resource} does not exist. Maybe you need to prepend action :create" return end @@ -240,10 +240,10 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service if current_startup_type != :automatic converge_by("enable service #{@new_resource}") do enable_service - Chef::Log.info("#{@new_resource} enabled") + logger.info("#{@new_resource} enabled") end else - Chef::Log.debug("#{@new_resource} already enabled - nothing to do") + logger.trace("#{@new_resource} already enabled - nothing to do") end load_new_resource_state @new_resource.enabled(true) @@ -253,10 +253,10 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service if current_startup_type != :disabled converge_by("disable service #{@new_resource}") do disable_service - Chef::Log.info("#{@new_resource} disabled") + logger.info("#{@new_resource} disabled") end else - Chef::Log.debug("#{@new_resource} already disabled - nothing to do") + logger.trace("#{@new_resource} already disabled - nothing to do") end load_new_resource_state @new_resource.enabled(false) @@ -269,7 +269,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service set_startup_type(startup_type) end else - Chef::Log.debug("#{@new_resource} startup_type already #{startup_type} - nothing to do") + logger.trace("#{@new_resource} startup_type already #{startup_type} - nothing to do") end # Avoid changing enabled from true/false for now @@ -290,11 +290,11 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service begin Chef::ReservedNames::Win32::Security.add_account_right(canonicalize_username(username), SERVICE_RIGHT) rescue Chef::Exceptions::Win32APIError => err - Chef::Log.fatal "Logon-as-service grant failed with output: #{err}" + logger.fatal "Logon-as-service grant failed with output: #{err}" raise Chef::Exceptions::Service, "Logon-as-service grant failed for #{username}: #{err}" end - Chef::Log.info "Grant logon-as-service to user '#{username}' successful." + logger.info "Grant logon-as-service to user '#{username}' successful." true end @@ -356,7 +356,7 @@ class Chef::Provider::Service::Windows < Chef::Provider::Service def set_startup_type(type) startup_type = startup_type_to_int(type) - Chef::Log.debug "#{@new_resource.name} setting start_type to #{type}" + logger.trace "#{@new_resource.name} setting start_type to #{type}" Win32::Service.configure( :service_name => @new_resource.service_name, :start_type => startup_type diff --git a/lib/chef/provider/subversion.rb b/lib/chef/provider/subversion.rb index 4fece0ae40..abcc260a78 100644 --- a/lib/chef/provider/subversion.rb +++ b/lib/chef/provider/subversion.rb @@ -61,7 +61,7 @@ class Chef shell_out!(checkout_command, run_options) end else - Chef::Log.debug "#{new_resource} checkout destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do" + logger.trace "#{new_resource} checkout destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do" end end @@ -69,7 +69,7 @@ class Chef if target_dir_non_existent_or_empty? action_force_export else - Chef::Log.debug "#{new_resource} export destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do" + logger.trace "#{new_resource} export destination #{new_resource.destination} already exists or is a non-empty directory - nothing to do" end end @@ -83,11 +83,11 @@ class Chef assert_target_directory_valid! if ::File.exist?(::File.join(new_resource.destination, ".svn")) current_rev = find_current_revision - Chef::Log.debug "#{new_resource} current revision: #{current_rev} target revision: #{revision_int}" + logger.trace "#{new_resource} current revision: #{current_rev} target revision: #{revision_int}" unless current_revision_matches_target_revision? converge_by("sync #{new_resource.destination} from #{new_resource.repository}") do shell_out!(sync_command, run_options) - Chef::Log.info "#{new_resource} updated to revision: #{revision_int}" + logger.info "#{new_resource} updated to revision: #{revision_int}" end end else @@ -97,14 +97,14 @@ class Chef def sync_command c = scm :update, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.destination - Chef::Log.debug "#{new_resource} updated working copy #{new_resource.destination} to revision #{new_resource.revision}" + logger.trace "#{new_resource} updated working copy #{new_resource.destination} to revision #{new_resource.revision}" c end def checkout_command c = scm :checkout, new_resource.svn_arguments, verbose, authentication, proxy, "-r#{revision_int}", new_resource.repository, new_resource.destination - Chef::Log.info "#{new_resource} checked out #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" + logger.info "#{new_resource} checked out #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" c end @@ -113,7 +113,7 @@ class Chef args << new_resource.svn_arguments << verbose << authentication << proxy << "-r#{revision_int}" << new_resource.repository << new_resource.destination c = scm :export, *args - Chef::Log.info "#{new_resource} exported #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" + logger.info "#{new_resource} exported #{new_resource.repository} at revision #{new_resource.revision} to #{new_resource.destination}" c end @@ -175,7 +175,7 @@ class Chef rev = (repo_attrs["Last Changed Rev"] || repo_attrs["Revision"]) rev.strip! if rev raise "Could not parse `svn info` data: #{svn_info}" if repo_attrs.empty? - Chef::Log.debug "#{new_resource} resolved revision #{new_resource.revision} to #{rev}" + logger.trace "#{new_resource} resolved revision #{new_resource.revision} to #{rev}" rev end diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb index 18ea8ea92c..d8c83d2b4b 100644 --- a/lib/chef/provider/systemd_unit.rb +++ b/lib/chef/provider/systemd_unit.rb @@ -88,7 +88,7 @@ class Chef def action_enable if current_resource.static - Chef::Log.debug("#{new_resource.unit_name} is a static unit, enabling is a NOP.") + logger.trace("#{new_resource.unit_name} is a static unit, enabling is a NOP.") end unless current_resource.enabled || current_resource.static @@ -100,7 +100,7 @@ class Chef def action_disable if current_resource.static - Chef::Log.debug("#{new_resource.unit_name} is a static unit, disabling is a NOP.") + logger.trace("#{new_resource.unit_name} is a static unit, disabling is a NOP.") end if current_resource.enabled && !current_resource.static @@ -160,7 +160,7 @@ class Chef systemctl_execute!(:reload, new_resource.unit_name) end else - Chef::Log.debug("#{new_resource.unit_name} is not active, skipping reload.") + logger.trace("#{new_resource.unit_name} is not active, skipping reload.") end end diff --git a/lib/chef/provider/user.rb b/lib/chef/provider/user.rb index abdff441a5..18cf2d4d99 100644 --- a/lib/chef/provider/user.rb +++ b/lib/chef/provider/user.rb @@ -49,7 +49,7 @@ class Chef user_info = Etc.getpwnam(new_resource.username) rescue ArgumentError @user_exists = false - Chef::Log.debug("#{new_resource} user does not exist") + logger.trace("#{new_resource} user does not exist") user_info = nil end @@ -120,12 +120,12 @@ class Chef if !@user_exists converge_by("create user #{new_resource.username}") do create_user - Chef::Log.info("#{new_resource} created") + logger.info("#{new_resource} created") end elsif compare_user converge_by("alter user #{new_resource.username}") do manage_user - Chef::Log.info("#{new_resource} altered") + logger.info("#{new_resource} altered") end end end @@ -134,7 +134,7 @@ class Chef return unless @user_exists converge_by("remove user #{new_resource.username}") do remove_user - Chef::Log.info("#{new_resource} removed") + logger.info("#{new_resource} removed") end end @@ -142,7 +142,7 @@ class Chef return unless @user_exists && compare_user converge_by("manage user #{new_resource.username}") do manage_user - Chef::Log.info("#{new_resource} managed") + logger.info("#{new_resource} managed") end end @@ -150,7 +150,7 @@ class Chef return unless compare_user converge_by("modify user #{new_resource.username}") do manage_user - Chef::Log.info("#{new_resource} modified") + logger.info("#{new_resource} modified") end end @@ -158,10 +158,10 @@ class Chef if check_lock == false converge_by("lock the user #{new_resource.username}") do lock_user - Chef::Log.info("#{new_resource} locked") + logger.info("#{new_resource} locked") end else - Chef::Log.debug("#{new_resource} already locked - nothing to do") + logger.trace("#{new_resource} already locked - nothing to do") end end @@ -169,10 +169,10 @@ class Chef if check_lock == true converge_by("unlock user #{new_resource.username}") do unlock_user - Chef::Log.info("#{new_resource} unlocked") + logger.info("#{new_resource} unlocked") end else - Chef::Log.debug("#{new_resource} already unlocked - nothing to do") + logger.trace("#{new_resource} already unlocked - nothing to do") end end diff --git a/lib/chef/provider/user/aix.rb b/lib/chef/provider/user/aix.rb index 966cfd9e93..64a088dd5c 100644 --- a/lib/chef/provider/user/aix.rb +++ b/lib/chef/provider/user/aix.rb @@ -74,7 +74,7 @@ class Chef def add_password return unless current_resource.password != new_resource.password && new_resource.password - Chef::Log.debug("#{new_resource.username} setting password to #{new_resource.password}") + logger.trace("#{new_resource.username} setting password to #{new_resource.password}") command = "echo '#{new_resource.username}:#{new_resource.password}' | chpasswd -e" shell_out!(command) end @@ -85,10 +85,10 @@ class Chef # -m option does not work on aix, so move dir. universal_options.delete("-m") if ::File.directory?(current_resource.home) - Chef::Log.debug("Changing users home directory from #{current_resource.home} to #{new_resource.home}") + logger.trace("Changing users home directory from #{current_resource.home} to #{new_resource.home}") FileUtils.mv current_resource.home, new_resource.home else - Chef::Log.debug("Creating users home directory #{new_resource.home}") + logger.trace("Creating users home directory #{new_resource.home}") FileUtils.mkdir_p new_resource.home end end diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index bc865b17c5..50d255db8b 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -157,7 +157,7 @@ user password using shadow hash.") convert_group_name if new_resource.gid else @user_exists = false - Chef::Log.debug("#{new_resource} user does not exist") + logger.trace("#{new_resource} user does not exist") end current_resource @@ -333,7 +333,7 @@ user password using shadow hash.") end def move_home - Chef::Log.debug("#{new_resource} moving #{self} home from #{current_resource.home} to #{new_resource.home}") + logger.trace("#{new_resource} moving #{self} home from #{current_resource.home} to #{new_resource.home}") new_resource.gid(STAFF_GROUP_ID) if new_resource.gid.nil? src = current_resource.home FileUtils.mkdir_p(new_resource.home) diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb index 48c05cc436..695dbfd539 100644 --- a/lib/chef/provider/user/pw.rb +++ b/lib/chef/provider/user/pw.rb @@ -78,13 +78,13 @@ class Chef field_symbol = field.to_sym next unless current_resource.send(field_symbol) != new_resource.send(field_symbol) if new_resource.send(field_symbol) - Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}") + logger.trace("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}") opts << option opts << new_resource.send(field_symbol) end end if new_resource.manage_home - Chef::Log.debug("#{new_resource} is managing the users home directory") + logger.trace("#{new_resource} is managing the users home directory") opts << "-m" end opts @@ -92,11 +92,11 @@ class Chef def modify_password if !new_resource.password.nil? && (current_resource.password != new_resource.password) - Chef::Log.debug("#{new_resource} updating password") + logger.trace("#{new_resource} updating password") command = "pw usermod #{new_resource.username} -H 0" shell_out!(command, input: new_resource.password.to_s) else - Chef::Log.debug("#{new_resource} no change needed to password") + logger.trace("#{new_resource} no change needed to password") end end end diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb index 25ec13fe5c..59074d5ba8 100644 --- a/lib/chef/provider/user/solaris.rb +++ b/lib/chef/provider/user/solaris.rb @@ -83,7 +83,7 @@ class Chef def manage_password return unless current_resource.password != new_resource.password && new_resource.password - Chef::Log.debug("#{new_resource} setting password to #{new_resource.password}") + logger.trace("#{new_resource} setting password to #{new_resource.password}") write_shadow_file end diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb index 0a32126903..47c0ece101 100644 --- a/lib/chef/provider/user/useradd.rb +++ b/lib/chef/provider/user/useradd.rb @@ -118,10 +118,10 @@ class Chef if updating_home? opts << "-d" << new_resource.home if new_resource.manage_home - Chef::Log.debug("#{new_resource} managing the users home directory") + logger.trace("#{new_resource} managing the users home directory") opts << "-m" else - Chef::Log.debug("#{new_resource} setting home to #{new_resource.home}") + logger.trace("#{new_resource} setting home to #{new_resource.home}") end end opts << "-o" if new_resource.non_unique @@ -132,7 +132,7 @@ class Chef def update_options(field, option, opts) return unless current_resource.send(field).to_s != new_resource.send(field).to_s return unless new_resource.send(field) - Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field)}") + logger.trace("#{new_resource} setting #{field} to #{new_resource.send(field)}") opts << option << new_resource.send(field).to_s end diff --git a/lib/chef/provider/user/windows.rb b/lib/chef/provider/user/windows.rb index 2b69197626..994f1a6774 100644 --- a/lib/chef/provider/user/windows.rb +++ b/lib/chef/provider/user/windows.rb @@ -36,7 +36,7 @@ class Chef def load_current_resource if new_resource.gid - Chef::Log.warn("The 'gid' (or 'group') property is not implemented on the Windows platform. Please use the `members` property of the 'group' resource to assign a user to a group.") + logger.warn("The 'gid' (or 'group') property is not implemented on the Windows platform. Please use the `members` property of the 'group' resource to assign a user to a group.") end @current_resource = Chef::Resource::User.new(new_resource.name) @@ -51,7 +51,7 @@ class Chef rescue Chef::Exceptions::UserIDNotFound => e # e.message should be "The user name could not be found" but checking for that could cause a localization bug @user_exists = false - Chef::Log.debug("#{new_resource} does not exist (#{e.message})") + logger.trace("#{new_resource} does not exist (#{e.message})") end current_resource @@ -64,7 +64,7 @@ class Chef # <false>:: If the users are identical def compare_user unless @net_user.validate_credentials(new_resource.password) - Chef::Log.debug("#{new_resource} password has changed") + logger.trace("#{new_resource} password has changed") return true end [ :uid, :comment, :home, :shell ].any? do |user_attrib| @@ -112,7 +112,7 @@ class Chef next unless current_resource.send(field_symbol) != new_resource.send(field_symbol) next unless new_resource.send(field_symbol) unless field_symbol == :password - Chef::Log.debug("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}") + logger.trace("#{new_resource} setting #{field} to #{new_resource.send(field_symbol)}") end opts[option.to_sym] = new_resource.send(field_symbol) end diff --git a/lib/chef/provider/whyrun_safe_ruby_block.rb b/lib/chef/provider/whyrun_safe_ruby_block.rb index 6e43dd4766..ee4a659b00 100644 --- a/lib/chef/provider/whyrun_safe_ruby_block.rb +++ b/lib/chef/provider/whyrun_safe_ruby_block.rb @@ -25,7 +25,7 @@ class Chef new_resource.block.call new_resource.updated_by_last_action(true) @run_context.events.resource_update_applied(new_resource, :create, "execute the whyrun_safe_ruby_block #{new_resource.name}") - Chef::Log.info("#{new_resource} called") + logger.info("#{new_resource} called") end end end diff --git a/lib/chef/provider/windows_env.rb b/lib/chef/provider/windows_env.rb index 085783d750..4e7fa34216 100644 --- a/lib/chef/provider/windows_env.rb +++ b/lib/chef/provider/windows_env.rb @@ -46,7 +46,7 @@ class Chef current_resource.value(env_value(new_resource.key_name)) else @key_exists = false - Chef::Log.debug("#{new_resource} key does not exist") + logger.trace("#{new_resource} key does not exist") end current_resource @@ -81,12 +81,12 @@ class Chef if @key_exists if requires_modify_or_create? modify_env - Chef::Log.info("#{new_resource} altered") + logger.info("#{new_resource} altered") new_resource.updated_by_last_action(true) end else create_env - Chef::Log.info("#{new_resource} created") + logger.info("#{new_resource} created") new_resource.updated_by_last_action(true) end end @@ -101,7 +101,7 @@ class Chef return false unless new_resource.delim #no delim: delete the key needs_delete = new_values.any? { |v| current_values.include?(v) } if !needs_delete - Chef::Log.debug("#{new_resource} element '#{new_resource.value}' does not exist") + logger.trace("#{new_resource} element '#{new_resource.value}' does not exist") return true #do not delete the key else new_value = @@ -114,7 +114,7 @@ class Chef else old_value = new_resource.value(new_value) create_env - Chef::Log.debug("#{new_resource} deleted #{old_value} element") + logger.trace("#{new_resource} deleted #{old_value} element") new_resource.updated_by_last_action(true) return true #we removed the element and updated; do not delete the key end @@ -124,7 +124,7 @@ class Chef def action_delete if ( ENV[new_resource.key_name] || @key_exists ) && !delete_element delete_env - Chef::Log.info("#{new_resource} deleted") + logger.info("#{new_resource} deleted") new_resource.updated_by_last_action(true) end end @@ -133,7 +133,7 @@ class Chef if @key_exists if requires_modify_or_create? modify_env - Chef::Log.info("#{new_resource} modified") + logger.info("#{new_resource} modified") new_resource.updated_by_last_action(true) end else diff --git a/lib/chef/provider/windows_task.rb b/lib/chef/provider/windows_task.rb index c52d520373..02b68b1296 100644 --- a/lib/chef/provider/windows_task.rb +++ b/lib/chef/provider/windows_task.rb @@ -75,9 +75,9 @@ class Chef def action_create if current_resource.exists - Chef::Log.debug "#{new_resource} task exists" + logger.trace "#{new_resource} task exists" if !(task_need_update? || new_resource.force) - Chef::Log.info "#{new_resource} task does not need updating and force is not specified - nothing to do" + logger.info "#{new_resource} task does not need updating and force is not specified - nothing to do" return end # Setting the attributes of new_resource as current_resource. @@ -128,74 +128,74 @@ class Chef def action_run if current_resource.exists - Chef::Log.debug "#{new_resource} task exists" + logger.trace "#{new_resource} task exists" if current_resource.status == :running - Chef::Log.info "#{new_resource} task is currently running, skipping run" + logger.info "#{new_resource} task is currently running, skipping run" else converge_by("run scheduled task #{new_resource}") do run_schtasks "RUN" end end else - Chef::Log.warn "#{new_resource} task does not exist - nothing to do" + logger.warn "#{new_resource} task does not exist - nothing to do" end end def action_delete if current_resource.exists - Chef::Log.debug "#{new_resource} task exists" + logger.trace "#{new_resource} task exists" converge_by("delete scheduled task #{new_resource}") do # always need to force deletion run_schtasks "DELETE", "F" => "" end else - Chef::Log.warn "#{new_resource} task does not exist - nothing to do" + logger.warn "#{new_resource} task does not exist - nothing to do" end end def action_end if current_resource.exists - Chef::Log.debug "#{new_resource} task exists" + logger.trace "#{new_resource} task exists" if current_resource.status != :running - Chef::Log.debug "#{new_resource} is not running - nothing to do" + logger.trace "#{new_resource} is not running - nothing to do" else converge_by("#{new_resource} task ended") do run_schtasks "END" end end else - Chef::Log.warn "#{new_resource} task does not exist - nothing to do" + logger.warn "#{new_resource} task does not exist - nothing to do" end end def action_enable if current_resource.exists - Chef::Log.debug "#{new_resource} task exists" + logger.trace "#{new_resource} task exists" if current_resource.enabled - Chef::Log.debug "#{new_resource} already enabled - nothing to do" + logger.trace "#{new_resource} already enabled - nothing to do" else converge_by("#{new_resource} task enabled") do run_schtasks "CHANGE", "ENABLE" => "" end end else - Chef::Log.fatal "#{new_resource} task does not exist - nothing to do" + logger.fatal "#{new_resource} task does not exist - nothing to do" raise Errno::ENOENT, "#{new_resource}: task does not exist, cannot enable" end end def action_disable if current_resource.exists - Chef::Log.info "#{new_resource} task exists" + logger.info "#{new_resource} task exists" if current_resource.enabled converge_by("#{new_resource} task disabled") do run_schtasks "CHANGE", "DISABLE" => "" end else - Chef::Log.warn "#{new_resource} already disabled - nothing to do" + logger.warn "#{new_resource} already disabled - nothing to do" end else - Chef::Log.warn "#{new_resource} task does not exist - nothing to do" + logger.warn "#{new_resource} task does not exist - nothing to do" end end @@ -214,8 +214,8 @@ class Chef if options["TR"] cmd += "/TR \"#{options["TR"]} \" " unless task_action == "DELETE" end - Chef::Log.debug("running: ") - Chef::Log.debug(" #{cmd}") + logger.trace("running: ") + logger.trace(" #{cmd}") shell_out!(cmd, returns: [0]) end # rubocop:enable Style/StringLiteralsInInterpolation @@ -236,7 +236,7 @@ class Chef return true if new_resource.day.to_s.casecmp(current_resource.day.to_s) != 0 || new_resource.months.to_s.casecmp(current_resource.months.to_s) != 0 rescue - Chef::Log.debug "caught a raise in task_needs_update?" + logger.trace "caught a raise in task_needs_update?" end false @@ -314,7 +314,7 @@ class Chef def get_system_short_date_format return @system_short_date_format if @system_short_date_format - Chef::Log.debug "Finding system date format" + logger.trace "Finding system date format" task_script = <<-EOH [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 [Globalization.Cultureinfo]::CurrentCulture.DateTimeFormat.ShortDatePattern @@ -349,7 +349,7 @@ class Chef "execution_time_limit" => "Settings/ExecutionTimeLimit", } - Chef::Log.debug "looking for existing tasks" + logger.trace "looking for existing tasks" task_script = <<-EOH [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 @@ -368,12 +368,12 @@ class Chef end options.each do |option| - Chef::Log.debug "Removing former #{option} if any" + logger.trace "Removing former #{option} if any" doc.root.elements.delete(xml_element_mapping[option]) option_value = new_resource.send("#{option}") if option_value - Chef::Log.debug "Setting #{option} as #{option_value}" + logger.trace "Setting #{option} as #{option_value}" split_xml_path = xml_element_mapping[option].split("/") # eg. if xml_element_mapping[option] = "Actions/Exec/WorkingDirectory" element_name = split_xml_path.last # element_name = "WorkingDirectory" cwd_element = REXML::Element.new(element_name) @@ -403,7 +403,7 @@ class Chef end def load_task_hash(task_name) - Chef::Log.debug "Looking for existing tasks" + logger.trace "Looking for existing tasks" task_script = <<-EOH [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 diff --git a/lib/chef/provider/zypper_repository.rb b/lib/chef/provider/zypper_repository.rb index e9d1f84272..369d23a396 100644 --- a/lib/chef/provider/zypper_repository.rb +++ b/lib/chef/provider/zypper_repository.rb @@ -34,7 +34,7 @@ class Chef if new_resource.gpgautoimportkeys install_gpg_key(new_resource.gpgkey) else - Chef::Log.debug("'gpgautoimportkeys' property is set to false. Skipping key import.") + logger.trace("'gpgautoimportkeys' property is set to false. Skipping key import.") end declare_resource(:template, "/etc/zypp/repos.d/#{escaped_repo_name}.repo") do @@ -105,10 +105,10 @@ class Chef # @return [Symbol] :remote_file or :cookbook_file def key_type(uri) if uri.start_with?("http") - Chef::Log.debug("Will use :remote_file resource to cache the gpg key locally") + logger.trace("Will use :remote_file resource to cache the gpg key locally") :remote_file elsif has_cookbook_file?(uri) - Chef::Log.debug("Will use :cookbook_file resource to cache the gpg key locally") + logger.trace("Will use :cookbook_file resource to cache the gpg key locally") :cookbook_file else raise Chef::Exceptions::FileNotFound, "Cannot determine location of gpgkey. Must start with 'http' or be a file managed by Chef." @@ -123,7 +123,7 @@ class Chef so = shell_out("rpm -qa gpg-pubkey*") # expected output & match: http://rubular.com/r/RdF7EcXEtb status = /gpg-pubkey-#{key_fingerprint(key_path)}/.match(so.stdout) - Chef::Log.debug("GPG key at #{key_path} is known by rpm? #{status ? "true" : "false"}") + logger.trace("GPG key at #{key_path} is known by rpm? #{status ? "true" : "false"}") status end @@ -135,7 +135,7 @@ class Chef so = shell_out!("gpg --with-fingerprint #{key_path}") # expected output and match: http://rubular.com/r/BpfMjxySQM fingerprint = /pub\s*\S*\/(\S*)/.match(so.stdout)[1].downcase - Chef::Log.debug("GPG fingerprint of key at #{key_path} is #{fingerprint}") + logger.trace("GPG fingerprint of key at #{key_path} is #{fingerprint}") fingerprint end @@ -143,7 +143,7 @@ class Chef # @param [String] uri the uri of the local or remote gpg key def install_gpg_key(uri) unless uri - Chef::Log.debug("'gpgkey' property not provided or set to nil. Skipping key import.") + logger.trace("'gpgkey' property not provided or set to nil. Skipping key import.") return end diff --git a/lib/chef/provider_resolver.rb b/lib/chef/provider_resolver.rb index dacdb2b54f..c7779e52a7 100644 --- a/lib/chef/provider_resolver.rb +++ b/lib/chef/provider_resolver.rb @@ -95,7 +95,7 @@ class Chef # a provider to say "assuming /etc/init.d/whatever would have been installed" and in the non-why-run case we # need to make a best guess at "cannot find /etc/init.d/whatever". We are essentially defining a "default" provider # for the platform, which is the best we can do, but which might give misleading errors, but we cannot read minds. - Chef::Log.debug "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway." + Chef::Log.trace "No providers responded true to `supports?` for action #{action} on resource #{resource}, falling back to enabled handlers so we can return something anyway." supported_handlers = enabled_handlers end @@ -118,14 +118,14 @@ class Chef # try dynamically finding a provider based on querying the providers to see what they support def maybe_dynamic_provider_resolution(resource, action) - Chef::Log.debug "Providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}" + Chef::Log.trace "Providers for generic #{resource.resource_name} resource enabled on node include: #{enabled_handlers}" handler = prioritized_handlers.first if handler - Chef::Log.debug "Provider for action #{action} on resource #{resource} is #{handler}" + Chef::Log.trace "Provider for action #{action} on resource #{resource} is #{handler}" else - Chef::Log.debug "Dynamic provider resolver FAILED to resolve a provider for action #{action} on resource #{resource}" + Chef::Log.trace "Dynamic provider resolver FAILED to resolve a provider for action #{action} on resource #{resource}" end handler diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 26298e5b1d..46bc25b713 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -148,6 +148,7 @@ class Chef @not_if = [] @only_if = [] @source_line = nil + @deprecated = false # We would like to raise an error when the user gives us a guard # interpreter and a ruby_block to the guard. In order to achieve this # we need to understand when the user overrides the default guard @@ -1181,8 +1182,8 @@ class Chef # Internal Resource Interface (for Chef) # - FORBIDDEN_IVARS = [:@run_context, :@logger, :@not_if, :@only_if, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message] - HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@logger, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message] + FORBIDDEN_IVARS = [:@run_context, :@logger, :@not_if, :@only_if, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated] + HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@logger, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider, :@description, :@introduced, :@examples, :@validation_message, :@deprecated] include Chef::Mixin::ConvertToClassName extend Chef::Mixin::ConvertToClassName @@ -1406,6 +1407,14 @@ class Chef @examples end + def self.deprecated(deprecated = "NOT_PASSED") + if deprecated != "NOT_PASSED" + @deprecated = true + @deprecated_message = deprecated + end + @deprecated + end + # # The cookbook in which this Resource was defined (if any). # diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index ed6fce2e5c..578e6066a2 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -80,6 +80,10 @@ class Chef c end + def logger + @parent_resource.logger + end + def initialize(parent_resource, command, opts, &block) @command, @command_opts = command, opts @block = block @@ -87,7 +91,7 @@ class Chef end def verify(path, opts = {}) - Chef::Log.debug("Running verification[#{self}] on #{path}") + logger.trace("Running verification[#{self}] on #{path}") if @block verify_block(path, opts) elsif @command.is_a?(Symbol) diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index 0e4c3f826c..c0f6f835ad 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -43,7 +43,7 @@ class Chef def build_from_file(cookbook_name, filename, run_context) if LWRPBase.loaded_lwrps[filename] - Chef::Log.debug("Custom resource #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.") + Chef::Log.trace("Custom resource #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.") return loaded_lwrps[filename] end @@ -63,7 +63,7 @@ class Chef define_singleton_method(:inspect) { to_s } end - Chef::Log.debug("Loaded contents of #{filename} into resource #{resource_name} (#{resource_class})") + Chef::Log.trace("Loaded contents of #{filename} into resource #{resource_name} (#{resource_class})") LWRPBase.loaded_lwrps[filename] = true diff --git a/lib/chef/resource/sudo.rb b/lib/chef/resource/sudo.rb index f8c4bf5af1..ec60b419a4 100644 --- a/lib/chef/resource/sudo.rb +++ b/lib/chef/resource/sudo.rb @@ -160,7 +160,7 @@ class Chef Chef::Log.warn("#{new_resource.filename} will be rendered, but will not take effect because the #{new_resource.config_prefix}/sudoers config lacks the includedir directive that loads configs from #{new_resource.config_prefix}/sudoers.d/!") if ::File.readlines("#{new_resource.config_prefix}/sudoers").grep(/includedir/).empty? if new_resource.template - Chef::Log.debug("Template property provided, all other properties ignored.") + logger.trace("Template property provided, all other properties ignored.") declare_resource(:template, "#{target}#{new_resource.filename}") do source new_resource.template diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb index 42eafcf613..1ac906790a 100644 --- a/lib/chef/resource/windows_feature_dism.rb +++ b/lib/chef/resource/windows_feature_dism.rb @@ -51,7 +51,7 @@ class Chef fail_if_unavailable # fail if the features don't exist fail_if_removed # fail if the features are in removed state - Chef::Log.debug("Windows features needing installation: #{features_to_install.empty? ? 'none' : features_to_install.join(',')}") + logger.trace("Windows features needing installation: #{features_to_install.empty? ? 'none' : features_to_install.join(',')}") unless features_to_install.empty? message = "install Windows feature#{'s' if features_to_install.count > 1} #{features_to_install.join(',')}" converge_by(message) do @@ -71,7 +71,7 @@ class Chef reload_cached_dism_data unless node["dism_features_cache"] - Chef::Log.debug("Windows features needing removal: #{features_to_remove.empty? ? 'none' : features_to_remove.join(',')}") + logger.trace("Windows features needing removal: #{features_to_remove.empty? ? 'none' : features_to_remove.join(',')}") unless features_to_remove.empty? message = "remove Windows feature#{'s' if features_to_remove.count > 1} #{features_to_remove.join(',')}" @@ -92,7 +92,7 @@ class Chef fail_if_unavailable # fail if the features don't exist - Chef::Log.debug("Windows features needing deletion: #{features_to_delete.empty? ? 'none' : features_to_delete.join(',')}") + logger.trace("Windows features needing deletion: #{features_to_delete.empty? ? 'none' : features_to_delete.join(',')}") unless features_to_delete.empty? message = "delete Windows feature#{'s' if features_to_delete.count > 1} #{features_to_delete.join(',')} from the image" converge_by(message) do @@ -157,7 +157,7 @@ class Chef # a much faster run when no features actually need to be installed / removed. # @return [void] def reload_cached_dism_data - Chef::Log.debug("Caching Windows features available via dism.exe.") + logger.trace("Caching Windows features available via dism.exe.") node.override["dism_features_cache"] = Mash.new node.override["dism_features_cache"]["enabled"] = [] node.override["dism_features_cache"]["disabled"] = [] @@ -178,7 +178,7 @@ class Chef add_to_feature_mash("disabled", feature_details_raw) end end - Chef::Log.debug("The cache contains\n#{node['dism_features_cache']}") + logger.trace("The cache contains\n#{node['dism_features_cache']}") end # parse the feature string and add the values to the appropriate array diff --git a/lib/chef/resource/windows_font.rb b/lib/chef/resource/windows_font.rb index a1f7fa153b..7ff098cc88 100644 --- a/lib/chef/resource/windows_font.rb +++ b/lib/chef/resource/windows_font.rb @@ -42,7 +42,7 @@ class Chef description "Install a font to the system fonts directory." if font_exists? - Chef::Log.debug("Not installing font: #{new_resource.font_name} as font already installed.") + logger.trace("Not installing font: #{new_resource.font_name} as font already installed.") else retrieve_cookbook_font install_font @@ -92,7 +92,7 @@ class Chef def font_exists? require "win32ole" if RUBY_PLATFORM =~ /mswin|mingw32|windows/ fonts_dir = WIN32OLE.new("WScript.Shell").SpecialFolders("Fonts") - Chef::Log.debug("Seeing if the font at #{Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)} exists") + logger.trace("Seeing if the font at #{Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)} exists") ::File.exist?(Chef::Util::PathHelper.join(fonts_dir, new_resource.font_name)) end @@ -112,13 +112,13 @@ class Chef begin require "uri" if remote_file_schema?(URI.parse(new_resource.source).scheme) - Chef::Log.debug("source property starts with ftp/http. Using source property unmodified") + logger.trace("source property starts with ftp/http. Using source property unmodified") return new_resource.source end rescue URI::InvalidURIError Chef::Log.warn("source property of #{new_resource.source} could not be processed as a URI. Check the format you provided.") end - Chef::Log.debug("source property does not start with ftp/http. Prepending with file:// as it appears to be a local file.") + logger.trace("source property does not start with ftp/http. Prepending with file:// as it appears to be a local file.") "file://#{new_resource.source}" end end diff --git a/lib/chef/resource/windows_pagefile.rb b/lib/chef/resource/windows_pagefile.rb index 42178c4473..c9d9fc6e29 100644 --- a/lib/chef/resource/windows_pagefile.rb +++ b/lib/chef/resource/windows_pagefile.rb @@ -96,7 +96,7 @@ class Chef # @return [Boolean] def exists?(pagefile) @exists ||= begin - Chef::Log.debug("Checking if #{pagefile} exists by runing: wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list") + logger.trace("Checking if #{pagefile} exists by runing: wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list") cmd = shell_out("wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list", returns: [0]) cmd.stderr.empty? && (cmd.stdout =~ /SettingID=#{get_setting_id(pagefile)}/i) end @@ -110,7 +110,7 @@ class Chef # @return [Boolean] def max_and_min_set?(pagefile, min, max) @max_and_min_set ||= begin - Chef::Log.debug("Checking if #{pagefile} min: #{min} and max #{max} are set") + logger.trace("Checking if #{pagefile} min: #{min} and max #{max} are set") cmd = shell_out("wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" list /format:list", returns: [0]) cmd.stderr.empty? && (cmd.stdout =~ /InitialSize=#{min}/i) && (cmd.stdout =~ /MaximumSize=#{max}/i) end @@ -121,7 +121,7 @@ class Chef # @param [String] pagefile path to the pagefile def create(pagefile) converge_by("create pagefile #{pagefile}") do - Chef::Log.debug("Running wmic.exe pagefileset create name=\"#{pagefile}\"") + logger.trace("Running wmic.exe pagefileset create name=\"#{pagefile}\"") cmd = shell_out("wmic.exe pagefileset create name=\"#{pagefile}\"") check_for_errors(cmd.stderr) end @@ -132,7 +132,7 @@ class Chef # @param [String] pagefile path to the pagefile def delete(pagefile) converge_by("remove pagefile #{pagefile}") do - Chef::Log.debug("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" delete") + logger.trace("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" delete") cmd = shell_out("wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" delete") check_for_errors(cmd.stderr) end @@ -143,7 +143,7 @@ class Chef # @return [Boolean] def automatic_managed? @automatic_managed ||= begin - Chef::Log.debug("Checking if pagefiles are automatically managed") + logger.trace("Checking if pagefiles are automatically managed") cmd = shell_out("wmic.exe computersystem where name=\"%computername%\" get AutomaticManagedPagefile /format:list") cmd.stderr.empty? && (cmd.stdout =~ /AutomaticManagedPagefile=TRUE/i) end @@ -152,7 +152,7 @@ class Chef # turn on automatic management of all pagefiles by Windows def set_automatic_managed converge_by("set pagefile to Automatic Managed") do - Chef::Log.debug("Running wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=True") + logger.trace("Running wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=True") cmd = shell_out("wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=True") check_for_errors(cmd.stderr) end @@ -161,7 +161,7 @@ class Chef # turn off automatic management of all pagefiles by Windows def unset_automatic_managed converge_by("set pagefile to User Managed") do - Chef::Log.debug("Running wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=False") + logger.trace("Running wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=False") cmd = shell_out("wmic.exe computersystem where name=\"%computername%\" set AutomaticManagedPagefile=False") check_for_errors(cmd.stderr) end @@ -174,7 +174,7 @@ class Chef # @param [String] max the minimum size of the pagefile def set_custom_size(pagefile, min, max) converge_by("set #{pagefile} to InitialSize=#{min} & MaximumSize=#{max}") do - Chef::Log.debug("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=#{min},MaximumSize=#{max}") + logger.trace("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=#{min},MaximumSize=#{max}") cmd = shell_out("wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=#{min},MaximumSize=#{max}", returns: [0]) check_for_errors(cmd.stderr) end @@ -185,7 +185,7 @@ class Chef # @param [String] pagefile path to the pagefile def set_system_managed(pagefile) converge_by("set #{pagefile} to System Managed") do - Chef::Log.debug("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0") + logger.trace("Running wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0") cmd = shell_out("wmic.exe pagefileset where SettingID=\"#{get_setting_id(pagefile)}\" set InitialSize=0,MaximumSize=0", returns: [0]) check_for_errors(cmd.stderr) end diff --git a/lib/chef/resource/windows_printer.rb b/lib/chef/resource/windows_printer.rb index 3ad12e35c7..93e82e8e32 100644 --- a/lib/chef/resource/windows_printer.rb +++ b/lib/chef/resource/windows_printer.rb @@ -73,7 +73,7 @@ class Chef # @return [Boolean] def printer_exists?(name) printer_reg_key = PRINTERS_REG_KEY + name - Chef::Log.debug "Checking to see if this reg key exists: '#{printer_reg_key}'" + logger.trace "Checking to see if this reg key exists: '#{printer_reg_key}'" registry_key_exists?(printer_reg_key) end diff --git a/lib/chef/resource/windows_printer_port.rb b/lib/chef/resource/windows_printer_port.rb index 6d2b293e9f..1c31500587 100644 --- a/lib/chef/resource/windows_printer_port.rb +++ b/lib/chef/resource/windows_printer_port.rb @@ -63,7 +63,7 @@ class Chef def port_exists?(name) port_reg_key = PORTS_REG_KEY + name - Chef::Log.debug "Checking to see if this reg key exists: '#{port_reg_key}'" + logger.trace "Checking to see if this reg key exists: '#{port_reg_key}'" registry_key_exists?(port_reg_key) end diff --git a/lib/chef/resource_reporter.rb b/lib/chef/resource_reporter.rb index 53e7ea9e30..c76ac0a4a3 100644 --- a/lib/chef/resource_reporter.rb +++ b/lib/chef/resource_reporter.rb @@ -153,7 +153,7 @@ class Chef Chef::Log.info(message + reason + reporting_status) else reporting_status = "Disabling reporting for run." - Chef::Log.debug(message + reason + reporting_status) + Chef::Log.trace(message + reason + reporting_status) end end @@ -237,9 +237,9 @@ class Chef run_data = prepare_run_data resource_history_url = "reports/nodes/#{node_name}/runs/#{run_id}" Chef::Log.info("Sending resource update report (run-id: #{run_id})") - Chef::Log.debug run_data.inspect + Chef::Log.trace run_data.inspect compressed_data = encode_gzip(Chef::JSONCompat.to_json(run_data)) - Chef::Log.debug("Sending compressed run data...") + Chef::Log.trace("Sending compressed run data...") # Since we're posting compressed data we can not directly call post which expects JSON begin @rest_client.raw_request(:POST, resource_history_url, headers({ "Content-Encoding" => "gzip" }), compressed_data) @@ -252,7 +252,7 @@ class Chef end end else - Chef::Log.debug("Server doesn't support resource history, skipping resource report.") + Chef::Log.trace("Server doesn't support resource history, skipping resource report.") end end diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb index a5c44f65b3..779377c042 100644 --- a/lib/chef/resource_resolver.rb +++ b/lib/chef/resource_resolver.rb @@ -77,14 +77,14 @@ class Chef # @api private use Chef::ResourceResolver.resolve instead. def resolve # log this so we know what resources will work for the generic resource on the node (early cut) - Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" + Chef::Log.trace "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" handler = prioritized_handlers.first if handler - Chef::Log.debug "Resource for #{resource_name} is #{handler}" + Chef::Log.trace "Resource for #{resource_name} is #{handler}" else - Chef::Log.debug "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}" + Chef::Log.trace "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}" end handler @@ -92,7 +92,7 @@ class Chef # @api private def list - Chef::Log.debug "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" + Chef::Log.trace "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" prioritized_handlers end diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index bc676bc27f..2b8c7cda30 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -326,8 +326,7 @@ class Chef # @see DSL::IncludeRecipe#load_recipe # def load_recipe(recipe_name, current_cookbook: nil) - # FIXME(log): Should be trace - logger.debug("Loading recipe #{recipe_name} via include_recipe") + logger.trace("Loading recipe #{recipe_name} via include_recipe") cookbook_name, recipe_short_name = Chef::Recipe.parse_recipe_name(recipe_name, current_cookbook: current_cookbook) @@ -342,8 +341,7 @@ ERROR_MESSAGE end if loaded_fully_qualified_recipe?(cookbook_name, recipe_short_name) - # FIXME(log): Should be trace - logger.debug("I am not loading #{recipe_name}, because I have already seen it.") + logger.trace("I am not loading #{recipe_name}, because I have already seen it.") false else loaded_recipe(cookbook_name, recipe_short_name) @@ -367,8 +365,7 @@ ERROR_MESSAGE raise Chef::Exceptions::RecipeNotFound, "could not find recipe file #{recipe_file}" end - # FIXME(log): Should be trace - logger.debug("Loading recipe file #{recipe_file}") + logger.trace("Loading recipe file #{recipe_file}") recipe = Chef::Recipe.new("@recipe_files", recipe_file, self) recipe.from_file(recipe_file) recipe diff --git a/lib/chef/shell/shell_session.rb b/lib/chef/shell/shell_session.rb index ce2e457461..aec2152063 100644 --- a/lib/chef/shell/shell_session.rb +++ b/lib/chef/shell/shell_session.rb @@ -252,7 +252,7 @@ module Shell # DoppelGanger implementation of build_node. preserves as many of the node's # attributes, and does not save updates to the server def build_node - Chef::Log.debug("Building node object for #{@node_name}") + Chef::Log.trace("Building node object for #{@node_name}") @node = Chef::Node.find_or_create(node_name) ohai_data = @ohai.data.merge(@node.automatic_attrs) @node.consume_external_attrs(ohai_data, nil) diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index 61bc2bf666..b5c85df56d 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -64,7 +64,7 @@ class Chef def use_tempfile_if_missing(file) tempfile = nil unless File.exists?(file) - Chef::Log.debug("File #{file} does not exist to diff against, using empty tempfile") + Chef::Log.trace("File #{file} does not exist to diff against, using empty tempfile") tempfile = Tempfile.new("chef-diff") file = tempfile.path end @@ -139,7 +139,7 @@ class Chef return "(new content is binary, diff output suppressed)" if is_binary?(new_file) begin - Chef::Log.debug("Running: diff -u #{old_file} #{new_file}") + Chef::Log.trace("Running: diff -u #{old_file} #{new_file}") diff_str = udiff(old_file, new_file) rescue Exception => e diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index 8b492d483a..3e9475bac2 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -26,7 +26,7 @@ class Chef::Util::DSC end def configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags) - Chef::Log.debug("DSC: DSC code:\n '#{code}'") + Chef::Log.trace("DSC: DSC code:\n '#{code}'") generated_script_path = write_document_generation_script(code, "chef_dsc", imports) begin configuration_document_from_script_path(generated_script_path, "chef_dsc", configuration_flags, shellout_flags) diff --git a/lib/chef/util/dsc/lcm_output_parser.rb b/lib/chef/util/dsc/lcm_output_parser.rb index f19f637b6d..658d5c7d8f 100644 --- a/lib/chef/util/dsc/lcm_output_parser.rb +++ b/lib/chef/util/dsc/lcm_output_parser.rb @@ -130,7 +130,7 @@ class Chef end current_resource = { :name => info } else - Chef::Log.debug("Ignoring op_action #{op_action}: Read line #{line}") + Chef::Log.trace("Ignoring op_action #{op_action}: Read line #{line}") end when :end # Make sure we log the last line diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb index 07109f7f92..81aaa098c0 100644 --- a/lib/chef/util/dsc/local_configuration_manager.rb +++ b/lib/chef/util/dsc/local_configuration_manager.rb @@ -46,7 +46,7 @@ class Chef::Util::DSC private def run_configuration_cmdlet(configuration_document, apply_configuration, shellout_flags) - Chef::Log.debug("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.") + Chef::Log.trace("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.") start_operation_timing status = nil @@ -63,10 +63,10 @@ class Chef::Util::DSC end_operation_timing remove_configuration_document if last_operation_execution_time_seconds - Chef::Log.debug("DSC: DSC operation completed in #{last_operation_execution_time_seconds} seconds.") + Chef::Log.trace("DSC: DSC operation completed in #{last_operation_execution_time_seconds} seconds.") end end - Chef::Log.debug("DSC: Completed call to DSC Local Config Manager") + Chef::Log.trace("DSC: Completed call to DSC Local Config Manager") status end @@ -110,7 +110,7 @@ class Chef::Util::DSC end def configuration_update_required?(command_output) - Chef::Log.debug("DSC: DSC returned the following '-whatif' output from test operation:\n#{command_output}") + Chef::Log.trace("DSC: DSC returned the following '-whatif' output from test operation:\n#{command_output}") begin Parser.parse(command_output, ps_version_gte_5?) rescue Chef::Exceptions::LCMParser => e diff --git a/lib/chef/util/selinux.rb b/lib/chef/util/selinux.rb index 8b4c38754c..0d973b0376 100644 --- a/lib/chef/util/selinux.rb +++ b/lib/chef/util/selinux.rb @@ -51,7 +51,7 @@ class Chef restorecon_flags = [ "-R" ] restorecon_flags << "-r" if recursive restorecon_flags << file_path - Chef::Log.debug("Restoring selinux security content with #{restorecon_path}") + Chef::Log.trace("Restoring selinux security content with #{restorecon_path}") shell_out_compact!(restorecon_path, restorecon_flags) else Chef::Log.warn "Can not find 'restorecon' on the system. Skipping selinux security context restore." diff --git a/lib/chef/version.rb b/lib/chef/version.rb index beec856d66..2ec814cc09 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.163") + VERSION = Chef::VersionString.new("14.0.166") end # diff --git a/lib/chef/win32/mutex.rb b/lib/chef/win32/mutex.rb index a14a160f56..2264479734 100644 --- a/lib/chef/win32/mutex.rb +++ b/lib/chef/win32/mutex.rb @@ -55,7 +55,7 @@ class Chef when WAIT_ABANDONED # Previous owner of the mutex died before it can release the # mutex. Log a warning and continue. - Chef::Log.debug "Existing owner of the mutex exited prematurely." + Chef::Log.trace "Existing owner of the mutex exited prematurely." break when WAIT_OBJECT_0 # Mutex is successfully acquired. diff --git a/lib/chef/win32/registry.rb b/lib/chef/win32/registry.rb index 4a1dbe3eac..1193911b00 100644 --- a/lib/chef/win32/registry.rb +++ b/lib/chef/win32/registry.rb @@ -63,30 +63,30 @@ class Chef def set_value(key_path, value) data = value[:data] data = data.to_s if value[:type] == :string - Chef::Log.debug("Updating value #{value[:name]} in registry key #{key_path} with type #{value[:type]} and data #{data}") + Chef::Log.trace("Updating value #{value[:name]} in registry key #{key_path} with type #{value[:type]} and data #{data}") key_exists!(key_path) hive, key = get_hive_and_key(key_path) if value_exists?(key_path, value) if data_exists?(key_path, value) - Chef::Log.debug("Value #{value[:name]} in registry key #{key_path} already had those values, not updated") + Chef::Log.trace("Value #{value[:name]} in registry key #{key_path} already had those values, not updated") return false else hive.open(key, ::Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry_system_architecture) do |reg| reg.write(value[:name], get_type_from_name(value[:type]), data) end - Chef::Log.debug("Value #{value[:name]} in registry key #{key_path} updated") + Chef::Log.trace("Value #{value[:name]} in registry key #{key_path} updated") end else hive.open(key, ::Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry_system_architecture) do |reg| reg.write(value[:name], get_type_from_name(value[:type]), data) end - Chef::Log.debug("Value #{value[:name]} in registry key #{key_path} created") + Chef::Log.trace("Value #{value[:name]} in registry key #{key_path} created") end true end def delete_value(key_path, value) - Chef::Log.debug("Deleting value #{value[:name]} from registry key #{key_path}") + Chef::Log.trace("Deleting value #{value[:name]} from registry key #{key_path}") if value_exists?(key_path, value) begin hive, key = get_hive_and_key(key_path) @@ -95,38 +95,38 @@ class Chef end hive.open(key, ::Win32::Registry::KEY_SET_VALUE | registry_system_architecture) do |reg| reg.delete_value(value[:name]) - Chef::Log.debug("Deleted value #{value[:name]} from registry key #{key_path}") + Chef::Log.trace("Deleted value #{value[:name]} from registry key #{key_path}") end else - Chef::Log.debug("Value #{value[:name]} in registry key #{key_path} does not exist, not updated") + Chef::Log.trace("Value #{value[:name]} in registry key #{key_path} does not exist, not updated") end true end def create_key(key_path, recursive) - Chef::Log.debug("Creating registry key #{key_path}") + Chef::Log.trace("Creating registry key #{key_path}") if keys_missing?(key_path) if recursive == true - Chef::Log.debug("Registry key #{key_path} has missing subkeys, and recursive specified, creating them....") + Chef::Log.trace("Registry key #{key_path} has missing subkeys, and recursive specified, creating them....") create_missing(key_path) else raise Chef::Exceptions::Win32RegNoRecursive, "Registry key #{key_path} has missing subkeys, and recursive not specified" end end if key_exists?(key_path) - Chef::Log.debug("Registry key #{key_path} already exists, doing nothing") + Chef::Log.trace("Registry key #{key_path} already exists, doing nothing") else hive, key = get_hive_and_key(key_path) hive.create(key, ::Win32::Registry::KEY_WRITE | registry_system_architecture) - Chef::Log.debug("Registry key #{key_path} created") + Chef::Log.trace("Registry key #{key_path} created") end true end def delete_key(key_path, recursive) - Chef::Log.debug("Deleting registry key #{key_path}") + Chef::Log.trace("Deleting registry key #{key_path}") unless key_exists?(key_path) - Chef::Log.debug("Registry key #{key_path}, does not exist, not deleting") + Chef::Log.trace("Registry key #{key_path}, does not exist, not deleting") return true end if has_subkeys?(key_path) && !recursive @@ -142,7 +142,7 @@ class Chef hive.open(key_parent, ::Win32::Registry::KEY_WRITE | registry_system_architecture) do |reg| reg.delete_key(key, recursive) end - Chef::Log.debug("Registry key #{key_path} deleted") + Chef::Log.trace("Registry key #{key_path} deleted") true end @@ -357,7 +357,7 @@ class Chef missing_key_arr.each do |intermediate_key| existing_key_path = existing_key_path << "\\" << intermediate_key if !key_exists?(existing_key_path) - Chef::Log.debug("Recursively creating registry key #{existing_key_path}") + Chef::Log.trace("Recursively creating registry key #{existing_key_path}") hive.create(get_key(existing_key_path), ::Win32::Registry::KEY_ALL_ACCESS | registry_system_architecture) end end diff --git a/lib/chef/win32/security.rb b/lib/chef/win32/security.rb index 374d31e8a3..2f903d6c93 100644 --- a/lib/chef/win32/security.rb +++ b/lib/chef/win32/security.rb @@ -645,7 +645,7 @@ class Chef # display token elevation details token_elevation_type = get_token_information_elevation_type(process_token) - Chef::Log.debug("Token Elevation Type: #{token_elevation_type}") + Chef::Log.trace("Token Elevation Type: #{token_elevation_type}") elevation_result = FFI::Buffer.new(:ulong) elevation_result_size = FFI::MemoryPointer.new(:uint32) diff --git a/omnibus/Gemfile.lock b/omnibus/Gemfile.lock index b68e7ee13e..3ffec313cc 100644 --- a/omnibus/Gemfile.lock +++ b/omnibus/Gemfile.lock @@ -31,13 +31,13 @@ GEM addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) awesome_print (1.8.0) - aws-sdk (2.11.19) - aws-sdk-resources (= 2.11.19) - aws-sdk-core (2.11.19) + aws-sdk (2.11.21) + aws-sdk-resources (= 2.11.21) + aws-sdk-core (2.11.21) aws-sigv4 (~> 1.0) jmespath (~> 1.0) - aws-sdk-resources (2.11.19) - aws-sdk-core (= 2.11.19) + aws-sdk-resources (2.11.21) + aws-sdk-core (= 2.11.21) aws-sigv4 (1.0.2) berkshelf (4.3.5) addressable (~> 2.3, >= 2.3.4) diff --git a/spec/functional/http/simple_spec.rb b/spec/functional/http/simple_spec.rb index e792cc8d75..fcabd3f308 100644 --- a/spec/functional/http/simple_spec.rb +++ b/spec/functional/http/simple_spec.rb @@ -87,11 +87,11 @@ describe Chef::HTTP::Simple do it_behaves_like "downloading all the things" - context "when Chef::Log.level = :debug" do + context "when Chef::Log.level = :trace" do before do - Chef::Log.level = :debug + Chef::Log.level = :trace @debug_log = "" - allow(Chef::Log).to receive(:debug) { |str| @debug_log << str } + allow(Chef::Log).to receive(:trace) { |str| @debug_log << str } end let(:source) { "http://localhost:9000" } diff --git a/spec/functional/notifications_spec.rb b/spec/functional/notifications_spec.rb index 8d8b2d970c..87afbd8359 100644 --- a/spec/functional/notifications_spec.rb +++ b/spec/functional/notifications_spec.rb @@ -26,7 +26,7 @@ describe "Notifications" do before do # By default, every provider will do nothing - p = Chef::Provider.new(nil, run_context) + p = Chef::Provider.new(Chef::Resource.new("lies"), run_context) allow_any_instance_of(Chef::Resource).to receive(:provider_for_action).and_return(p) allow(p).to receive(:run_action) end diff --git a/spec/functional/resource/link_spec.rb b/spec/functional/resource/link_spec.rb index 8073bbc92e..2b8b509730 100644 --- a/spec/functional/resource/link_spec.rb +++ b/spec/functional/resource/link_spec.rb @@ -27,6 +27,7 @@ describe Chef::Resource::Link do let(:file_base) { "file_spec" } let(:expect_updated?) { true } + let(:logger) { double("Mixlib::Log::Child").as_null_object } # We create the files in a different directory than tmp to exercise # different file deployment strategies more completely. @@ -163,6 +164,7 @@ describe Chef::Resource::Link do cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) cookbook_collection = Chef::CookbookCollection.new(Chef::CookbookLoader.new(cookbook_repo)) run_context = Chef::RunContext.new(node, cookbook_collection, events) + allow(run_context).to receive(:logger).and_return(logger) resource = Chef::Resource::Link.new(target_file, run_context) resource.to(to) resource @@ -184,7 +186,7 @@ describe Chef::Resource::Link do describe "the :delete action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:delete) end @@ -205,7 +207,7 @@ describe Chef::Resource::Link do describe "the :delete action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:delete) end @@ -226,7 +228,7 @@ describe Chef::Resource::Link do describe "the :create action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end @@ -248,7 +250,7 @@ describe Chef::Resource::Link do describe "the :create action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end @@ -270,7 +272,7 @@ describe Chef::Resource::Link do describe "the :create action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end it "preserves the hard link" do @@ -295,7 +297,7 @@ describe Chef::Resource::Link do describe "the :create action" do before(:each) do @info = [] - allow(Chef::Log).to receive(:info) { |msg| @info << msg } + allow(logger).to receive(:info) { |msg| @info << msg } resource.run_action(:create) end it "links to the target file" do diff --git a/spec/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb index f61a51c636..56ae962ee4 100644 --- a/spec/functional/resource/user/windows_spec.rb +++ b/spec/functional/resource/user/windows_spec.rb @@ -31,6 +31,7 @@ describe Chef::Provider::User::Windows, :windows_only do end let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:logger) { double("Mixlib::Log::Child").as_null_object } let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:new_resource) do Chef::Resource::User.new(username, run_context).tap do |r| @@ -45,6 +46,7 @@ describe Chef::Provider::User::Windows, :windows_only do before do delete_user(username) + allow(run_context).to receive(:logger).and_return(logger) end describe "action :create" do @@ -69,7 +71,7 @@ describe Chef::Provider::User::Windows, :windows_only do context "with a gid specified" do it "warns unsupported" do - expect(Chef::Log).to receive(:warn).with(/not implemented/) + expect(logger).to receive(:warn).with(/not implemented/) new_resource.gid("agroup") new_resource.run_action(:create) end diff --git a/spec/unit/audit/audit_event_proxy_spec.rb b/spec/unit/audit/audit_event_proxy_spec.rb index 820e670f1c..0e35343352 100644 --- a/spec/unit/audit/audit_event_proxy_spec.rb +++ b/spec/unit/audit/audit_event_proxy_spec.rb @@ -44,7 +44,7 @@ describe Chef::Audit::AuditEventProxy do let(:parents) { [double("ExampleGroup")] } it "notifies control_group_started event" do - expect(Chef::Log).to receive(:debug). + expect(Chef::Log).to receive(:trace). with("Entered \`control_group\` block named poots") expect(events).to receive(:control_group_started). with(description) diff --git a/spec/unit/audit/audit_reporter_spec.rb b/spec/unit/audit/audit_reporter_spec.rb index 5239364113..3edee46932 100644 --- a/spec/unit/audit/audit_reporter_spec.rb +++ b/spec/unit/audit/audit_reporter_spec.rb @@ -34,8 +34,8 @@ describe Chef::Audit::AuditReporter do describe "#audit_phase_start" do - it "notifies audit phase start to debug log" do - expect(Chef::Log).to receive(:debug).with(/Audit Reporter starting/) + it "notifies audit phase start to trace log" do + expect(Chef::Log).to receive(:trace).with(/Audit Reporter starting/) reporter.audit_phase_start(run_status) end @@ -126,8 +126,8 @@ EOM let(:response) { double("response", :code => code) } before do - expect(Chef::Log).to receive(:debug).with(/Sending audit report/) - expect(Chef::Log).to receive(:debug).with(/Audit Report/) + expect(Chef::Log).to receive(:trace).with(/Sending audit report/) + expect(Chef::Log).to receive(:trace).with(/Audit Report/) allow(error).to receive(:response).and_return(response) expect(error).to receive(:respond_to?).with(:response).and_return(true) end @@ -137,7 +137,7 @@ EOM let(:code) { "404" } it "logs that the server doesn't support audit reporting" do - expect(Chef::Log).to receive(:debug).with(/Server doesn't support audit reporting/) + expect(Chef::Log).to receive(:trace).with(/Server doesn't support audit reporting/) reporter.run_completed(node) end end @@ -203,12 +203,12 @@ EOM context "when auditing is not enabled" do before do - allow(Chef::Log).to receive(:debug) + allow(Chef::Log).to receive(:trace) end it "doesn't send reports" do expect(reporter).to receive(:auditing_enabled?).and_return(false) - expect(Chef::Log).to receive(:debug).with("Audit Reports are disabled. Skipping sending reports.") + expect(Chef::Log).to receive(:trace).with("Audit Reports are disabled. Skipping sending reports.") reporter.run_completed(node) end @@ -217,13 +217,13 @@ EOM context "when the run fails before audits" do before do - allow(Chef::Log).to receive(:debug) + allow(Chef::Log).to receive(:trace) end it "doesn't send reports" do expect(reporter).to receive(:auditing_enabled?).and_return(true) expect(reporter).to receive(:run_status).and_return(nil) - expect(Chef::Log).to receive(:debug).with("Run failed before audit mode was initialized, not sending audit report to server") + expect(Chef::Log).to receive(:trace).with("Run failed before audit mode was initialized, not sending audit report to server") reporter.run_completed(node) end @@ -313,8 +313,8 @@ EOM describe "#audit_phase_complete" do include_context "audit data" - it "notifies audit phase finished to debug log" do - expect(Chef::Log).to receive(:debug).with(/Audit Reporter completed/) + it "notifies audit phase finished to trace log" do + expect(Chef::Log).to receive(:trace).with(/Audit Reporter completed/) reporter.audit_phase_complete("Output from audit mode") end @@ -331,8 +331,8 @@ EOM let(:error) { double("Exception") } - it "notifies audit phase failed to debug log" do - expect(Chef::Log).to receive(:debug).with(/Audit Reporter failed/) + it "notifies audit phase failed to trace log" do + expect(Chef::Log).to receive(:trace).with(/Audit Reporter failed/) reporter.audit_phase_failed(error, "Output from audit mode") end diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb index a91feec26d..a2cb35e60d 100644 --- a/spec/unit/cookbook/metadata_spec.rb +++ b/spec/unit/cookbook/metadata_spec.rb @@ -871,7 +871,7 @@ describe Chef::Cookbook::Metadata do describe "from_file" do it "ignores unknown metadata fields in metadata.rb files" do - expect(Chef::Log).to receive(:debug).with(/ignoring method some_spiffy_new_metadata_field/) + expect(Chef::Log).to receive(:trace).with(/ignoring method some_spiffy_new_metadata_field/) Tempfile.open("metadata.rb") do |f| f.write <<-EOF some_spiffy_new_metadata_field "stuff its set to" diff --git a/spec/unit/http/validate_content_length_spec.rb b/spec/unit/http/validate_content_length_spec.rb index 5067d36d38..1f24acb94a 100644 --- a/spec/unit/http/validate_content_length_spec.rb +++ b/spec/unit/http/validate_content_length_spec.rb @@ -85,8 +85,8 @@ describe Chef::HTTP::ValidateContentLength do before(:each) do @original_log_level = Chef::Log.level - Chef::Log.level = :debug - allow(Chef::Log).to receive(:debug) do |message| + Chef::Log.level = :trace + allow(Chef::Log).to receive(:trace) do |message| debug_stream.puts message end end @@ -111,7 +111,7 @@ describe Chef::HTTP::ValidateContentLength do describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } - it "should skip validation and log for debug" do + it "should skip validation and log for trace" do run_content_length_validation expect(debug_output).to include("HTTP server did not include a Content-Length header in response") end @@ -126,7 +126,7 @@ describe Chef::HTTP::ValidateContentLength do describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } - it "should skip validation and log for debug" do + it "should skip validation and log for trace" do run_content_length_validation expect(debug_output).to include("HTTP server responded with a negative Content-Length header (-1), cannot identify truncated downloads.") end @@ -180,7 +180,7 @@ describe Chef::HTTP::ValidateContentLength do describe "when running #{req_type} request" do let(:request_type) { req_type.to_sym } - it "should skip validation and log for debug" do + it "should skip validation and log for trace" do run_content_length_validation expect(debug_output).to include("Transfer-Encoding header is set, skipping Content-Length check.") end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 81c0b8a6cf..624261fb8b 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -118,7 +118,7 @@ describe Chef::Knife::Bootstrap do let(:bootstrap_template) { File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) } it "loads the given file as the template" do - expect(Chef::Log).to receive(:debug) + expect(Chef::Log).to receive(:trace) expect(knife.find_template).to eq(File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb"))) end end diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb index 009bc5f4b1..4423ccf64e 100644 --- a/spec/unit/lwrp_spec.rb +++ b/spec/unit/lwrp_spec.rb @@ -57,7 +57,7 @@ describe "LWRP" do Object.const_set("LwrpFoo", Class.new) file = File.expand_path( "lwrp/resources/foo.rb", CHEF_SPEC_DATA) expect(Chef::Log).not_to receive(:info).with(/Skipping/) - expect(Chef::Log).not_to receive(:debug).with(/anymore/) + expect(Chef::Log).not_to receive(:trace).with(/anymore/) Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) Object.send(:remove_const, "LwrpFoo") end @@ -66,7 +66,7 @@ describe "LWRP" do Object.const_set("LwrpBuckPasser", Class.new) file = File.expand_path( "lwrp/providers/buck_passer.rb", CHEF_SPEC_DATA) expect(Chef::Log).not_to receive(:info).with(/Skipping/) - expect(Chef::Log).not_to receive(:debug).with(/anymore/) + expect(Chef::Log).not_to receive(:trace).with(/anymore/) Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil) Object.send(:remove_const, "LwrpBuckPasser") end @@ -81,7 +81,7 @@ describe "LWRP" do end Dir[File.expand_path( "lwrp/resources/*", CHEF_SPEC_DATA)].each do |file| - expect(Chef::Log).to receive(:debug).with(/Skipping/) + expect(Chef::Log).to receive(:trace).with(/Skipping/) Chef::Resource::LWRPBase.build_from_file("lwrp", file, nil) end end @@ -92,7 +92,7 @@ describe "LWRP" do end Dir[File.expand_path( "lwrp/providers/*", CHEF_SPEC_DATA)].each do |file| - expect(Chef::Log).to receive(:debug).with(/Skipping/) + expect(Chef::Log).to receive(:trace).with(/Skipping/) Chef::Provider::LWRPBase.build_from_file("lwrp", file, nil) end end diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 996585ab98..79c4baa89f 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -118,6 +118,19 @@ describe "Chef::Resource.property" do end end + context "deprecated properties" do + it "does not create a deprecation warning on definition" do + expect { resource_class.class_eval { property :x, String, deprecated: 10 } }.not_to raise_error Chef::Exceptions::DeprecatedFeatureError + end + + with_property ":x, deprecated: 'a deprecated property'" do + it "deprecated properties emit a deprecation warning" do + expect(Chef).to receive(:deprecated).with(:property, "a deprecated property") + expect(resource.x 10).to eq 10 + end + end + end + with_property ":x, name_property: true" do context "and subclass" do let(:subresource_class) do @@ -1143,6 +1156,17 @@ describe "Chef::Resource.property" do end + context "with aliased properties" do + with_property ":real, Integer" do + it "should set the real property and emit a deprecation message" do + expect(Chef).to receive(:deprecated).with(:property, "we don't like the deprecated property no more") + resource_class.class_eval { deprecated_property_alias :deprecated, :real, "we don't like the deprecated property no more" } + resource.deprecated 10 + expect(resource.real).to eq 10 + end + end + end + context "redefining Object methods" do it "disallows redefining Object methods" do expect { resource_class.class_eval { property :hash } }.to raise_error(ArgumentError) diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index f49cc7d3da..f27392de5d 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -25,7 +25,8 @@ require "support/shared/unit/provider/file" describe Chef::Provider::CookbookFile do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/cron/unix_spec.rb b/spec/unit/provider/cron/unix_spec.rb index 5e1fcb35ab..62b941c4aa 100644 --- a/spec/unit/provider/cron/unix_spec.rb +++ b/spec/unit/provider/cron/unix_spec.rb @@ -41,10 +41,15 @@ describe Chef::Provider::Cron::Unix do let(:exitstatus) { 0 } let(:shell_out) { double("Mixlib::ShellOut", :status => status, :stdout => stdout, :stderr => stderr) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + it "is a Chef::Provider:Cron" do expect(provider).to be_a(Chef::Provider::Cron) end + before do + allow(run_context).to receive(:logger).and_return(logger) + end describe "read_crontab" do let(:stderr) { "" } let(:stdout) do @@ -59,7 +64,7 @@ describe Chef::Provider::Cron::Unix do end before do - allow(Chef::Log).to receive(:debug) + allow(logger).to receive(:trace) allow(shell_out).to receive(:format_for_exception).and_return("formatted command output") allow(provider).to receive(:shell_out).with("/usr/bin/crontab -l", :user => username).and_return(shell_out) end @@ -83,7 +88,7 @@ describe Chef::Provider::Cron::Unix do it "logs the crontab output to debug" do provider.send(:read_crontab) - expect(Chef::Log).to have_received(:debug).with("formatted command output") + expect(logger).to have_received(:trace).with("formatted command output") end end @@ -98,7 +103,7 @@ describe Chef::Provider::Cron::Unix do it "logs the crontab output to debug" do provider.send(:read_crontab) rescue nil - expect(Chef::Log).to have_received(:debug).with("formatted command output") + expect(logger).to have_received(:trace).with("formatted command output") end end end diff --git a/spec/unit/provider/cron_spec.rb b/spec/unit/provider/cron_spec.rb index ef629ebd52..5673ecc317 100644 --- a/spec/unit/provider/cron_spec.rb +++ b/spec/unit/provider/cron_spec.rb @@ -19,16 +19,23 @@ require "spec_helper" describe Chef::Provider::Cron do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + + before do + @node = Chef::Node.new + @events = Chef::EventDispatch::Dispatcher.new + @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) + + @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context) + @new_resource.user "root" + @new_resource.minute "30" + @new_resource.command "/bin/true" + @provider = Chef::Provider::Cron.new(@new_resource, @run_context) + end + describe "when with special time string" do before do - @node = Chef::Node.new - @events = Chef::EventDispatch::Dispatcher.new - @run_context = Chef::RunContext.new(@node, {}, @events) - - @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context) - @new_resource.user "root" - @new_resource.minute "30" - @new_resource.command "/bin/true" @new_resource.time :reboot @provider = Chef::Provider::Cron.new(@new_resource, @run_context) end @@ -113,7 +120,7 @@ CRONTAB end it "should report the match" do - expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end @@ -141,18 +148,6 @@ CRONTAB end end - before do - @node = Chef::Node.new - @events = Chef::EventDispatch::Dispatcher.new - @run_context = Chef::RunContext.new(@node, {}, @events) - - @new_resource = Chef::Resource::Cron.new("cronhole some stuff", @run_context) - @new_resource.user "root" - @new_resource.minute "30" - @new_resource.command "/bin/true" - @provider = Chef::Provider::Cron.new(@new_resource, @run_context) - end - describe "when examining the current system state" do context "with no crontab for the user" do before :each do @@ -166,7 +161,7 @@ CRONTAB end it "should report an empty crontab" do - expect(Chef::Log).to receive(:debug).with("Cron empty for '#{@new_resource.user}'") + expect(logger).to receive(:trace).with("Cron empty for '#{@new_resource.user}'") @provider.load_current_resource end end @@ -190,7 +185,7 @@ CRONTAB end it "should report no entry found" do - expect(Chef::Log).to receive(:debug).with("Cron '#{@new_resource.name}' not found") + expect(logger).to receive(:trace).with("Cron '#{@new_resource.name}' not found") @provider.load_current_resource end @@ -296,7 +291,7 @@ CRONTAB end it "should report the match" do - expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end end @@ -332,7 +327,7 @@ CRONTAB end it "should report the match" do - expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") + expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'") @provider.load_current_resource end end @@ -478,7 +473,7 @@ TEST=LOL end it "should log the action" do - expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry") + expect(logger).to receive(:info).with("cron[cronhole some stuff] added crontab entry") @provider.run_action(:create) end end @@ -540,7 +535,7 @@ TEST=LOL end it "should log the action" do - expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] added crontab entry") + expect(logger).to receive(:info).with("cron[cronhole some stuff] added crontab entry") @provider.run_action(:create) end end @@ -605,7 +600,7 @@ TEST=LOL end it "should log the action" do - expect(Chef::Log).to receive(:info).with("cron[cronhole some stuff] updated crontab entry") + expect(logger).to receive(:info).with("cron[cronhole some stuff] updated crontab entry") @provider.run_action(:create) end end @@ -719,8 +714,8 @@ CRONTAB end it "should log nothing changed" do - expect(Chef::Log).to receive(:debug).with("Found cron '#{@new_resource.name}'") - expect(Chef::Log).to receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'") + expect(logger).to receive(:trace).with("Found cron '#{@new_resource.name}'") + expect(logger).to receive(:trace).with("Skipping existing cron entry '#{@new_resource.name}'") @provider.run_action(:create) end end @@ -739,7 +734,7 @@ CRONTAB it "should do nothing" do expect(@provider).not_to receive(:write_crontab) - expect(Chef::Log).not_to receive(:info) + expect(logger).not_to receive(:info) @provider.run_action(:delete) end @@ -806,7 +801,7 @@ FOO=test end it "should log the action" do - expect(Chef::Log).to receive(:info).with("#{@new_resource} deleted crontab entry") + expect(logger).to receive(:info).with("#{@new_resource} deleted crontab entry") @provider.run_action(:delete) end end diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb index d8d4ed2286..fed9cd5ece 100644 --- a/spec/unit/provider/file_spec.rb +++ b/spec/unit/provider/file_spec.rb @@ -34,7 +34,8 @@ describe Chef::Provider::File do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb index cf3f0237f5..6e40e41579 100644 --- a/spec/unit/provider/group/dscl_spec.rb +++ b/spec/unit/provider/group/dscl_spec.rb @@ -19,10 +19,13 @@ require "spec_helper" describe Chef::Provider::Group::Dscl do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::Group.new("aj") @current_resource = Chef::Resource::Group.new("aj") @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) @@ -45,8 +48,7 @@ describe Chef::Provider::Group::Dscl do describe "safe_dscl" do before do - @node = Chef::Node.new - @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) + @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) allow(@provider).to receive(:dscl).and_return(["cmd", @status, "stdout", "stderr"]) end @@ -93,8 +95,7 @@ describe Chef::Provider::Group::Dscl do describe "get_free_gid" do before do - @node = Chef::Node.new - @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) + @provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context) allow(@provider).to receive(:safe_dscl).and_return("\naj 200\njt 201\n") end @@ -115,8 +116,6 @@ describe Chef::Provider::Group::Dscl do describe "gid_used?" do before do - @node = Chef::Node.new - @provider = Chef::Provider::Group::Dscl.new(@node, @new_resource) allow(@provider).to receive(:safe_dscl).and_return(<<-eos someprogram somethingElse:gid = ( 500 @@ -197,7 +196,7 @@ describe Chef::Provider::Group::Dscl do end it "should log an appropriate message" do - expect(Chef::Log).to receive(:debug).with("group[aj] removing group members all your base") + expect(logger).to receive(:trace).with("group[aj] removing group members all your base") @provider.set_members end @@ -215,7 +214,7 @@ describe Chef::Provider::Group::Dscl do end it "should log an appropriate debug message" do - expect(Chef::Log).to receive(:debug).with("group[aj] setting group members all, your, base") + expect(logger).to receive(:trace).with("group[aj] setting group members all, your, base") @provider.set_members end diff --git a/spec/unit/provider/group/gpasswd_spec.rb b/spec/unit/provider/group/gpasswd_spec.rb index add87bf008..287951a1a9 100644 --- a/spec/unit/provider/group/gpasswd_spec.rb +++ b/spec/unit/provider/group/gpasswd_spec.rb @@ -19,10 +19,13 @@ require "spec_helper" describe Chef::Provider::Group::Gpasswd, "modify_group_members" do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::Group.new("wheel") @new_resource.members %w{lobster rage fist} @new_resource.append false @@ -65,7 +68,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do end it "logs a message and sets group's members to 'none'" do - expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(logger).to receive(:trace).with("group[wheel] setting group members to: none") expect(@provider).to receive(:shell_out!).with("gpasswd", "-M", "", "wheel") @provider.modify_group_members end @@ -85,7 +88,7 @@ describe Chef::Provider::Group::Gpasswd, "modify_group_members" do describe "when the resource specifies group members" do it "should log an appropriate debug message" do - expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: lobster, rage, fist") + expect(logger).to receive(:trace).with("group[wheel] setting group members to: lobster, rage, fist") allow(@provider).to receive(:shell_out!) @provider.modify_group_members end diff --git a/spec/unit/provider/group/groupmod_spec.rb b/spec/unit/provider/group/groupmod_spec.rb index 6629b718d0..3f36a5b8a6 100644 --- a/spec/unit/provider/group/groupmod_spec.rb +++ b/spec/unit/provider/group/groupmod_spec.rb @@ -19,10 +19,13 @@ require "spec_helper" describe Chef::Provider::Group::Groupmod do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::Group.new("wheel") @new_resource.gid 123 @new_resource.members %w{lobster rage fist} @@ -61,7 +64,7 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and sets group's members to 'none', then removes existing group members" do - expect(Chef::Log).to receive(:debug).with("group[wheel] setting group members to: none") + expect(logger).to receive(:trace).with("group[wheel] setting group members to: none") expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel") expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel") expect(@provider).to receive(:shell_out!).with("group", "del", "wheel_bak") @@ -76,7 +79,7 @@ describe Chef::Provider::Group::Groupmod do end it "logs a message and does not modify group membership" do - expect(Chef::Log).to receive(:debug).with("group[wheel] not changing group members, the group has no members to add") + expect(logger).to receive(:trace).with("group[wheel] not changing group members, the group has no members to add") expect(@provider).not_to receive(:shell_out!) @provider.manage_group end @@ -89,7 +92,7 @@ describe Chef::Provider::Group::Groupmod do end it "updates group membership correctly" do - allow(Chef::Log).to receive(:debug) + allow(logger).to receive(:trace) expect(@provider).to receive(:shell_out!).with("group", "mod", "-n", "wheel_bak", "wheel") expect(@provider).to receive(:shell_out!).with("user", "mod", "-G", "wheel", "lobster") expect(@provider).to receive(:shell_out!).with("group", "add", "-g", "123", "-o", "wheel") diff --git a/spec/unit/provider/group/pw_spec.rb b/spec/unit/provider/group/pw_spec.rb index ee9ceda8c2..736ba0671b 100644 --- a/spec/unit/provider/group/pw_spec.rb +++ b/spec/unit/provider/group/pw_spec.rb @@ -19,10 +19,13 @@ require "spec_helper" describe Chef::Provider::Group::Pw do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::Group.new("wheel") @new_resource.gid 50 @@ -93,7 +96,7 @@ describe Chef::Provider::Group::Pw do end it "should log an appropriate message" do - expect(Chef::Log).to receive(:debug).with("group[wheel] removing group members: all,your,base") + expect(logger).to receive(:trace).with("group[wheel] removing group members: all,your,base") @provider.set_members_options end @@ -109,7 +112,7 @@ describe Chef::Provider::Group::Pw do end it "should log an appropriate debug message" do - expect(Chef::Log).to receive(:debug).with("group[wheel] adding group members: all,your,base") + expect(logger).to receive(:trace).with("group[wheel] adding group members: all,your,base") @provider.set_members_options end diff --git a/spec/unit/provider/link_spec.rb b/spec/unit/provider/link_spec.rb index b233fac72b..10dbdc1766 100644 --- a/spec/unit/provider/link_spec.rb +++ b/spec/unit/provider/link_spec.rb @@ -26,10 +26,12 @@ if Chef::Platform.windows? end describe Chef::Resource::Link do + let(:logger) { double("Mixlib::Log::Child").as_null_object } let(:provider) do node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(node, {}, @events) + allow(run_context).to receive(:logger).and_return(logger) Chef::Provider::Link.new(new_resource, run_context) end let(:new_resource) do @@ -270,7 +272,7 @@ describe Chef::Resource::Link do it "invokes Dir.delete method to delete the link" do expect(::Dir).to receive(:delete).with(provider.new_resource.target_file) - expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted") + expect(logger).to receive(:info).with("#{provider.new_resource} deleted") provider.run_action(:delete) end end @@ -283,7 +285,7 @@ describe Chef::Resource::Link do it "invokes File.delete method to delete the link" do expect(::File).to receive(:delete).with(provider.new_resource.target_file) - expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted") + expect(logger).to receive(:info).with("#{provider.new_resource} deleted") provider.run_action(:delete) end end @@ -296,7 +298,7 @@ describe Chef::Resource::Link do it "invokes File.delete method to delete the link" do expect(::File).to receive(:delete).with(provider.new_resource.target_file) - expect(Chef::Log).to receive(:info).with("#{provider.new_resource} deleted") + expect(logger).to receive(:info).with("#{provider.new_resource} deleted") provider.run_action(:delete) end end diff --git a/spec/unit/provider/log_spec.rb b/spec/unit/provider/log_spec.rb index ce7b1af55a..deb2024640 100644 --- a/spec/unit/provider/log_spec.rb +++ b/spec/unit/provider/log_spec.rb @@ -32,44 +32,49 @@ describe Chef::Provider::Log::ChefLog do let(:provider) { Chef::Provider::Log::ChefLog.new(new_resource, run_context) } - it "should write the string to the Chef::Log object at default level (info)" do - expect(Chef::Log).to receive(:info).with(log_str).and_return(true) + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before do + allow(run_context).to receive(:logger).and_return(logger) + end + + it "should write the string to the logger object at default level (info)" do + expect(logger).to receive(:info).with(log_str).and_return(true) provider.run_action(:write) end - it "should write the string to the Chef::Log object at debug level" do + it "should write the string to the logger object at debug level" do new_resource.level :debug - expect(Chef::Log).to receive(:debug).with(log_str).and_return(true) + expect(logger).to receive(:debug).with(log_str).and_return(true) provider.run_action(:write) end - it "should write the string to the Chef::Log object at info level" do + it "should write the string to the logger object at info level" do new_resource.level :info - expect(Chef::Log).to receive(:info).with(log_str).and_return(true) + expect(logger).to receive(:info).with(log_str).and_return(true) provider.run_action(:write) end - it "should write the string to the Chef::Log object at warn level" do + it "should write the string to the logger object at warn level" do new_resource.level :warn - expect(Chef::Log).to receive(:warn).with(log_str).and_return(true) + expect(logger).to receive(:warn).with(log_str).and_return(true) provider.run_action(:write) end - it "should write the string to the Chef::Log object at error level" do + it "should write the string to the logger object at error level" do new_resource.level :error - expect(Chef::Log).to receive(:error).with(log_str).and_return(true) + expect(logger).to receive(:error).with(log_str).and_return(true) provider.run_action(:write) end - it "should write the string to the Chef::Log object at fatal level" do + it "should write the string to the logger object at fatal level" do new_resource.level :fatal - expect(Chef::Log).to receive(:fatal).with(log_str).and_return(true) + expect(logger).to receive(:fatal).with(log_str).and_return(true) provider.run_action(:write) end it "should print the string in why-run mode" do Chef::Config[:why_run] = true - expect(Chef::Log).to receive(:info).with(log_str).and_return(true) + expect(logger).to receive(:info).with(log_str).and_return(true) provider.run_action(:write) end diff --git a/spec/unit/provider/package/apt_spec.rb b/spec/unit/provider/package/apt_spec.rb index b461a39673..78c517b9a0 100644 --- a/spec/unit/provider/package/apt_spec.rb +++ b/spec/unit/provider/package/apt_spec.rb @@ -20,6 +20,7 @@ require "spec_helper" require "ostruct" describe Chef::Provider::Package::Apt do + let(:logger) { double("Mixlib::Log::Child").as_null_object } # XXX: sorry this is ugly and was done quickly to get 12.0.2 out, this file needs a rewrite to use # let blocks and shared examples @@ -27,6 +28,7 @@ describe Chef::Provider::Package::Apt do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::AptPackage.new("irssi", @run_context) @status = double("Status", :exitstatus => 0) @@ -418,7 +420,7 @@ mpg123 1.12.1-0ubuntu1 ).and_return(instance_double( Mixlib::ShellOut, stdout: "irssi") ) - expect(Chef::Log).to receive(:debug).with("#{@provider.new_resource} is already locked") + expect(logger).to receive(:trace).with("#{@provider.new_resource} is already locked") @provider.new_resource.package_name = ["irssi"] @provider.action_lock @@ -440,7 +442,7 @@ mpg123 1.12.1-0ubuntu1 ).and_return(instance_double( Mixlib::ShellOut, stdout: "") ) - expect(Chef::Log).to receive(:debug).with("#{@provider.new_resource} is already unlocked") + expect(logger).to receive(:trace).with("#{@provider.new_resource} is already unlocked") @provider.new_resource.package_name = ["irssi"] @provider.action_unlock diff --git a/spec/unit/provider/package/bff_spec.rb b/spec/unit/provider/package/bff_spec.rb index 1018f2d3e9..abe1d4155c 100644 --- a/spec/unit/provider/package/bff_spec.rb +++ b/spec/unit/provider/package/bff_spec.rb @@ -19,10 +19,12 @@ require "spec_helper" describe Chef::Provider::Package::Bff do + let(:logger) { double("Mixlib::Log::Child").as_null_object } before(:each) do @node = Chef::Node.new @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @new_resource = Chef::Resource::Package.new("samba.base") @new_resource.source("/tmp/samba.base") @@ -79,7 +81,7 @@ describe Chef::Provider::Package::Bff do status = double("Status", :stdout => info, :exitstatus => 0) expect(@provider).to receive(:shell_out).with("installp", "-L", "-d", "/tmp/samba.base", timeout: 900).and_return(status) expect(@provider).to receive(:shell_out).with("lslpp", "-lcq", "samba.base", timeout: 900).and_return(@empty_status) - expect(Chef::Log).to receive(:warn).once.with(%r{bff package by product name}) + expect(logger).to receive(:warn).once.with(%r{bff package by product name}) @provider.load_current_resource expect(@provider.current_resource.package_name).to eq("samba.base") diff --git a/spec/unit/provider/package/homebrew_spec.rb b/spec/unit/provider/package/homebrew_spec.rb index 572c54e83d..833fa7bd3e 100644 --- a/spec/unit/provider/package/homebrew_spec.rb +++ b/spec/unit/provider/package/homebrew_spec.rb @@ -20,7 +20,8 @@ require "spec_helper" describe Chef::Provider::Package::Homebrew do let(:node) { Chef::Node.new } let(:events) { double("Chef::Events").as_null_object } - let(:run_context) { double("Chef::RunContext", node: node, events: events) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } let(:new_resource) { Chef::Resource::HomebrewPackage.new("emacs") } let(:current_resource) { Chef::Resource::HomebrewPackage.new("emacs") } diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index 071cba23d8..28bd371539 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -33,8 +33,10 @@ require "ostruct" describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do include GemspecBackcompatCreator + let(:logger) { double("Mixlib::Log::Child").as_null_object } before do @gem_env = Chef::Provider::Package::Rubygems::CurrentGemEnvironment.new + allow(@gem_env).to receive(:logger).and_return(logger) end it "determines the gem paths from the in memory rubygems" do diff --git a/spec/unit/provider/package_spec.rb b/spec/unit/provider/package_spec.rb index 8333d5bd0d..da74c932a8 100644 --- a/spec/unit/provider/package_spec.rb +++ b/spec/unit/provider/package_spec.rb @@ -26,6 +26,7 @@ describe Chef::Provider::Package do node end let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:logger) { double("Mixlib::Log::Child").as_null_object } let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:new_resource) { Chef::Resource::Package.new("install emacs") } let(:current_resource) { Chef::Resource::Package.new("install emacs") } @@ -39,6 +40,10 @@ describe Chef::Provider::Package do provider end + before do + allow(run_context).to receive(:logger).and_return(logger) + end + describe "when installing a package" do before(:each) do provider.current_resource = current_resource @@ -166,7 +171,7 @@ describe Chef::Provider::Package do it "should print the word 'uninstalled' if there was no original version" do allow(current_resource).to receive(:version).and_return(nil) - expect(Chef::Log).to receive(:info).with("package[install emacs] upgraded emacs to 1.0") + expect(logger).to receive(:info).with("package[install emacs] upgraded emacs to 1.0") provider.run_action(:upgrade) expect(new_resource).to be_updated_by_last_action end @@ -287,7 +292,7 @@ describe Chef::Provider::Package do expect(provider).to receive(:get_preseed_file).and_return("/var/cache/preseed-test") allow(provider).to receive(:preseed_package).and_return(true) allow(provider).to receive(:reconfig_package).and_return(true) - expect(Chef::Log).to receive(:info).with("package[install emacs] reconfigured") + expect(logger).to receive(:info).with("package[install emacs] reconfigured") expect(provider).to receive(:reconfig_package) provider.run_action(:reconfig) expect(new_resource).to be_updated @@ -296,7 +301,7 @@ describe Chef::Provider::Package do it "should debug log and not reconfigure the package if the package is not installed" do allow(current_resource).to receive(:version).and_return(nil) - expect(Chef::Log).to receive(:debug).with("package[install emacs] is NOT installed - nothing to do") + expect(logger).to receive(:trace).with("package[install emacs] is NOT installed - nothing to do") expect(provider).not_to receive(:reconfig_package) provider.run_action(:reconfig) expect(new_resource).not_to be_updated_by_last_action @@ -305,7 +310,7 @@ describe Chef::Provider::Package do it "should debug log and not reconfigure the package if no response_file is given" do allow(current_resource).to receive(:version).and_return("1.0") allow(new_resource).to receive(:response_file).and_return(nil) - expect(Chef::Log).to receive(:debug).with("package[install emacs] no response_file provided - nothing to do") + expect(logger).to receive(:trace).with("package[install emacs] no response_file provided - nothing to do") expect(provider).not_to receive(:reconfig_package) provider.run_action(:reconfig) expect(new_resource).not_to be_updated_by_last_action @@ -316,7 +321,7 @@ describe Chef::Provider::Package do allow(new_resource).to receive(:response_file).and_return(true) expect(provider).to receive(:get_preseed_file).and_return(false) allow(provider).to receive(:preseed_package).and_return(false) - expect(Chef::Log).to receive(:debug).with("package[install emacs] preseeding has not changed - nothing to do") + expect(logger).to receive(:trace).with("package[install emacs] preseeding has not changed - nothing to do") expect(provider).not_to receive(:reconfig_package) provider.run_action(:reconfig) expect(new_resource).not_to be_updated_by_last_action diff --git a/spec/unit/provider/registry_key_spec.rb b/spec/unit/provider/registry_key_spec.rb index 3fb9468f5d..096fe9b9ed 100644 --- a/spec/unit/provider/registry_key_spec.rb +++ b/spec/unit/provider/registry_key_spec.rb @@ -313,7 +313,13 @@ describe Chef::Provider::RegistryKey do end describe Chef::Provider::RegistryKey, "key_missing?" do - let(:provider) { Chef::Provider::RegistryKey.new(nil, nil) } + let(:node) { Chef::Node.new } + let(:events) { double("Chef::Events").as_null_object } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", node: node, events: events, logger: logger) } + let(:new_resource) { Chef::Resource::RegistryKey.new("emacs") } + let(:provider) { Chef::Provider::RegistryKey.new(new_resource, run_context) } + let(:all_keys_present_in_all_hash) do [ { :name => "input1_value1", :type => :string, :data => "my_value1" }, { :name => "input1_value2", :type => :string, :data => "my_value2" }, diff --git a/spec/unit/provider/remote_file_spec.rb b/spec/unit/provider/remote_file_spec.rb index 6ceb1d450d..3f91377c60 100644 --- a/spec/unit/provider/remote_file_spec.rb +++ b/spec/unit/provider/remote_file_spec.rb @@ -36,7 +36,8 @@ describe Chef::Provider::RemoteFile do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/service/macosx_spec.rb b/spec/unit/provider/service/macosx_spec.rb index 704c7a802e..5f8bbc4a39 100644 --- a/spec/unit/provider/service/macosx_spec.rb +++ b/spec/unit/provider/service/macosx_spec.rb @@ -44,6 +44,7 @@ describe Chef::Provider::Service::Macosx do context "when service name is given as" do let(:node) { Chef::Node.new } let(:events) { Chef::EventDispatch::Dispatcher.new } + let(:logger) { double("Mixlib::Log::Child").as_null_object } let(:run_context) { Chef::RunContext.new(node, {}, events) } let(:provider) { described_class.new(new_resource, run_context) } let(:launchctl_stdout) { StringIO.new } @@ -73,6 +74,7 @@ XML end let(:service_label) { "io.redis.redis-server" } before do + allow(run_context).to receive(:logger).and_return(logger) allow(Dir).to receive(:glob).and_return([plist], []) @stat = double("File::Stat", { :uid => 501 }) allow(File).to receive(:stat).and_return(@stat) @@ -260,7 +262,7 @@ SVC_LIST it "shows warning message if service is already running" do allow(current_resource).to receive(:running).and_return(true) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] already running, not starting") + expect(logger).to receive(:trace).with("macosx_service[#{service_name}] already running, not starting") provider.start_service end @@ -292,7 +294,7 @@ SVC_LIST it "shows warning message if service is not running" do allow(current_resource).to receive(:running).and_return(false) - expect(Chef::Log).to receive(:debug).with("macosx_service[#{service_name}] not running, not stopping") + expect(logger).to receive(:trace).with("macosx_service[#{service_name}] not running, not stopping") provider.stop_service end diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index ce9154cb72..7cfc645b32 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -23,6 +23,8 @@ require "mixlib/shellout" describe Chef::Provider::Service::Windows, "load_current_resource", :windows_only do include_context "Win32" + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:chef_service_name) { "chef-client" } let(:new_resource) { Chef::Resource::WindowsService.new(chef_service_name) } @@ -77,8 +79,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl end let(:provider) do - prvdr = Chef::Provider::Service::Windows.new(new_resource, - Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new)) + run_context = Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new) + allow(run_context).to receive(:logger).and_return(logger) + prvdr = Chef::Provider::Service::Windows.new(new_resource, run_context) prvdr.current_resource = Chef::Resource::WindowsService.new("current-chef") prvdr end @@ -268,7 +271,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl end it "logs debug message" do - expect(Chef::Log).to receive(:debug).with("windows_service[#{chef_service_name}] already exists - nothing to do") + expect(logger).to receive(:trace).with("windows_service[#{chef_service_name}] already exists - nothing to do") provider.action_create end @@ -348,7 +351,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl end it "logs debug message" do - expect(Chef::Log).to receive(:debug).with("windows_service[#{chef_service_name}] does not exist - nothing to do") + expect(logger).to receive(:trace).with("windows_service[#{chef_service_name}] does not exist - nothing to do") provider.action_delete end @@ -421,7 +424,7 @@ describe Chef::Provider::Service::Windows, "load_current_resource", :windows_onl end it "logs warning" do - expect(Chef::Log).to receive(:warn) + expect(logger).to receive(:warn) .with("windows_service[#{chef_service_name}] does not exist. Maybe you need to prepend action :create") provider.action_configure end diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb index 306fd6ea71..9f69772bc8 100644 --- a/spec/unit/provider/template_spec.rb +++ b/spec/unit/provider/template_spec.rb @@ -26,7 +26,8 @@ require "support/shared/unit/provider/file" describe Chef::Provider::Template do let(:node) { double("Chef::Node") } let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } + let(:logger) { double("Mixlib::Log::Child").as_null_object } + let(:run_context) { double("Chef::RunContext", :node => node, :events => events, :logger => logger) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end @@ -58,9 +59,6 @@ describe Chef::Provider::Template do context "when creating the template" do - let(:node) { double("Chef::Node") } - let(:events) { double("Chef::Events").as_null_object } # mock all the methods - let(:run_context) { double("Chef::RunContext", :node => node, :events => events) } let(:enclosing_directory) do canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "templates"))) end diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index 82f3c1ab2a..179926e5e6 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -28,11 +28,14 @@ class Chef end describe Chef::Provider::User::Windows do + let(:logger) { double("Mixlib::Log::Child").as_null_object } + before(:each) do @node = Chef::Node.new @new_resource = Chef::Resource::User::WindowsUser.new("monkey") @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, {}, @events) + allow(@run_context).to receive(:logger).and_return(logger) @current_resource = Chef::Resource::User::WindowsUser.new("monkey") @net_user = double("Chef::Util::Windows::NetUser") diff --git a/spec/unit/provider/zypper_repository_spec.rb b/spec/unit/provider/zypper_repository_spec.rb index a366a33e86..2509452672 100644 --- a/spec/unit/provider/zypper_repository_spec.rb +++ b/spec/unit/provider/zypper_repository_spec.rb @@ -35,10 +35,12 @@ EOF describe Chef::Provider::ZypperRepository do let(:new_resource) { Chef::Resource::ZypperRepository.new("Nginx Repository") } + let(:logger) { double("Mixlib::Log::Child").as_null_object } let(:provider) do node = Chef::Node.new events = Chef::EventDispatch::Dispatcher.new run_context = Chef::RunContext.new(node, {}, events) + allow(run_context).to receive(:logger).and_return(logger) Chef::Provider::ZypperRepository.new(new_resource, run_context) end @@ -58,7 +60,7 @@ describe Chef::Provider::ZypperRepository do it "skips key import if gpgautoimportkeys is false" do new_resource.gpgautoimportkeys(false) expect(provider).to receive(:declare_resource) - expect(Chef::Log).to receive(:debug) + expect(logger).to receive(:trace) provider.run_action(:create) end end @@ -117,7 +119,7 @@ describe Chef::Provider::ZypperRepository do describe "#install_gpg_key" do it "skips installing the key if a nil value for key is passed" do - expect(Chef::Log).to receive(:debug) + expect(logger).to receive(:trace) provider.install_gpg_key(nil) end end diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index 0ea704084c..97a4fe4b30 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -635,7 +635,7 @@ describe Chef::ResourceReporter do end it "prints an error about the 404" do - expect(Chef::Log).to receive(:debug).with(/404/) + expect(Chef::Log).to receive(:trace).with(/404/) @resource_reporter.run_started(@run_status) end |