diff options
24 files changed, 283 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 669726d562..e07a822020 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,20 @@ <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ --> -<!-- latest_release 15.0.305 --> -## [v15.0.305](https://github.com/chef/chef/tree/v15.0.305) (2019-05-22) +<!-- latest_release 15.0.310 --> +## [v15.0.310](https://github.com/chef/chef/tree/v15.0.310) (2019-05-24) #### Merged Pull Requests -- Gate requires with idempotency check [#8544](https://github.com/chef/chef/pull/8544) ([lamont-granquist](https://github.com/lamont-granquist)) +- Fix for knife bootstrap inheritance issue with knife plugins [#8585](https://github.com/chef/chef/pull/8585) ([Vasu1105](https://github.com/Vasu1105)) <!-- latest_release --> <!-- release_rollup since=15.0.300 --> ### Changes not yet released to rubygems.org #### Merged Pull Requests +- Fix for knife bootstrap inheritance issue with knife plugins [#8585](https://github.com/chef/chef/pull/8585) ([Vasu1105](https://github.com/Vasu1105)) <!-- 15.0.310 --> +- Preserve train connection in target mode to prevent running duplicate OS detection commands [#8590](https://github.com/chef/chef/pull/8590) ([btm](https://github.com/btm)) <!-- 15.0.309 --> +- Better target mode shell_out [#8584](https://github.com/chef/chef/pull/8584) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.308 --> +- Fix service enable idempotency in sles11 [#8256](https://github.com/chef/chef/pull/8256) ([dheerajd-msys](https://github.com/dheerajd-msys)) <!-- 15.0.307 --> +- Fix delete_resource for resources [#8570](https://github.com/chef/chef/pull/8570) ([artem-sidorenko](https://github.com/artem-sidorenko)) <!-- 15.0.306 --> - Gate requires with idempotency check [#8544](https://github.com/chef/chef/pull/8544) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.305 --> - Better target mode no-creds errors [#8571](https://github.com/chef/chef/pull/8571) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.304 --> - Fix chef-config requires lines [#8545](https://github.com/chef/chef/pull/8545) ([lamont-granquist](https://github.com/lamont-granquist)) <!-- 15.0.303 --> diff --git a/Gemfile.lock b/Gemfile.lock index c6a80dc67b..26254c136f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -27,11 +27,11 @@ GIT PATH remote: . specs: - chef (15.0.305) + chef (15.0.310) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 15.0.305) + chef-config (= 15.0.310) chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) ed25519 (~> 1.2) @@ -57,11 +57,11 @@ PATH train-core (~> 2.0, >= 2.0.12) tty-screen (~> 0.6) uuidtools (~> 2.1.5) - chef (15.0.305-universal-mingw32) + chef (15.0.310-universal-mingw32) addressable bcrypt_pbkdf (~> 1.0) bundler (>= 1.10) - chef-config (= 15.0.305) + chef-config (= 15.0.310) chef-zero (>= 14.0.11) diff-lcs (~> 1.2, >= 1.2.4) ed25519 (~> 1.2) @@ -103,13 +103,13 @@ PATH PATH remote: chef-bin specs: - chef-bin (15.0.305) - chef (= 15.0.305) + chef-bin (15.0.310) + chef (= 15.0.310) PATH remote: chef-config specs: - chef-config (15.0.305) + chef-config (15.0.310) addressable fuzzyurl mixlib-config (>= 2.2.12, < 4.0) @@ -1 +1 @@ -15.0.305
\ No newline at end of file +15.0.310
\ No newline at end of file diff --git a/chef-bin/lib/chef-bin/version.rb b/chef-bin/lib/chef-bin/version.rb index 882cc4cc6c..2259dab254 100644 --- a/chef-bin/lib/chef-bin/version.rb +++ b/chef-bin/lib/chef-bin/version.rb @@ -21,7 +21,7 @@ module ChefBin CHEFBIN_ROOT = File.expand_path("../..", __FILE__) - VERSION = "15.0.305".freeze + VERSION = "15.0.310".freeze end # diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb index 9b01f41b7e..d699cc2a36 100644 --- a/chef-config/lib/chef-config/version.rb +++ b/chef-config/lib/chef-config/version.rb @@ -21,7 +21,7 @@ module ChefConfig CHEFCONFIG_ROOT = File.expand_path("../..", __FILE__) - VERSION = "15.0.305".freeze + VERSION = "15.0.310".freeze end # diff --git a/lib/chef/chef_fs/knife.rb b/lib/chef/chef_fs/knife.rb index 18a2958cb5..bfb354bade 100644 --- a/lib/chef/chef_fs/knife.rb +++ b/lib/chef/chef_fs/knife.rb @@ -40,8 +40,6 @@ class Chef # Ensure we always get to do our includes, whether subclass calls deps or not c.deps do end - - c.options.merge!(options) end option :repo_mode, diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 5057fd5880..2460dbaed8 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -88,6 +88,7 @@ class Chef end def self.inherited(subclass) + super unless subclass.unnamed? subcommands[subclass.snake_case_name] = subclass subcommand_files[subclass.snake_case_name] += diff --git a/lib/chef/knife/cookbook_site_download.rb b/lib/chef/knife/cookbook_site_download.rb index 655bf602a5..4fc435f957 100644 --- a/lib/chef/knife/cookbook_site_download.rb +++ b/lib/chef/knife/cookbook_site_download.rb @@ -25,7 +25,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site download COOKBOOK [VERSION] (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_install.rb b/lib/chef/knife/cookbook_site_install.rb index badbcc9b98..a9c15661ff 100644 --- a/lib/chef/knife/cookbook_site_install.rb +++ b/lib/chef/knife/cookbook_site_install.rb @@ -25,7 +25,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site install COOKBOOK [VERSION] (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_list.rb b/lib/chef/knife/cookbook_site_list.rb index 81e1ffc278..27c836c247 100644 --- a/lib/chef/knife/cookbook_site_list.rb +++ b/lib/chef/knife/cookbook_site_list.rb @@ -25,7 +25,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site list (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_search.rb b/lib/chef/knife/cookbook_site_search.rb index 8aa195fe22..9e36afc5ff 100644 --- a/lib/chef/knife/cookbook_site_search.rb +++ b/lib/chef/knife/cookbook_site_search.rb @@ -25,7 +25,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site search QUERY (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_share.rb b/lib/chef/knife/cookbook_site_share.rb index 99d9d612df..d959784bb9 100644 --- a/lib/chef/knife/cookbook_site_share.rb +++ b/lib/chef/knife/cookbook_site_share.rb @@ -26,7 +26,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site share COOKBOOK [CATEGORY] (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_show.rb b/lib/chef/knife/cookbook_site_show.rb index ef1f61a6ca..84a7c249e5 100644 --- a/lib/chef/knife/cookbook_site_show.rb +++ b/lib/chef/knife/cookbook_site_show.rb @@ -25,7 +25,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site show COOKBOOK [VERSION] (options)" category "deprecated" diff --git a/lib/chef/knife/cookbook_site_unshare.rb b/lib/chef/knife/cookbook_site_unshare.rb index 13f02dd4d7..f712ad97e4 100644 --- a/lib/chef/knife/cookbook_site_unshare.rb +++ b/lib/chef/knife/cookbook_site_unshare.rb @@ -26,7 +26,6 @@ class Chef # Handle the subclassing (knife doesn't do this :() dependency_loaders.concat(superclass.dependency_loaders) - options.merge!(superclass.options) banner "knife cookbook site unshare COOKBOOK (options)" category "deprecated" diff --git a/lib/chef/provider/service/insserv.rb b/lib/chef/provider/service/insserv.rb index b61ec8d686..270ce2c274 100644 --- a/lib/chef/provider/service/insserv.rb +++ b/lib/chef/provider/service/insserv.rb @@ -36,7 +36,9 @@ class Chef super # Look for a /etc/rc.*/SnnSERVICE link to signify that the service would be started in a runlevel - if Dir.glob("/etc/rc**/S*#{Chef::Util::PathHelper.escape_glob_dir(current_resource.service_name)}").empty? + service_name = Chef::Util::PathHelper.escape_glob_dir(current_resource.service_name) + + if Dir.glob("/etc/rc*/**/S*#{service_name}").empty? current_resource.enabled false else current_resource.enabled true diff --git a/lib/chef/resource_collection.rb b/lib/chef/resource_collection.rb index c2bb463bfb..0293f380b0 100644 --- a/lib/chef/resource_collection.rb +++ b/lib/chef/resource_collection.rb @@ -60,8 +60,9 @@ class Chef end def delete(key) - resource_list.delete(key) - resource_set.delete(key) + res = resource_set.delete(key) + resource_list.delete(res.to_s) + res end # @deprecated diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index 7c19a33383..49b904aeed 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -604,7 +604,7 @@ class Chef # @return [Train::Plugins::Transport::BaseConnection] # def transport_connection - transport.connection + @transport_connection ||= transport.connection end # diff --git a/lib/chef/version.rb b/lib/chef/version.rb index 8a242d7f8e..2f68006264 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -23,7 +23,7 @@ require_relative "version_string" class Chef CHEF_ROOT = File.expand_path("../..", __FILE__) - VERSION = Chef::VersionString.new("15.0.305") + VERSION = Chef::VersionString.new("15.0.310") end # diff --git a/spec/functional/assets/inittest b/spec/functional/assets/inittest new file mode 100644 index 0000000000..dc542a965a --- /dev/null +++ b/spec/functional/assets/inittest @@ -0,0 +1,36 @@ +#!/bin/sh + +TMPDIR="${TMPDIR:-/tmp}" + +function create_chef_txt { + touch $TMPDIR/inittest.txt +} + +function delete_chef_txt { + rm $TMPDIR/inittest.txt +} + +function rename_chef_txt { + mv $TMPDIR/inittest.txt $TMPDIR/$1 +} + +case "$1" in +start ) + create_chef_txt + ;; +stop ) + delete_chef_txt + ;; +status ) + [ -f $TMPDIR/inittest.txt ] || [ -f $TMPDIR/inittest_reload.txt ] || [ -f $TMPDIR/inittest_restart.txt ] + ;; +reload ) + rename_chef_txt "inittest_reload.txt" + ;; +restart ) + rename_chef_txt "inittest_restart.txt" + ;; +* ) + echo "Usage: $0 (start | stop | restart | reload)" + exit 1 +esac diff --git a/spec/functional/resource/insserv_spec.rb b/spec/functional/resource/insserv_spec.rb new file mode 100644 index 0000000000..a923753019 --- /dev/null +++ b/spec/functional/resource/insserv_spec.rb @@ -0,0 +1,205 @@ +# encoding: UTF-8 +# +# Author:: Dheeraj Dubey (<dheeraj.dubey@msystechnologies.com>) +# Copyright:: Copyright 2009-2019, 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" +require "functional/resource/base" +require "chef/mixin/shell_out" +require "fileutils" + +describe Chef::Resource::Service, :requires_root, :sles11 do + + include Chef::Mixin::ShellOut + + def service_should_be_enabled + expect(shell_out!("/sbin/insserv -r -f #{new_resource.service_name}").exitstatus).to eq(0) + expect(shell_out!("/sbin/insserv -d -f #{new_resource.service_name}").exitstatus).to eq(0) + !Dir.glob("/etc/rc*/**/S*#{service_name}").empty? + end + + def service_should_be_disabled + expect(shell_out!("/sbin/insserv -r -f #{new_resource.service_name}").exitstatus).to eq(0) + Dir.glob("/etc/rc*/**/S*#{service_name}").empty? + end + + # Platform specific validation routines. + def service_should_be_started(file_name) + # The existence of this file indicates that the service was started. + expect(File.exists?("#{Dir.tmpdir}/#{file_name}")).to be_truthy + end + + def service_should_be_stopped(file_name) + expect(File.exists?("#{Dir.tmpdir}/#{file_name}")).to be_falsey + end + + def delete_test_files + files = Dir.glob("#{Dir.tmpdir}/init[a-z_]*.txt") + File.delete(*files) + end + + # Actual tests + let(:new_resource) do + new_resource = Chef::Resource::Service.new("inittest", run_context) + new_resource.provider Chef::Provider::Service::Insserv + new_resource.supports({ status: true, restart: true, reload: true }) + new_resource + end + + let(:provider) do + provider = new_resource.provider_for_action(new_resource.action) + provider + end + + let (:service_name) { "Chef::Util::PathHelper.escape_glob_dir(current_resource.service_name)" } + + let(:current_resource) do + provider.load_current_resource + provider.current_resource + end + + before(:all) do + File.delete("/etc/init.d/inittest") if File.exists?("/etc/init.d/inittest") + FileUtils.cp((File.join(File.dirname(__FILE__), "/../assets/inittest")).to_s, "/etc/init.d/inittest") + end + + after(:all) do + File.delete("/etc/init.d/inittest") if File.exists?("/etc/init.d/inittest") + end + + before(:each) do + delete_test_files + end + + after(:each) do + delete_test_files + end + + describe "start service" do + it "should start the service" do + new_resource.run_action(:start) + service_should_be_started("inittest.txt") + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + new_resource.run_action(:start) + service_should_be_started("inittest.txt") + expect(new_resource).to be_updated_by_last_action + new_resource.run_action(:start) + service_should_be_started("inittest.txt") + expect(new_resource).not_to be_updated_by_last_action + end + end + + describe "stop service" do + before do + new_resource.run_action(:start) + end + + it "should stop the service" do + new_resource.run_action(:stop) + service_should_be_stopped("inittest.txt") + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + new_resource.run_action(:stop) + service_should_be_stopped("inittest.txt") + expect(new_resource).to be_updated_by_last_action + new_resource.run_action(:stop) + service_should_be_stopped("inittest.txt") + expect(new_resource).not_to be_updated_by_last_action + end + end + + describe "restart service" do + before do + new_resource.run_action(:start) + end + + it "should restart the service" do + new_resource.run_action(:restart) + service_should_be_started("inittest_restart.txt") + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + skip "FIXME: restart is not idempotent" + new_resource.run_action(:restart) + service_should_be_disabled + expect(new_resource).to be_updated_by_last_action + new_resource.run_action(:restart) + service_should_be_disabled + expect(new_resource).not_to be_updated_by_last_action + end + end + + describe "reload service" do + before do + new_resource.run_action(:start) + end + + it "should reload the service" do + new_resource.run_action(:reload) + service_should_be_started("inittest_reload.txt") + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + skip "FIXME: reload is not idempotent" + new_resource.run_action(:reload) + service_should_be_disabled + expect(new_resource).to be_updated_by_last_action + new_resource.run_action(:reload) + service_should_be_disabled + expect(new_resource).not_to be_updated_by_last_action + end + end + + describe "enable service" do + it "should enable the service" do + new_resource.run_action(:enable) + service_should_be_enabled + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + new_resource.run_action(:enable) + service_should_be_enabled + new_resource.run_action(:enable) + service_should_be_enabled + expect(new_resource).not_to be_updated_by_last_action + end + end + + describe "disable_service" do + it "should disable the service" do + new_resource.run_action(:disable) + service_should_be_disabled + expect(new_resource).to be_updated_by_last_action + end + + it "should be idempotent" do + new_resource.run_action(:disable) + service_should_be_disabled + new_resource.run_action(:disable) + service_should_be_disabled + expect(new_resource).not_to be_updated_by_last_action + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 027be2e619..adfb262637 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -172,6 +172,7 @@ RSpec.configure do |config| config.filter_run_excluding linux_only: true unless linux? config.filter_run_excluding aix_only: true unless aix? config.filter_run_excluding suse_only: true unless suse? + config.filter_run_excluding sles11: true unless sles11? config.filter_run_excluding debian_family_only: true unless debian_family? config.filter_run_excluding supports_cloexec: true unless supports_cloexec? config.filter_run_excluding selinux_only: true unless selinux_enabled? diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index c4ab1db265..02f8c28345 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -162,6 +162,10 @@ def rhel6? rhel? && !!(ohai[:platform_version].to_i == 6) end +def sles11? + suse? && !!(ohai[:platform_version].to_i == 11) +end + def rhel7? rhel? && !!(ohai[:platform_version].to_i == 7) end diff --git a/spec/unit/provider/service/insserv_service_spec.rb b/spec/unit/provider/service/insserv_service_spec.rb index f2fe19db59..bd8a155bde 100644 --- a/spec/unit/provider/service/insserv_service_spec.rb +++ b/spec/unit/provider/service/insserv_service_spec.rb @@ -36,7 +36,7 @@ describe Chef::Provider::Service::Insserv do describe "load_current_resource" do describe "when startup links exist" do before do - allow(Dir).to receive(:glob).with("/etc/rc**/S*initgrediant").and_return(["/etc/rc5.d/S18initgrediant", "/etc/rc2.d/S18initgrediant", "/etc/rc4.d/S18initgrediant", "/etc/rc3.d/S18initgrediant"]) + allow(Dir).to receive(:glob).with("/etc/rc*/**/S*initgrediant").and_return(["/etc/rc.d/rc5.d/S18initgrediant", "/etc/rc.d/rc2.d/S18initgrediant", "/etc/rc.d/rc4.d/S18initgrediant", "/etc/rc.d/rc3.d/S18initgrediant"]) end it "sets the current enabled status to true" do @@ -47,7 +47,7 @@ describe Chef::Provider::Service::Insserv do describe "when startup links do not exist" do before do - allow(Dir).to receive(:glob).with("/etc/rc**/S*initgrediant").and_return([]) + allow(Dir).to receive(:glob).with("/etc/rc*/**/S*initgrediant").and_return([]) end it "sets the current enabled status to false" do diff --git a/spec/unit/resource_collection_spec.rb b/spec/unit/resource_collection_spec.rb index c12a005cfc..7f59246a88 100644 --- a/spec/unit/resource_collection_spec.rb +++ b/spec/unit/resource_collection_spec.rb @@ -183,6 +183,14 @@ describe Chef::ResourceCollection do expect(rc).to be_empty end + it "should allow to delete resources with different providers" do + pkg = Chef::Resource::YumPackage.new("monkey") + rc.insert(pkg, instance_name: "monkey", resource_type: "package") + expect(rc).not_to be_empty + expect(rc.delete("package[monkey]")).to eql(pkg) + expect(rc).to be_empty + end + it "should raise an exception if you send something strange to delete" do expect { rc.delete(:symbol) }.to raise_error(ArgumentError) end |