summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2015-07-09 13:35:27 -0700
committerClaire McQuin <claire@getchef.com>2015-07-21 09:47:50 -0700
commit68506520e8962ae685a551bfb3594272c68d31f0 (patch)
tree21860f72dd4e0ba562e56aacfe82a5367c022015
parent542eebb54f20bde83612cff37ea1d7156ca0ffd1 (diff)
downloadohai-68506520e8962ae685a551bfb3594272c68d31f0.tar.gz
Use Ohai.config
-rw-r--r--lib/ohai/application.rb8
-rw-r--r--lib/ohai/config.rb2
-rw-r--r--lib/ohai/dsl/plugin.rb2
-rw-r--r--lib/ohai/hints.rb2
-rw-r--r--lib/ohai/loader.rb4
-rw-r--r--lib/ohai/system.rb4
-rw-r--r--spec/spec_helper.rb6
-rw-r--r--spec/unit/dsl/plugin_spec.rb4
-rw-r--r--spec/unit/hints_spec.rb8
-rw-r--r--spec/unit/system_spec.rb100
10 files changed, 45 insertions, 95 deletions
diff --git a/lib/ohai/application.rb b/lib/ohai/application.rb
index 264df0f2..4388fdf7 100644
--- a/lib/ohai/application.rb
+++ b/lib/ohai/application.rb
@@ -82,8 +82,8 @@ class Ohai::Application
end
def configure_logging
- Ohai::Log.init(Ohai::Config[:log_location])
- Ohai::Log.level = Ohai::Config[:log_level]
+ Ohai::Log.init(Ohai.config[:log_location])
+ Ohai::Log.level = Ohai.config[:log_level]
end
def run_application
@@ -103,12 +103,12 @@ class Ohai::Application
# Log a fatal error message to both STDERR and the Logger, exit the application
def fatal!(msg, err = -1)
STDERR.puts("FATAL: #{msg}")
- Chef::Log.fatal(msg)
+ Ohai::Log.fatal(msg)
Process.exit err
end
def exit!(msg, err = -1)
- Chef::Log.debug(msg)
+ Ohai::Log.debug(msg)
Process.exit err
end
end
diff --git a/lib/ohai/config.rb b/lib/ohai/config.rb
index 988c2328..1e8404c1 100644
--- a/lib/ohai/config.rb
+++ b/lib/ohai/config.rb
@@ -34,7 +34,7 @@ module Ohai
# otherwise they will get method_missing'd to nil.
private
def self.default_hints_path
- [ platform_specific_path('/etc/chef/ohai/hints') ]
+ [ ChefConfig::Config.platform_specific_path('/etc/chef/ohai/hints') ]
end
def self.default_plugin_path
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
index 86ccc622..48048910 100644
--- a/lib/ohai/dsl/plugin.rb
+++ b/lib/ohai/dsl/plugin.rb
@@ -92,7 +92,7 @@ module Ohai
def run
@has_run = true
- if Ohai::Config[:disabled_plugins].include?(name)
+ if Ohai.config[:disabled_plugins].include?(name)
Ohai::Log.debug("Skipping disabled plugin #{name}")
else
run_plugin
diff --git a/lib/ohai/hints.rb b/lib/ohai/hints.rb
index c8b0bc1b..603a1e46 100644
--- a/lib/ohai/hints.rb
+++ b/lib/ohai/hints.rb
@@ -29,7 +29,7 @@ module Ohai
@hints ||= Hash.new
return @hints[name] if @hints[name]
- Ohai::Config[:hints_path].each do |path|
+ Ohai.config[:hints_path].each do |path|
filename = File.join(path, "#{name}.json")
if File.exist?(filename)
begin
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb
index 44c77321..1c7519df 100644
--- a/lib/ohai/loader.rb
+++ b/lib/ohai/loader.rb
@@ -24,7 +24,7 @@ require 'pathname'
module Ohai
# Ohai plugin loader. Finds all the plugins in your
- # `Ohai::Config[:plugin_path]` (supports a single or multiple path setting
+ # `Ohai.config[:plugin_path]` (supports a single or multiple path setting
# here), evaluates them and returns plugin objects.
class Loader
@@ -57,7 +57,7 @@ module Ohai
# Searches all plugin paths and returns an Array of PluginFile objects
# representing each plugin file.
def plugin_files_by_dir
- Array(Ohai::Config[:plugin_path]).inject([]) do |plugin_files, plugin_path|
+ Array(Ohai.config[:plugin_path]).inject([]) do |plugin_files, plugin_path|
plugin_files + PluginFile.find_all_in(plugin_path)
end
end
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 5df6c7f9..c98ac1af 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -49,8 +49,8 @@ module Ohai
@v6_dependency_solver = Hash.new
# configure logging
- Ohai::Log.init(Ohai::Config[:log_location])
- Ohai::Log.level = Ohai::Config[:log_level]
+ Ohai::Log.init(Ohai.config[:log_location])
+ Ohai::Log.level = Ohai.config[:log_level]
@loader = Ohai::Loader.new(self)
@runner = Ohai::Runner.new(self, true)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 7017d985..8d561ea8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -11,7 +11,7 @@ require 'spec/support/platform_helpers'
require 'spec/support/integration_helper'
require 'wmi-lite'
require 'ohai'
-Ohai::Config[:log_level] = :error
+Ohai.config[:log_level] = :error
PLUGIN_PATH = File.expand_path("../../lib/ohai/plugins", __FILE__)
SPEC_PLUGIN_PATH = File.expand_path("../data/plugins", __FILE__)
@@ -118,6 +118,10 @@ RSpec.configure do |config|
config.run_all_when_everything_filtered = true
config.before :each do
+ # TODO: Change to Ohai.config once Ohai::Config is deprecated fully. Needs
+ # to stay Ohai::Config for now so that top-level attributes will get cleared
+ # out between tests (config_spec should be the only place where top-level
+ # config attributes are set).
Ohai::Config.reset
end
end
diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb
index 25ca166d..dc4c1681 100644
--- a/spec/unit/dsl/plugin_spec.rb
+++ b/spec/unit/dsl/plugin_spec.rb
@@ -38,7 +38,7 @@ shared_examples "Ohai::DSL::Plugin" do
describe "when plugin is enabled" do
before do
- allow(Ohai::Config).to receive(:[]).with(:disabled_plugins).and_return([ ])
+ allow(Ohai.config).to receive(:[]).with(:disabled_plugins).and_return([ ])
end
it "should run the plugin" do
@@ -54,7 +54,7 @@ shared_examples "Ohai::DSL::Plugin" do
describe "if the plugin is disabled" do
before do
- allow(Ohai::Config).to receive(:[]).with(:disabled_plugins).and_return([ :TestPlugin ])
+ allow(Ohai.config).to receive(:[]).with(:disabled_plugins).and_return([ :TestPlugin ])
end
it "should not run the plugin" do
diff --git a/spec/unit/hints_spec.rb b/spec/unit/hints_spec.rb
index 5faf0af8..84c0e2a7 100644
--- a/spec/unit/hints_spec.rb
+++ b/spec/unit/hints_spec.rb
@@ -24,16 +24,16 @@ describe "Ohai::Hints" do
extend IntegrationSupport
before do
- @original_hints = Ohai::Config[:hints_path]
+ @original_hints = Ohai.config[:hints_path]
end
after do
- Ohai::Config[:hints_path] = @original_hints
+ Ohai.config[:hints_path] = @original_hints
end
when_plugins_directory "doesn't contain any hints" do
before do
- Ohai::Config[:hints_path] = [ path_to(".") ]
+ Ohai.config[:hints_path] = [ path_to(".") ]
end
it "hint? should return nil" do
@@ -50,7 +50,7 @@ EOF
EOF
before do
- Ohai::Config[:hints_path] = [ path_to(".") ]
+ Ohai.config[:hints_path] = [ path_to(".") ]
end
it "hint? should return the data for full hints" do
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index 0830e499..0eb7f439 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -51,8 +51,7 @@ provides 'fish'
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "load_plugins() should load all the plugins" do
@@ -85,12 +84,7 @@ provides 'bear'
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to("repo1"), path_to("repo2") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to("repo1"), path_to("repo2") ]
end
it "load_plugins() should load all the plugins" do
@@ -106,14 +100,6 @@ EOF
end
describe "when running plugins" do
- before do
- @original_config = Ohai::Config[:plugin_path]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
- end
-
when_plugins_directory "contains v6 plugins only" do
with_plugin("zoo.rb", <<EOF)
provides 'zoo'
@@ -126,7 +112,7 @@ park("plants")
EOF
it "should collect data from all the plugins" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:zoo]).to eq("animals")
expect(ohai.data[:park]).to eq("plants")
@@ -134,15 +120,15 @@ EOF
describe "when using :disabled_plugins" do
before do
- Ohai::Config[:disabled_plugins] = [ "zoo" ]
+ Ohai.config[:disabled_plugins] = [ "zoo" ]
end
after do
- Ohai::Config[:disabled_plugins] = [ ]
+ Ohai.config[:disabled_plugins] = [ ]
end
it "shouldn't run disabled version 6 plugins" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:zoo]).to be_nil
expect(ohai.data[:park]).to eq("plants")
@@ -245,7 +231,7 @@ end
EOF
it "should collect platform specific" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:message]).to eq("platform_specific_message")
end
@@ -272,14 +258,14 @@ end
EOF
it "should collect data from all the plugins" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:zoo]).to eq("animals")
expect(ohai.data[:park]).to eq("plants")
end
it "should write an error to Ohai::Log" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
# Make sure the stubbing of runner is not overriden with reset_system during test
allow(ohai).to receive(:reset_system)
allow(ohai.instance_variable_get("@runner")).to receive(:run_plugin).and_raise(Ohai::Exceptions::AttributeNotFound)
@@ -289,15 +275,15 @@ EOF
describe "when using :disabled_plugins" do
before do
- Ohai::Config[:disabled_plugins] = [ :Zoo ]
+ Ohai.config[:disabled_plugins] = [ :Zoo ]
end
after do
- Ohai::Config[:disabled_plugins] = [ ]
+ Ohai.config[:disabled_plugins] = [ ]
end
it "shouldn't run disabled plugins" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:zoo]).to be_nil
expect(ohai.data[:park]).to eq("plants")
@@ -338,15 +324,15 @@ EOF
describe "when using :disabled_plugins" do
before do
- Ohai::Config[:disabled_plugins] = [ :Zoo, 'my_plugins::park' ]
+ Ohai.config[:disabled_plugins] = [ :Zoo, 'my_plugins::park' ]
end
after do
- Ohai::Config[:disabled_plugins] = [ ]
+ Ohai.config[:disabled_plugins] = [ ]
end
it "shouldn't run disabled plugins" do
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
ohai.all_plugins
expect(ohai.data[:zoo]).to be_nil
expect(ohai.data[:nature]).to eq("cougars")
@@ -384,12 +370,7 @@ end
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "should collect all data" do
@@ -427,12 +408,7 @@ end
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "version 6 should run" do
@@ -475,12 +451,7 @@ end
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "should collect all the data properly" do
@@ -502,12 +473,7 @@ message v7message
EOF
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "should raise DependencyNotFound" do
@@ -525,12 +491,7 @@ EOF
E
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "reloads only the v6 plugin when given a specific plugin to load" do
@@ -552,12 +513,7 @@ EOF
E
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "should rerun the plugin providing the desired attributes" do
@@ -611,17 +567,12 @@ EOF
E
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
+ Ohai.config[:plugin_path] = [ path_to(".") ]
Ohai::Log.init(STDOUT)
Ohai::Log.level = :debug
ohai.all_plugins
end
- after do
- Ohai::Config[:plugin_path] = @original_config
- end
-
it "should rerun the plugin providing the desired attributes" do
expect(ohai.data[:desired_attr_count]).to eq(1)
ohai.refresh_plugins("desired_attr")
@@ -682,12 +633,7 @@ EOF
E
before do
- @original_config = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [ path_to(".") ]
- end
-
- after do
- Ohai::Config[:plugin_path] = @original_config
+ Ohai.config[:plugin_path] = [ path_to(".") ]
end
it "should run all the plugins when a top level attribute is specified" do