diff options
author | Claire McQuin <claire@getchef.com> | 2015-07-20 17:17:15 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2015-07-27 09:24:19 -0700 |
commit | b34f65e313c282926967093904d04dd248a6cd83 (patch) | |
tree | 2ad312cc814aa74ab04aaff6675d8e5b016aa90c | |
parent | 247a910aaf8b6d78df56780f800a05a5120f0e2b (diff) | |
download | chef-b34f65e313c282926967093904d04dd248a6cd83.tar.gz |
Mute :log_level and :log_location deprecation warnings from ohai config.
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | chef.gemspec | 2 | ||||
-rw-r--r-- | lib/chef/config.rb | 30 | ||||
-rw-r--r-- | spec/unit/config_spec.rb | 31 |
4 files changed, 66 insertions, 2 deletions
@@ -5,6 +5,11 @@ gem "activesupport", "< 4.0.0", :group => :compat_testing, :platform => "ruby" gem 'chef-config', path: "chef-config" +# REMOVEME once there is a release of Ohai with these changes, and the +# chef.gemspec is updated. +gem 'ohai', github: 'chef/ohai', + ref: '7556a1d55808c459f3a9fad88e2a2371f361f3e0' + group(:docgen) do gem "tomlrb" gem "yard" diff --git a/chef.gemspec b/chef.gemspec index f4f8a31207..4df2bf4196 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -21,7 +21,7 @@ Gem::Specification.new do |s| s.add_dependency "mixlib-log", "~> 1.3" s.add_dependency "mixlib-authentication", "~> 1.3" s.add_dependency "mixlib-shellout", ">= 2.0.0.rc.0", "< 3.0" - s.add_dependency "ohai", "~> 8.0" + # s.add_dependency "ohai", "~> 8.0" s.add_dependency "ffi-yajl", "~> 2.2" s.add_dependency "net-ssh", "~> 2.6" diff --git a/lib/chef/config.rb b/lib/chef/config.rb index d3ed6b3a8f..6382af14c2 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -30,8 +30,17 @@ ChefConfig.logger = Chef::Log require 'chef-config/config' require 'chef/platform/query_helpers' +# Ohai::Config defines its own log_level and log_location. When loaded, it will +# override the default ChefConfig::Config values. We save them here before +# loading ohai/config so that we can override them again inside Chef::Config. +# +# REMOVEME once these configurables are removed from the top level of Ohai. +LOG_LEVEL = ChefConfig::Config[:log_level] unless defined? LOG_LEVEL +LOG_LOCATION = ChefConfig::Config[:log_location] unless defined? LOG_LOCATION + # Load the ohai config into the chef config. We can't have an empty ohai -# configuration context because `ohai.plugins_path << some_path` won't work. +# configuration context because `ohai.plugins_path << some_path` won't work, +# and providing default ohai config values here isn't DRY. require 'ohai/config' class Chef @@ -52,5 +61,24 @@ class Chef evt_loggers end + # Override the default values that were set by Ohai. + # + # REMOVEME once these configurables are removed from the top level of Ohai. + default :log_level, LOG_LEVEL + default :log_location, LOG_LOCATION + + # Ohai::Config[:log_level] is deprecated and warns when set. Unfortunately, + # there is no way to distinguish between setting log_level and setting + # Ohai::Config[:log_level]. Since log_level and log_location are used by + # chef-client and other tools (e.g., knife), we will mute the warnings here + # by redefining the config_attr_writer to not warn for these options. + # + # REMOVEME once the warnings for these configurables are removed from Ohai. + [ :log_level, :log_location ].each do |option| + config_attr_writer option do |value| + value + end + end + end end diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb new file mode 100644 index 0000000000..8d155c61ab --- /dev/null +++ b/spec/unit/config_spec.rb @@ -0,0 +1,31 @@ + +require 'spec_helper' + +require 'chef/config' + +RSpec.describe Chef::Config do + + shared_examples_for "deprecated by ohai but not deprecated" do + it "does not emit a deprecation warning when set" do + expect(Chef::Log).to_not receive(:warn). + with(/Ohai::Config\[:#{option}\] is deprecated/) + Chef::Config[option] = value + expect(Chef::Config[option]).to eq(value) + end + end + + describe ":log_level" do + include_examples "deprecated by ohai but not deprecated" do + let(:option) { :log_level } + let(:value) { :debug } + end + end + + describe ":log_location" do + include_examples "deprecated by ohai but not deprecated" do + let(:option) { :log_location } + let(:value) { "path/to/log" } + end + end + +end |