diff options
author | Thom May <thom@may.lt> | 2017-04-03 08:16:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 08:16:54 +0100 |
commit | 1a5f6b60744ad14f2c0549d77f9eb70569e0bc28 (patch) | |
tree | b4a9a6818578d4b13d9e113430b823a249d68649 | |
parent | a76ea5b18eea7db18d817f9cdf08db83977e8ff4 (diff) | |
parent | 2be754388ee4c03239cc29a9d84b33a05a1e44e1 (diff) | |
download | chef-1a5f6b60744ad14f2c0549d77f9eb70569e0bc28.tar.gz |
Merge pull request #5989 from chef/lcg/deprecated-knife-subcommand-apis
Chef-13: remove deprecated knife subcommand APIs
-rw-r--r-- | lib/chef/knife.rb | 5 | ||||
-rw-r--r-- | lib/chef/knife/core/custom_manifest_loader.rb | 69 | ||||
-rw-r--r-- | lib/chef/knife/core/subcommand_loader.rb | 34 | ||||
-rw-r--r-- | spec/unit/knife/core/custom_manifest_loader_spec.rb | 41 | ||||
-rw-r--r-- | spec/unit/knife/core/subcommand_loader_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/core/ui_spec.rb | 3 |
6 files changed, 5 insertions, 153 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 47ce85b9e3..9c8b984054 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Author:: Christopher Brown (<cb@chef.io>) -# Copyright:: Copyright 2009-2016, Chef Software Inc. +# Copyright:: Copyright 2009-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -265,8 +265,7 @@ class Chef ui.fatal("Cannot find subcommand for: '#{args.join(' ')}'") # Mention rehash when the subcommands cache(plugin_manifest.json) is used - if subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::HashedCommandLoader) || - subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::CustomManifestLoader) + if subcommand_loader.is_a?(Chef::Knife::SubcommandLoader::HashedCommandLoader) ui.info("If this is a recently installed plugin, please run 'knife rehash' to update the subcommands cache.") end diff --git a/lib/chef/knife/core/custom_manifest_loader.rb b/lib/chef/knife/core/custom_manifest_loader.rb deleted file mode 100644 index 9fe51599af..0000000000 --- a/lib/chef/knife/core/custom_manifest_loader.rb +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright:: Copyright 2015-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. -# - -require "chef/version" -class Chef - class Knife - class SubcommandLoader - - # - # Load a subcommand from a user-supplied - # manifest file - # - class CustomManifestLoader < Chef::Knife::SubcommandLoader - attr_accessor :manifest - def initialize(chef_config_dir, plugin_manifest) - super(chef_config_dir) - @manifest = plugin_manifest - end - - # If the user has created a ~/.chef/plugin_manifest.json file, we'll use - # that instead of inspecting the on-system gems to find the plugins. The - # file format is expected to look like: - # - # { "plugins": { - # "knife-ec2": { - # "paths": [ - # "/home/alice/.rubymanagerthing/gems/knife-ec2-x.y.z/lib/chef/knife/ec2_server_create.rb", - # "/home/alice/.rubymanagerthing/gems/knife-ec2-x.y.z/lib/chef/knife/ec2_server_delete.rb" - # ] - # } - # } - # } - # - # Extraneous content in this file is ignored. This is intentional so that we - # can adapt the file format for potential behavior changes to knife in - # the future. - def find_subcommands_via_manifest - # Format of subcommand_files is "relative_path" (something you can - # Kernel.require()) => full_path. The relative path isn't used - # currently, so we just map full_path => full_path. - subcommand_files = {} - manifest["plugins"].each do |plugin_name, plugin_manifest| - plugin_manifest["paths"].each do |cmd_path| - subcommand_files[cmd_path] = cmd_path - end - end - subcommand_files.merge(find_subcommands_via_dirglob) - end - - def subcommand_files - @subcommand_files ||= (find_subcommands_via_manifest.values + site_subcommands).flatten.uniq - end - end - end - end -end diff --git a/lib/chef/knife/core/subcommand_loader.rb b/lib/chef/knife/core/subcommand_loader.rb index 30a438b780..14b6479b53 100644 --- a/lib/chef/knife/core/subcommand_loader.rb +++ b/lib/chef/knife/core/subcommand_loader.rb @@ -1,6 +1,6 @@ # Author:: Christopher Brown (<cb@chef.io>) # Author:: Daniel DeLeo (<dan@chef.io>) -# Copyright:: Copyright 2009-2016, Chef Software Inc. +# Copyright:: Copyright 2009-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,7 +20,6 @@ require "chef/version" require "chef/util/path_helper" require "chef/knife/core/gem_glob_loader" require "chef/knife/core/hashed_command_loader" -require "chef/knife/core/custom_manifest_loader" class Chef class Knife @@ -38,7 +37,6 @@ class Chef # class SubcommandLoader attr_reader :chef_config_dir - attr_reader :env # A small factory method. Eventually, this is the only place # where SubcommandLoader should know about its subclasses, but @@ -50,9 +48,6 @@ class Chef if autogenerated_manifest? Chef::Log.debug("Using autogenerated hashed command manifest #{plugin_manifest_path}") Knife::SubcommandLoader::HashedCommandLoader.new(chef_config_dir, plugin_manifest) - elsif custom_manifest? - Chef.deprecated(:internal_api, "Using custom manifest #{plugin_manifest_path} is deprecated. Please use a `knife rehash` autogenerated manifest instead.") - Knife::SubcommandLoader::CustomManifestLoader.new(chef_config_dir, plugin_manifest) else Knife::SubcommandLoader::GemGlobLoader.new(chef_config_dir) end @@ -72,10 +67,6 @@ class Chef plugin_manifest? && plugin_manifest.key?(HashedCommandLoader::KEY) end - def self.custom_manifest? - plugin_manifest? && plugin_manifest.key?("plugins") - end - def self.plugin_manifest Chef::JSONCompat.from_json(File.read(plugin_manifest_path)) end @@ -84,14 +75,8 @@ class Chef Chef::Util::PathHelper.home(".chef", "plugin_manifest.json") end - def initialize(chef_config_dir, env = nil) + def initialize(chef_config_dir) @chef_config_dir = chef_config_dir - - # Deprecated and un-used instance variable. - @env = env - unless env.nil? - Chef.deprecated(:internal_api, "The env argument to Chef::Knife::SubcommandLoader is deprecated. If you are using env to inject/mock HOME, consider mocking Chef::Util::PathHelper.home instead.") - end end # Load all the sub-commands @@ -149,21 +134,6 @@ class Chef end # - # Subclassses should define this themselves. Eventually, this will raise a - # NotImplemented error, but for now, we mimic the behavior the user was likely - # to get in the past. - # - def subcommand_files - Chef.deprecated :internal_api, "Using Chef::Knife::SubcommandLoader directly is deprecated. -Please use Chef::Knife::SubcommandLoader.for_config(chef_config_dir, env)" - @subcommand_files ||= if Chef::Knife::SubcommandLoader.plugin_manifest? - Chef::Knife::SubcommandLoader::CustomManifestLoader.new(chef_config_dir, env).subcommand_files - else - Chef::Knife::SubcommandLoader::GemGlobLoader.new(chef_config_dir, env).subcommand_files - end - end - - # # Utility function for finding an element in a hash given an array # of words and a separator. We find the the longest key in the # hash composed of the given words joined by the separator. diff --git a/spec/unit/knife/core/custom_manifest_loader_spec.rb b/spec/unit/knife/core/custom_manifest_loader_spec.rb deleted file mode 100644 index 814ac8a027..0000000000 --- a/spec/unit/knife/core/custom_manifest_loader_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright:: Copyright 2015-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. -# - -require "spec_helper" - -describe Chef::Knife::SubcommandLoader::CustomManifestLoader do - let(:ec2_server_create_plugin) { "/usr/lib/ruby/gems/knife-ec2-0.5.12/lib/chef/knife/ec2_server_create.rb" } - let(:manifest_content) do - { "plugins" => { - "knife-ec2" => { - "paths" => [ - ec2_server_create_plugin, - ], - }, - }, - } - end - let(:loader) do - Chef::Knife::SubcommandLoader::CustomManifestLoader.new(File.join(CHEF_SPEC_DATA, "knife-site-subcommands"), - manifest_content) - end - - it "uses paths from the manifest instead of searching gems" do - expect(Gem::Specification).not_to receive(:latest_specs).and_call_original - expect(loader.subcommand_files).to include(ec2_server_create_plugin) - end -end diff --git a/spec/unit/knife/core/subcommand_loader_spec.rb b/spec/unit/knife/core/subcommand_loader_spec.rb index b235102a0b..5db0bb73e5 100644 --- a/spec/unit/knife/core/subcommand_loader_spec.rb +++ b/spec/unit/knife/core/subcommand_loader_spec.rb @@ -43,12 +43,6 @@ describe Chef::Knife::SubcommandLoader do allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"_autogenerated_command_paths\": {}}") expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::HashedCommandLoader end - - it "creates a CustomManifestLoader with then manifest has a key other than _autogenerated_command_paths" do - Chef::Config[:treat_deprecation_warnings_as_errors] = false - allow(File).to receive(:read).with(File.join(home, ".chef", "plugin_manifest.json")).and_return("{ \"plugins\": {}}") - expect(Chef::Knife::SubcommandLoader.for_config(config_dir)).to be_a Chef::Knife::SubcommandLoader::CustomManifestLoader - end end context "when ~/.chef/plugin_manifest.json does not exist" do diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 38614f44d9..0b986258b7 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -3,7 +3,7 @@ # Author:: Tim Hinderliter (<tim@chef.io>) # Author:: Daniel DeLeo (<dan@chef.io>) # Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,6 @@ describe Chef::Knife::UI do :field_separator => ".", } @ui = Chef::Knife::UI.new(@out, @err, @in, @config) - Chef::Config[:treat_deprecation_warnings_as_errors] = false end class TestObject < OpenStruct |