tests: uitests: Fail if virt-manager is already running

We don't want to connect to an existing app and possibly mess
up host state
This commit is contained in:
Cole Robinson 2018-09-04 12:36:50 -04:00
parent e6c7e46a54
commit 40461c58ef
2 changed files with 13 additions and 0 deletions

View File

@ -15,6 +15,7 @@ def _vm_wrapper(vmname, uri="qemu:///system"):
"""
def wrap1(fn):
def wrapper(self, *args, **kwargs):
self.app.error_if_already_running()
xmlfile = "%s/xml/%s.xml" % (os.path.dirname(__file__), vmname)
conn = libvirt.open(uri)
dom = conn.defineXML(open(xmlfile).read())

View File

@ -10,6 +10,7 @@ import subprocess
import sys
import unittest
from gi.repository import Gio
import pyatspi
import dogtail.tree
@ -341,6 +342,16 @@ class VMMDogtailApp(object):
self.open()
return self._topwin
def error_if_already_running(self):
# Ensure virt-manager isn't already running
dbus = Gio.DBusProxy.new_sync(
Gio.bus_get_sync(Gio.BusType.SESSION, None), 0, None,
"org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", None)
if "org.virt-manager.virt-manager" in dbus.ListNames():
raise RuntimeError("virt-manager is already running. "
"Close it before running this test suite.")
def is_running(self):
return bool(self._proc and self._proc.poll() is None)
@ -363,6 +374,7 @@ class VMMDogtailApp(object):
"--test-first-run", "--no-fork", "--connect", self.uri]
cmd += extra_opts
self.error_if_already_running()
self._proc = subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
self._root = dogtail.tree.root.application("virt-manager")
self._topwin = self._root.find(None, "(frame|dialog|alert)")