diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-04-01 10:12:27 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-04-01 10:12:27 -0700 |
commit | 9a42b4d5588013d36e4357702911119400cc1ef4 (patch) | |
tree | 05607cc55129ba139369b470849417e3f491176e | |
parent | ad3ef0854ffd962f7d124612ee0bad18115212c5 (diff) | |
download | chef-9a42b4d5588013d36e4357702911119400cc1ef4.tar.gz |
convert remaining popen4 code to shell_out
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/provider/erl_call.rb | 44 | ||||
-rw-r--r-- | lib/chef/provider/mdadm.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/service/debian.rb | 36 | ||||
-rw-r--r-- | lib/chef/provider/service/upstart.rb | 21 | ||||
-rw-r--r-- | lib/chef/provider/user/pw.rb | 8 |
5 files changed, 35 insertions, 78 deletions
diff --git a/lib/chef/provider/erl_call.rb b/lib/chef/provider/erl_call.rb index 56591e2068..b73341bb16 100644 --- a/lib/chef/provider/erl_call.rb +++ b/lib/chef/provider/erl_call.rb @@ -56,44 +56,18 @@ class Chef command = "erl_call -e #{distributed} #{node} #{cookie}" converge_by("run erlang block") do - begin - pid, stdin, stdout, stderr = popen4(command, :waitlast => true) + so = shell_out!(command, input: new_resource.code) - Chef::Log.debug("#{new_resource} running") - Chef::Log.debug("#{new_resource} command: #{command}") - Chef::Log.debug("#{new_resource} code: #{new_resource.code}") - - new_resource.code.each_line { |line| stdin.puts(line.chomp) } - - stdin.close - - Chef::Log.debug("#{new_resource} output: ") - - stdout_output = "" - stdout.each_line { |line| stdout_output << line } - stdout.close - - stderr_output = "" - stderr.each_line { |line| stderr_output << line } - stderr.close - - # fail if stderr contains anything - if stderr_output.length > 0 - raise Chef::Exceptions::ErlCall, stderr_output - end - - # fail if the first 4 characters aren't "{ok," - unless stdout_output[0..3].include?("{ok,") - raise Chef::Exceptions::ErlCall, stdout_output - end - - new_resource.updated_by_last_action(true) + # fail if stderr contains anything + if so.stderr.length > 0 + raise Chef::Exceptions::ErlCall, so.stderr + end - Chef::Log.debug("#{new_resource} #{stdout_output}") - Chef::Log.info("#{@new_resouce} ran successfully") - ensure - Process.wait(pid) if pid + # fail if the first 4 characters aren't "{ok," + unless so.stdout[0..3].include?("{ok,") + raise Chef::Exceptions::ErlCall, so.stdout end + end end diff --git a/lib/chef/provider/mdadm.rb b/lib/chef/provider/mdadm.rb index 5c972462bc..7d7b26acfa 100644 --- a/lib/chef/provider/mdadm.rb +++ b/lib/chef/provider/mdadm.rb @@ -25,10 +25,6 @@ class Chef provides :mdadm - def popen4 - raise Exception, "deprecated" - end - def load_current_resource @current_resource = Chef::Resource::Mdadm.new(new_resource.name) current_resource.raid_device(new_resource.raid_device) diff --git a/lib/chef/provider/service/debian.rb b/lib/chef/provider/service/debian.rb index 9d11032055..58a43d27f8 100644 --- a/lib/chef/provider/service/debian.rb +++ b/lib/chef/provider/service/debian.rb @@ -1,6 +1,6 @@ # # Author:: AJ Christensen (<aj@hjksolutions.com>) -# Copyright:: Copyright 2008-2016, Chef Software Inc. +# Copyright:: Copyright 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -35,8 +35,6 @@ class Chef def load_current_resource super - @priority_success = true - @rcd_status = nil current_resource.priority(get_priority) current_resource.enabled(service_currently_enabled?(current_resource.priority)) current_resource @@ -54,8 +52,8 @@ class Chef end requirements.assert(:all_actions) do |a| - a.assertion { @priority_success } - a.failure_message Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{current_resource.service_name} failed - #{@rcd_status.inspect}" + a.assertion { @so_priority.exitstatus == 0 } + a.failure_message Chef::Exceptions::Service, "/usr/sbin/update-rc.d -n -f #{current_resource.service_name} failed - #{@so_priority.inspect}" # This can happen if the service is not yet installed,so we'll fake it. a.whyrun ["Unable to determine priority of service, assuming service would have been correctly installed earlier in the run.", "Assigning temporary priorities to continue.", @@ -75,19 +73,18 @@ class Chef def get_priority priority = {} - @rcd_status = popen4("/usr/sbin/update-rc.d -n -f #{current_resource.service_name} remove") do |pid, stdin, stdout, stderr| - - [stdout, stderr].each do |iop| - iop.each_line do |line| - if UPDATE_RC_D_PRIORITIES =~ line - # priority[runlevel] = [ S|K, priority ] - # S = Start, K = Kill - # debian runlevels: 0 Halt, 1 Singleuser, 2 Multiuser, 3-5 == 2, 6 Reboot - priority[$1] = [($2 == "S" ? :start : :stop), $3] - end - if line =~ UPDATE_RC_D_ENABLED_MATCHES - enabled = true - end + @so_priority = shell_out!("/usr/sbin/update-rc.d -n -f #{current_resource.service_name} remove") + + [@so_priority.stdout, @so_priority.stderr].each do |iop| + iop.each_line do |line| + if UPDATE_RC_D_PRIORITIES =~ line + # priority[runlevel] = [ S|K, priority ] + # S = Start, K = Kill + # debian runlevels: 0 Halt, 1 Singleuser, 2 Multiuser, 3-5 == 2, 6 Reboot + priority[$1] = [($2 == "S" ? :start : :stop), $3] + end + if line =~ UPDATE_RC_D_ENABLED_MATCHES + enabled = true end end end @@ -98,9 +95,6 @@ class Chef priority = priority[2].last end - unless @rcd_status.exitstatus == 0 - @priority_success = false - end priority end diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index f10660f57a..9783b3b3a5 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -240,17 +240,16 @@ class Chef def upstart_goal_state command = "/sbin/status #{@job}" - status = popen4(command) do |pid, stdin, stdout, stderr| - stdout.each_line do |line| - # service goal/state - # OR - # service (instance) goal/state - # OR - # service (goal) state - line =~ UPSTART_STATE_FORMAT - data = Regexp.last_match - return data[1] - end + so = shell_out(command) + so.stdout.each_line do |line| + # service goal/state + # OR + # service (instance) goal/state + # OR + # service (goal) state + line =~ UPSTART_STATE_FORMAT + data = Regexp.last_match + return data[1] end end diff --git a/lib/chef/provider/user/pw.rb b/lib/chef/provider/user/pw.rb index cf47bb7fde..06bd221d26 100644 --- a/lib/chef/provider/user/pw.rb +++ b/lib/chef/provider/user/pw.rb @@ -94,13 +94,7 @@ class Chef if !new_resource.password.nil? && (current_resource.password != new_resource.password) Chef::Log.debug("#{new_resource} updating password") command = "pw usermod #{new_resource.username} -H 0" - status = popen4(command, waitlast: true) do |pid, stdin, stdout, stderr| - stdin.puts new_resource.password.to_s - end - - unless status.exitstatus == 0 - raise Chef::Exceptions::User, "pw failed - #{status.inspect}!" - end + shell_out!(command, input: new_resource.password.to_s) else Chef::Log.debug("#{new_resource} no change needed to password") end |