From da080c472fc415b0ce918f4dd4a1ab143bb1bca4 Mon Sep 17 00:00:00 2001 From: Philip Hands Date: Mon, 14 Mar 2016 15:36:16 +0100 Subject: rough attempt to grab the good cucumber bits from recent tails --- features/support/helpers/exec_helper.rb | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'features/support/helpers/exec_helper.rb') diff --git a/features/support/helpers/exec_helper.rb b/features/support/helpers/exec_helper.rb index b0d3a9cd..42f6532a 100644 --- a/features/support/helpers/exec_helper.rb +++ b/features/support/helpers/exec_helper.rb @@ -10,13 +10,11 @@ class VMCommand @returncode, @stdout, @stderr = VMCommand.execute(vm, cmd, options) end - def VMCommand.wait_until_remote_shell_is_up(vm, timeout = 30) - begin - Timeout::timeout(timeout) do - VMCommand.execute(vm, "true", { :user => "root", :spawn => false }) + def VMCommand.wait_until_remote_shell_is_up(vm, timeout = 90) + try_for(timeout, :msg => "Remote shell seems to be down") do + Timeout::timeout(3) do + VMCommand.execute(vm, "echo 'hello?'") end - rescue Timeout::Error - raise "Remote shell seems to be down" end end @@ -27,21 +25,21 @@ class VMCommand # response will always be [0, "", ""] (only used as an # ACK). execute() will always block until a response is received, # though. Spawning is useful when starting processes in the - # background (or running scripts that does the same) like the - # vidalia-wrapper, or any application we want to interact with. + # background (or running scripts that does the same) like our + # onioncircuits wrapper, or any application we want to interact with. def VMCommand.execute(vm, cmd, options = {}) options[:user] ||= "root" options[:spawn] ||= false type = options[:spawn] ? "spawn" : "call" socket = TCPSocket.new("127.0.0.1", vm.get_remote_shell_port) - STDERR.puts "#{type}ing as #{options[:user]}: #{cmd}" if $debug + debug_log("#{type}ing as #{options[:user]}: #{cmd}") begin socket.puts(JSON.dump([type, options[:user], cmd])) s = socket.readline(sep = "\0").chomp("\0") ensure socket.close end - STDERR.puts "#{type} returned: #{s}" if $debug + debug_log("#{type} returned: #{s}") if not(options[:spawn]) begin return JSON.load(s) rescue JSON::ParserError @@ -58,4 +56,16 @@ class VMCommand return @returncode == 0 end + def failure? + return not(success?) + end + + def to_s + "Return status: #{@returncode}\n" + + "STDOUT:\n" + + @stdout + + "STDERR:\n" + + @stderr + end + end -- cgit v1.2.3-70-g09d2