summaryrefslogtreecommitdiffstats
path: root/features/support/helpers/display_helper.rb
diff options
context:
space:
mode:
authorPhilip Hands <phil@hands.com>2016-03-14 15:36:16 +0100
committerHolger Levsen <holger@layer-acht.org>2016-04-28 21:52:10 +0200
commitda080c472fc415b0ce918f4dd4a1ab143bb1bca4 (patch)
treebf63179f32f0eda0c2d5796e3e31c18c3c1185cf /features/support/helpers/display_helper.rb
parent26a9e8ec2bcae03db4d663d87b44d8708d64fdc2 (diff)
downloadjenkins.debian.net-da080c472fc415b0ce918f4dd4a1ab143bb1bca4.tar.xz
rough attempt to grab the good cucumber bits from recent tails
Diffstat (limited to 'features/support/helpers/display_helper.rb')
-rw-r--r--features/support/helpers/display_helper.rb51
1 files changed, 24 insertions, 27 deletions
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