diff options
author | kaustubh-d <kaustubh@clogeny.com> | 2013-08-09 04:41:08 -0500 |
---|---|---|
committer | adamedx <adamed@opscode.com> | 2013-08-19 21:24:42 -0700 |
commit | b0df12937a4bb24ea9e10de5ea1dfb46241dfd5b (patch) | |
tree | 6d21b5974faab8635862c7ce9ff6f3233cba0329 /spec/functional/shell_spec.rb | |
parent | 77905e9456c86772f74cfc9e72c272cc89ca3187 (diff) | |
download | chef-b0df12937a4bb24ea9e10de5ea1dfb46241dfd5b.tar.gz |
aix - rewrite chef-shell functional test using popen4 as ruby pty does not work on aix
Diffstat (limited to 'spec/functional/shell_spec.rb')
-rw-r--r-- | spec/functional/shell_spec.rb | 48 |
1 files changed, 15 insertions, 33 deletions
diff --git a/spec/functional/shell_spec.rb b/spec/functional/shell_spec.rb index 90f421ca11..4c73b64485 100644 --- a/spec/functional/shell_spec.rb +++ b/spec/functional/shell_spec.rb @@ -19,6 +19,7 @@ require 'spec_helper' require 'chef/version' require 'chef/shell' +require 'chef/mixin/command/unix' describe Shell do @@ -26,6 +27,7 @@ describe Shell do # not catch cases where chef-shell fails to boot because of changes in # chef/client.rb describe "smoke tests", :unix_only => true do + include Chef::Mixin::Command::Unix def read_until(io, expected_value) start = Time.new @@ -45,46 +47,26 @@ describe Shell do buffer end - 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) - # Windows ruby installs don't (always?) have PTY, - # so hide the require here - 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 = '' + 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, exitstatus] - rescue PTY::ChildExited => e - [output, e.status] + [output, status.exitstatus] end it "boots correctly with -lauto" do output, exitstatus = run_chef_shell_with("-lauto") - exitstatus.should be_success + output.should include("done") + expect(exitstatus).to eq(0) end it "sets the log_level from the command line" do @@ -94,7 +76,7 @@ describe Shell do read_until(out, show_log_level_code) end output.should include("===fatal===") - exitstatus.should be_success + expect(exitstatus).to eq(0) end end |