summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2015-08-07 12:42:42 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2015-08-07 12:42:42 -0700
commit4a3ede96a443a99748b2092e8c58d40ff8b2e104 (patch)
tree50b54fceadaf51c025c18557861f647cdee44d92
parent9d76430aa9f60c825862043aa7899bf3bf06211f (diff)
parentb882a1c1b9a746e76535915e9ecf0d4d4185dd6f (diff)
downloadchef-4a3ede96a443a99748b2092e8c58d40ff8b2e104.tar.gz
Merge pull request #3689 from chef/mcquin/ohai-config
Add ohai configuration context to config.
-rw-r--r--chef.gemspec2
-rw-r--r--lib/chef/config.rb33
-rw-r--r--spec/unit/config_spec.rb31
3 files changed, 64 insertions, 2 deletions
diff --git a/chef.gemspec b/chef.gemspec
index f4f8a31207..6361fb42f5 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.6.0.alpha.1", "< 9"
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 9beb18b53e..6382af14c2 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -28,9 +28,21 @@ require 'chef-config/logger'
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,
+# and providing default ohai config values here isn't DRY.
+require 'ohai/config'
+
class Chef
Config = ChefConfig::Config
@@ -49,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