From c31f32c1455dc0d3743c78f42e237af7c2092921 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Mon, 29 Jan 2018 16:36:53 -0800 Subject: Remove support for Ohai V6 plugins This doesn't refactor anything. Just removes the old support in the most brutal way possible. Cleanup to come. Signed-off-by: Tim Smith --- lib/ohai/dsl.rb | 1 - lib/ohai/dsl/plugin.rb | 1 + lib/ohai/dsl/plugin/versionvi.rb | 61 ------- lib/ohai/loader.rb | 52 +----- lib/ohai/runner.rb | 2 - lib/ohai/system.rb | 66 -------- spec/data/plugins/messages.rb | 8 - spec/data/plugins/v6message.rb | 2 - spec/unit/dsl/plugin_spec.rb | 33 ---- spec/unit/loader_spec.rb | 62 ------- spec/unit/plugins/fail_spec.rb | 55 ------ spec/unit/runner_spec.rb | 37 ---- spec/unit/system_spec.rb | 353 --------------------------------------- 13 files changed, 4 insertions(+), 729 deletions(-) delete mode 100644 lib/ohai/dsl/plugin/versionvi.rb delete mode 100644 spec/data/plugins/messages.rb delete mode 100644 spec/data/plugins/v6message.rb diff --git a/lib/ohai/dsl.rb b/lib/ohai/dsl.rb index 025f6be5..7ee6645a 100644 --- a/lib/ohai/dsl.rb +++ b/lib/ohai/dsl.rb @@ -18,5 +18,4 @@ # require "ohai/dsl/plugin" -require "ohai/dsl/plugin/versionvi" require "ohai/dsl/plugin/versionvii" diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb index f187aeaf..a0d8c150 100644 --- a/lib/ohai/dsl/plugin.rb +++ b/lib/ohai/dsl/plugin.rb @@ -49,6 +49,7 @@ module Ohai plugin = nil + # avoid already initialized constant warnings if already defined if NamedPlugin.strict_const_defined?(name) plugin = NamedPlugin.const_get(name) plugin.class_eval(&block) 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 () -# 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 64ae44bc..eb28e1e4 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -58,13 +58,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 @@ -81,7 +76,6 @@ module Ohai load_plugin_class(plugin_file.path, plugin_file.plugin_root) end - collect_v6_plugins collect_v7_plugins end @@ -101,10 +95,7 @@ module Ohai def load_plugin(plugin_path, plugin_dir_path = nil) plugin_class = load_plugin_class(plugin_path, plugin_dir_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 + if plugin_class < Ohai::DSL::Plugin::VersionVII load_v7_plugin(plugin_class) else raise Exceptions::IllegalPluginDefinition, "cannot create plugin of type #{plugin_class}" @@ -133,11 +124,8 @@ module Ohai 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) +Version 6 plugins are no longer supported by Ohai. This plugin will need to be updated \ +to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax.") end end @@ -148,46 +136,12 @@ 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) plugin_class = eval(contents, TOPLEVEL_BINDING, plugin_path) unless plugin_class.kind_of?(Class) && plugin_class < Ohai::DSL::Plugin diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 05fd7cfc..0820924a 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -45,8 +45,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 diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 13d60bf0..78da59b4 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 @@ -54,7 +53,6 @@ module Ohai def reset_system @data = Mash.new @provides_map = ProvidesMap.new - @v6_dependency_solver = Hash.new configure_ohai configure_logging if @cli @@ -87,19 +85,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) @@ -132,57 +117,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 - # if you are changing any of the APIs below. - # - 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 - - if plugins.empty? - raise Ohai::Exceptions::DependencyNotFound, "Can not find a plugin for dependency #{plugin_ref}" - else - plugins.each do |plugin| - begin - @runner.run_plugin(plugin) - rescue SystemExit, Interrupt - raise - rescue Ohai::Exceptions::DependencyCycle, Ohai::Exceptions::AttributeNotFound => e - Ohai::Log.error("Encountered error while running plugins: #{e.inspect}") - raise - rescue Exception, Errno::ENOENT => e - Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") - end - end - end - end - # Re-runs plugins that provide the attributes specified by # +attribute_filter+. If +attribute_filter+ is not given, re-runs all # plugins. diff --git a/spec/data/plugins/messages.rb b/spec/data/plugins/messages.rb deleted file mode 100644 index 98a621d4..00000000 --- a/spec/data/plugins/messages.rb +++ /dev/null @@ -1,8 +0,0 @@ -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..07384c6d 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -33,68 +33,6 @@ describe Ohai::Loader do end end - when_plugins_directory "contains both V6 & V7 plugins" do - with_plugin("zoo.rb", < Date: Thu, 15 Feb 2018 10:53:49 -0800 Subject: Remove another v6 plugin reference Signed-off-by: Tim Smith --- lib/ohai/runner.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/ohai/runner.rb b/lib/ohai/runner.rb index 0820924a..ba3985dc 100644 --- a/lib/ohai/runner.rb +++ b/lib/ohai/runner.rb @@ -42,8 +42,7 @@ module Ohai end begin - case plugin.version - when :version7 + if plugin.version == :version7 run_v7_plugin(plugin) else raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" @@ -59,12 +58,6 @@ module Ohai Ohai::Log.debug("Plugin #{plugin.name} took #{elapsed.total} seconds to run.") 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? -- cgit v1.2.1 From 5a662a4463cce6cd479e8042f92fd6bfb9c85269 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 15 Feb 2018 10:58:31 -0800 Subject: Raise on V6 plugins instead of warning Signed-off-by: Tim Smith --- lib/ohai/loader.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index eb28e1e4..452eff92 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -91,7 +91,6 @@ 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) return nil unless plugin_class.kind_of?(Class) @@ -123,9 +122,10 @@ module Ohai 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 are no longer supported by Ohai. This plugin will need to be updated \ -to the v7 Ohai plugin format. See https://docs.chef.io/ohai_custom.html for v7 syntax.") + raise Exceptions::IllegalPluginDefinition, "[DEPRECATION] Plugin at #{plugin_path}"\ + " is a version 6 plugin. Version 6 plugins are no longer supported by Ohai. This"\ + " plugin will need to be updated to the v7 Ohai plugin format. See"\ + " https://docs.chef.io/ohai_custom.html for v7 syntax." end end -- cgit v1.2.1