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/display_helper.rb | 51 ++++++++++++++---------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'features/support/helpers/display_helper.rb') diff --git a/features/support/helpers/display_helper.rb b/features/support/helpers/display_helper.rb index 354935f0..b4dce733 100644 --- a/features/support/helpers/display_helper.rb +++ b/features/support/helpers/display_helper.rb @@ -6,8 +6,22 @@ class Display @x_display = x_display end + def active? + p = IO.popen(["xprop", "-display", @x_display, + "-name", "#{@domain} (1) - Virt Viewer", + :err => ["/dev/null", "w"]]) + Process.wait(p.pid) + $?.success? + end + def start - start_virtviewer(@domain) + @virtviewer = IO.popen(["virt-viewer", "--direct", + "--kiosk", + "--reconnect", + "--connect", "qemu:///system", + "--display", @x_display, + @domain, + :err => ["/dev/null", "w"]]) # We wait for the display to be active to not lose actions # (e.g. key presses via sikuli) that come immediately after # starting (or restoring) a vm @@ -17,35 +31,18 @@ class Display end def stop - stop_virtviewer + return if @virtviewer.nil? + Process.kill("TERM", @virtviewer.pid) + @virtviewer.close + rescue IOError + # IO.pid throws this if the process wasn't started yet. Possibly + # there's a race when doing a start() and then quickly running + # stop(). end def restart - stop_virtviewer - start_virtviewer(@domain) - end - - def start_virtviewer(domain) - # virt-viewer forks, so we cannot (easily) get the child pid - # and use it in active? and stop_virtviewer below... - IO.popen(["virt-viewer", "-d", - "-f", - "-r", - "-c", "qemu:///system", - ["--display=", @x_display].join(''), - domain, - "&"].join(' ')) + stop + start end - def active? - p = IO.popen("xprop -display #{@x_display} " + - "-name '#{@domain} (1) - Virt Viewer' 2>/dev/null") - Process.wait(p.pid) - p.close - $? == 0 - end - - def stop_virtviewer - system("killall virt-viewer") - end end -- cgit v1.2.3-54-g00ecf