summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaustubh-d <kaustubh@clogeny.com>2014-11-18 14:56:22 +0530
committerBryan McLellan <btm@opscode.com>2015-02-17 09:16:38 -0500
commit6909f4074dbd9cee5906333f693bd282476a6ac5 (patch)
tree7deb7fcea3b0409b23986f317649f8ec18fa241e
parentaa9b233614da81c506929cc1c36eb509a4e2c97e (diff)
downloadchef-6909f4074dbd9cee5906333f693bd282476a6ac5.tar.gz
fix aix related providers to replace popen4 with mixlib shell_out
-rw-r--r--lib/chef/provider/group.rb2
-rw-r--r--lib/chef/provider/group/dscl.rb7
-rw-r--r--lib/chef/provider/ifconfig.rb50
-rw-r--r--lib/chef/provider/ifconfig/aix.rb52
-rw-r--r--lib/chef/provider/mount.rb4
-rw-r--r--lib/chef/provider/mount/mount.rb7
-rw-r--r--lib/chef/provider/package.rb5
-rw-r--r--lib/chef/provider/package/aix.rb55
-rw-r--r--lib/chef/provider/package/dpkg.rb29
-rw-r--r--lib/chef/provider/package/macports.rb11
-rw-r--r--lib/chef/provider/package/pacman.rb28
-rw-r--r--lib/chef/provider/package/portage.rb7
-rw-r--r--lib/chef/provider/package/rpm.rb3
-rw-r--r--lib/chef/provider/package/solaris.rb38
-rw-r--r--lib/chef/provider/package/yum.rb6
-rw-r--r--lib/chef/provider/package/zypper.rb35
-rwxr-xr-xspec/functional/resource/aix_service_spec.rb3
-rw-r--r--spec/functional/version_spec.rb2
-rw-r--r--spec/unit/provider/group/dscl_spec.rb13
-rw-r--r--spec/unit/provider/ifconfig/aix_spec.rb5
-rw-r--r--spec/unit/provider/ifconfig_spec.rb4
-rw-r--r--spec/unit/provider/mount/mount_spec.rb12
-rw-r--r--spec/unit/provider/package/aix_spec.rb43
-rw-r--r--spec/unit/provider/package/dpkg_spec.rb26
-rw-r--r--spec/unit/provider/package/macports_spec.rb28
-rw-r--r--spec/unit/provider/package/pacman_spec.rb29
-rw-r--r--spec/unit/provider/package/portage_spec.rb22
-rw-r--r--spec/unit/provider/package/solaris_spec.rb45
-rw-r--r--spec/unit/provider/package/zypper_spec.rb21
29 files changed, 283 insertions, 309 deletions
diff --git a/lib/chef/provider/group.rb b/lib/chef/provider/group.rb
index 35a16c870c..29738cc046 100644
--- a/lib/chef/provider/group.rb
+++ b/lib/chef/provider/group.rb
@@ -17,12 +17,14 @@
#
require 'chef/provider'
+require 'chef/mixin/shell_out'
require 'chef/mixin/command'
require 'etc'
class Chef
class Provider
class Group < Chef::Provider
+ include Chef::Mixin::ShellOut
include Chef::Mixin::Command
attr_accessor :group_exists
attr_accessor :change_desc
diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb
index e06c090f50..a59a94aa98 100644
--- a/lib/chef/provider/group/dscl.rb
+++ b/lib/chef/provider/group/dscl.rb
@@ -24,10 +24,9 @@ class Chef
def dscl(*args)
host = "."
stdout_result = ""; stderr_result = ""; cmd = "dscl #{host} -#{args.join(' ')}"
- status = popen4(cmd) do |pid, stdin, stdout, stderr|
- stdout.each { |line| stdout_result << line }
- stderr.each { |line| stderr_result << line }
- end
+ status = shell_out(cmd)
+ status.stdout.each_line { |line| stdout_result << line }
+ status.stderr.each_line { |line| stderr_result << line }
return [cmd, status, stdout_result, stderr_result]
end
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index ac52100b56..06080c90c3 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -18,6 +18,7 @@
require 'chef/log'
require 'chef/mixin/command'
+require 'chef/mixin/shell_out'
require 'chef/provider'
require 'chef/resource/file'
require 'chef/exceptions'
@@ -38,6 +39,7 @@ require 'erb'
class Chef
class Provider
class Ifconfig < Chef::Provider
+ include Chef::Mixin::ShellOut
include Chef::Mixin::Command
attr_accessor :config_template
@@ -59,32 +61,30 @@ class Chef
@ifconfig_success = true
@interfaces = {}
- @status = popen4("ifconfig") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
-
- if !line[0..9].strip.empty?
- @int_name = line[0..9].strip
- @interfaces[@int_name] = {"hwaddr" => (line =~ /(HWaddr)/ ? ($') : "nil").strip.chomp }
- else
- @interfaces[@int_name]["inet_addr"] = (line =~ /inet addr:(\S+)/ ? ($1) : "nil") if line =~ /inet addr:/
- @interfaces[@int_name]["bcast"] = (line =~ /Bcast:(\S+)/ ? ($1) : "nil") if line =~ /Bcast:/
- @interfaces[@int_name]["mask"] = (line =~ /Mask:(\S+)/ ? ($1) : "nil") if line =~ /Mask:/
- @interfaces[@int_name]["mtu"] = (line =~ /MTU:(\S+)/ ? ($1) : "nil") if line =~ /MTU:/
- @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? ($1) : "nil") if line =~ /Metric:/
- end
+ @status = shell_out("ifconfig")
+ @status.stdout.each_line do |line|
+ if !line[0..9].strip.empty?
+ @int_name = line[0..9].strip
+ @interfaces[@int_name] = {"hwaddr" => (line =~ /(HWaddr)/ ? ($') : "nil").strip.chomp }
+ else
+ @interfaces[@int_name]["inet_addr"] = (line =~ /inet addr:(\S+)/ ? ($1) : "nil") if line =~ /inet addr:/
+ @interfaces[@int_name]["bcast"] = (line =~ /Bcast:(\S+)/ ? ($1) : "nil") if line =~ /Bcast:/
+ @interfaces[@int_name]["mask"] = (line =~ /Mask:(\S+)/ ? ($1) : "nil") if line =~ /Mask:/
+ @interfaces[@int_name]["mtu"] = (line =~ /MTU:(\S+)/ ? ($1) : "nil") if line =~ /MTU:/
+ @interfaces[@int_name]["metric"] = (line =~ /Metric:(\S+)/ ? ($1) : "nil") if line =~ /Metric:/
+ end
- if @interfaces.has_key?(@new_resource.device)
- @interface = @interfaces.fetch(@new_resource.device)
-
- @current_resource.target(@new_resource.target)
- @current_resource.device(@new_resource.device)
- @current_resource.inet_addr(@interface["inet_addr"])
- @current_resource.hwaddr(@interface["hwaddr"])
- @current_resource.bcast(@interface["bcast"])
- @current_resource.mask(@interface["mask"])
- @current_resource.mtu(@interface["mtu"])
- @current_resource.metric(@interface["metric"])
- end
+ if @interfaces.has_key?(@new_resource.device)
+ @interface = @interfaces.fetch(@new_resource.device)
+
+ @current_resource.target(@new_resource.target)
+ @current_resource.device(@new_resource.device)
+ @current_resource.inet_addr(@interface["inet_addr"])
+ @current_resource.hwaddr(@interface["hwaddr"])
+ @current_resource.bcast(@interface["bcast"])
+ @current_resource.mask(@interface["mask"])
+ @current_resource.mtu(@interface["mtu"])
+ @current_resource.metric(@interface["metric"])
end
end
@current_resource
diff --git a/lib/chef/provider/ifconfig/aix.rb b/lib/chef/provider/ifconfig/aix.rb
index 460b1ba7f2..8fead44bc6 100644
--- a/lib/chef/provider/ifconfig/aix.rb
+++ b/lib/chef/provider/ifconfig/aix.rb
@@ -30,35 +30,33 @@ class Chef
found_interface = false
interface = {}
- @status = popen4("ifconfig -a") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
-
- if !found_interface
- if line =~ /^(\S+):\sflags=(\S+)/
- # We have interface name, if this is the interface for @current_resource, load info else skip till next interface is found.
- if $1 == @new_resource.device
- # Found interface
- found_interface = true
- @interface_exists = true
- @current_resource.target(@new_resource.target)
- @current_resource.device($1)
- interface[:flags] = $2
- @current_resource.metric($1) if line =~ /metric\s(\S+)/
- end
+ @status = shell_out("ifconfig -a")
+ @status.stdout.each_line do |line|
+ if !found_interface
+ if line =~ /^(\S+):\sflags=(\S+)/
+ # We have interface name, if this is the interface for @current_resource, load info else skip till next interface is found.
+ if $1 == @new_resource.device
+ # Found interface
+ found_interface = true
+ @interface_exists = true
+ @current_resource.target(@new_resource.target)
+ @current_resource.device($1)
+ interface[:flags] = $2
+ @current_resource.metric($1) if line =~ /metric\s(\S+)/
end
+ end
+ else
+ # parse interface related information, stop when next interface is found.
+ if line =~ /^(\S+):\sflags=(\S+)/
+ # we are done parsing interface info and hit another one, so stop.
+ found_interface = false
+ break
else
- # parse interface related information, stop when next interface is found.
- if line =~ /^(\S+):\sflags=(\S+)/
- # we are done parsing interface info and hit another one, so stop.
- found_interface = false
- break
- else
- if found_interface
- # read up interface info
- @current_resource.inet_addr($1) if line =~ /inet\s(\S+)\s/
- @current_resource.bcast($1) if line =~ /broadcast\s(\S+)/
- @current_resource.mask(hex_to_dec_netmask($1)) if line =~ /netmask\s(\S+)\s/
- end
+ if found_interface
+ # read up interface info
+ @current_resource.inet_addr($1) if line =~ /inet\s(\S+)\s/
+ @current_resource.bcast($1) if line =~ /broadcast\s(\S+)/
+ @current_resource.mask(hex_to_dec_netmask($1)) if line =~ /netmask\s(\S+)\s/
end
end
end
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index b46604260e..1631d87033 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -18,14 +18,14 @@
#
require 'chef/log'
-require 'chef/mixin/command'
+require 'chef/mixin/shell_out'
require 'chef/provider'
class Chef
class Provider
class Mount < Chef::Provider
- include Chef::Mixin::Command
+ include Chef::Mixin::ShellOut
attr_accessor :unmount_retries
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index c1d4fb2223..0a6e269d2d 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -213,10 +213,9 @@ class Chef
@real_device = @new_resource.device
else
@real_device = ""
- status = popen4("/sbin/findfs #{device_fstab}") do |pid, stdin, stdout, stderr|
- device_line = stdout.first # stdout.first consumes
- @real_device = device_line.chomp unless device_line.nil?
- end
+ ret = shell_out("/sbin/findfs #{device_fstab}")
+ device_line = ret.stdout.lines.first # stdout.first consumes
+ @real_device = device_line.chomp unless device_line.nil?
end
end
@real_device
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index fd317a3a31..de6d399ee3 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -16,6 +16,7 @@
# limitations under the License.
#
+require 'chef/mixin/shell_out'
require 'chef/mixin/command'
require 'chef/log'
require 'chef/file_cache'
@@ -24,9 +25,7 @@ require 'chef/platform'
class Chef
class Provider
class Package < Chef::Provider
-
- # @todo: validate no subclasses need this and nuke it
- include Chef::Mixin::Command
+ include Chef::Mixin::ShellOut
#
# Hook that subclasses use to populate the candidate_version(s)
diff --git a/lib/chef/provider/package/aix.rb b/lib/chef/provider/package/aix.rb
index 88de4679ba..107f914c05 100644
--- a/lib/chef/provider/package/aix.rb
+++ b/lib/chef/provider/package/aix.rb
@@ -52,34 +52,30 @@ class Chef
@package_source_found = ::File.exists?(@new_resource.source)
if @package_source_found
Chef::Log.debug("#{@new_resource} checking pkg status")
- status = popen4("installp -L -d #{@new_resource.source}") do |pid, stdin, stdout, stderr|
- package_found = false
- stdout.each do |line|
- case line
- when /#{@new_resource.package_name}:/
- package_found = true
- fields = line.split(":")
- @new_resource.version(fields[2])
- end
+ ret = shell_out("installp -L -d #{@new_resource.source}")
+ ret.stdout.each_line do | line |
+ case line
+ when /#{@new_resource.package_name}:/
+ fields = line.split(":")
+ @new_resource.version(fields[2])
end
end
end
end
Chef::Log.debug("#{@new_resource} checking install state")
- status = popen4("lslpp -lcq #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /#{@current_resource.package_name}/
- fields = line.split(":")
- Chef::Log.debug("#{@new_resource} version #{fields[2]} is already installed")
- @current_resource.version(fields[2])
- end
+ ret = shell_out("lslpp -lcq #{@current_resource.package_name}")
+ ret.stdout.each_line do | line |
+ case line
+ when /#{@current_resource.package_name}/
+ fields = line.split(":")
+ Chef::Log.debug("#{@new_resource} version #{fields[2]} is already installed")
+ @current_resource.version(fields[2])
end
end
- unless status.exitstatus == 0 || status.exitstatus == 1
- raise Chef::Exceptions::Package, "lslpp failed - #{status.inspect}!"
+ unless ret.exitstatus == 0 || ret.exitstatus == 1
+ raise Chef::Exceptions::Package, "lslpp failed - #{ret.format_for_exception}!"
end
@current_resource
@@ -87,19 +83,18 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
- status = popen4("installp -L -d #{@new_resource.source}") do |pid, stdin, stdout, stderr|
- stdout.each_line do |line|
- case line
- when /\w:#{Regexp.escape(@new_resource.package_name)}:(.*)/
- fields = line.split(":")
- @candidate_version = fields[2]
- @new_resource.version(fields[2])
- Chef::Log.debug("#{@new_resource} setting install candidate version to #{@candidate_version}")
- end
+ 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)}:(.*)/
+ fields = line.split(":")
+ @candidate_version = fields[2]
+ @new_resource.version(fields[2])
+ Chef::Log.debug("#{@new_resource} setting install candidate version to #{@candidate_version}")
end
end
- unless status.exitstatus == 0
- raise Chef::Exceptions::Package, "installp -L -d #{@new_resource.source} - #{status.inspect}!"
+ unless ret.exitstatus == 0
+ raise Chef::Exceptions::Package, "installp -L -d #{@new_resource.source} - #{ret.format_for_exception}!"
end
@candidate_version
end
diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb
index 3a9cecc660..1500aa9a7e 100644
--- a/lib/chef/provider/package/dpkg.rb
+++ b/lib/chef/provider/package/dpkg.rb
@@ -61,12 +61,10 @@ class Chef
if @source_exists
# Get information from the package if supplied
Chef::Log.debug("#{@new_resource} checking dpkg status")
- status = popen4("dpkg-deb -W #{@new_resource.source}") do |pid, stdin, stdout, stderr|
- stdout.each_line do |line|
- if pkginfo = DPKG_INFO.match(line)
- @current_resource.package_name(pkginfo[1])
- @new_resource.version(pkginfo[2])
- end
+ shell_out("dpkg-deb -W #{@new_resource.source}").stdout.each_line do |line|
+ if pkginfo = DPKG_INFO.match(line)
+ @current_resource.package_name(pkginfo[1])
+ @new_resource.version(pkginfo[2])
end
end
else
@@ -79,16 +77,15 @@ class Chef
# Check to see if it is installed
package_installed = nil
Chef::Log.debug("#{@new_resource} checking install state")
- status = popen4("dpkg -s #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each_line do |line|
- case line
- when DPKG_INSTALLED
- package_installed = true
- when DPKG_VERSION
- if package_installed
- Chef::Log.debug("#{@new_resource} current version is #{$1}")
- @current_resource.version($1)
- end
+ status = shell_out("dpkg -s #{@current_resource.package_name}")
+ status.stdout.each_line do |line|
+ case line
+ when DPKG_INSTALLED
+ package_installed = true
+ when DPKG_VERSION
+ if package_installed
+ Chef::Log.debug("#{@new_resource} current version is #{$1}")
+ @current_resource.version($1)
end
end
end
diff --git a/lib/chef/provider/package/macports.rb b/lib/chef/provider/package/macports.rb
index 248dc75d28..b252344c99 100644
--- a/lib/chef/provider/package/macports.rb
+++ b/lib/chef/provider/package/macports.rb
@@ -83,12 +83,11 @@ class Chef
private
def get_response_from_command(command)
output = nil
- status = popen4(command) do |pid, stdin, stdout, stderr|
- begin
- output = stdout.read
- rescue Exception
- raise Chef::Exceptions::Package, "Could not read from STDOUT on command: #{command}"
- end
+ status = shell_out(command)
+ begin
+ output = status.stdout
+ rescue Exception
+ raise Chef::Exceptions::Package, "Could not read from STDOUT on command: #{command}"
end
unless status.exitstatus == 0 || status.exitstatus == 1
raise Chef::Exceptions::Package, "#{command} failed - #{status.insect}!"
diff --git a/lib/chef/provider/package/pacman.rb b/lib/chef/provider/package/pacman.rb
index 45edda5c5d..f16fc811f5 100644
--- a/lib/chef/provider/package/pacman.rb
+++ b/lib/chef/provider/package/pacman.rb
@@ -34,13 +34,12 @@ class Chef
@current_resource.version(nil)
Chef::Log.debug("#{@new_resource} checking pacman for #{@new_resource.package_name}")
- status = popen4("pacman -Qi #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /^Version(\s?)*: (.+)$/
- Chef::Log.debug("#{@new_resource} current version is #{$2}")
- @current_resource.version($2)
- end
+ status = shell_out("pacman -Qi #{@new_resource.package_name}")
+ status.stdout.each_line do |line|
+ case line
+ when /^Version(\s?)*: (.+)$/
+ Chef::Log.debug("#{@new_resource} current version is #{$2}")
+ @current_resource.version($2)
end
end
@@ -63,14 +62,13 @@ class Chef
package_repos = repos.map {|r| Regexp.escape(r) }.join('|')
- status = popen4("pacman -Sl") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /^(#{package_repos}) #{Regexp.escape(@new_resource.package_name)} (.+)$/
- # $2 contains a string like "4.4.0-1" or "3.10-4 [installed]"
- # simply split by space and use first token
- @candidate_version = $2.split(" ").first
- end
+ status = shell_out("pacman -Sl")
+ status.stdout.each_line do |line|
+ case line
+ when /^(#{package_repos}) #{Regexp.escape(@new_resource.package_name)} (.+)$/
+ # $2 contains a string like "4.4.0-1" or "3.10-4 [installed]"
+ # simply split by space and use first token
+ @candidate_version = $2.split(" ").first
end
end
diff --git a/lib/chef/provider/package/portage.rb b/lib/chef/provider/package/portage.rb
index 816e262ab0..bb047ad2fa 100644
--- a/lib/chef/provider/package/portage.rb
+++ b/lib/chef/provider/package/portage.rb
@@ -92,10 +92,9 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
- status = popen4("emerge --color n --nospinner --search #{@new_resource.package_name.split('/').last}") do |pid, stdin, stdout, stderr|
- available, installed = parse_emerge(@new_resource.package_name, stdout.read)
- @candidate_version = available
- end
+ status = shell_out("emerge --color n --nospinner --search #{@new_resource.package_name.split('/').last}")
+ available, installed = parse_emerge(@new_resource.package_name, status.stdout)
+ @candidate_version = available
unless status.exitstatus == 0
raise Chef::Exceptions::Package, "emerge --search failed - #{status.inspect}!"
diff --git a/lib/chef/provider/package/rpm.rb b/lib/chef/provider/package/rpm.rb
index c96261bcd1..fa784c2943 100644
--- a/lib/chef/provider/package/rpm.rb
+++ b/lib/chef/provider/package/rpm.rb
@@ -60,8 +60,7 @@ class Chef
end
Chef::Log.debug("#{@new_resource} checking rpm status")
- status = shell_out!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}")
- status.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 /^([\w\d+_.-]+)\s([\w\d_.-]+)$/
@current_resource.package_name($1)
diff --git a/lib/chef/provider/package/solaris.rb b/lib/chef/provider/package/solaris.rb
index 53dd00dd07..a2cfd93ef6 100644
--- a/lib/chef/provider/package/solaris.rb
+++ b/lib/chef/provider/package/solaris.rb
@@ -55,25 +55,22 @@ class Chef
@package_source_found = ::File.exists?(@new_resource.source)
if @package_source_found
Chef::Log.debug("#{@new_resource} checking pkg status")
- status = popen4("pkginfo -l -d #{@new_resource.source} #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /VERSION:\s+(.+)/
- @new_resource.version($1)
- end
+ 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)
end
end
end
end
Chef::Log.debug("#{@new_resource} checking install state")
- status = popen4("pkginfo -l #{@current_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /VERSION:\s+(.+)/
- Chef::Log.debug("#{@new_resource} version #{$1} is already installed")
- @current_resource.version($1)
- end
+ status = shell_out("pkginfo -l #{@current_resource.package_name}")
+ status.stdout.each_line do |line|
+ case line
+ when /VERSION:\s+(.+)/
+ Chef::Log.debug("#{@new_resource} version #{$1} is already installed")
+ @current_resource.version($1)
end
end
@@ -90,14 +87,13 @@ class Chef
def candidate_version
return @candidate_version if @candidate_version
- status = popen4("pkginfo -l -d #{@new_resource.source} #{new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each_line do |line|
- case line
- when /VERSION:\s+(.+)/
- @candidate_version = $1
- @new_resource.version($1)
- Chef::Log.debug("#{@new_resource} setting install candidate version to #{@candidate_version}")
- end
+ status = shell_out("pkginfo -l -d #{@new_resource.source} #{new_resource.package_name}")
+ status.stdout.each_line do |line|
+ case line
+ when /VERSION:\s+(.+)/
+ @candidate_version = $1
+ @new_resource.version($1)
+ Chef::Log.debug("#{@new_resource} setting install candidate version to #{@candidate_version}")
end
end
unless status.exitstatus == 0
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index 05fb76c4f5..405e4177ab 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -18,7 +18,7 @@
require 'chef/config'
require 'chef/provider/package'
-require 'chef/mixin/command'
+require 'chef/mixin/command' # handle_command_failures
require 'chef/mixin/shell_out'
require 'chef/resource/package'
require 'singleton'
@@ -1010,7 +1010,7 @@ class Chef
if status.exitstatus > 0
command_output = "STDOUT: #{stdout}"
command_output << "STDERR: #{stderr}"
- handle_command_failures(status, command_output, {})
+ Chef::Mixin::Command.handle_command_failures(status, command_output, {})
end
end
@@ -1327,4 +1327,4 @@ class Chef
end
end
end
-end \ No newline at end of file
+end
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index b00bef0f92..2cd321660b 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -38,24 +38,23 @@ class Chef
version=''
oud_version=''
Chef::Log.debug("#{@new_resource} checking zypper")
- status = popen4("zypper --non-interactive info #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /^Version: (.+)$/
- version = $1
- Chef::Log.debug("#{@new_resource} version #{$1}")
- when /^Installed: Yes$/
- is_installed=true
- Chef::Log.debug("#{@new_resource} is installed")
-
- when /^Installed: No$/
- is_installed=false
- Chef::Log.debug("#{@new_resource} is not installed")
- when /^Status: out-of-date \(version (.+) installed\)$/
- is_out_of_date=true
- oud_version=$1
- Chef::Log.debug("#{@new_resource} out of date version #{$1}")
- end
+ status = shell_out("zypper --non-interactive info #{@new_resource.package_name}")
+ status.stdout.each_line do |line|
+ case line
+ when /^Version: (.+)$/
+ version = $1
+ Chef::Log.debug("#{@new_resource} version #{$1}")
+ when /^Installed: Yes$/
+ is_installed=true
+ Chef::Log.debug("#{@new_resource} is installed")
+
+ when /^Installed: No$/
+ is_installed=false
+ Chef::Log.debug("#{@new_resource} is not installed")
+ when /^Status: out-of-date \(version (.+) installed\)$/
+ is_out_of_date=true
+ oud_version=$1
+ Chef::Log.debug("#{@new_resource} out of date version #{$1}")
end
end
diff --git a/spec/functional/resource/aix_service_spec.rb b/spec/functional/resource/aix_service_spec.rb
index 6008fdea8f..9dec87db93 100755
--- a/spec/functional/resource/aix_service_spec.rb
+++ b/spec/functional/resource/aix_service_spec.rb
@@ -73,6 +73,9 @@ shared_examples "src service" do
end
describe Chef::Resource::Service, :requires_root, :aix_only do
+
+ include Chef::Mixin::ShellOut
+
def get_user_id
shell_out("id -u #{ENV['USER']}").stdout.chomp
end
diff --git a/spec/functional/version_spec.rb b/spec/functional/version_spec.rb
index 71ba4d5b2f..cd5bbc7678 100644
--- a/spec/functional/version_spec.rb
+++ b/spec/functional/version_spec.rb
@@ -28,7 +28,7 @@ describe "Chef Versions" do
binaries.each do |binary|
it "#{binary} version should be sane" do
- expect(shell_out!("ruby #{File.join("bin", binary)} -v", :cwd => chef_dir).stdout.chomp).to eq("Chef: #{Chef::VERSION}")
+ expect(shell_out!("ruby #{File.join("bin", binary)} -v", :cwd => chef_dir).stdout.chomp).to include("Chef: #{Chef::VERSION}")
end
end
diff --git a/spec/unit/provider/group/dscl_spec.rb b/spec/unit/provider/group/dscl_spec.rb
index e09365a828..d84e4e1d57 100644
--- a/spec/unit/provider/group/dscl_spec.rb
+++ b/spec/unit/provider/group/dscl_spec.rb
@@ -27,16 +27,13 @@ describe Chef::Provider::Group::Dscl do
@current_resource = Chef::Resource::Group.new("aj")
@provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
@provider.current_resource = @current_resource
- @status = double("Process::Status", :exitstatus => 0)
- @pid = 2342
- @stdin = StringIO.new
- @stdout = StringIO.new("\n")
- @stderr = StringIO.new("")
- allow(@provider).to receive(:popen4).and_yield(@pid,@stdin,@stdout,@stderr).and_return(@status)
+
+ @status = double(:stdout => "\n", :stderr => "", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(@status)
end
- it "should run popen4 with the supplied array of arguments appended to the dscl command" do
- expect(@provider).to receive(:popen4).with("dscl . -cmd /Path arg1 arg2")
+ it "should run shell_out with the supplied array of arguments appended to the dscl command" do
+ expect(@provider).to receive(:shell_out).with("dscl . -cmd /Path arg1 arg2")
@provider.dscl("cmd", "/Path", "arg1", "arg2")
end
diff --git a/spec/unit/provider/ifconfig/aix_spec.rb b/spec/unit/provider/ifconfig/aix_spec.rb
index 6e685823ac..0b6fa33614 100644
--- a/spec/unit/provider/ifconfig/aix_spec.rb
+++ b/spec/unit/provider/ifconfig/aix_spec.rb
@@ -49,10 +49,11 @@ IFCONFIG
describe "#load_current_resource" do
before do
- status = double("Status", :exitstatus => 0)
- expect(@provider).to receive(:popen4).with("ifconfig -a").and_yield(@pid,@stdin,StringIO.new(@ifconfig_output),@stderr).and_return(status)
+ @status = double(:stdout => @ifconfig_output, :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@new_resource.device "en0"
end
+
it "should load given interface with attributes." do
current_resource = @provider.load_current_resource
expect(current_resource.inet_addr).to eq("172.29.174.58")
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index 126112dd43..d290ab7066 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -42,8 +42,8 @@ describe Chef::Provider::Ifconfig do
end
describe Chef::Provider::Ifconfig, "load_current_resource" do
before do
- status = double("Status", :exitstatus => 1)
- expect(@provider).to receive(:popen4).and_return status
+ @status = double(:stdout => "", :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
end
it "should track state of ifconfig failure." do
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index 7e9531a8ac..7a37ffe74e 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -54,10 +54,11 @@ describe Chef::Provider::Mount::Mount do
end
it "should accecpt device_type :uuid", :not_supported_on_solaris do
+ @status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1)
@new_resource.device_type :uuid
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
@stdout_findfs = double("STDOUT", :first => "/dev/sdz1")
- expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status)
+ expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(@status)
@provider.load_current_resource()
@provider.mountable?
end
@@ -93,11 +94,10 @@ describe Chef::Provider::Mount::Mount do
end
it "should raise an error if the mount device (uuid) does not exist", :not_supported_on_solaris do
+ status = double(:stdout => "", :exitstatus => 1)
@new_resource.device_type :uuid
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
- status_findfs = double("Status", :exitstatus => 1)
- stdout_findfs = double("STDOUT", :first => nil)
- expect(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs)
+ expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status)
expect(::File).to receive(:exists?).with("").and_return(false)
expect { @provider.load_current_resource();@provider.mountable? }.to raise_error(Chef::Exceptions::Mount)
end
@@ -307,10 +307,10 @@ describe Chef::Provider::Mount::Mount do
end
it "should mount the filesystem specified by uuid", :not_supported_on_solaris do
+ status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1)
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
@new_resource.device_type :uuid
- @stdout_findfs = double("STDOUT", :first => "/dev/sdz1")
- allow(@provider).to receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status)
@stdout_mock = double('stdout mock')
allow(@stdout_mock).to receive(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}")
expect(@provider).to receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}").and_return(@stdout_mock)
diff --git a/spec/unit/provider/package/aix_spec.rb b/spec/unit/provider/package/aix_spec.rb
index a39ab096c7..5bc861b849 100644
--- a/spec/unit/provider/package/aix_spec.rb
+++ b/spec/unit/provider/package/aix_spec.rb
@@ -36,23 +36,23 @@ describe Chef::Provider::Package::Aix do
@bffinfo ="/usr/lib/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX:
/etc/objrepos:samba.base:3.3.12.0::COMMITTED:I:Samba for AIX:"
- @status = double("Status", :exitstatus => 0)
+ @status = double("Status", :stdout => "", :exitstatus => 0)
end
it "should create a current resource with the name of new_resource" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.name).to eq("samba.base")
end
it "should set the current resource bff package name to the new resource bff package name" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("samba.base")
end
it "should raise an exception if a source is supplied but not found" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
allow(::File).to receive(:exists?).and_return(false)
@provider.load_current_resource
@provider.define_resource_requirements
@@ -60,10 +60,9 @@ describe Chef::Provider::Package::Aix do
end
it "should get the source package version from lslpp if provided" do
- @stdout = StringIO.new(@bffinfo)
- @stdin, @stderr = StringIO.new, StringIO.new
- expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_return(@status)
+ status = double("Status", :stdout => @bffinfo, :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(status)
+ expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("samba.base")
@@ -71,31 +70,33 @@ describe Chef::Provider::Package::Aix do
end
it "should return the current version installed if found by lslpp" do
+ status = double("Status", :stdout => @bffinfo, :exitstatus => 0)
@stdout = StringIO.new(@bffinfo)
@stdin, @stderr = StringIO.new, StringIO.new
- expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status)
- expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(status)
@provider.load_current_resource
expect(@provider.current_resource.version).to eq("3.3.12.0")
end
it "should raise an exception if the source is not set but we are installing" do
+ status = double("Status", :stdout => "", :exitstatus => 1, :format_for_exception => "")
@new_resource = Chef::Resource::Package.new("samba.base")
@provider = Chef::Provider::Package::Aix.new(@new_resource, @run_context)
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
end
it "should raise an exception if installp/lslpp fails to run" do
- @status = double("Status", :exitstatus => -1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => -1, :format_for_exception => "")
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package)
end
it "should return a current resource with a nil version if the package is not found" do
- @stdout = StringIO.new
- expect(@provider).to receive(:popen4).with("installp -L -d /tmp/samba.base").and_return(@status)
- expect(@provider).to receive(:popen4).with("lslpp -lcq samba.base").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => "", :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).with("installp -L -d /tmp/samba.base").and_return(status)
+ expect(@provider).to receive(:shell_out).with("lslpp -lcq samba.base").and_return(status)
@provider.load_current_resource
expect(@provider.current_resource.version).to be_nil
end
@@ -104,19 +105,19 @@ describe Chef::Provider::Package::Aix do
describe "candidate_version" do
it "should return the candidate_version variable if already setup" do
@provider.candidate_version = "3.3.12.0"
- expect(@provider).not_to receive(:popen4)
+ expect(@provider).not_to receive(:shell_out )
@provider.candidate_version
end
it "should lookup the candidate_version if the variable is not already set" do
- @status = double("Status", :exitstatus => 0)
- expect(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
@provider.candidate_version
end
it "should throw and exception if the exitstatus is not 0" do
- @status = double("Status", :exitstatus => 1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ @status = double(:stdout => "", :exitstatus => 1, :format_for_exception => "")
+ allow(@provider).to receive(:shell_out).and_return(@status)
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package)
end
diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb
index 154809f88c..c838306c35 100644
--- a/spec/unit/provider/package/dpkg_spec.rb
+++ b/spec/unit/provider/package/dpkg_spec.rb
@@ -28,12 +28,8 @@ describe Chef::Provider::Package::Dpkg do
@provider = Chef::Provider::Package::Dpkg.new(@new_resource, @run_context)
- @stdin = StringIO.new
- @stdout = StringIO.new
- @status = double("Status", :exitstatus => 0)
- @stderr = StringIO.new
- @pid = double("PID")
- allow(@provider).to receive(:popen4).and_return(@status)
+ @status = double(:stdout => "", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(@status)
allow(::File).to receive(:exists?).and_return(true)
end
@@ -54,8 +50,8 @@ describe Chef::Provider::Package::Dpkg do
describe 'gets the source package version from dpkg-deb' do
def check_version(version)
- @stdout = StringIO.new("wget\t#{version}")
- allow(@provider).to receive(:popen4).with("dpkg-deb -W #{@new_resource.source}").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @status = double(:stdout => "wget\t#{version}", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).with("dpkg-deb -W #{@new_resource.source}").and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("wget")
expect(@new_resource.version).to eq(version)
@@ -79,8 +75,9 @@ describe Chef::Provider::Package::Dpkg do
end
it "gets the source package name from dpkg-deb correctly when the package name has `-', `+' or `.' characters" do
- @stdout = StringIO.new("f.o.o-pkg++2\t1.11.4-1ubuntu1")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ stdout = "f.o.o-pkg++2\t1.11.4-1ubuntu1"
+ status = double(:stdout => stdout, :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).and_return(status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2")
end
@@ -94,7 +91,7 @@ describe Chef::Provider::Package::Dpkg do
end
it "should return the current version installed if found by dpkg" do
- @stdout = StringIO.new(<<-DPKG_S)
+ stdout = <<-DPKG_S
Package: wget
Status: install ok installed
Priority: important
@@ -107,15 +104,16 @@ Config-Version: 1.11.4-1ubuntu1
Depends: libc6 (>= 2.8~20080505), libssl0.9.8 (>= 0.9.8f-5)
Conflicts: wget-ssl
DPKG_S
- allow(@provider).to receive(:popen4).with("dpkg -s wget").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => stdout, :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).with("dpkg -s wget").and_return(status)
@provider.load_current_resource
expect(@provider.current_resource.version).to eq("1.11.4-1ubuntu1")
end
it "should raise an exception if dpkg fails to run" do
- @status = double("Status", :exitstatus => -1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => -1)
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package)
end
end
diff --git a/spec/unit/provider/package/macports_spec.rb b/spec/unit/provider/package/macports_spec.rb
index 23a8233c66..9822fb3928 100644
--- a/spec/unit/provider/package/macports_spec.rb
+++ b/spec/unit/provider/package/macports_spec.rb
@@ -29,11 +29,11 @@ describe Chef::Provider::Package::Macports do
@provider = Chef::Provider::Package::Macports.new(@new_resource, @run_context)
allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource)
- @status = double("Status", :exitstatus => 0)
- @stdin = StringIO.new
- @stdout = StringIO.new
- @stderr = StringIO.new
- @pid = 2342
+ # @status = double(:stdout => "", :exitstatus => 0)
+ # @stdin = StringIO.new
+ # @stdout = StringIO.new
+ # @stderr = StringIO.new
+ # @pid = 2342
end
describe "load_current_resource" do
@@ -70,33 +70,33 @@ describe Chef::Provider::Package::Macports do
describe "current_installed_version" do
it "should return the current version if the package is installed" do
- expect(@stdout).to receive(:read).and_return(<<EOF
+ stdout = <<EOF
The following ports are currently installed:
openssl @0.9.8k_0 (active)
EOF
- )
- expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => stdout, :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.current_installed_version).to eq("0.9.8k_0")
end
it "should return nil if a package is not currently installed" do
- expect(@stdout).to receive(:read).and_return(" \n")
- expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => " \n", :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.current_installed_version).to be_nil
end
end
describe "macports_candidate_version" do
it "should return the latest available version of a given package" do
- expect(@stdout).to receive(:read).and_return("version: 4.2.7\n")
- expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => "version: 4.2.7\n", :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.macports_candidate_version).to eq("4.2.7")
end
it "should return nil if there is no version for a given package" do
- expect(@stdout).to receive(:read).and_return("Error: port fadsfadsfads not found\n")
- expect(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => "Error: port fadsfadsfads not found\n", :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.macports_candidate_version).to be_nil
end
end
diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb
index 9fa5f9667c..3b8848c41b 100644
--- a/spec/unit/provider/package/pacman_spec.rb
+++ b/spec/unit/provider/package/pacman_spec.rb
@@ -26,10 +26,11 @@ describe Chef::Provider::Package::Pacman do
@new_resource = Chef::Resource::Package.new("nano")
@current_resource = Chef::Resource::Package.new("nano")
- @status = double("Status", :exitstatus => 0)
+ @status = double(:stdout => "", :exitstatus => 0)
@provider = Chef::Provider::Package::Pacman.new(@new_resource, @run_context)
allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource)
- allow(@provider).to receive(:popen4).and_return(@status)
+
+ allow(@provider).to receive(:shell_out).and_return(@status)
@stdin = StringIO.new
@stdout = StringIO.new(<<-ERR)
error: package "nano" not found
@@ -50,24 +51,23 @@ ERR
end
it "should run pacman query with the package name" do
- expect(@provider).to receive(:popen4).with("pacman -Qi #{@new_resource.package_name}").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("pacman -Qi #{@new_resource.package_name}").and_return(@status)
@provider.load_current_resource
end
it "should read stdout on pacman" do
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- expect(@stdout).to receive(:each).and_return(true)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
end
it "should set the installed version to nil on the current resource if pacman installed version not exists" do
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
expect(@current_resource).to receive(:version).with(nil).and_return(true)
@provider.load_current_resource
end
it "should set the installed version if pacman has one" do
- @stdout = StringIO.new(<<-PACMAN)
+ stdout = <<-PACMAN
Name : nano
Version : 2.2.2-1
URL : http://www.nano-editor.org
@@ -88,14 +88,16 @@ Install Reason : Explicitly installed
Install Script : Yes
Description : Pico editor clone with enhancements
PACMAN
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+
+ status = double(:stdout => stdout, :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(status)
@provider.load_current_resource
expect(@current_resource.version).to eq("2.2.2-1")
end
it "should set the candidate version if pacman has one" do
- allow(@stdout).to receive(:each).and_yield("core nano 2.2.3-1")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => "core nano 2.2.3-1", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(status)
@provider.load_current_resource
expect(@provider.candidate_version).to eql("2.2.3-1")
end
@@ -119,10 +121,10 @@ Include = /etc/pacman.d/mirrorlist
Include = /etc/pacman.d/mirrorlist
PACMAN_CONF
+ status = double(:stdout => "customrepo nano 1.2.3-4", :exitstatus => 0)
allow(::File).to receive(:exists?).with("/etc/pacman.conf").and_return(true)
allow(::File).to receive(:read).with("/etc/pacman.conf").and_return(@pacman_conf)
- allow(@stdout).to receive(:each).and_yield("customrepo nano 1.2.3-4")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(status)
@provider.load_current_resource
expect(@provider.candidate_version).to eql("1.2.3-4")
@@ -139,8 +141,7 @@ PACMAN_CONF
end
it "should raise an exception if pacman does not return a candidate version" do
- allow(@stdout).to receive(:each).and_yield("")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package)
end
diff --git a/spec/unit/provider/package/portage_spec.rb b/spec/unit/provider/package/portage_spec.rb
index f83eda45de..55743dbeaf 100644
--- a/spec/unit/provider/package/portage_spec.rb
+++ b/spec/unit/provider/package/portage_spec.rb
@@ -102,13 +102,13 @@ describe Chef::Provider::Package::Portage, "load_current_resource" do
describe Chef::Provider::Package::Portage, "candidate_version" do
it "should return the candidate_version variable if already set" do
@provider.candidate_version = "1.0.0"
- expect(@provider).not_to receive(:popen4)
+ expect(@provider).not_to receive(:shell_out)
@provider.candidate_version
end
it "should throw an exception if the exitstatus is not 0" do
- @status = double("Status", :exitstatus => 1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package)
end
@@ -143,8 +143,8 @@ Searching...
License: GPL-2
EOF
- @status = double("Status", :exitstatus => 0)
- expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status)
+ status = double(:stdout => output, :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.candidate_version).to eq("1.6.0.6")
end
@@ -179,9 +179,9 @@ Searching...
License: GPL-2
EOF
- @status = double("Status", :exitstatus => 0)
+ status = double(:stdout => output, :exitstatus => 0)
@provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context)
- expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.candidate_version).to eq("1.6.0.6")
end
@@ -224,9 +224,9 @@ Searching...
License: GPL-2
EOF
- @status = double("Status", :exitstatus => 0)
+ status = double(:stdout => output, :exitstatus => 0)
@provider = Chef::Provider::Package::Portage.new(@new_resource_without_category, @run_context)
- expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package)
end
@@ -269,9 +269,9 @@ Searching...
License: GPL-2
EOF
- @status = double("Status", :exitstatus => 0)
+ status = double(:stdout => output, :exitstatus => 0)
@provider = Chef::Provider::Package::Portage.new(@new_resource, @run_context)
- expect(@provider).to receive(:popen4).and_yield(nil, nil, StringIO.new(output), nil).and_return(@status)
+ expect(@provider).to receive(:shell_out).and_return(status)
expect(@provider.candidate_version).to eq("1.6.0.6")
end
end
diff --git a/spec/unit/provider/package/solaris_spec.rb b/spec/unit/provider/package/solaris_spec.rb
index 332fa9db1a..c348d665e8 100644
--- a/spec/unit/provider/package/solaris_spec.rb
+++ b/spec/unit/provider/package/solaris_spec.rb
@@ -46,23 +46,23 @@ INSTDATE: Nov 04 2009 01:02
HOTLINE: Please contact your local service provider
PKGINFO
- @status = double("Status", :exitstatus => 0)
+ @status = double("Status",:stdout => "", :exitstatus => 0)
end
it "should create a current resource with the name of new_resource" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.name).to eq("SUNWbash")
end
it "should set the current reource package name to the new resource package name" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("SUNWbash")
end
it "should raise an exception if a source is supplied but not found" do
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
allow(::File).to receive(:exists?).and_return(false)
@provider.load_current_resource
@provider.define_resource_requirements
@@ -70,10 +70,9 @@ PKGINFO
end
it "should get the source package version from pkginfo if provided" do
- @stdout = StringIO.new(@pkginfo)
- @stdin, @stderr = StringIO.new, StringIO.new
- expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_return(@status)
+ status = double(:stdout => @pkginfo, :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(status)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("SUNWbash")
@@ -81,10 +80,9 @@ PKGINFO
end
it "should return the current version installed if found by pkginfo" do
- @stdout = StringIO.new(@pkginfo)
- @stdin, @stderr = StringIO.new, StringIO.new
- expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status)
- expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => @pkginfo, :exitstatus => 0)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(status)
@provider.load_current_resource
expect(@provider.current_resource.version).to eq("11.10.0,REV=2005.01.08.05.16")
end
@@ -92,20 +90,19 @@ PKGINFO
it "should raise an exception if the source is not set but we are installing" do
@new_resource = Chef::Resource::Package.new("SUNWbash")
@provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context)
- allow(@provider).to receive(:popen4).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
expect { @provider.run_action(:install) }.to raise_error(Chef::Exceptions::Package)
end
it "should raise an exception if pkginfo fails to run" do
- @status = double("Status", :exitstatus => -1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => -1)
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.load_current_resource }.to raise_error(Chef::Exceptions::Package)
end
it "should return a current resource with a nil version if the package is not found" do
- @stdout = StringIO.new
- expect(@provider).to receive(:popen4).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status)
- expect(@provider).to receive(:popen4).with("pkginfo -l SUNWbash").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l -d /tmp/bash.pkg SUNWbash").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("pkginfo -l SUNWbash").and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.version).to be_nil
end
@@ -114,20 +111,20 @@ PKGINFO
describe "candidate_version" do
it "should return the candidate_version variable if already setup" do
@provider.candidate_version = "11.10.0,REV=2005.01.08.05.16"
- expect(@provider).not_to receive(:popen4)
+ expect(@provider).not_to receive(:shell_out)
@provider.candidate_version
end
it "should lookup the candidate_version if the variable is not already set" do
- @status = double("Status", :exitstatus => 0)
- allow(@provider).to receive(:popen4).and_return(@status)
- expect(@provider).to receive(:popen4)
+ status = double(:stdout => "", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(status)
+ expect(@provider).to receive(:shell_out)
@provider.candidate_version
end
it "should throw and exception if the exitstatus is not 0" do
- @status = double("Status", :exitstatus => 1)
- allow(@provider).to receive(:popen4).and_return(@status)
+ status = double(:stdout => "", :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).and_return(status)
expect { @provider.candidate_version }.to raise_error(Chef::Exceptions::Package)
end
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 17d99640e6..706ad722dd 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -27,14 +27,10 @@ describe Chef::Provider::Package::Zypper do
@current_resource = Chef::Resource::Package.new("cups")
- @status = double("Status", :exitstatus => 0)
-
@provider = Chef::Provider::Package::Zypper.new(@new_resource, @run_context)
allow(Chef::Resource::Package).to receive(:new).and_return(@current_resource)
- allow(@provider).to receive(:popen4).and_return(@status)
- @stderr = StringIO.new
- @stdout = StringIO.new
- @pid = double("PID")
+ @status = double(:stdout => "\n", :exitstatus => 0)
+ allow(@provider).to receive(:shell_out).and_return(@status)
allow(@provider).to receive(:`).and_return("2.0")
end
@@ -50,27 +46,28 @@ describe Chef::Provider::Package::Zypper do
end
it "should run zypper info with the package name" do
- expect(@provider).to receive(:popen4).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status)
+ expect(@provider).to receive(:shell_out).with("zypper --non-interactive info #{@new_resource.package_name}").and_return(@status)
@provider.load_current_resource
end
it "should set the installed version to nil on the current resource if zypper info installed version is (none)" do
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(@status)
expect(@current_resource).to receive(:version).with(nil).and_return(true)
@provider.load_current_resource
end
it "should set the installed version if zypper info has one" do
- @stdout = StringIO.new("Version: 1.0\nInstalled: Yes\n")
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ status = double(:stdout => "Version: 1.0\nInstalled: Yes\n", :exitstatus => 0)
+
+ allow(@provider).to receive(:shell_out).and_return(status)
expect(@current_resource).to receive(:version).with("1.0").and_return(true)
@provider.load_current_resource
end
it "should set the candidate version if zypper info has one" do
- @stdout = StringIO.new("Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)")
+ status = double(:stdout => "Version: 1.0\nInstalled: No\nStatus: out-of-date (version 0.9 installed)", :exitstatus => 0)
- allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ allow(@provider).to receive(:shell_out).and_return(status)
@provider.load_current_resource
expect(@provider.candidate_version).to eql("1.0")
end