diff options
Diffstat (limited to 'lib/chef')
45 files changed, 285 insertions, 249 deletions
diff --git a/lib/chef/mixin/shell_out.rb b/lib/chef/mixin/shell_out.rb index e7010bb989..a17b428159 100644 --- a/lib/chef/mixin/shell_out.rb +++ b/lib/chef/mixin/shell_out.rb @@ -21,61 +21,102 @@ require "chef/mixin/path_sanity" class Chef module Mixin module ShellOut - include Chef::Mixin::PathSanity + extend Chef::Mixin::PathSanity # PREFERRED APIS: # - # shell_out_compact and shell_out_compact! flatten their array arguments and remove nils and pass - # the resultant array to shell_out. this actually eliminates spaces-in-args bugs because this: + # all consumers should now call shell_out!/shell_out. # - # shell_out!("command #{arg}") + # on unix the shell_out API supports the clean_array() kind of syntax (below) so that + # array args are flat/compact/to_s'd. on windows, array args aren't supported to its + # up to the caller to join(" ") on arrays of strings. # - # becomes two arguments if arg has spaces and requires quotations: + # the shell_out_compacted/shell_out_compacted! APIs are private but are intended for use + # in rspec tests, and should ideally always be used to make code refactorings that do not + # change behavior easier: # - # shell_out!("command '#{arg}'") + # allow(provider).to receive(:shell_out_compacted!).with("foo", "bar", "baz") + # provider.shell_out!("foo", [ "bar", nil, "baz"]) + # provider.shell_out!(["foo", nil, "bar" ], ["baz"]) # - # using shell_out_compact! this becomes: - # - # shell_out_compact!("command", arg) - # - # and spaces in the arg just works and it does not become two arguments (and the shell quoting around - # the argument must actually be removed). - # - # there's also an implicit join between all the array elements, and nested arrays are flattened which - # means that odd where-do-i-put-the-spaces options handling just works, and instead of this: - # - # opts = "" # needs to be empty string for when foo and bar are both missing - # opts << " -foo" if needs_foo? # needs the leading space on both of these - # opts << " -bar" if needs_bar? - # shell_out!("cmd#{opts}") # have to think way too hard about why there's no space here - # - # becomes: - # - # opts = [] - # opts << "-foo" if needs_foo? - # opts << "-bar" if needs_bar? - # shell_out_compact!("cmd", opts) - # - # and opts can be an empty array or nil and it'll work out fine. - # - # generally its best to use shell_out_compact! in code and setup expectations on shell_out! in tests + # note that shell_out_compacted also includes adding the magical timeout option to force + # people to setup expectations on that value explicitly. it does not include the default_env + # mangling in order to avoid users having to setup an expectation on anything other than + # setting `default_env: false` and allow us to make tweak to the default_env without breaking + # a thousand unit tests. # - def shell_out_compact(*args, **options) + def shell_out_compact(*args, **options) # FIXME: deprecate + if options.empty? + shell_out_compact(*args) + else + shell_out_compact(*args, **options) + end + end + + def shell_out_compact!(*args, **options) # FIXME: deprecate + if options.empty? + shell_out_compact!(*args) + else + shell_out_compact!(*args, **options) + end + end + + def shell_out_compact_timeout(*args, **options) # FIXME: deprecate + if options.empty? + shell_out_compact(*args) + else + shell_out_compact(*args, **options) + end + end + + def shell_out_compact_timeout!(*args, **options) # FIXME: deprecate + if options.empty? + shell_out_compact!(*args) + else + shell_out_compact!(*args, **options) + end + end + + def shell_out_with_systems_locale(*args, **options) # FIXME: deprecate + if options.empty? + shell_out(*args, default_env: false) + else + shell_out(*args, default_env: false, **options) + end + end + + def shell_out_with_systems_locale!(*args, **options) # FIXME: deprecate + if options.empty? + shell_out!(*args, default_env: false) + else + shell_out!(*args, default_env: false, **options) + 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") + args.flatten.reject { |i| i.nil? || i == "" }.map(&:to_s).join(" ") + end + + def shell_out(*args, **options) + options = options.dup options = Chef::Mixin::ShellOut.maybe_add_timeout(self, options) if options.empty? - shell_out(*clean_array(*args)) + shell_out_compacted(*Chef::Mixin::ShellOut.clean_array(*args)) else - shell_out(*clean_array(*args), **options) + shell_out_compacted(*Chef::Mixin::ShellOut.clean_array(*args), **options) end end - def shell_out_compact!(*args, **options) + def shell_out!(*args, **options) + options = options.dup options = Chef::Mixin::ShellOut.maybe_add_timeout(self, options) if options.empty? - shell_out!(*clean_array(*args)) + shell_out_compacted!(*Chef::Mixin::ShellOut.clean_array(*args)) else - shell_out!(*clean_array(*args), **options) + shell_out_compacted!(*Chef::Mixin::ShellOut.clean_array(*args), **options) end end @@ -84,7 +125,7 @@ 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) - if obj.is_a?(Chef::Provider) && !obj.new_resource.is_a?(Chef::Resource::LWRPBase) && obj.new_resource.respond_to?(:timeout) && !options.key?(:timeout) + 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 @@ -92,22 +133,10 @@ class Chef options end - def shell_out_compact_timeout(*args, **options) - shell_out_compact(*args, **options) - end - - def shell_out_compact_timeout!(*args, **options) - 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 - # for debugging, shell_out and shell_out! both will display command output to the tty when the log level is debug - # Generally speaking, 'extend Chef::Mixin::ShellOut' in your recipes and include 'Chef::Mixin::ShellOut' in your LWRPs - # You can also call Mixlib::Shellout.new directly, but you lose all of the above functionality - - # we use 'en_US.UTF-8' by default because we parse localized strings in English as an API and - # generally must support UTF-8 unicode. - def shell_out(*args, **options) + # helper function to mangle options when `default_env` is true + # + # @api private + def self.apply_default_env(options) options = options.dup default_env = options.delete(:default_env) default_env = true if default_env.nil? @@ -120,34 +149,37 @@ class Chef env_path => sanitized_path, }.update(options[env_key] || {}) end - shell_out_command(*args, **options) - end - - # call shell_out (using en_US.UTF-8) and raise errors - def shell_out!(*command_args) - cmd = shell_out(*command_args) - cmd.error! - cmd + options end - def shell_out_with_systems_locale(*args, **options) # FIXME: deprecate - shell_out(*args, default_env: false, **options) - end + private - def shell_out_with_systems_locale!(*args, **options) # FIXME: deprecate - shell_out!(*args, default_env: false, **options) + # this SHOULD be used for setting up expectations in rspec, see banner comment at top. + # + # the private constraint is meant to avoid code calling this directly, rspec expectations are fine. + # + def shell_out_compacted(*args, **options) + options = Chef::Mixin::ShellOut.apply_default_env(options) + if options.empty? + Chef::Mixin::ShellOut.shell_out_command(*args) + else + Chef::Mixin::ShellOut.shell_out_command(*args, **options) + end end - # Helper for subclasses to convert an array of string args into a string. It - # will compact nil or empty strings in the array and will join the array elements - # with spaces, without introducing any double spaces for nil/empty elements. + # this SHOULD be used for setting up expectations in rspec, see banner comment at top. # - # @param args [String] variable number of string arguments - # @return [String] nicely concatenated string or empty string - def a_to_s(*args) - # 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") - args.flatten.reject { |i| i.nil? || i == "" }.map(&:to_s).join(" ") + # the private constraint is meant to avoid code calling this directly, rspec expectations are fine. + # + def shell_out_compacted!(*args, **options) + options = Chef::Mixin::ShellOut.apply_default_env(options) + cmd = if options.empty? + Chef::Mixin::ShellOut.shell_out_command(*args) + else + Chef::Mixin::ShellOut.shell_out_command(*args, **options) + end + cmd.error! + cmd end # Helper for subclasses to reject nil out of an array. It allows @@ -166,20 +198,23 @@ class Chef # # @param args [String] variable number of string arguments # @return [Array] array of strings with nil and null string rejection - def clean_array(*args) + + def self.clean_array(*args) args.flatten.compact.map(&:to_s) end - private - - def shell_out_command(*command_args) - cmd = Mixlib::ShellOut.new(*command_args) + def self.shell_out_command(*args, **options) + cmd = if options.empty? + Mixlib::ShellOut.new(*args) + else + Mixlib::ShellOut.new(*args, **options) + end cmd.live_stream ||= io_for_live_stream cmd.run_command cmd end - def io_for_live_stream + def self.io_for_live_stream if STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.debug? STDOUT else @@ -187,7 +222,7 @@ class Chef end end - def env_path + def self.env_path if Chef::Platform.windows? "Path" else diff --git a/lib/chef/provider/group/aix.rb b/lib/chef/provider/group/aix.rb index 5c500e2753..7da07b8006 100644 --- a/lib/chef/provider/group/aix.rb +++ b/lib/chef/provider/group/aix.rb @@ -32,33 +32,33 @@ class Chef end def create_group - shell_out_compact!("mkgroup", set_options, new_resource.group_name) + shell_out!("mkgroup", set_options, new_resource.group_name) modify_group_members end def manage_group options = set_options if options.size > 0 - shell_out_compact!("chgroup", options, new_resource.group_name) + shell_out!("chgroup", options, new_resource.group_name) end modify_group_members end def remove_group - shell_out_compact!("rmgroup", new_resource.group_name) + shell_out!("rmgroup", new_resource.group_name) end def add_member(member) - shell_out_compact!("chgrpmem", "-m", "+", member, new_resource.group_name) + shell_out!("chgrpmem", "-m", "+", member, new_resource.group_name) end def set_members(members) return if members.empty? - shell_out_compact!("chgrpmem", "-m", "=", members.join(","), new_resource.group_name) + shell_out!("chgrpmem", "-m", "=", members.join(","), new_resource.group_name) end def remove_member(member) - shell_out_compact!("chgrpmem", "-m", "-", member, new_resource.group_name) + shell_out!("chgrpmem", "-m", "-", member, new_resource.group_name) end def set_options diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb index 81c7d66aa8..a5c4d27ddb 100644 --- a/lib/chef/provider/group/dscl.rb +++ b/lib/chef/provider/group/dscl.rb @@ -27,7 +27,7 @@ class Chef argdup = args.dup cmd = argdup.shift shellcmd = [ "dscl", ".", "-#{cmd}", argdup ] - status = shell_out_compact(shellcmd) + status = shell_out(shellcmd) stdout_result = "" stderr_result = "" status.stdout.each_line { |line| stdout_result << line } diff --git a/lib/chef/provider/group/gpasswd.rb b/lib/chef/provider/group/gpasswd.rb index d8aff10d5b..a5d6a378c0 100644 --- a/lib/chef/provider/group/gpasswd.rb +++ b/lib/chef/provider/group/gpasswd.rb @@ -39,18 +39,18 @@ class Chef def set_members(members) if members.empty? - shell_out_compact!("gpasswd", "-M", "", new_resource.group_name) + shell_out!("gpasswd", "-M", "", new_resource.group_name) else - shell_out_compact!("gpasswd", "-M", members.join(","), new_resource.group_name) + shell_out!("gpasswd", "-M", members.join(","), new_resource.group_name) end end def add_member(member) - shell_out_compact!("gpasswd", "-a", member, new_resource.group_name) + shell_out!("gpasswd", "-a", member, new_resource.group_name) end def remove_member(member) - shell_out_compact!("gpasswd", "-d", member, new_resource.group_name) + shell_out!("gpasswd", "-d", member, new_resource.group_name) end end end diff --git a/lib/chef/provider/group/groupadd.rb b/lib/chef/provider/group/groupadd.rb index 7d7fac146c..fb8f306034 100644 --- a/lib/chef/provider/group/groupadd.rb +++ b/lib/chef/provider/group/groupadd.rb @@ -44,19 +44,19 @@ class Chef # Create the group def create_group - shell_out_compact!("groupadd", set_options, groupadd_options) + shell_out!("groupadd", set_options, groupadd_options) modify_group_members end # Manage the group when it already exists def manage_group - shell_out_compact!("groupmod", set_options) + shell_out!("groupmod", set_options) modify_group_members end # Remove the group def remove_group - shell_out_compact!("groupdel", new_resource.group_name) + shell_out!("groupdel", new_resource.group_name) end def modify_group_members diff --git a/lib/chef/provider/group/groupmod.rb b/lib/chef/provider/group/groupmod.rb index 13f83db4c4..ac033e607d 100644 --- a/lib/chef/provider/group/groupmod.rb +++ b/lib/chef/provider/group/groupmod.rb @@ -32,7 +32,7 @@ class Chef # Create the group def create_group - shell_out_compact!("group", "add", set_options) + shell_out!("group", "add", set_options) add_group_members(new_resource.members) end @@ -79,14 +79,14 @@ class Chef # Remove the group def remove_group - shell_out_compact!("group", "del", new_resource.group_name) + shell_out!("group", "del", new_resource.group_name) end # Adds a list of usernames to the group using `user mod` def add_group_members(members) logger.trace("#{new_resource} adding members #{members.join(', ')}") unless members.empty? members.each do |user| - shell_out_compact!("user", "mod", "-G", new_resource.group_name, user) + shell_out!("user", "mod", "-G", new_resource.group_name, user) end end @@ -94,11 +94,11 @@ class Chef # "<name>_bak", create a new group with the same GID and # "<name>", then set correct members on that group def reset_group_membership - shell_out_compact!("group", "mod", "-n", "#{new_resource.group_name}_bak", new_resource.group_name) + shell_out!("group", "mod", "-n", "#{new_resource.group_name}_bak", new_resource.group_name) - shell_out_compact!("group", "add", set_options(overwrite_gid: true)) + shell_out!("group", "add", set_options(overwrite_gid: true)) - shell_out_compact!("group", "del", "#{new_resource.group_name}_bak") + shell_out!("group", "del", "#{new_resource.group_name}_bak") end # Little bit of magic as per Adam's useradd provider to pull and assign the command line flags diff --git a/lib/chef/provider/group/pw.rb b/lib/chef/provider/group/pw.rb index b0393a147e..2a1f294bde 100644 --- a/lib/chef/provider/group/pw.rb +++ b/lib/chef/provider/group/pw.rb @@ -48,24 +48,24 @@ class Chef command += [ "-M", new_resource.members.join(",") ] end - shell_out_compact!(command) + shell_out!(command) end # Manage the group when it already exists def manage_group member_options = set_members_options if member_options.empty? - shell_out_compact!("pw", "groupmod", set_options) + shell_out!("pw", "groupmod", set_options) else member_options.each do |option| - shell_out_compact!("pw", "groupmod", set_options, option) + shell_out!("pw", "groupmod", set_options, option) end end end # Remove the group def remove_group - shell_out_compact!("pw", "groupdel", new_resource.group_name) + shell_out!("pw", "groupdel", new_resource.group_name) end # Little bit of magic as per Adam's useradd provider to pull and assign the command line flags diff --git a/lib/chef/provider/group/suse.rb b/lib/chef/provider/group/suse.rb index 0790d2c2d9..7e8473c901 100644 --- a/lib/chef/provider/group/suse.rb +++ b/lib/chef/provider/group/suse.rb @@ -66,7 +66,7 @@ class Chef end def add_member(member) - shell_out_compact!("groupmod", "-A", member, new_resource.group_name) + shell_out!("groupmod", "-A", member, new_resource.group_name) end def to_remove(members) @@ -74,7 +74,7 @@ class Chef end def remove_member(member) - shell_out_compact!("groupmod", "-R", member, new_resource.group_name) + shell_out!("groupmod", "-R", member, new_resource.group_name) end end diff --git a/lib/chef/provider/group/usermod.rb b/lib/chef/provider/group/usermod.rb index 3874f7b4de..6b040b7190 100644 --- a/lib/chef/provider/group/usermod.rb +++ b/lib/chef/provider/group/usermod.rb @@ -66,7 +66,7 @@ class Chef end def add_member(member) - shell_out_compact!("usermod", append_flags, new_resource.group_name, member) + shell_out!("usermod", append_flags, new_resource.group_name, member) end def remove_member(member) diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb index 243c8ee9c3..f3d65d7c7c 100644 --- a/lib/chef/provider/ifconfig.rb +++ b/lib/chef/provider/ifconfig.rb @@ -163,7 +163,7 @@ class Chef unless new_resource.device == loopback_device command = add_command converge_by("run #{command.join(' ')} to add #{new_resource}") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} added") end end @@ -179,7 +179,7 @@ class Chef return if new_resource.device == loopback_device command = enable_command converge_by("run #{command.join(' ')} to enable #{new_resource}") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} enabled") end end @@ -189,7 +189,7 @@ class Chef if current_resource.device command = delete_command converge_by("run #{command.join(' ')} to delete #{new_resource}") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} deleted") end else @@ -204,7 +204,7 @@ class Chef if current_resource.device command = disable_command converge_by("run #{command.join(' ')} to disable #{new_resource}") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} disabled") end else diff --git a/lib/chef/provider/ifconfig/aix.rb b/lib/chef/provider/ifconfig/aix.rb index b68c5d5364..f9ecc1f22e 100644 --- a/lib/chef/provider/ifconfig/aix.rb +++ b/lib/chef/provider/ifconfig/aix.rb @@ -31,7 +31,7 @@ class Chef found_interface = false interface = {} - @status = shell_out_compact("ifconfig", "-a") + @status = shell_out("ifconfig", "-a") @status.stdout.each_line do |line| if !found_interface if line =~ /^(\S+):\sflags=(\S+)/ diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index 6a7b2bc276..ddd2fa5dd6 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -307,7 +307,7 @@ class Chef # used by subclasses. deprecated. use #a_to_s instead. def expand_options(options) # its deprecated but still work to do to deprecate it fully - #Chef.deprecated(:package_misc, "expand_options is deprecated, use shell_out_compact instead") + #Chef.deprecated(:package_misc, "expand_options is deprecated, use shell_out instead") if options " #{options.is_a?(Array) ? Shellwords.join(options) : options}" else @@ -668,17 +668,17 @@ class Chef end end - def shell_out_with_timeout(*command_args) + def shell_out_with_timeout(*command_args) # FIXME: deprecated shell_out(*add_timeout_option(command_args)) end - def shell_out_with_timeout!(*command_args) + 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_compact instead") + #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 diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index b644848442..f245e481a3 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -81,7 +81,7 @@ class Chef def locked_packages @locked_packages ||= begin - locked = shell_out_compact!("apt-mark", "showhold") + locked = shell_out!("apt-mark", "showhold") locked.stdout.each_line.map do |line| line.strip end @@ -140,9 +140,9 @@ class Chef # # @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2 def version_compare(v1, v2) - if !shell_out_compact("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? + if !shell_out("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? 1 - elsif !shell_out_compact("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? + elsif !shell_out("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? 0 else -1 @@ -153,7 +153,7 @@ class Chef # interactive prompts. Command is run with default localization rather # than forcing locale to "C", so command output may not be stable. def run_noninteractive(*args) - shell_out_compact!(*args, env: { "DEBIAN_FRONTEND" => "noninteractive" }) + shell_out!(*args, env: { "DEBIAN_FRONTEND" => "noninteractive" }) end def default_release_options diff --git a/lib/chef/provider/package/bff.rb b/lib/chef/provider/package/bff.rb index 256a1499eb..652fad447b 100644 --- a/lib/chef/provider/package/bff.rb +++ b/lib/chef/provider/package/bff.rb @@ -49,7 +49,7 @@ class Chef if package_source_found? logger.trace("#{new_resource} checking pkg status") - ret = shell_out_compact("installp", "-L", "-d", new_resource.source) + ret = shell_out("installp", "-L", "-d", new_resource.source) ret.stdout.each_line do |line| case line when /:#{new_resource.package_name}:/ @@ -65,7 +65,7 @@ class Chef end logger.trace("#{new_resource} checking install state") - ret = shell_out_compact("lslpp", "-lcq", current_resource.package_name) + ret = shell_out("lslpp", "-lcq", current_resource.package_name) ret.stdout.each_line do |line| case line when /#{current_resource.package_name}/ @@ -85,7 +85,7 @@ class Chef def candidate_version return @candidate_version if @candidate_version if package_source_found? - ret = shell_out_compact("installp", "-L", "-d", new_resource.source) + ret = shell_out("installp", "-L", "-d", new_resource.source) ret.stdout.each_line do |line| case line when /\w:#{Regexp.escape(new_resource.package_name)}:(.*)/ @@ -112,10 +112,10 @@ class Chef def install_package(name, version) logger.trace("#{new_resource} package install options: #{options}") if options.nil? - shell_out_compact!("installp", "-aYF", "-d", new_resource.source, new_resource.package_name) + shell_out!("installp", "-aYF", "-d", new_resource.source, new_resource.package_name) logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") else - shell_out_compact!("installp", "-aYF", options, "-d", new_resource.source, new_resource.package_name) + shell_out!("installp", "-aYF", options, "-d", new_resource.source, new_resource.package_name) logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") end end @@ -124,10 +124,10 @@ class Chef def remove_package(name, version) if options.nil? - shell_out_compact!("installp", "-u", name) + shell_out!("installp", "-u", name) logger.trace("#{new_resource} removed version #{new_resource.version}") else - shell_out_compact!("installp", "-u", options, name) + shell_out!("installp", "-u", options, name) logger.trace("#{new_resource} removed version #{new_resource.version}") end end diff --git a/lib/chef/provider/package/chocolatey.rb b/lib/chef/provider/package/chocolatey.rb index a6abdd5b46..c60483d0dc 100644 --- a/lib/chef/provider/package/chocolatey.rb +++ b/lib/chef/provider/package/chocolatey.rb @@ -171,7 +171,7 @@ EOS # @param args [String] variable number of string arguments # @return [Mixlib::ShellOut] object returned from shell_out! def choco_command(*args) - shell_out_with_timeout!(args_to_string(choco_exe, *args), returns: new_resource.returns) + shell_out!(args_to_string(choco_exe, *args), returns: new_resource.returns) end # Use the available_packages Hash helper to create an array suitable for diff --git a/lib/chef/provider/package/dnf.rb b/lib/chef/provider/package/dnf.rb index 0233c0a838..2339b4cabe 100644 --- a/lib/chef/provider/package/dnf.rb +++ b/lib/chef/provider/package/dnf.rb @@ -121,7 +121,7 @@ class Chef private def resolve_source_to_version_obj - shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line| + shell_out!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line| # this is another case of committing the sin of doing some lightweight mangling of RPM versions in ruby -- but the output of the rpm command # does not match what the dnf library accepts. case line @@ -167,7 +167,7 @@ class Chef end def dnf(*args) - shell_out_compact!("dnf", *args) + shell_out!("dnf", *args) end def safe_version_array diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb index 0b6a9c8ba2..de5b2858e7 100644 --- a/lib/chef/provider/package/dpkg.rb +++ b/lib/chef/provider/package/dpkg.rb @@ -113,9 +113,9 @@ class Chef # # @return [Integer] 1 if v1 > v2. 0 if they're equal. -1 if v1 < v2 def version_compare(v1, v2) - if !shell_out_compact("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? + if !shell_out("dpkg", "--compare-versions", v1.to_s, "gt", v2.to_s).error? 1 - elsif !shell_out_compact("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? + elsif !shell_out("dpkg", "--compare-versions", v1.to_s, "eq", v2.to_s).error? 0 else -1 @@ -124,7 +124,7 @@ class Chef def read_current_version_of_package(package_name) logger.trace("#{new_resource} checking install state of #{package_name}") - status = shell_out_compact!("dpkg", "-s", package_name, returns: [0, 1]) + status = shell_out!("dpkg", "-s", package_name, returns: [0, 1]) package_installed = false status.stdout.each_line do |line| case line @@ -149,10 +149,10 @@ class Chef end end - # Runs command via shell_out_with_timeout with magic environment to disable + # Runs command via shell_out with magic environment to disable # interactive prompts. def run_noninteractive(*command) - shell_out_compact!(*command, env: { "DEBIAN_FRONTEND" => "noninteractive" }) + shell_out!(*command, env: { "DEBIAN_FRONTEND" => "noninteractive" }) end # Returns true if all sources exist. Returns false if any do not, or if no @@ -192,7 +192,7 @@ class Chef begin pkginfos = resolved_source_array.map do |src| logger.trace("#{new_resource} checking #{src} dpkg status") - status = shell_out_compact!("dpkg-deb", "-W", src) + status = shell_out!("dpkg-deb", "-W", src) status.stdout end Hash[*package_name_array.zip(pkginfos).flatten] diff --git a/lib/chef/provider/package/freebsd/base.rb b/lib/chef/provider/package/freebsd/base.rb index c9b3bf222b..bf704a5cae 100644 --- a/lib/chef/provider/package/freebsd/base.rb +++ b/lib/chef/provider/package/freebsd/base.rb @@ -47,7 +47,7 @@ class Chef # Otherwise look up the path to the ports directory using 'whereis' else - whereis = shell_out_compact!("whereis", "-s", port, env: nil) + whereis = shell_out!("whereis", "-s", port, env: nil) unless path = whereis.stdout[/^#{Regexp.escape(port)}:\s+(.+)$/, 1] raise Chef::Exceptions::Package, "Could not find port with the name #{port}" end @@ -57,7 +57,7 @@ class Chef def makefile_variable_value(variable, dir = nil) options = dir ? { cwd: dir } : {} - make_v = shell_out_compact!("make", "-V", variable, options.merge!(env: nil, returns: [0, 1])) + make_v = shell_out!("make", "-V", variable, options.merge!(env: nil, returns: [0, 1])) make_v.exitstatus == 0 ? make_v.stdout.strip.split($OUTPUT_RECORD_SEPARATOR).first : nil # $\ is the line separator, i.e. newline. end end diff --git a/lib/chef/provider/package/freebsd/pkg.rb b/lib/chef/provider/package/freebsd/pkg.rb index 800bca681c..c847ae5658 100644 --- a/lib/chef/provider/package/freebsd/pkg.rb +++ b/lib/chef/provider/package/freebsd/pkg.rb @@ -34,24 +34,24 @@ class Chef case new_resource.source when /^http/, /^ftp/ if new_resource.source =~ /\/$/ - shell_out_compact!("pkg_add", "-r", package_name, env: { "PACKAGESITE" => new_resource.source, "LC_ALL" => nil }).status + shell_out!("pkg_add", "-r", package_name, env: { "PACKAGESITE" => new_resource.source, "LC_ALL" => nil }).status else - shell_out_compact!("pkg_add", "-r", package_name, env: { "PACKAGEROOT" => new_resource.source, "LC_ALL" => nil }).status + shell_out!("pkg_add", "-r", package_name, env: { "PACKAGEROOT" => new_resource.source, "LC_ALL" => nil }).status end logger.trace("#{new_resource} installed from: #{new_resource.source}") when /^\// - shell_out_compact!("pkg_add", file_candidate_version_path, env: { "PKG_PATH" => new_resource.source, "LC_ALL" => nil }).status + shell_out!("pkg_add", file_candidate_version_path, env: { "PKG_PATH" => new_resource.source, "LC_ALL" => nil }).status logger.trace("#{new_resource} installed from: #{new_resource.source}") else - shell_out_compact!("pkg_add", "-r", latest_link_name, env: nil).status + shell_out!("pkg_add", "-r", latest_link_name, env: nil).status end end end def remove_package(name, version) - shell_out_compact!("pkg_delete", "#{package_name}-#{version || current_resource.version}", env: nil).status + shell_out!("pkg_delete", "#{package_name}-#{version || current_resource.version}", env: nil).status end # The name of the package (without the version number) as understood by pkg_add and pkg_info. @@ -72,7 +72,7 @@ class Chef end def current_installed_version - pkg_info = shell_out_compact!("pkg_info", "-E", "#{package_name}*", env: nil, returns: [0, 1]) + pkg_info = shell_out!("pkg_info", "-E", "#{package_name}*", env: nil, returns: [0, 1]) pkg_info.stdout[/^#{Regexp.escape(package_name)}-(.+)/, 1] end diff --git a/lib/chef/provider/package/freebsd/pkgng.rb b/lib/chef/provider/package/freebsd/pkgng.rb index ab64753e88..250baf0fac 100644 --- a/lib/chef/provider/package/freebsd/pkgng.rb +++ b/lib/chef/provider/package/freebsd/pkgng.rb @@ -28,21 +28,21 @@ class Chef unless current_resource.version case new_resource.source when /^(http|ftp|\/)/ - shell_out_compact!("pkg", "add", options, new_resource.source, env: { "LC_ALL" => nil }).status + shell_out!("pkg", "add", options, new_resource.source, env: { "LC_ALL" => nil }).status logger.trace("#{new_resource} installed from: #{new_resource.source}") else - shell_out_compact!("pkg", "install", "-y", options, name, env: { "LC_ALL" => nil }).status + shell_out!("pkg", "install", "-y", options, name, env: { "LC_ALL" => nil }).status end end end def remove_package(name, version) options_dup = options && options.map { |str| str.sub(repo_regex, "") }.reject!(&:empty?) - shell_out_compact!("pkg", "delete", "-y", options_dup, "#{name}#{version ? '-' + version : ''}", env: nil).status + shell_out!("pkg", "delete", "-y", options_dup, "#{name}#{version ? '-' + version : ''}", env: nil).status end def current_installed_version - pkg_info = shell_out_compact!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70]) + pkg_info = shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70]) pkg_info.stdout[/^Version +: (.+)$/, 1] end @@ -61,7 +61,7 @@ class Chef options = $1.split(" ") end - pkg_query = shell_out_compact!("pkg", "rquery", options, "%v", new_resource.package_name, env: nil) + pkg_query = shell_out!("pkg", "rquery", options, "%v", new_resource.package_name, env: nil) pkg_query.exitstatus == 0 ? pkg_query.stdout.strip.split(/\n/).last : nil end diff --git a/lib/chef/provider/package/freebsd/port.rb b/lib/chef/provider/package/freebsd/port.rb index 96a96ad030..7a46bbaf97 100644 --- a/lib/chef/provider/package/freebsd/port.rb +++ b/lib/chef/provider/package/freebsd/port.rb @@ -26,18 +26,18 @@ class Chef include PortsHelper def install_package(name, version) - shell_out_compact!("make", "-DBATCH", "install", "clean", timeout: 1800, env: nil, cwd: port_dir).status + shell_out!("make", "-DBATCH", "install", "clean", timeout: 1800, env: nil, cwd: port_dir).status end def remove_package(name, version) - shell_out_compact!("make", "deinstall", timeout: 300, env: nil, cwd: port_dir).status + shell_out!("make", "deinstall", timeout: 300, env: nil, cwd: port_dir).status end def current_installed_version pkg_info = if new_resource.supports_pkgng? - shell_out_compact!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70]) + shell_out!("pkg", "info", new_resource.package_name, env: nil, returns: [0, 70]) else - shell_out_compact!("pkg_info", "-E", "#{new_resource.package_name}*", env: nil, returns: [0, 1]) + shell_out!("pkg_info", "-E", "#{new_resource.package_name}*", env: nil, returns: [0, 1]) end pkg_info.stdout[/^#{Regexp.escape(new_resource.package_name)}-(.+)/, 1] end diff --git a/lib/chef/provider/package/homebrew.rb b/lib/chef/provider/package/homebrew.rb index 319ce992f7..1a7407486b 100644 --- a/lib/chef/provider/package/homebrew.rb +++ b/lib/chef/provider/package/homebrew.rb @@ -128,7 +128,7 @@ class Chef logger.trace "Executing '#{command.join(' ')}' as user '#{homebrew_user.name}'" # FIXME: this 1800 second default timeout should be deprecated - output = shell_out_compact!(*command, timeout: 1800, user: homebrew_uid, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil }) + output = shell_out!(*command, timeout: 1800, user: homebrew_uid, environment: { "HOME" => homebrew_user.dir, "RUBYOPT" => nil, "TMPDIR" => nil }) output.stdout.chomp end diff --git a/lib/chef/provider/package/ips.rb b/lib/chef/provider/package/ips.rb index 11455ce9cd..f7fdb95e4d 100644 --- a/lib/chef/provider/package/ips.rb +++ b/lib/chef/provider/package/ips.rb @@ -1,7 +1,7 @@ # # Author:: Jason J. W. Williams (<williamsjj@digitar.com>) # Author:: Stephen Nelson-Smith (<sns@chef.io>) -# Copyright:: Copyright 2011-2017, Chef Software Inc. +# Copyright:: Copyright 2011-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -42,14 +42,14 @@ class Chef end def get_current_version - shell_out_compact("pkg", "info", new_resource.package_name).stdout.each_line do |line| + shell_out("pkg", "info", new_resource.package_name).stdout.each_line do |line| return $1.split[0] if line =~ /^\s+Version: (.*)/ end nil end def get_candidate_version - shell_out_compact!("pkg", "info", "-r", new_resource.package_name).stdout.each_line do |line| + shell_out!("pkg", "info", "-r", new_resource.package_name).stdout.each_line do |line| return $1.split[0] if line =~ /Version: (.*)/ end nil @@ -68,7 +68,7 @@ class Chef command = [ "pkg", options, "install", "-q" ] command << "--accept" if new_resource.accept_license command << "#{name}@#{version}" - shell_out_compact!(command) + shell_out!(command) end def upgrade_package(name, version) @@ -77,7 +77,7 @@ class Chef def remove_package(name, version) package_name = "#{name}@#{version}" - shell_out_compact!( "pkg", options, "uninstall", "-q", package_name ) + shell_out!( "pkg", options, "uninstall", "-q", package_name ) end end end diff --git a/lib/chef/provider/package/macports.rb b/lib/chef/provider/package/macports.rb index 11113baf6f..384435778d 100644 --- a/lib/chef/provider/package/macports.rb +++ b/lib/chef/provider/package/macports.rb @@ -49,21 +49,21 @@ class Chef unless current_resource.version == version command = [ "port", options, "install", name ] command << "@#{version}" if version && !version.empty? - shell_out_compact!(command) + shell_out!(command) end end def purge_package(name, version) command = [ "port", options, "uninstall", name ] command << "@#{version}" if version && !version.empty? - shell_out_compact!(command) + shell_out!(command) end def remove_package(name, version) command = [ "port", options, "deactivate", name ] command << "@#{version}" if version && !version.empty? - shell_out_compact!(command) + shell_out!(command) end def upgrade_package(name, version) @@ -76,7 +76,7 @@ class Chef # that hasn't been installed. install_package(name, version) elsif current_version != version - shell_out_compact!( "port", options, "upgrade", name, "@#{version}" ) + shell_out!( "port", options, "upgrade", name, "@#{version}" ) end end @@ -84,7 +84,7 @@ class Chef def get_response_from_command(command) output = nil - status = shell_out_compact(command) + status = shell_out(command) begin output = status.stdout rescue Exception diff --git a/lib/chef/provider/package/msu.rb b/lib/chef/provider/package/msu.rb index c4e53a0fdf..9dbea31c82 100644 --- a/lib/chef/provider/package/msu.rb +++ b/lib/chef/provider/package/msu.rb @@ -125,7 +125,7 @@ class Chef def extract_msu_contents(msu_file, destination) with_os_architecture(nil) do - shell_out_with_timeout!("#{ENV['SYSTEMROOT']}\\system32\\expand.exe -f:* #{msu_file} #{destination}") + shell_out!("#{ENV['SYSTEMROOT']}\\system32\\expand.exe -f:* #{msu_file} #{destination}") end end diff --git a/lib/chef/provider/package/openbsd.rb b/lib/chef/provider/package/openbsd.rb index d8c12c6f6c..3408aef944 100644 --- a/lib/chef/provider/package/openbsd.rb +++ b/lib/chef/provider/package/openbsd.rb @@ -72,7 +72,7 @@ class Chef if parts = name.match(/^(.+?)--(.+)/) # use double-dash for stems with flavors, see man page for pkg_add name = parts[1] end - shell_out_compact!("pkg_add", "-r", package_string(name, version), env: { "PKG_PATH" => pkg_path }).status + shell_out!("pkg_add", "-r", package_string(name, version), env: { "PKG_PATH" => pkg_path }).status logger.trace("#{new_resource.package_name} installed") end end @@ -81,7 +81,7 @@ class Chef if parts = name.match(/^(.+?)--(.+)/) name = parts[1] end - shell_out_compact!("pkg_delete", package_string(name, version), env: nil).status + shell_out!("pkg_delete", package_string(name, version), env: nil).status end private @@ -92,7 +92,7 @@ class Chef else new_resource.package_name end - pkg_info = shell_out_compact!("pkg_info", "-e", "#{name}->0", env: nil, returns: [0, 1]) + pkg_info = shell_out!("pkg_info", "-e", "#{name}->0", env: nil, returns: [0, 1]) result = pkg_info.stdout[/^inst:#{Regexp.escape(name)}-(.+?)\s/, 1] logger.trace("installed_version of '#{new_resource.package_name}' is '#{result}'") result @@ -101,7 +101,7 @@ class Chef def candidate_version @candidate_version ||= begin results = [] - shell_out_compact!("pkg_info", "-I", package_string(new_resource.package_name, new_resource.version), env: nil, returns: [0, 1]).stdout.each_line do |line| + shell_out!("pkg_info", "-I", package_string(new_resource.package_name, new_resource.version), env: nil, returns: [0, 1]).stdout.each_line do |line| results << if parts = new_resource.package_name.match(/^(.+?)--(.+)/) line[/^#{Regexp.escape(parts[1])}-(.+?)\s/, 1] else diff --git a/lib/chef/provider/package/pacman.rb b/lib/chef/provider/package/pacman.rb index 2f08ee7d28..4a3b795700 100644 --- a/lib/chef/provider/package/pacman.rb +++ b/lib/chef/provider/package/pacman.rb @@ -32,7 +32,7 @@ class Chef current_resource.package_name(new_resource.package_name) logger.trace("#{new_resource} checking pacman for #{new_resource.package_name}") - status = shell_out_compact("pacman", "-Qi", new_resource.package_name) + status = shell_out("pacman", "-Qi", new_resource.package_name) status.stdout.each_line do |line| case line when /^Version(\s?)*: (.+)$/ @@ -60,7 +60,7 @@ class Chef package_repos = repos.map { |r| Regexp.escape(r) }.join("|") - status = shell_out_compact("pacman", "-Sl") + status = shell_out("pacman", "-Sl") status.stdout.each_line do |line| case line when /^(#{package_repos}) #{Regexp.escape(new_resource.package_name)} (.+)$/ @@ -82,7 +82,7 @@ class Chef end def install_package(name, version) - shell_out_compact!( "pacman", "--sync", "--noconfirm", "--noprogressbar", options, name) + shell_out!( "pacman", "--sync", "--noconfirm", "--noprogressbar", options, name) end def upgrade_package(name, version) @@ -90,7 +90,7 @@ class Chef end def remove_package(name, version) - shell_out_compact!( "pacman", "--remove", "--noconfirm", "--noprogressbar", options, name ) + shell_out!( "pacman", "--remove", "--noconfirm", "--noprogressbar", options, name ) end def purge_package(name, version) diff --git a/lib/chef/provider/package/paludis.rb b/lib/chef/provider/package/paludis.rb index 50267610c2..3550b155d5 100644 --- a/lib/chef/provider/package/paludis.rb +++ b/lib/chef/provider/package/paludis.rb @@ -35,7 +35,7 @@ class Chef installed = false re = Regexp.new("(.*)[[:blank:]](.*)[[:blank:]](.*)$") - shell_out_compact!("cave", "-L", "warning", "print-ids", "-M", "none", "-m", new_resource.package_name, "-f", "%c/%p %v %r\n").stdout.each_line do |line| + shell_out!("cave", "-L", "warning", "print-ids", "-M", "none", "-m", new_resource.package_name, "-f", "%c/%p %v %r\n").stdout.each_line do |line| res = re.match(line) next if res.nil? case res[3] @@ -58,7 +58,7 @@ class Chef else new_resource.package_name.to_s end - shell_out_compact!("cave", "-L", "warning", "resolve", "-x", options, pkg) + shell_out!("cave", "-L", "warning", "resolve", "-x", options, pkg) end def upgrade_package(name, version) @@ -72,7 +72,7 @@ class Chef new_resource.package_name.to_s end - shell_out_compact!("cave", "-L", "warning", "uninstall", "-x", options, pkg) + shell_out!("cave", "-L", "warning", "uninstall", "-x", options, pkg) end def purge_package(name, version) diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb index 4676f0ace4..11cbe99d18 100644 --- a/lib/chef/provider/package/portage.rb +++ b/lib/chef/provider/package/portage.rb @@ -66,7 +66,7 @@ class Chef def candidate_version return @candidate_version if @candidate_version - pkginfo = shell_out_compact("portageq", "best_visible", "/", new_resource.package_name) + pkginfo = shell_out("portageq", "best_visible", "/", new_resource.package_name) if pkginfo.exitstatus != 0 pkginfo.stderr.each_line do |line| @@ -106,7 +106,7 @@ class Chef pkg = "~#{name}-#{$1}" end - shell_out_compact!( "emerge", "-g", "--color", "n", "--nospinner", "--quiet", options, pkg ) + shell_out!( "emerge", "-g", "--color", "n", "--nospinner", "--quiet", options, pkg ) end def upgrade_package(name, version) @@ -120,7 +120,7 @@ class Chef new_resource.package_name.to_s end - shell_out_compact!( "emerge", "--unmerge", "--color", "n", "--nospinner", "--quiet", options, pkg ) + shell_out!( "emerge", "--unmerge", "--color", "n", "--nospinner", "--quiet", options, pkg ) end def purge_package(name, version) diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb index 8e3de23a14..3d070cee17 100644 --- a/lib/chef/provider/package/rpm.rb +++ b/lib/chef/provider/package/rpm.rb @@ -57,7 +57,7 @@ class Chef end logger.trace("#{new_resource} checking rpm status") - shell_out_compact!("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", new_resource.source).stdout.each_line do |line| + shell_out!("rpm", "-qp", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", new_resource.source).stdout.each_line do |line| case line when /^(\S+)\s(\S+)$/ current_resource.package_name($1) @@ -73,7 +73,7 @@ class Chef end logger.trace("#{new_resource} checking install state") - @rpm_status = shell_out_compact("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", current_resource.package_name) + @rpm_status = shell_out("rpm", "-q", "--queryformat", "%{NAME} %{VERSION}-%{RELEASE}\n", current_resource.package_name) @rpm_status.stdout.each_line do |line| case line when /^(\S+)\s(\S+)$/ @@ -88,12 +88,12 @@ class Chef def install_package(name, version) if current_resource.version if allow_downgrade - shell_out_compact!("rpm", options, "-U", "--oldpackage", new_resource.source) + shell_out!("rpm", options, "-U", "--oldpackage", new_resource.source) else - shell_out_compact!("rpm", options, "-U", new_resource.source) + shell_out!("rpm", options, "-U", new_resource.source) end else - shell_out_compact!("rpm", options, "-i", new_resource.source) + shell_out!("rpm", options, "-i", new_resource.source) end end @@ -101,9 +101,9 @@ class Chef def remove_package(name, version) if version - shell_out_compact!("rpm", options, "-e", "#{name}-#{version}") + shell_out!("rpm", options, "-e", "#{name}-#{version}") else - shell_out_compact!("rpm", options, "-e", name) + shell_out!("rpm", options, "-e", name) end end diff --git a/lib/chef/provider/package/rubygems.rb b/lib/chef/provider/package/rubygems.rb index 6b04af547b..d99dce8972 100644 --- a/lib/chef/provider/package/rubygems.rb +++ b/lib/chef/provider/package/rubygems.rb @@ -547,9 +547,9 @@ class Chef end src_str = src.empty? ? "" : " #{src.join(" ")}" if !version.nil? && !version.empty? - shell_out_with_timeout!("#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src_str}#{opts}", env: nil) + shell_out!("#{gem_binary_path} install #{name} -q --no-rdoc --no-ri -v \"#{version}\"#{src_str}#{opts}", env: nil) else - shell_out_with_timeout!("#{gem_binary_path} install \"#{name}\" -q --no-rdoc --no-ri #{src_str}#{opts}", env: nil) + shell_out!("#{gem_binary_path} install \"#{name}\" -q --no-rdoc --no-ri #{src_str}#{opts}", env: nil) end end @@ -573,9 +573,9 @@ class Chef def uninstall_via_gem_command(name, version) if version - shell_out_with_timeout!("#{gem_binary_path} uninstall #{name} -q -x -I -v \"#{version}\"#{opts}", env: nil) + shell_out!("#{gem_binary_path} uninstall #{name} -q -x -I -v \"#{version}\"#{opts}", env: nil) else - shell_out_with_timeout!("#{gem_binary_path} uninstall #{name} -q -x -I -a#{opts}", env: nil) + shell_out!("#{gem_binary_path} uninstall #{name} -q -x -I -a#{opts}", env: nil) end end diff --git a/lib/chef/provider/package/smartos.rb b/lib/chef/provider/package/smartos.rb index e78fcec580..4623196c13 100644 --- a/lib/chef/provider/package/smartos.rb +++ b/lib/chef/provider/package/smartos.rb @@ -43,7 +43,7 @@ class Chef def check_package_state(name) logger.trace("#{new_resource} checking package #{name}") version = nil - info = shell_out_compact!("/opt/local/sbin/pkg_info", "-E", "#{name}*", env: nil, returns: [0, 1]) + info = shell_out!("/opt/local/sbin/pkg_info", "-E", "#{name}*", env: nil, returns: [0, 1]) if info.stdout version = info.stdout[/^#{new_resource.package_name}-(.+)/, 1] @@ -58,7 +58,7 @@ class Chef return @candidate_version if @candidate_version name = nil version = nil - pkg = shell_out_compact!("/opt/local/bin/pkgin", "se", new_resource.package_name, env: nil, returns: [0, 1]) + pkg = shell_out!("/opt/local/bin/pkgin", "se", new_resource.package_name, env: nil, returns: [0, 1]) pkg.stdout.each_line do |line| case line when /^#{new_resource.package_name}/ @@ -72,7 +72,7 @@ class Chef def install_package(name, version) logger.trace("#{new_resource} installing package #{name} version #{version}") package = "#{name}-#{version}" - out = shell_out_compact!("/opt/local/bin/pkgin", "-y", "install", package, env: nil) + out = shell_out!("/opt/local/bin/pkgin", "-y", "install", package, env: nil) end def upgrade_package(name, version) @@ -83,7 +83,7 @@ class Chef def remove_package(name, version) logger.trace("#{new_resource} removing package #{name} version #{version}") package = name.to_s - out = shell_out_compact!("/opt/local/bin/pkgin", "-y", "remove", package, env: nil) + out = shell_out!("/opt/local/bin/pkgin", "-y", "remove", package, env: nil) end end diff --git a/lib/chef/provider/package/solaris.rb b/lib/chef/provider/package/solaris.rb index 1acc25d242..01958df1ee 100644 --- a/lib/chef/provider/package/solaris.rb +++ b/lib/chef/provider/package/solaris.rb @@ -55,7 +55,7 @@ class Chef @package_source_found = ::File.exist?(new_resource.source) if @package_source_found logger.trace("#{new_resource} checking pkg status") - shell_out_compact("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name).stdout.each_line do |line| + shell_out("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name).stdout.each_line do |line| case line when /VERSION:\s+(.+)/ new_resource.version($1) @@ -65,7 +65,7 @@ class Chef end logger.trace("#{new_resource} checking install state") - status = shell_out_compact("pkginfo", "-l", current_resource.package_name) + status = shell_out("pkginfo", "-l", current_resource.package_name) status.stdout.each_line do |line| case line when /VERSION:\s+(.+)/ @@ -83,7 +83,7 @@ class Chef def candidate_version return @candidate_version if @candidate_version - status = shell_out_compact("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name) + status = shell_out("pkginfo", "-l", "-d", new_resource.source, new_resource.package_name) status.stdout.each_line do |line| case line when /VERSION:\s+(.+)/ @@ -106,7 +106,7 @@ class Chef else [ "pkgadd", "-n", "-d", new_resource.source, "all" ] end - shell_out_compact!(command) + shell_out!(command) logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") else command = if ::File.directory?(new_resource.source) # CHEF-4469 @@ -114,7 +114,7 @@ class Chef else [ "pkgadd", "-n", options, "-d", new_resource.source, "all" ] end - shell_out_compact!(*command) + shell_out!(*command) logger.trace("#{new_resource} installed version #{new_resource.version} from: #{new_resource.source}") end end @@ -123,10 +123,10 @@ class Chef def remove_package(name, version) if options.nil? - shell_out_compact!( "pkgrm", "-n", name ) + shell_out!( "pkgrm", "-n", name ) logger.trace("#{new_resource} removed version #{new_resource.version}") else - shell_out_compact!( "pkgrm", "-n", options, name ) + shell_out!( "pkgrm", "-n", options, name ) logger.trace("#{new_resource} removed version #{new_resource.version}") end end diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 325ffc9584..42dd11b43f 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -210,7 +210,7 @@ class Chef end def resolve_source_to_version_obj - shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line| + shell_out!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line| # this is another case of committing the sin of doing some lightweight mangling of RPM versions in ruby -- but the output of the rpm command # does not match what the yum library accepts. case line @@ -260,7 +260,7 @@ class Chef end def yum(*args) - shell_out_compact!(yum_binary, *args) + shell_out!(yum_binary, *args) end def safe_version_array diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb index 5aa4ec7762..058fcf1a6b 100644 --- a/lib/chef/provider/package/zypper.rb +++ b/lib/chef/provider/package/zypper.rb @@ -35,7 +35,7 @@ class Chef candidate_version = current_version = nil is_installed = false logger.trace("#{new_resource} checking zypper") - status = shell_out_compact!("zypper", "--non-interactive", "info", package_name) + status = shell_out!("zypper", "--non-interactive", "info", package_name) status.stdout.each_line do |line| case line when /^Version *: (.+) *$/ @@ -86,7 +86,7 @@ class Chef def locked_packages @locked_packages ||= begin - locked = shell_out_compact!("zypper", "locks") + locked = shell_out!("zypper", "locks") locked.stdout.each_line.map do |line| line.split("|").shift(2).last.strip end @@ -144,9 +144,9 @@ class Chef def zypper_package(command, *options, names, versions) zipped_names = zip(names, versions) if zypper_version < 1.0 - shell_out_compact!("zypper", gpg_checks, command, *options, "-y", names) + shell_out!("zypper", gpg_checks, command, *options, "-y", names) else - shell_out_compact!("zypper", "--non-interactive", gpg_checks, command, *options, zipped_names) + shell_out!("zypper", "--non-interactive", gpg_checks, command, *options, zipped_names) end end diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb index b23d0307cc..2195abfe29 100644 --- a/lib/chef/provider/route.rb +++ b/lib/chef/provider/route.rb @@ -133,7 +133,7 @@ class Chef else command = generate_command(:add) converge_by("run #{command.join(' ')} to add route") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} added") end end @@ -146,7 +146,7 @@ class Chef if is_running command = generate_command(:delete) converge_by("run #{command.join(' ')} to delete route ") do - shell_out_compact!(command) + shell_out!(command) logger.info("#{new_resource} removed") end else diff --git a/lib/chef/provider/service/simple.rb b/lib/chef/provider/service/simple.rb index 3270deb781..9bfcbb1410 100644 --- a/lib/chef/provider/service/simple.rb +++ b/lib/chef/provider/service/simple.rb @@ -163,6 +163,7 @@ class Chef end def ps_cmd + # XXX: magic attributes are a shitty api, need something better here and deprecate this attribute @run_context.node[:command] && @run_context.node[:command][:ps] end end diff --git a/lib/chef/provider/user/aix.rb b/lib/chef/provider/user/aix.rb index be6ff9d750..aca0511e41 100644 --- a/lib/chef/provider/user/aix.rb +++ b/lib/chef/provider/user/aix.rb @@ -24,7 +24,7 @@ class Chef provides :aix_user def create_user - shell_out_compact!("useradd", universal_options, useradd_options, new_resource.username) + shell_out!("useradd", universal_options, useradd_options, new_resource.username) add_password end @@ -32,11 +32,11 @@ class Chef add_password manage_home return if universal_options.empty? && usermod_options.empty? - shell_out_compact!("usermod", universal_options, usermod_options, new_resource.username) + shell_out!("usermod", universal_options, usermod_options, new_resource.username) end def remove_user - shell_out_compact!("userdel", userdel_options, new_resource.username) + shell_out!("userdel", userdel_options, new_resource.username) end # Aix does not support -r like other unix, sytem account is created by adding to 'system' group @@ -66,7 +66,7 @@ class Chef end def check_lock - lock_info = shell_out_compact!("lsuser", "-a", "account_locked", new_resource.username) + lock_info = shell_out!("lsuser", "-a", "account_locked", new_resource.username) if whyrun_mode? && passwd_s.stdout.empty? && lock_info.stderr.match(/does not exist/) # if we're in whyrun mode and the user is not yet created we assume it would be return false @@ -85,11 +85,11 @@ class Chef end def lock_user - shell_out_compact!("chuser", "account_locked=true", new_resource.username) + shell_out!("chuser", "account_locked=true", new_resource.username) end def unlock_user - shell_out_compact!("chuser", "account_locked=false", new_resource.username) + shell_out!("chuser", "account_locked=false", new_resource.username) end def universal_options diff --git a/lib/chef/provider/user/dscl.rb b/lib/chef/provider/user/dscl.rb index 67fe8f3762..c22329d0d6 100644 --- a/lib/chef/provider/user/dscl.rb +++ b/lib/chef/provider/user/dscl.rb @@ -326,7 +326,7 @@ user password using shadow hash.") end def ditto_home - shell_out_compact!("/usr/sbin/createhomedir", "-c", "-u", "#{new_resource.username}") + shell_out!("/usr/sbin/createhomedir", "-c", "-u", "#{new_resource.username}") end def move_home @@ -364,7 +364,7 @@ user password using shadow hash.") # Shadow info is saved as binary plist. Convert the info to binary plist. shadow_info_binary = StringIO.new - shell_out_compact("plutil", "-convert", "binary1", "-o", "-", "-", + shell_out("plutil", "-convert", "binary1", "-o", "-", "-", input: shadow_info.to_plist, live_stream: shadow_info_binary) if user_info.nil? @@ -586,7 +586,7 @@ user password using shadow hash.") # We flush the cache here in order to make sure that we read fresh information # for the user. - shell_out_compact("dscacheutil", "-flushcache") # FIXME: this is MacOS version dependent + shell_out("dscacheutil", "-flushcache") # FIXME: this is MacOS version dependent begin user_plist_file = "#{USER_PLIST_DIRECTORY}/#{new_resource.username}.plist" @@ -654,7 +654,7 @@ user password using shadow hash.") end def run_dscl(*args) - result = shell_out_compact("dscl", ".", "-#{args[0]}", args[1..-1]) + result = shell_out("dscl", ".", "-#{args[0]}", args[1..-1]) return "" if ( args.first =~ /^delete/ ) && ( result.exitstatus != 0 ) raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") unless result.exitstatus == 0 raise(Chef::Exceptions::DsclCommandFailed, "dscl error: #{result.inspect}") if result.stdout =~ /No such key: / @@ -662,7 +662,7 @@ user password using shadow hash.") end def run_plutil(*args) - result = shell_out_compact("plutil", "-#{args[0]}", args[1..-1]) + result = shell_out("plutil", "-#{args[0]}", args[1..-1]) raise(Chef::Exceptions::PlistUtilCommandFailed, "plutil error: #{result.inspect}") unless result.exitstatus == 0 if result.stdout.encoding == Encoding::ASCII_8BIT result.stdout.encode("utf-8", "binary", undef: :replace, invalid: :replace, replace: "?") @@ -672,7 +672,7 @@ user password using shadow hash.") end def convert_binary_plist_to_xml(binary_plist_string) - shell_out_compact("plutil", "-convert", "xml1", "-o", "-", "-", input: binary_plist_string).stdout + shell_out("plutil", "-convert", "xml1", "-o", "-", "-", input: binary_plist_string).stdout end def convert_to_binary(string) diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb index a846d2657a..7d3a3c1163 100644 --- a/lib/chef/provider/user/linux.rb +++ b/lib/chef/provider/user/linux.rb @@ -24,23 +24,23 @@ class Chef provides :user, os: "linux" def create_user - shell_out_compact!("useradd", universal_options, useradd_options, new_resource.username) + shell_out!("useradd", universal_options, useradd_options, new_resource.username) end def manage_user - shell_out_compact!("usermod", universal_options, usermod_options, new_resource.username) + shell_out!("usermod", universal_options, usermod_options, new_resource.username) end def remove_user - shell_out_compact!("userdel", userdel_options, new_resource.username) + shell_out!("userdel", userdel_options, new_resource.username) end def lock_user - shell_out_compact!("usermod", "-L", new_resource.username) + shell_out!("usermod", "-L", new_resource.username) end def unlock_user - shell_out_compact!("usermod", "-U", new_resource.username) + shell_out!("usermod", "-U", new_resource.username) end # common to usermod and useradd @@ -88,7 +88,7 @@ class Chef def check_lock # there's an old bug in rhel (https://bugzilla.redhat.com/show_bug.cgi?id=578534) # which means that both 0 and 1 can be success. - passwd_s = shell_out_compact("passwd", "-S", new_resource.username, returns: [ 0, 1 ]) + passwd_s = shell_out("passwd", "-S", new_resource.username, returns: [ 0, 1 ]) # checking "does not exist" has to come before exit code handling since centos and ubuntu differ in exit codes if passwd_s.stderr =~ /does not exist/ diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb index 695dbfd539..42d44bab51 100644 --- a/lib/chef/provider/user/pw.rb +++ b/lib/chef/provider/user/pw.rb @@ -31,19 +31,19 @@ class Chef end def create_user - shell_out_compact!("pw", "useradd", set_options) + shell_out!("pw", "useradd", set_options) modify_password end def manage_user - shell_out_compact!("pw", "usermod", set_options) + shell_out!("pw", "usermod", set_options) modify_password end def remove_user command = [ "pw", "userdel", new_resource.username ] command << "-r" if new_resource.manage_home - shell_out_compact!(command) + shell_out!(command) end def check_lock @@ -57,11 +57,11 @@ class Chef end def lock_user - shell_out_compact!("pw", "lock", new_resource.username) + shell_out!("pw", "lock", new_resource.username) end def unlock_user - shell_out_compact!("pw", "unlock", new_resource.username) + shell_out!("pw", "unlock", new_resource.username) end def set_options diff --git a/lib/chef/provider/user/solaris.rb b/lib/chef/provider/user/solaris.rb index 1abe660cfd..38e7f8cb31 100644 --- a/lib/chef/provider/user/solaris.rb +++ b/lib/chef/provider/user/solaris.rb @@ -30,18 +30,18 @@ class Chef PASSWORD_FILE = "/etc/shadow" def create_user - shell_out_compact!("useradd", universal_options, useradd_options, new_resource.username) + shell_out!("useradd", universal_options, useradd_options, new_resource.username) manage_password end def manage_user manage_password return if universal_options.empty? && usermod_options.empty? - shell_out_compact!("usermod", universal_options, usermod_options, new_resource.username) + shell_out!("usermod", universal_options, usermod_options, new_resource.username) end def remove_user - shell_out_compact!("userdel", userdel_options, new_resource.username) + shell_out!("userdel", userdel_options, new_resource.username) end def check_lock @@ -56,11 +56,11 @@ class Chef end def lock_user - shell_out_compact!("passwd", "-l", new_resource.username) + shell_out!("passwd", "-l", new_resource.username) end def unlock_user - shell_out_compact!("passwd", "-u", new_resource.username) + shell_out!("passwd", "-u", new_resource.username) end private diff --git a/lib/chef/provider/user/useradd.rb b/lib/chef/provider/user/useradd.rb index c09cc0d3a5..855da325a0 100644 --- a/lib/chef/provider/user/useradd.rb +++ b/lib/chef/provider/user/useradd.rb @@ -36,7 +36,7 @@ class Chef useradd.concat(universal_options) useradd.concat(useradd_options) end - shell_out_compact!(command) + shell_out!(command) end def manage_user @@ -44,7 +44,7 @@ class Chef command = compile_command("usermod") do |u| u.concat(universal_options) end - shell_out_compact!(command) + shell_out!(command) end def remove_user @@ -52,13 +52,13 @@ class Chef command << "-r" if new_resource.manage_home command << "-f" if new_resource.force command << new_resource.username - shell_out_compact!(command) + shell_out!(command) end def check_lock # we can get an exit code of 1 even when it's successful on # rhel/centos (redhat bug 578534). See additional error checks below. - passwd_s = shell_out_compact!("passwd", "-S", new_resource.username, returns: [0, 1]) + passwd_s = shell_out!("passwd", "-S", new_resource.username, returns: [0, 1]) if whyrun_mode? && passwd_s.stdout.empty? && passwd_s.stderr.match(/does not exist/) # if we're in whyrun mode and the user is not yet created we assume it would be return false @@ -79,7 +79,7 @@ class Chef unless passwd_s.exitstatus == 0 raise_lock_error = false if %w{redhat centos}.include?(node[:platform]) - passwd_version_check = shell_out_compact!("rpm", "-q", "passwd") + passwd_version_check = shell_out!("rpm", "-q", "passwd") passwd_version = passwd_version_check.stdout.chomp unless passwd_version == "passwd-0.73-1" @@ -96,11 +96,11 @@ class Chef end def lock_user - shell_out_compact!("usermod", "-L", new_resource.username) + shell_out!("usermod", "-L", new_resource.username) end def unlock_user - shell_out_compact!("usermod", "-U", new_resource.username) + shell_out!("usermod", "-U", new_resource.username) end def compile_command(base_command) diff --git a/lib/chef/resource/freebsd_package.rb b/lib/chef/resource/freebsd_package.rb index 234bbf8fd2..e85a75e906 100644 --- a/lib/chef/resource/freebsd_package.rb +++ b/lib/chef/resource/freebsd_package.rb @@ -46,7 +46,7 @@ class Chef # # @return [Boolean] do we support pkgng def supports_pkgng? - ships_with_pkgng? || !!shell_out_compact!("make", "-V", "WITH_PKGNG", :env => nil).stdout.match(/yes/i) + ships_with_pkgng? || !!shell_out!("make", "-V", "WITH_PKGNG", :env => nil).stdout.match(/yes/i) end private diff --git a/lib/chef/util/selinux.rb b/lib/chef/util/selinux.rb index 0d973b0376..fb0c98cff5 100644 --- a/lib/chef/util/selinux.rb +++ b/lib/chef/util/selinux.rb @@ -52,7 +52,7 @@ class Chef restorecon_flags << "-r" if recursive restorecon_flags << file_path Chef::Log.trace("Restoring selinux security content with #{restorecon_path}") - shell_out_compact!(restorecon_path, restorecon_flags) + shell_out!(restorecon_path, restorecon_flags) else Chef::Log.warn "Can not find 'restorecon' on the system. Skipping selinux security context restore." end |