tests: uitests: Add window cleanup tests

And fix some bugs I found as a result
This commit is contained in:
Cole Robinson
2018-03-17 19:42:19 -04:00
parent 259c70a090
commit 4d4a07c65b
6 changed files with 98 additions and 5 deletions

View File

@ -1,3 +1,5 @@
import dogtail.rawinput
from tests.uitests import utils as uiutils
@ -91,3 +93,74 @@ class Manager(uiutils.UITestCase):
manager.find("Memory usage", "table column header")
manager.find("Disk I/O", "table column header")
manager.find("Network I/O", "table column header")
def testManagerWindowCleanup(self):
"""
Open migrate, clone, delete, newvm, details, host windows, close the
connection, make sure they all disappear
"""
def _drag(win):
"""
Drag a window so it's not obscuring the manager window
"""
win.click()
clickX = win.position[0] + win.size[0] / 2
clickY = win.position[1] + 3
dogtail.rawinput.drag((clickX, clickY), (1000, 1000))
manager = self.app.topwin
# Open migrate dialog
c = manager.find("test-many-devices", "table cell")
c.click(button=3)
self.app.root.find("Migrate...", "menu item").click()
migrate = self.app.root.find("Migrate the virtual machine", "frame")
_drag(migrate)
# Open clone dialog
c = manager.find("test-clone", "table cell")
c.click(button=3)
self.app.root.find("Clone...", "menu item").click()
clone = self.app.root.find("Clone Virtual Machine", "frame")
_drag(clone)
# Open delete dialog
c.click()
manager.find("Edit", "menu").click()
manager.find("Delete", "menu item").click()
delete = self.app.root.find_fuzzy("Delete", "frame")
_drag(delete)
# Open NewVM
self.app.root.find("New", "push button").click()
create = self.app.root.find("New VM", "frame")
_drag(create)
# Open host
host = self._open_host_window("Virtual Networks")
_drag(host)
# Open details
details = self._open_details_window("test-many-devices")
_drag(details)
# Close the connection
c = manager.find_fuzzy("testdriver.xml", "table cell")
c.click(button=3)
self.app.root.find("conn-disconnect", "menu item").click()
# Ensure all those windows aren't showing
uiutils.check_in_loop(lambda: not migrate.showing)
uiutils.check_in_loop(lambda: not clone.showing)
uiutils.check_in_loop(lambda: not create.showing)
uiutils.check_in_loop(lambda: not details.showing)
uiutils.check_in_loop(lambda: not delete.showing)
# Delete the connection, ensure the host dialog disappears
c = manager.find_fuzzy("testdriver.xml", "table cell")
c.click(button=3)
self.app.root.find("conn-delete", "menu item").click()
err = self.app.root.find("vmm dialog", "alert")
err.find_fuzzy("will remove the connection", "label")
err.find_fuzzy("Yes", "push button").click()
uiutils.check_in_loop(lambda: not host.showing)

View File

@ -41,7 +41,7 @@ class vmmGObject(GObject.GObject):
_instance = None
# windowlist mapping, if applicable (vmmDetails, vmmHost, ...)
_instances = {}
_instances = None
# This saves a bunch of imports and typing
RUN_FIRST = GObject.SignalFlags.RUN_FIRST
@ -91,9 +91,11 @@ class vmmGObject(GObject.GObject):
# We set this to True which can help us catch instances
# where cleanup routines try to reinit singleton classes
self.__class__._instance = True
for k, v in list(self.__class__._instances.items()):
_instances = self.__class__._instances or {}
for k, v in list(_instances.items()):
if v == self:
self.__class__._instances.pop(k)
_instances.pop(k)
self._cleanup()

View File

@ -133,6 +133,8 @@ class vmmCloneVM(vmmGObjectUI):
try:
# Maintain one dialog per connection
uri = vm.conn.get_uri()
if cls._instances is None:
cls._instances = {}
if uri not in cls._instances:
cls._instances[uri] = vmmCloneVM()
cls._instances[uri].show(parentobj.topwin, vm)

View File

@ -348,6 +348,8 @@ class vmmDetails(vmmGObjectUI):
try:
# Maintain one dialog per VM
connkey = vm.get_connkey()
if cls._instances is None:
cls._instances = {}
if connkey not in cls._instances:
cls._instances[connkey] = vmmDetails(vm)
return cls._instances[connkey]

View File

@ -56,6 +56,8 @@ class vmmHost(vmmGObjectUI):
try:
# Maintain one dialog per connection
uri = conn.get_uri()
if cls._instances is None:
cls._instances = {}
if uri not in cls._instances:
cls._instances[uri] = vmmHost(conn)
cls._instances[uri].show()

View File

@ -89,7 +89,7 @@ class vmmMigrateDialog(vmmGObjectUI):
def show(self, parent, vm):
logging.debug("Showing migrate wizard")
self.vm = vm
self._set_vm(vm)
self._reset_state()
self.topwin.set_transient_for(parent)
self.topwin.present()
@ -97,9 +97,21 @@ class vmmMigrateDialog(vmmGObjectUI):
def close(self, ignore1=None, ignore2=None):
logging.debug("Closing migrate wizard")
self.topwin.hide()
self.vm = None
self._set_vm(None)
return 1
def _vm_removed(self, _conn, connkey):
if self.vm.get_connkey() == connkey:
self.close()
def _set_vm(self, newvm):
oldvm = self.vm
if oldvm:
oldvm.conn.disconnect_by_obj(self)
if newvm:
newvm.conn.connect("vm-removed", self._vm_removed)
self.vm = newvm
################
# Init helpers #