summaryrefslogtreecommitdiff
path: root/spec/functional/shell_spec.rb
diff options
context:
space:
mode:
authorkaustubh-d <kaustubh@clogeny.com>2013-08-13 08:47:18 +0530
committeradamedx <adamed@opscode.com>2013-08-19 21:24:42 -0700
commitbae70fad595be4810b0fc29cc892153279dd2d8b (patch)
tree386ead253b8bbfd4af7df5d081982420e825545a /spec/functional/shell_spec.rb
parentb0df12937a4bb24ea9e10de5ea1dfb46241dfd5b (diff)
downloadchef-bae70fad595be4810b0fc29cc892153279dd2d8b.tar.gz
change shell spec to use popen4 only for aix, others use pty.
Diffstat (limited to 'spec/functional/shell_spec.rb')
-rw-r--r--spec/functional/shell_spec.rb68
1 files changed, 53 insertions, 15 deletions
diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb
index 4c73b64485..518f1f7adf 100644
--- a/spec/functional/shell_spec.rb
+++ b/spec/functional/shell_spec.rb
@@ -16,7 +16,7 @@
# limitations under the License.
#
-require 'spec_helper'
+require 'functional/resource/base'
require 'chef/version'
require 'chef/shell'
require 'chef/mixin/command/unix'
@@ -47,20 +47,60 @@ describe Shell do
buffer
end
- def run_chef_shell_with(options)
- config = File.expand_path("shef-config.rb", CHEF_SPEC_DATA)
- path_to_chef_shell = File.expand_path("../../../bin/chef-shell", __FILE__)
- output = ''
- status = popen4("#{path_to_chef_shell} -c #{config} #{options}", :waitlast => true) do |pid, stdin, stdout, stderr|
- read_until(stdout, "chef >")
- yield stdout, stdin if block_given?
- stdin.write("'done'\n")
- output = read_until(stdout, '=> "done"')
- stdin.print("exit\n")
- read_until(stdout, "\n")
+ def wait_or_die(pid)
+ start = Time.new
+
+ until exitstatus = Process.waitpid2(pid, Process::WNOHANG)
+ if Time.new - start > 5
+ STDERR.puts("chef-shell tty did not exit cleanly, killing it")
+ Process.kill(:KILL, pid)
+ end
+ sleep 0.01
end
+ exitstatus[1]
+ end
+
+ def run_chef_shell_with(options)
+ case ohai[:platform]
+ when "aix"
+ config = File.expand_path("shef-config.rb", CHEF_SPEC_DATA)
+ path_to_chef_shell = File.expand_path("../../../bin/chef-shell", __FILE__)
+ output = ''
+ status = popen4("#{path_to_chef_shell} -c #{config} #{options}", :waitlast => true) do |pid, stdin, stdout, stderr|
+ read_until(stdout, "chef >")
+ yield stdout, stdin if block_given?
+ stdin.write("'done'\n")
+ output = read_until(stdout, '=> "done"')
+ stdin.print("exit\n")
+ read_until(stdout, "\n")
+ end
- [output, status.exitstatus]
+ [output, status.exitstatus]
+ else
+ # Windows ruby installs don't (always?) have PTY,
+ # so hide the require here
+ begin
+ require 'pty'
+ config = File.expand_path("shef-config.rb", CHEF_SPEC_DATA)
+ path_to_chef_shell = File.expand_path("../../../bin/chef-shell", __FILE__)
+ reader, writer, pid = PTY.spawn("#{path_to_chef_shell} -c #{config} #{options}")
+ read_until(reader, "chef >")
+ yield reader, writer if block_given?
+ writer.puts('"done"')
+ output = read_until(reader, '=> "done"')
+ writer.print("exit\n")
+ read_until(reader, "exit")
+ read_until(reader, "\n")
+ read_until(reader, "\n")
+ writer.close
+
+ exitstatus = wait_or_die(pid)
+
+ [output, exitstatus]
+ rescue PTY::ChildExited => e
+ [output, e.status]
+ end
+ end
end
it "boots correctly with -lauto" do
@@ -78,7 +118,5 @@ describe Shell do
output.should include("===fatal===")
expect(exitstatus).to eq(0)
end
-
end
-
end