summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2017-07-14 21:16:15 -0700
committerTim Smith <tsmith@chef.io>2017-07-14 21:24:58 -0700
commitce609ec38e4eb399cb2dad235dc0cd60612c9f36 (patch)
tree5b974b3cdcf9b967a09a8ec192d78af41801e67e
parent52041c2d84980f9411ee481d5ce75276a9d216a6 (diff)
downloadohai-legacy_free.tar.gz
Rip out V6 plugin supportlegacy_free
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/dsl/plugin/versionvi.rb61
-rw-r--r--lib/ohai/loader.rb76
-rw-r--r--lib/ohai/runner.rb8
-rw-r--r--lib/ohai/system.rb48
-rw-r--r--spec/data/plugins/messages.rb2
-rw-r--r--spec/data/plugins/v6message.rb2
-rw-r--r--spec/unit/dsl/plugin_spec.rb33
-rw-r--r--spec/unit/loader_spec.rb23
-rw-r--r--spec/unit/plugins/fail_spec.rb56
-rw-r--r--spec/unit/system_spec.rb248
10 files changed, 19 insertions, 538 deletions
diff --git a/lib/ohai/dsl/plugin/versionvi.rb b/lib/ohai/dsl/plugin/versionvi.rb
deleted file mode 100644
index 2a96c0fb..00000000
--- a/lib/ohai/dsl/plugin/versionvi.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# Author:: Serdar Sutay (<serdar@chef.io>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-module Ohai
- module DSL
- class Plugin
- class VersionVI < Plugin
- attr_reader :version
- attr_reader :source
-
- def initialize(controller, plugin_path, plugin_dir_path)
- super(controller.data)
- @controller = controller
- @version = :version6
- @source = plugin_path
- @plugin_dir_path = plugin_dir_path
- end
-
- def name
- # Ohai V6 doesn't have any name specification for plugins.
- # So we are using the partial path to infer the name of the plugin
- partial_path = Pathname.new(@source).relative_path_from(Pathname.new(@plugin_dir_path)).to_s
- partial_path.chomp(".rb").gsub("/", "::")
- end
-
- def self.version
- :version6
- end
-
- def self.collect_contents(contents)
- define_method(:run_plugin) { instance_eval(contents) }
- end
-
- def provides(*paths)
- Ohai::Log.debug("Skipping provides '#{paths.join(",")}' for plugin '#{name}'")
- end
-
- def require_plugin(plugin_ref)
- @controller.require_plugin(plugin_ref)
- end
-
- end
- end
- end
-end
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb
index f91425fc..0d66082e 100644
--- a/lib/ohai/loader.rb
+++ b/lib/ohai/loader.rb
@@ -30,11 +30,7 @@ module Ohai
class Loader
# Simple struct like objects to track the path of a plugin and the root
- # directory of plugins in which we found it. We don't care about the
- # relative paths of v7 plugins, but in v6 plugins, dependencies are
- # specified by calling `require_plugin` with a relative path. To manage
- # this, we track the path and root of each file as we discover them so we
- # can feed this into the v6 "dependency solver" as we load them.
+ # directory of plugins in which we found it.
PluginFile = Struct.new(:path, :plugin_root) do
# Finds all the *.rb files under the configured paths in :plugin_path
@@ -53,13 +49,8 @@ module Ohai
end
end
- # Simple struct to track a v6 plugin's class, file path, and the root of
- # the plugin dir from which it was loaded.
- V6PluginClass = Struct.new(:plugin_class, :plugin_path, :plugin_dir_path)
-
def initialize(controller)
@controller = controller
- @v6_plugin_classes = []
@v7_plugin_classes = []
end
@@ -73,10 +64,9 @@ module Ohai
def load_all
plugin_files_by_dir.each do |plugin_file|
- load_plugin_class(plugin_file.path, plugin_file.plugin_root)
+ load_plugin_file(plugin_file.path)
end
- collect_v6_plugins
collect_v7_plugins
end
@@ -84,7 +74,7 @@ module Ohai
from = [ Ohai.config[:plugin_path], from].flatten
plugin_files_by_dir(from).collect do |plugin_file|
Ohai::Log.debug "Loading additional plugin: #{plugin_file}"
- plugin = load_plugin_class(plugin_file.path, plugin_file.plugin_root)
+ plugin = load_plugin_file(plugin_file.path)
load_v7_plugin(plugin)
end
end
@@ -92,13 +82,10 @@ module Ohai
# Load a specified file as an ohai plugin and creates an instance of it.
# Not used by ohai itself, but can be used to load a plugin for testing
# purposes.
- # plugin_dir_path is required when loading a v6 plugin.
- def load_plugin(plugin_path, plugin_dir_path = nil)
- plugin_class = load_plugin_class(plugin_path, plugin_dir_path)
+ def load_plugin(plugin_path)
+ plugin_class = load_plugin_file(plugin_path)
return nil unless plugin_class.kind_of?(Class)
case
- when plugin_class < Ohai::DSL::Plugin::VersionVI
- load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
when plugin_class < Ohai::DSL::Plugin::VersionVII
load_v7_plugin(plugin_class)
else
@@ -108,31 +95,19 @@ module Ohai
# Reads the file specified by `plugin_path` and returns a class object for
# the ohai plugin defined therein.
- #
- # If `plugin_dir_path` is given, and the file at `plugin_path` is a v6
- # plugin, the 'relative path' of the plugin (used by `require_plugin()`) is
- # computed by finding the relative path from `plugin_dir_path` to `plugin_path`
- def load_plugin_class(plugin_path, plugin_dir_path = nil)
- # Read the contents of the plugin to understand if it's a V6 or V7 plugin.
+ def load_plugin_file(plugin_path)
+ # Read the contents of the plugin
contents = ""
begin
- Ohai::Log.debug("Loading plugin at #{plugin_path}")
+ Ohai::Log.debug("Reading plugin at #{plugin_path}")
contents << IO.read(plugin_path)
rescue IOError, Errno::ENOENT
Ohai::Log.warn("Unable to open or read plugin at #{plugin_path}")
return nil
end
- # We assume that a plugin is a V7 plugin if it contains Ohai.plugin in its contents.
if contents.include?("Ohai.plugin")
load_v7_plugin_class(contents, plugin_path)
- else
- Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \
-Version 6 plugins will not be supported in Chef/Ohai 14. \
-Please upgrade your plugin to version 7 plugin format. \
-For more information visit here: docs.chef.io/ohai_custom.html")
-
- load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
end
end
@@ -143,47 +118,14 @@ For more information visit here: docs.chef.io/ohai_custom.html")
@controller.provides_map.set_providers_for(plugin, plugin_provides)
end
- def v6_dependency_solver
- @controller.v6_dependency_solver
- end
-
- def collect_v6_plugins
- @v6_plugin_classes.each do |plugin_spec|
- plugin = load_v6_plugin(plugin_spec.plugin_class, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
- loaded_v6_plugin(plugin, plugin_spec.plugin_path, plugin_spec.plugin_dir_path)
- end
- end
-
def collect_v7_plugins
@v7_plugin_classes.each do |plugin_class|
load_v7_plugin(plugin_class)
end
end
- def load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
- plugin_class = Class.new(Ohai::DSL::Plugin::VersionVI) { collect_contents(contents) }
- @v6_plugin_classes << V6PluginClass.new(plugin_class, plugin_path, plugin_dir_path)
- plugin_class
- end
-
- def load_v6_plugin(plugin_class, plugin_path, plugin_dir_path)
- plugin_class.new(@controller, plugin_path, plugin_dir_path)
- end
-
- # Capture the plugin in @v6_dependency_solver if it is a V6 plugin
- # to be able to resolve V6 dependencies later on.
- # We are using the partial path in the dep solver as a key.
- def loaded_v6_plugin(plugin, plugin_file_path, plugin_dir_path)
- partial_path = Pathname.new(plugin_file_path).relative_path_from(Pathname.new(plugin_dir_path)).to_s
-
- unless v6_dependency_solver.has_key?(partial_path)
- v6_dependency_solver[partial_path] = plugin
- else
- Ohai::Log.debug("Plugin '#{plugin_file_path}' is already loaded.")
- end
- end
-
def load_v7_plugin_class(contents, plugin_path)
+ Ohai::Log.debug("Loading Ohai plugin class from #{plugin_path}")
plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path)
unless plugin_class.kind_of?(Class) && plugin_class < Ohai::DSL::Plugin
raise Ohai::Exceptions::IllegalPluginDefinition, "Plugin file cannot contain any statements after the plugin definition"
diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb
index 93ec46a3..61aaafa5 100644
--- a/lib/ohai/runner.rb
+++ b/lib/ohai/runner.rb
@@ -41,8 +41,6 @@ module Ohai
case plugin.version
when :version7
run_v7_plugin(plugin)
- when :version6
- run_v6_plugin(plugin)
else
raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}"
end
@@ -55,12 +53,6 @@ module Ohai
end
end
- def run_v6_plugin(plugin)
- return true if plugin.has_run?
-
- @safe_run ? plugin.safe_run : plugin.run
- end
-
def run_v7_plugin(plugin)
visited = [ plugin ]
until visited.empty?
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 1002e198..d9457810 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -37,7 +37,6 @@ module Ohai
attr_accessor :data
attr_reader :config
attr_reader :provides_map
- attr_reader :v6_dependency_solver
# the cli flag is used to determine if we're being constructed by
# something like chef-client (which doesn't not set this flag) and
@@ -53,7 +52,6 @@ module Ohai
def reset_system
@data = Mash.new
@provides_map = ProvidesMap.new
- @v6_dependency_solver = Hash.new
configure_ohai
configure_logging if @cli
@@ -61,7 +59,7 @@ module Ohai
@loader = Ohai::Loader.new(self)
@runner = Ohai::Runner.new(self, true)
- Ohai::Hints.refresh_hints()
+ Ohai::Hints.refresh_hints
# Remove the previously defined plugins
recursive_remove_constants(Ohai::NamedPlugin)
@@ -86,19 +84,6 @@ module Ohai
end
def run_plugins(safe = false, attribute_filter = nil)
- # First run all the version 6 plugins
- @v6_dependency_solver.values.each do |v6plugin|
- @runner.run_plugin(v6plugin)
- end
-
- # Users who are migrating from ohai 6 may give one or more Ohai 6 plugin
- # names as the +attribute_filter+. In this case we return early because
- # the v7 plugin provides map will not have an entry for this plugin.
- if attribute_filter && Array(attribute_filter).all? { |filter_item| have_v6_plugin?(filter_item) }
- return true
- end
-
- # Then run all the version 7 plugins
begin
@provides_map.all_plugins(attribute_filter).each do |plugin|
@runner.run_plugin(plugin)
@@ -121,15 +106,6 @@ module Ohai
freeze_strings!
end
- def have_v6_plugin?(name)
- @v6_dependency_solver.values.any? { |v6plugin| v6plugin.name == name }
- end
-
- def pathify_v6_plugin(plugin_name)
- path_components = plugin_name.split("::")
- File.join(path_components) + ".rb"
- end
-
#
# Below APIs are from V6.
# Make sure that you are not breaking backwards compatibility
@@ -137,22 +113,14 @@ module Ohai
#
def require_plugin(plugin_ref, force = false)
plugins = [ ]
- # This method is only callable by version 6 plugins.
- # First we check if there exists a v6 plugin that fulfills the dependency.
- if @v6_dependency_solver.has_key? pathify_v6_plugin(plugin_ref)
- # Note that: partial_path looks like Plugin::Name
- # keys for @v6_dependency_solver are in form 'plugin/name.rb'
- plugins << @v6_dependency_solver[pathify_v6_plugin(plugin_ref)]
- else
# While looking up V7 plugins we need to convert the plugin_ref to an attribute.
- attribute = plugin_ref.gsub("::", "/")
- begin
- plugins = @provides_map.find_providers_for([attribute])
- rescue Ohai::Exceptions::AttributeNotFound
- Ohai::Log.debug("Can not find any v7 plugin that provides #{attribute}")
- plugins = [ ]
- end
- end
+ attribute = plugin_ref.gsub("::", "/")
+ begin
+ plugins = @provides_map.find_providers_for([attribute])
+ rescue Ohai::Exceptions::AttributeNotFound
+ Ohai::Log.debug("Cannot find any v7 plugin that provides #{attribute}")
+ plugins = [ ]
+ end
if plugins.empty?
raise Ohai::Exceptions::DependencyNotFound, "Can not find a plugin for dependency #{plugin_ref}"
diff --git a/spec/data/plugins/messages.rb b/spec/data/plugins/messages.rb
index 98a621d4..bda3a2bf 100644
--- a/spec/data/plugins/messages.rb
+++ b/spec/data/plugins/messages.rb
@@ -1,8 +1,6 @@
-require_plugin 'v6message'
require_plugin 'v7message'
provides 'messages'
messages Mash.new
-messages[:v6message] = v6message
messages[:v7message] = v7message
diff --git a/spec/data/plugins/v6message.rb b/spec/data/plugins/v6message.rb
deleted file mode 100644
index c21982fe..00000000
--- a/spec/data/plugins/v6message.rb
+++ /dev/null
@@ -1,2 +0,0 @@
-provides 'v6message'
-v6message "update me!"
diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb
index c1ed623c..5000b112 100644
--- a/spec/unit/dsl/plugin_spec.rb
+++ b/spec/unit/dsl/plugin_spec.rb
@@ -631,36 +631,3 @@ describe Ohai::DSL::Plugin::VersionVII do
let(:version) { :version7 }
end
end
-
-describe Ohai::DSL::Plugin::VersionVI do
- describe "#version" do
- it "saves the plugin version as :version6" do
- plugin = Class.new(Ohai::DSL::Plugin::VersionVI) {}
- expect(plugin.version).to eql(:version6)
- end
- end
-
- describe "#provides" do
- let(:ohai) { Ohai::System.new }
-
- it "logs a debug message when provides is used" do
- allow(Ohai::Log).to receive(:debug)
- expect(Ohai::Log).to receive(:debug).with(/Skipping provides/)
- plugin = Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin")
- plugin.provides("attribute")
- end
-
- it "does not update the provides map for version 6 plugins." do
- plugin = Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin")
- plugin.provides("attribute")
- expect(ohai.provides_map.map).to be_empty
- end
-
- end
-
- it_behaves_like "Ohai::DSL::Plugin" do
- let(:ohai) { Ohai::System.new }
- let(:plugin) { Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin") }
- let(:version) { :version6 }
- end
-end
diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb
index 8331ae65..648d6b46 100644
--- a/spec/unit/loader_spec.rb
+++ b/spec/unit/loader_spec.rb
@@ -33,7 +33,7 @@ describe Ohai::Loader do
end
end
- when_plugins_directory "contains both V6 & V7 plugins" do
+ when_plugins_directory "contains V7 plugins" do
with_plugin("zoo.rb", <<EOF)
Ohai.plugin(:Zoo) do
provides 'seals'
@@ -46,10 +46,6 @@ Ohai.plugin(:Zoo) do
end
EOF
- with_plugin("lake.rb", <<EOF)
-provides 'fish'
-EOF
-
describe "load_plugin() method" do
describe "when loading a v7 plugin" do
let(:plugin) { loader.load_plugin(path_to("zoo.rb")) }
@@ -70,23 +66,6 @@ EOF
end
end
- describe "when loading a v6 plugin" do
- let(:plugin) { loader.load_plugin(path_to("lake.rb"), path_to(".")) }
-
- before(:each) do
- expect(Ohai::Log).to receive(:warn).with(/\[DEPRECATION\]/)
- end
-
- it "does not add this plugin's provided attributes to the provides map" do
- plugin
- expect(provides_map.map).to be_empty
- end
-
- it "saves the plugin's source" do
- expect(plugin.source).to eql(path_to("lake.rb"))
- end
- end
-
it "logs a warning if a plugin doesn't exist" do
expect(Ohai::Log).to receive(:warn).with(/Unable to open or read plugin/)
loader.load_plugin(path_to("rainier.rb"), path_to("."))
diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb
index 859011c7..4b079b9c 100644
--- a/spec/unit/plugins/fail_spec.rb
+++ b/spec/unit/plugins/fail_spec.rb
@@ -161,51 +161,6 @@ shared_examples "a v7 run failure" do
end
end
-=begin
-shared_examples "a v6 run failure" do
- before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
- # ignore
- end
- end
-
- before(:each) do
- fail_file = File.open("#{tmp}/plugins/fail.rb", "w+")
- fail_file.write(failstr)
- fail_file.close
- end
-
- after(:each) do
- File.delete("#{tmp}/plugins/fail.rb")
- end
-
- after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
- # ignore
- end
- end
-
- before(:each) do
- @ohai = Ohai::System.new
- @loader = Ohai::Loader.new(@ohai)
- end
-
- it "should not add data keys" do
- @loader.load_plugin("#{tmp}/plugins/fail.rb")
- @ohai.data.should_not have_key("fail")
- end
-
- it "should write to Ohai::Log" do
- Ohai::Log.should_receive(:warn).once
- @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run
- end
-end
-=end
-
describe "when using DSL commands outside Ohai.plugin block" do
failstr1 = <<EOF
provides "fail"
@@ -301,15 +256,4 @@ EOF
let(:failstr) { failstr }
end
end
-
-describe "when setting undeclared attribute" do
- failstr = <<EOF
-provides "fail"
-other "attribute"
-EOF
-
- it_behaves_like "a v6 run failure" do
- let(:failstr) { failstr }
- end
-end
=end
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index b212ea0b..1bd2a4bc 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -35,10 +35,6 @@ describe "Ohai::System" do
expect(ohai.provides_map).to be_a_kind_of(Ohai::ProvidesMap)
end
- it "sets @v6_dependency_solver to a Hash" do
- expect(ohai.v6_dependency_solver).to be_a_kind_of(Hash)
- end
-
it "merges provided configuration options into the ohai config context" do
config = {
disabled_plugins: [ :Foo, :Baz ],
@@ -89,17 +85,13 @@ describe "Ohai::System" do
end
end
- when_plugins_directory "contains v6 and v7 plugins" do
+ when_plugins_directory "contains v7 plugins" do
with_plugin("zoo.rb", <<EOF)
Ohai.plugin(:Zoo) do
provides 'seals'
end
EOF
- with_plugin("lake.rb", <<EOF)
-provides 'fish'
-EOF
-
before do
Ohai.config[:plugin_path] = [ path_to(".") ]
end
@@ -107,7 +99,6 @@ EOF
it "load_plugins() should load all the plugins" do
ohai.load_plugins
expect(ohai.provides_map.map.keys).to include("seals")
- expect(ohai.v6_dependency_solver.keys).to include("lake.rb")
expect(Ohai::NamedPlugin.const_get(:Zoo)).to eq(Ohai::NamedPlugin::Zoo)
end
end
@@ -119,20 +110,12 @@ Ohai.plugin(:Zoo) do
end
EOF
- with_plugin("repo1/lake.rb", <<EOF)
-provides 'fish'
-EOF
-
with_plugin("repo2/nature.rb", <<EOF)
Ohai.plugin(:Nature) do
provides 'crabs'
end
EOF
- with_plugin("repo2/mountain.rb", <<EOF)
-provides 'bear'
-EOF
-
before do
Ohai.config[:plugin_path] = [ path_to("repo1"), path_to("repo2") ]
end
@@ -141,8 +124,6 @@ EOF
ohai.load_plugins
expect(ohai.provides_map.map.keys).to include("seals")
expect(ohai.provides_map.map.keys).to include("crabs")
- expect(ohai.v6_dependency_solver.keys).to include("lake.rb")
- expect(ohai.v6_dependency_solver.keys).to include("mountain.rb")
expect(Ohai::NamedPlugin.const_get(:Zoo)).to eq(Ohai::NamedPlugin::Zoo)
expect(Ohai::NamedPlugin.const_get(:Nature)).to eq(Ohai::NamedPlugin::Nature)
end
@@ -150,123 +131,6 @@ EOF
end
describe "when running plugins" do
- when_plugins_directory "contains v6 plugins only" do
- with_plugin("zoo.rb", <<EOF)
-provides 'zoo'
-zoo("animals")
-EOF
-
- with_plugin("park.rb", <<EOF)
-provides 'park'
-park("plants")
-EOF
-
- it "should collect data from all the plugins" do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- ohai.all_plugins
- expect(ohai.data[:zoo]).to eq("animals")
- expect(ohai.data[:park]).to eq("plants")
- expect(ohai.data[:zoo]).to be_frozen
- expect(ohai.data[:park]).to be_frozen
- end
-
- describe "when using :disabled_plugins" do
- before do
- Ohai.config[:disabled_plugins] = [ "zoo" ]
- end
-
- after do
- Ohai.config[:disabled_plugins] = [ ]
- end
-
- it "shouldn't run disabled version 6 plugins" do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- ohai.all_plugins
- expect(ohai.data[:zoo]).to be_nil
- expect(ohai.data[:park]).to eq("plants")
- end
- end
-
- describe "when running in whitelist mode" do
- let(:ohai_system) { Ohai::System.new }
-
- let(:primary_plugin_class) do
- Ohai.plugin(:Primary) do
- provides "primary"
- depends "dependency/one"
- depends "dependency/two"
- collect_data {}
- end
- end
-
- let(:dependency_plugin_one_class) do
- Ohai.plugin(:DependencyOne) do
- provides "dependency/one"
- collect_data {}
- end
- end
-
- let(:dependency_plugin_two_class) do
- Ohai.plugin(:DependencyTwo) do
- provides "dependency/two"
- collect_data {}
- end
- end
-
- let(:unrelated_plugin_class) do
- Ohai.plugin(:Unrelated) do
- provides "whatever"
- collect_data {}
- end
- end
-
- let(:v6_plugin_class) do
- Class.new(Ohai::DSL::Plugin::VersionVI) { collect_contents("v6_key('v6_data')") }
- end
-
- let(:primary_plugin) { primary_plugin_class.new(ohai_system) }
- let(:dependency_plugin_one) { dependency_plugin_one_class.new(ohai_system) }
- let(:dependency_plugin_two) { dependency_plugin_two_class.new(ohai_system) }
- let(:unrelated_plugin) { unrelated_plugin_class.new(ohai_system) }
- let(:v6_plugin) { v6_plugin_class.new(ohai_system, "/v6_plugin.rb", "/") }
-
- before do
- allow(ohai_system).to receive(:load_plugins) # TODO: temporary hack - don't run unrelated plugins...
- [ primary_plugin, dependency_plugin_one, dependency_plugin_two, unrelated_plugin].each do |plugin|
- plugin_provides = plugin.class.provides_attrs
- ohai_system.provides_map.set_providers_for(plugin, plugin_provides)
- end
-
- ohai_system.v6_dependency_solver["v6_plugin"] = v6_plugin
-
- # Instead of calling all plugins we call load and run directly so that the information we setup is not cleared by all_plugins
- ohai_system.load_plugins
- ohai_system.run_plugins(true, "primary")
- end
-
- # This behavior choice is somewhat arbitrary, based on what creates the
- # least code complexity in legacy v6 plugin format support. Once we
- # ship 7.0, though, we need to stick to the same behavior.
- it "runs v6 plugins" do
- expect(v6_plugin.has_run?).to be true
- end
-
- it "runs plugins that provide the requested attributes" do
- expect(primary_plugin.has_run?).to be true
- end
-
- it "runs dependencies of plugins that provide requested attributes" do
- expect(dependency_plugin_one.has_run?).to be true
- expect(dependency_plugin_two.has_run?).to be true
- end
-
- it "does not run plugins that are irrelevant to the requested attributes" do
- expect(unrelated_plugin.has_run?).to be false
- end
-
- end
- end
-
when_plugins_directory "contains a v7 plugins with :default and platform specific blocks" do
with_plugin("message.rb", <<EOF)
Ohai.plugin(:Message) do
@@ -443,118 +307,8 @@ EOF
end
end
- describe "require_plugin()" do
- when_plugins_directory "contains v6 and v7 plugin with the same name" do
- with_plugin("message.rb", <<EOF)
-provides 'message'
-
-message "From Version 6"
-EOF
-
- with_plugin("v7/message.rb", <<EOF)
-Ohai.plugin(:Message) do
- provides 'message'
-
- collect_data(:default) do
- message "From Version 7"
- end
-end
-EOF
-
- before do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- end
-
- it "version 6 should run" do
- ohai.load_plugins
- ohai.require_plugin("message")
- expect(ohai.data[:message]).to eql("From Version 6")
- end
- end
-
- when_plugins_directory "a v6 plugin that requires a v7 plugin with dependencies" do
- with_plugin("message.rb", <<EOF)
-provides 'message'
-
-require_plugin 'v7message'
-
-message Mash.new
-message[:v6message] = "Hellos from 6"
-message[:copy_message] = v7message
-EOF
-
- with_plugin("v7message.rb", <<EOF)
-Ohai.plugin(:V7message) do
- provides 'v7message'
- depends 'zoo'
-
- collect_data(:default) do
- v7message ("Hellos from 7: " + zoo)
- end
-end
-EOF
-
- with_plugin("zoo.rb", <<EOF)
-Ohai.plugin(:Zoo) do
- provides 'zoo'
-
- collect_data(:default) do
- zoo "animals"
- end
-end
-EOF
-
- before do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- end
-
- it "should collect all the data properly" do
- ohai.all_plugins
- expect(ohai.data[:v7message]).to eq("Hellos from 7: animals")
- expect(ohai.data[:zoo]).to eq("animals")
- expect(ohai.data[:message][:v6message]).to eq("Hellos from 6")
- expect(ohai.data[:message][:copy_message]).to eq("Hellos from 7: animals")
- end
- end
-
- when_plugins_directory "a v6 plugin that requires non-existing v7 plugin" do
- with_plugin("message.rb", <<EOF)
-provides 'message'
-
-require_plugin 'v7message'
-
-message v7message
-EOF
-
- before do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- end
-
- it "should raise DependencyNotFound" do
- expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::DependencyNotFound)
- end
- end
- end
-
describe "when Chef OHAI resource executes :reload action" do
- when_plugins_directory "contains a v6 plugin" do
- with_plugin("a_v6plugin.rb", <<-E)
- plugin_data Mash.new
- plugin_data[:foo] = :bar
- E
-
- before do
- Ohai.config[:plugin_path] = [ path_to(".") ]
- end
-
- it "reloads only the v6 plugin when given a specific plugin to load" do
- ohai.all_plugins
- expect { ohai.all_plugins("a_v6plugin") }.not_to raise_error
- end
-
- end
-
when_plugins_directory "contains a random plugin" do
with_plugin("random.rb", <<-E)
Ohai.plugin(:Random) do