diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-05-31 19:21:59 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-05-31 19:21:59 -0700 |
commit | b458142bc388fe0c62018a749f89e650c8f8ae6d (patch) | |
tree | bfbd517925a2126801d78dd1219567e2ad3c66d2 /lib/chef/mixin/shell_out.rb | |
parent | a3ced2c6b92d842ea93515337e575fd1f18dad17 (diff) | |
download | chef-b458142bc388fe0c62018a749f89e650c8f8ae6d.tar.gz |
Make shell_out_compact automatically pick up timeouts
This should apply to core resources, not cookbooks.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/mixin/shell_out.rb')
-rw-r--r-- | lib/chef/mixin/shell_out.rb | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index 236ef844b1..ae83035b4f 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -62,6 +62,7 @@ class Chef # def shell_out_compact(*args, **options) + options = maybe_add_timeout(options) if options.empty? shell_out(*clean_array(*args)) else @@ -70,6 +71,7 @@ class Chef end def shell_out_compact!(*args, **options) + options = maybe_add_timeout(options) if options.empty? shell_out!(*clean_array(*args)) else @@ -77,22 +79,21 @@ class Chef end end - # helper sugar for resources that support passing timeouts to shell_out + def maybe_add_timeout(options) + if is_a?(Chef::Provider) && !new_resource.is_a?(Chef::Resource::LWRPBase) && new_resource.respond_to?(:timeout) + options = options.dup + options[:timeout] = new_resource.timeout if new_resource.timeout + options[:timeout] = 900 unless options.key?(:timeout) + end + options + end def shell_out_compact_timeout(*args, **options) - raise "object is not a resource that supports timeouts" unless respond_to?(:new_resource) && new_resource.respond_to?(:timeout) - options_dup = options.dup - options_dup[:timeout] = new_resource.timeout if new_resource.timeout - options_dup[:timeout] = 900 unless options_dup.key?(:timeout) - shell_out_compact(*args, **options_dup) + shell_out_compact(*args, **options) end def shell_out_compact_timeout!(*args, **options) - raise "object is not a resource that supports timeouts" unless respond_to?(:new_resource) && new_resource.respond_to?(:timeout) - options_dup = options.dup - options_dup[:timeout] = new_resource.timeout if new_resource.timeout - options_dup[:timeout] = 900 unless options_dup.key?(:timeout) - shell_out_compact!(*args, **options_dup) + shell_out_compact!(*args, **options) end # shell_out! runs a command on the system and will raise an error if the command fails, which is what you want |