diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-06-21 10:47:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 10:47:10 -0700 |
commit | afc61f349906a8c884f7f060c5e50c856e2d9885 (patch) | |
tree | deae73ef766d5c5b18c869132f11a7eaef92f43d /lib/chef | |
parent | 1561069fd0ad769270ebe5b3a81aae30aad9bab1 (diff) | |
parent | 56f673f0bfee707c4d0bba91d50e4ae4582a5eba (diff) | |
download | chef-afc61f349906a8c884f7f060c5e50c856e2d9885.tar.gz |
Merge pull request #7382 from chef/lcg/deprecate-shell-out-methods
deprecate old shell_out APIs
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/deprecated.rb | 6 | ||||
-rw-r--r-- | lib/chef/mixin/shell_out.rb | 47 | ||||
-rw-r--r-- | lib/chef/provider/package.rb | 23 |
3 files changed, 39 insertions, 37 deletions
diff --git a/lib/chef/deprecated.rb b/lib/chef/deprecated.rb index d9a8df7b83..74c600bef9 100644 --- a/lib/chef/deprecated.rb +++ b/lib/chef/deprecated.rb @@ -1,5 +1,5 @@ #-- -# Copyright:: Copyright 2016-2017, Chef Software Inc. +# Copyright:: Copyright 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -217,6 +217,10 @@ class Chef end end + class ShellOut < Base + target 26 + end + class Generic < Base def url "https://docs.chef.io/chef_deprecations_client.html" diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index 2c67d34630..f38c6e262d 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -46,7 +46,8 @@ class Chef # a thousand unit tests. # - def shell_out_compact(*args, **options) # FIXME: deprecate + def shell_out_compact(*args, **options) + Chef.deprecated(:shell_out, "shell_out_compact should be replaced by shell_out") if options.empty? shell_out(*args) else @@ -54,7 +55,8 @@ class Chef end end - def shell_out_compact!(*args, **options) # FIXME: deprecate + def shell_out_compact!(*args, **options) + Chef.deprecated(:shell_out, "shell_out_compact! should be replaced by shell_out!") if options.empty? shell_out!(*args) else @@ -62,23 +64,26 @@ class Chef end end - def shell_out_compact_timeout(*args, **options) # FIXME: deprecate + def shell_out_compact_timeout(*args, **options) + Chef.deprecated(:shell_out, "shell_out_compact_timeout should be replaced by shell_out") if options.empty? - shell_out(*args) + shell_out(*args, argument_that_will_go_away_in_chef_15_so_do_not_use_it: true) else - shell_out(*args, **options) + shell_out(*args, argument_that_will_go_away_in_chef_15_so_do_not_use_it: true, **options) end end - def shell_out_compact_timeout!(*args, **options) # FIXME: deprecate + def shell_out_compact_timeout!(*args, **options) + Chef.deprecated(:shell_out, "shell_out_compact_timeout! should be replaced by shell_out!") if options.empty? - shell_out!(*args) + shell_out!(*args, argument_that_will_go_away_in_chef_15_so_do_not_use_it: true) else - shell_out!(*args, **options) + shell_out!(*args, argument_that_will_go_away_in_chef_15_so_do_not_use_it: true, **options) end end - def shell_out_with_systems_locale(*args, **options) # FIXME: deprecate + def shell_out_with_systems_locale(*args, **options) + Chef.deprecated(:shell_out, "shell_out_with_systems_locale should be replaced by shell_out with the default_env option set to false") if options.empty? shell_out(*args, default_env: false) else @@ -86,7 +91,8 @@ class Chef end end - def shell_out_with_systems_locale!(*args, **options) # FIXME: deprecate + def shell_out_with_systems_locale!(*args, **options) + Chef.deprecated(:shell_out, "shell_out_with_systems_locale! should be replaced by shell_out! with the default_env option set to false") if options.empty? shell_out!(*args, default_env: false) else @@ -94,9 +100,8 @@ class Chef end end - def a_to_s(*args) # FIXME: deprecate - # can't quite deprecate this yet - #Chef.deprecated(:package_misc, "a_to_s is deprecated use shell_out_compact or shell_out_compact_timeout instead") + def a_to_s(*args) + Chef.deprecated(:shell_out, "a_to_s is deprecated use shell_out with splat-args") args.flatten.reject { |i| i.nil? || i == "" }.map(&:to_s).join(" ") end @@ -125,13 +130,21 @@ class Chef # module method to not pollute namespaces, but that means we need self injected as an arg # @api private def self.maybe_add_timeout(obj, options) + options = options.dup + force = options.delete(:argument_that_will_go_away_in_chef_15_so_do_not_use_it) # remove in Chef-15 + # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here + default_val = 900 + if !force + return options if options.key?(:timeout) # leave this line in Chef-15, delete the rest of the conditional + else + default_val = options[:timeout] if options.key?(:timeout) # delete in Chef-15 + end # note that we can't define an empty Chef::Resource::LWRPBase because that breaks descendants tracker, so we'd have to instead require the file here, which would pull in half # of chef, so instead convert to using strings. once descendants tracker is gone, we can just declare the empty classes instead and use `is_a?` against the symbols. # (be nice if ruby supported strings in `is_a?` for looser coupling). - if obj.class.ancestors.map(&:to_s).include?("Chef::Provider") && !obj.class.ancestors.map(&:to_s).include?("Chef::Resource::LWRPBase") && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout) - options = options.dup - # historically resources have not properly declared defaults on their timeouts, so a default default of 900s was enforced here - options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : 900 + # FIXME: just use `if obj.respond_to?(:new_resource) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout)` in Chef 15 + if obj.respond_to?(:new_resource) && ( force || ( obj.class.ancestors.map(&:name).include?("Chef::Provider") && !obj.class.ancestors.map(&:name).include?("Chef::Resource::LWRPBase") && !obj.class.ancestors.map(&:name).include?("Chef::Resource::ActionClass") && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout) ) ) + options[:timeout] = obj.new_resource.timeout ? obj.new_resource.timeout.to_f : default_val end options end diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index ddd2fa5dd6..0af4f87d7f 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -668,27 +668,12 @@ class Chef end end - def shell_out_with_timeout(*command_args) # FIXME: deprecated - shell_out(*add_timeout_option(command_args)) + def shell_out_with_timeout(*command_args) + shell_out_compact_timeout(*command_args) end - def shell_out_with_timeout!(*command_args) # FIXME: deprecated - shell_out!(*add_timeout_option(command_args)) - end - - def add_timeout_option(command_args) - # this is deprecated but its not quite done yet - #Chef.deprecated(:package_misc, "shell_out_with_timeout and add_timeout_option are deprecated methods, use shell_out instead") - args = command_args.dup - if args.last.is_a?(Hash) - options = args.pop.dup - options[:timeout] = new_resource.timeout if new_resource.timeout - options[:timeout] = 900 unless options.key?(:timeout) - args << options - else - args << { timeout: new_resource.timeout ? new_resource.timeout : 900 } - end - args + def shell_out_with_timeout!(*command_args) + shell_out_compact_timeout!(*command_args) end end end |