uitests: Finish inspection.py coverage

As much as we can. There's not any current way to actually test
the full guestfs implementation, so we exclude it all

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson
2020-09-05 15:04:36 -04:00
parent 55fd4ccd23
commit cb49648106
2 changed files with 31 additions and 14 deletions
+17
View File
@@ -29,6 +29,8 @@ class VMMInspection(uiutils.UITestCase):
# Use the test suite inspection mocking to test parts # Use the test suite inspection mocking to test parts
# of the UI that interact with inspection data # of the UI that interact with inspection data
self.app.open(enable_libguestfs=True) self.app.open(enable_libguestfs=True)
manager = self.app.topwin
details = self._open_details_window("test-clone") details = self._open_details_window("test-clone")
details.find("OS information", "table cell").click() details.find("OS information", "table cell").click()
tab = details.find("os-tab") tab = details.find("os-tab")
@@ -53,3 +55,18 @@ class VMMInspection(uiutils.UITestCase):
details.find("OS information", "table cell").click() details.find("OS information", "table cell").click()
tab = details.find("os-tab") tab = details.find("os-tab")
tab.find_fuzzy("Fake test error no disks") tab.find_fuzzy("Fake test error no disks")
# Closing and reopening a connection triggers some libguest
# cache reading
details.keyCombo("<alt>F4")
manager.click()
c = manager.find_fuzzy("testdriver.xml", "table cell")
c.click()
c.click(button=3)
self.app.root.find("conn-disconnect", "menu item").click()
manager.click()
c = manager.find_fuzzy("testdriver.xml", "table cell")
c.click()
c.click(button=3)
self.app.root.find("conn-connect", "menu item").click()
self.sleep(2)
+14 -14
View File
@@ -58,7 +58,7 @@ def _make_fake_data(vm):
return data return data
def _perform_inspection(conn, vm): def _perform_inspection(conn, vm): # pragma: no cover
""" """
Perform the actual guestfs interaction and return results in Perform the actual guestfs interaction and return results in
a vmmInspectionData object a vmmInspectionData object
@@ -191,7 +191,7 @@ class vmmInspection(vmmGObject):
def get_instance(cls): def get_instance(cls):
if not cls._instance: if not cls._instance:
if not cls.libguestfs_installed(): if not cls.libguestfs_installed():
return None return None # pragma: no cover
cls._instance = vmmInspection() cls._instance = vmmInspection()
return cls._instance return cls._instance
@@ -202,10 +202,10 @@ class vmmInspection(vmmGObject):
import guestfs as ignore # pylint: disable=import-error import guestfs as ignore # pylint: disable=import-error
log.debug("python guestfs is installed") log.debug("python guestfs is installed")
cls._libguestfs_installed = True cls._libguestfs_installed = True
except ImportError: except ImportError: # pragma: no cover
log.debug("python guestfs is not installed") log.debug("python guestfs is not installed")
cls._libguestfs_installed = False cls._libguestfs_installed = False
except Exception: except Exception: # pragma: no cover
log.debug("error importing guestfs", log.debug("error importing guestfs",
exc_info=True) exc_info=True)
cls._libguestfs_installed = False cls._libguestfs_installed = False
@@ -230,7 +230,7 @@ class vmmInspection(vmmGObject):
connmanager.connect("conn-added", self._conn_added_cb) connmanager.connect("conn-added", self._conn_added_cb)
connmanager.connect("conn-removed", self._conn_removed_cb) connmanager.connect("conn-removed", self._conn_removed_cb)
for conn in connmanager.conns.values(): for conn in connmanager.conns.values():
self._conn_added_cb(connmanager, conn) self._conn_added_cb(connmanager, conn) # pragma: no cover
self._start() self._start()
@@ -242,11 +242,11 @@ class vmmInspection(vmmGObject):
def _conn_added_cb(self, connmanager, conn): def _conn_added_cb(self, connmanager, conn):
uri = conn.get_uri() uri = conn.get_uri()
if uri in self._uris: if uri in self._uris:
return return # pragma: no cover
self._uris.append(uri) self._uris.append(uri)
conn.connect("vm-added", self._vm_added_cb) conn.connect("vm-added", self._vm_added_cb)
for vm in conn.list_vms(): for vm in conn.list_vms(): # pragma: no cover
self._vm_added_cb(conn, vm.get_name()) self._vm_added_cb(conn, vm.get_name())
def _conn_removed_cb(self, connmanager, uri): def _conn_removed_cb(self, connmanager, uri):
@@ -255,7 +255,7 @@ class vmmInspection(vmmGObject):
def _vm_added_cb(self, conn, vm): def _vm_added_cb(self, conn, vm):
# Called by the main thread whenever a VM is added to vmlist. # Called by the main thread whenever a VM is added to vmlist.
name = vm.get_name() name = vm.get_name()
if name.startswith("guestfs-"): if name.startswith("guestfs-"): # pragma: no cover
log.debug("ignore libvirt/guestfs temporary VM %s", name) log.debug("ignore libvirt/guestfs temporary VM %s", name)
return return
@@ -290,11 +290,11 @@ class vmmInspection(vmmGObject):
connmanager = vmmConnectionManager.get_instance() connmanager = vmmConnectionManager.get_instance()
conn = connmanager.conns.get(uri) conn = connmanager.conns.get(uri)
if not conn: if not conn:
return return # pragma: no cover
vm = conn.get_vm_by_name(vmname) vm = conn.get_vm_by_name(vmname)
if not vm: if not vm:
return return # pragma: no cover
# Try processing a single VM, keeping into account whether it was # Try processing a single VM, keeping into account whether it was
# visited already, and whether there are cached data for it. # visited already, and whether there are cached data for it.
@@ -313,7 +313,7 @@ class vmmInspection(vmmGObject):
try: try:
data = self._inspect_vm(conn, vm) data = self._inspect_vm(conn, vm)
except Exception as e: except Exception as e: # pragma: no cover
data = _inspection_error(_("Error inspection VM: %s") % str(e)) data = _inspection_error(_("Error inspection VM: %s") % str(e))
log.exception("%s: exception while processing", prettyvm) log.exception("%s: exception while processing", prettyvm)
@@ -321,15 +321,15 @@ class vmmInspection(vmmGObject):
def _inspect_vm(self, conn, vm): def _inspect_vm(self, conn, vm):
if self._thread is None: if self._thread is None:
return return # pragma: no cover
if conn.is_remote(): if conn.is_remote(): # pragma: no cover
return _inspection_error( return _inspection_error(
_("Cannot inspect VM on remote connection")) _("Cannot inspect VM on remote connection"))
if conn.is_test(): if conn.is_test():
return _make_fake_data(vm) return _make_fake_data(vm)
return _perform_inspection(conn, vm) return _perform_inspection(conn, vm) # pragma: no cover
############## ##############