diff options
author | Thom May <thom@may.lt> | 2018-02-16 09:55:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-16 09:55:31 +0000 |
commit | 380cf7eba190b3c26f69f29462ed42add6ebd56e (patch) | |
tree | ada8eee5d95adb6d4c6310c5366973e361641939 /lib/ohai/loader.rb | |
parent | 39200b29290b1cc4c42d62a48bc689092d5d5d97 (diff) | |
parent | 5a662a4463cce6cd479e8042f92fd6bfb9c85269 (diff) | |
download | ohai-380cf7eba190b3c26f69f29462ed42add6ebd56e.tar.gz |
Merge pull request #1127 from chef/remove_v6_plugins
Initial removal of support for Ohai V6 plugins
Diffstat (limited to 'lib/ohai/loader.rb')
-rw-r--r-- | lib/ohai/loader.rb | 56 |
1 files changed, 5 insertions, 51 deletions
diff --git a/lib/ohai/loader.rb b/lib/ohai/loader.rb index f91425fc..d4d78811 100644 --- a/lib/ohai/loader.rb +++ b/lib/ohai/loader.rb @@ -53,13 +53,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 @@ -76,7 +71,6 @@ module Ohai load_plugin_class(plugin_file.path, plugin_file.plugin_root) end - collect_v6_plugins collect_v7_plugins end @@ -92,14 +86,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) 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}" @@ -127,12 +117,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 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) + 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 @@ -143,46 +131,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 |