virtManager: Misc coverage annotations

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-08-22 15:42:08 -04:00
parent dc41f61e5e
commit 1684049fa3
8 changed files with 47 additions and 51 deletions

View File

@ -68,7 +68,7 @@ class vmmGObject(GObject.GObject):
def cleanup(self): def cleanup(self):
if self.__cleaned_up: if self.__cleaned_up:
return return # pragma: no cover
# Do any cleanup required to drop reference counts so object is # Do any cleanup required to drop reference counts so object is
# actually reaped by python. Usually means unregistering callbacks # actually reaped by python. Usually means unregistering callbacks
@ -93,7 +93,7 @@ class vmmGObject(GObject.GObject):
self.disconnect(h) self.disconnect(h)
for h in self._gobject_timeouts[:]: for h in self._gobject_timeouts[:]:
self.remove_gobject_timeout(h) self.remove_gobject_timeout(h)
except Exception: except Exception: # pragma: no cover
log.exception("Error cleaning up %s", self) log.exception("Error cleaning up %s", self)
self.__cleaned_up = True self.__cleaned_up = True
@ -110,7 +110,7 @@ class vmmGObject(GObject.GObject):
try: try:
if config.vmmConfig.is_initialized() and self._leak_check: if config.vmmConfig.is_initialized() and self._leak_check:
self.config.remove_object(self.object_key) self.config.remove_object(self.object_key)
except Exception: except Exception: # pragma: no cover
log.exception("Error removing %s", self.object_key) log.exception("Error removing %s", self.object_key)
@property @property
@ -171,7 +171,7 @@ class vmmGObject(GObject.GObject):
""" """
GObject emit() wrapper to simplify callers GObject emit() wrapper to simplify callers
""" """
if not self._is_main_thread(): if not self._is_main_thread(): # pragma: no cover
log.error("emitting signal from non-main thread. This is a bug " log.error("emitting signal from non-main thread. This is a bug "
"please report it. thread=%s self=%s signal=%s", "please report it. thread=%s self=%s signal=%s",
self._thread_name(), self, signal_name) self._thread_name(), self, signal_name)
@ -189,6 +189,18 @@ class vmmGObject(GObject.GObject):
GLib.source_remove(handle) GLib.source_remove(handle)
self._gobject_timeouts.remove(handle) self._gobject_timeouts.remove(handle)
def _start_thread(self, target=None, name=None, args=None, kwargs=None):
# Helper for starting a daemonized thread
t = threading.Thread(target=target, name=name,
args=args or [], kwargs=kwargs or {})
t.daemon = True
t.start()
##############################
# Internal debugging helpers #
##############################
def _refcount(self): def _refcount(self):
return sys.getrefcount(self) return sys.getrefcount(self)
@ -199,18 +211,11 @@ class vmmGObject(GObject.GObject):
msg, self.object_key, self._refcount(), msg, self.object_key, self._refcount(),
"".join(traceback.format_stack())) "".join(traceback.format_stack()))
def _gc_get_referrers(self): def _gc_get_referrers(self): # pragma: no cover
import gc import gc
import pprint import pprint
pprint.pprint(gc.get_referrers(self)) pprint.pprint(gc.get_referrers(self))
def _start_thread(self, target=None, name=None, args=None, kwargs=None):
# Helper for starting a daemonized thread
t = threading.Thread(target=target, name=name,
args=args or [], kwargs=kwargs or {})
t.daemon = True
t.start()
def _thread_name(self): def _thread_name(self):
return threading.current_thread().name return threading.current_thread().name
@ -304,7 +309,7 @@ class vmmGObjectUI(vmmGObject):
def cleanup(self): def cleanup(self):
if self.__cleaned_up: if self.__cleaned_up:
return return # pragma: no cover
try: try:
self.close() self.close()
@ -314,7 +319,7 @@ class vmmGObjectUI(vmmGObject):
self.topwin.destroy() self.topwin.destroy()
self.topwin = None self.topwin = None
self._err = None self._err = None
except Exception: except Exception: # pragma: no cover
log.exception("Error cleaning up %s", self) log.exception("Error cleaning up %s", self)
self.__cleaned_up = True self.__cleaned_up = True
@ -343,7 +348,7 @@ class vmmGObjectUI(vmmGObject):
cursor = Gdk.Cursor.new_from_name( cursor = Gdk.Cursor.new_from_name(
gdk_window.get_display(), cursor_type) gdk_window.get_display(), cursor_type)
gdk_window.set_cursor(cursor) gdk_window.set_cursor(cursor)
except Exception: except Exception: # pragma: no cover
# If a cursor icon theme isn't installed this can cause errors # If a cursor icon theme isn't installed this can cause errors
# https://bugzilla.redhat.com/show_bug.cgi?id=1516588 # https://bugzilla.redhat.com/show_bug.cgi?id=1516588
log.debug("Error setting cursor_type=%s", log.debug("Error setting cursor_type=%s",

View File

@ -122,7 +122,7 @@ class vmmCloneVM(vmmGObjectUI):
if uri not in cls._instances: if uri not in cls._instances:
cls._instances[uri] = vmmCloneVM() cls._instances[uri] = vmmCloneVM()
cls._instances[uri].show(parentobj.topwin, vm) cls._instances[uri].show(parentobj.topwin, vm)
except Exception as e: except Exception as e: # pragma: no cover
parentobj.err.show_err( parentobj.err.show_err(
_("Error launching clone dialog: %s") % str(e)) _("Error launching clone dialog: %s") % str(e))

View File

@ -39,7 +39,7 @@ class _vmmDeleteBase(vmmGObjectUI):
if not cls._instance: if not cls._instance:
cls._instance = vmmDeleteDialog() cls._instance = vmmDeleteDialog()
cls._instance.show(parentobj.topwin, vm) cls._instance.show(parentobj.topwin, vm)
except Exception as e: except Exception as e: # pragma: no cover
parentobj.err.show_err( parentobj.err.show_err(
_("Error launching delete dialog: %s") % str(e)) _("Error launching delete dialog: %s") % str(e))

View File

@ -12,7 +12,7 @@ from gi.repository import Gtk
BASECOLOR = Gtk.StyleContext().lookup_color("theme_base_color")[1] BASECOLOR = Gtk.StyleContext().lookup_color("theme_base_color")[1]
def rect_print(name, rect): def rect_print(name, rect): # pragma: no cover
# For debugging # For debugging
print("%s: height=%d, width=%d, x=%d, y=%d" % print("%s: height=%d, width=%d, x=%d, y=%d" %
(name, rect.height, rect.width, rect.x, rect.y)) (name, rect.height, rect.width, rect.x, rect.y))
@ -53,7 +53,7 @@ def _line_helper(cairo_ct, bottom_baseline, points, for_fill=False):
def draw_line(cairo_ct, y, h, points): def draw_line(cairo_ct, y, h, points):
if not len(points): if not len(points):
return return # pragma: no cover
last_point = _line_helper(cairo_ct, y + h, points) last_point = _line_helper(cairo_ct, y + h, points)
if not last_point: if not last_point:
@ -66,7 +66,7 @@ def draw_line(cairo_ct, y, h, points):
def draw_fill(cairo_ct, x, y, w, h, points, taper=False): def draw_fill(cairo_ct, x, y, w, h, points, taper=False):
if not len(points): if not len(points):
return return # pragma: no cover
_line_helper(cairo_ct, y + h, points, for_fill=True) _line_helper(cairo_ct, y + h, points, for_fill=True)
@ -175,10 +175,9 @@ class CellRendererSparkline(Gtk.CellRenderer):
def get_y(index): def get_y(index):
baseline_y = graph_y + graph_height baseline_y = graph_y + graph_height
n = index
if self.reversed: if self.reversed:
n = (len(self.data_array) - index - 1) n = (len(self.data_array) - index - 1)
else:
n = index
val = self.data_array[n] val = self.data_array[n]
y = baseline_y - (graph_height * val) y = baseline_y - (graph_height * val)
@ -216,19 +215,14 @@ class CellRendererSparkline(Gtk.CellRenderer):
def do_get_size(self, widget, cell_area=None): def do_get_size(self, widget, cell_area=None):
ignore = widget ignore = widget
ignore = cell_area
FIXED_WIDTH = len(self.data_array) FIXED_WIDTH = len(self.data_array)
FIXED_HEIGHT = 15 FIXED_HEIGHT = 15
xpad = self.get_property("xpad") xpad = self.get_property("xpad")
ypad = self.get_property("ypad") ypad = self.get_property("ypad")
xoffset = 0
if cell_area: yoffset = 0
# What to do here? haven't encountered this in practice
xoffset = 0
yoffset = 0
else:
xoffset = 0
yoffset = 0
width = ((xpad * 2) + FIXED_WIDTH) width = ((xpad * 2) + FIXED_WIDTH)
height = ((ypad * 2) + FIXED_HEIGHT) height = ((ypad * 2) + FIXED_HEIGHT)
@ -239,7 +233,7 @@ class CellRendererSparkline(Gtk.CellRenderer):
# variables can't be named like that # variables can't be named like that
def _sanitize_param_spec_name(self, name): def _sanitize_param_spec_name(self, name):
return name.replace("-", "_") return name.replace("-", "_")
def do_get_property(self, param_spec): def do_get_property(self, param_spec): # pragma: no cover
name = self._sanitize_param_spec_name(param_spec.name) name = self._sanitize_param_spec_name(param_spec.name)
return getattr(self, name) return getattr(self, name)
def do_set_property(self, param_spec, value): def do_set_property(self, param_spec, value):
@ -365,7 +359,7 @@ class Sparkline(Gtk.DrawingArea):
return 0 return 0
def do_size_request(self, requisition): def do_size_request(self, requisition): # pragma: no cover
width = len(self.data_array) / self.num_sets width = len(self.data_array) / self.num_sets
height = 20 height = 20
@ -376,7 +370,7 @@ class Sparkline(Gtk.DrawingArea):
# variables can't be named like that # variables can't be named like that
def _sanitize_param_spec_name(self, name): def _sanitize_param_spec_name(self, name):
return name.replace("-", "_") return name.replace("-", "_")
def do_get_property(self, param_spec): def do_get_property(self, param_spec): # pragma: no cover
name = self._sanitize_param_spec_name(param_spec.name) name = self._sanitize_param_spec_name(param_spec.name)
return getattr(self, name) return getattr(self, name)
def do_set_property(self, param_spec, value): def do_set_property(self, param_spec, value):

View File

@ -10,10 +10,6 @@ import libvirt
from virtinst import log from virtinst import log
if not hasattr(libvirt, "VIR_DOMAIN_PMSUSPENDED"):
setattr(libvirt, "VIR_DOMAIN_PMSUSPENDED", 7)
class _LibvirtEnumMap(object): class _LibvirtEnumMap(object):
""" """
Helper for mapping libvirt event int values to their API names Helper for mapping libvirt event int values to their API names
@ -74,7 +70,7 @@ class _LibvirtEnumMap(object):
elif status == libvirt.VIR_DOMAIN_PAUSED: elif status == libvirt.VIR_DOMAIN_PAUSED:
return _("Paused") return _("Paused")
elif status == libvirt.VIR_DOMAIN_SHUTDOWN: elif status == libvirt.VIR_DOMAIN_SHUTDOWN:
return _("Shutting Down") return _("Shutting Down") # pragma: no cover
elif status == libvirt.VIR_DOMAIN_SHUTOFF: elif status == libvirt.VIR_DOMAIN_SHUTOFF:
if has_managed_save: if has_managed_save:
return _("Saved") return _("Saved")
@ -85,8 +81,9 @@ class _LibvirtEnumMap(object):
elif status == libvirt.VIR_DOMAIN_PMSUSPENDED: elif status == libvirt.VIR_DOMAIN_PMSUSPENDED:
return _("Suspended") return _("Suspended")
log.debug("Unknown status %s, returning 'Unknown'", status) log.debug( # pragma: no cover
return _("Unknown") "Unknown status %s, returning 'Unknown'", status)
return _("Unknown") # pragma: no cover
@staticmethod @staticmethod
def pretty_status_reason(status, reason): def pretty_status_reason(status, reason):
@ -142,11 +139,11 @@ class _LibvirtEnumMap(object):
ret = {} ret = {}
for key in [a for a in dir(libvirt) if re.match(regex, a)]: for key in [a for a in dir(libvirt) if re.match(regex, a)]:
val = getattr(libvirt, key) val = getattr(libvirt, key)
if type(val) is not int: if type(val) is not int: # pragma: no cover
log.debug("libvirt regex=%s key=%s val=%s " log.debug("libvirt regex=%s key=%s val=%s "
"isn't an integer", regex, key, val) "isn't an integer", regex, key, val)
continue continue
if val in ret: if val in ret: # pragma: no cover
log.debug("libvirt regex=%s key=%s val=%s is already " log.debug("libvirt regex=%s key=%s val=%s is already "
"in dict as key=%s", regex, key, val, regex[val]) "in dict as key=%s", regex, key, val, regex[val])
continue continue
@ -168,7 +165,7 @@ class _LibvirtEnumMap(object):
if eventmap: if eventmap:
if event not in eventmap: if event not in eventmap:
event = next(iter(eventmap)) event = next(iter(eventmap)) # pragma: no cover
eventstr = eventmap[event] eventstr = eventmap[event]
detail1map = self._get_map(eventstr, detail1map = self._get_map(eventstr,
self._DETAIL1_PREFIX.get(eventstr)) self._DETAIL1_PREFIX.get(eventstr))

View File

@ -32,7 +32,7 @@ class vmmMigrateDialog(vmmGObjectUI):
if not cls._instance: if not cls._instance:
cls._instance = vmmMigrateDialog() cls._instance = vmmMigrateDialog()
cls._instance.show(parentobj.topwin, vm) cls._instance.show(parentobj.topwin, vm)
except Exception as e: except Exception as e: # pragma: no cover
parentobj.err.show_err( parentobj.err.show_err(
_("Error launching migrate dialog: %s") % str(e)) _("Error launching migrate dialog: %s") % str(e))

View File

@ -213,7 +213,7 @@ class vmmStoragePool(vmmLibvirtObject):
we just updated it. we just updated it.
""" """
if not self.is_active(): if not self.is_active():
return return # pragma: no cover
self._backend.refresh(0) self._backend.refresh(0)
if self._using_events() and not _from_object_init: if self._using_events() and not _from_object_init:

View File

@ -38,7 +38,7 @@ class vmmVMWindow(vmmGObjectUI):
if key not in cls._instances: if key not in cls._instances:
cls._instances[key] = vmmVMWindow(vm) cls._instances[key] = vmmVMWindow(vm)
return cls._instances[key] return cls._instances[key]
except Exception as e: except Exception as e: # pragma: no cover
if not parentobj: if not parentobj:
raise raise
parentobj.err.show_err( parentobj.err.show_err(
@ -229,7 +229,7 @@ class vmmVMWindow(vmmGObjectUI):
if self.console.details_viewer_is_visible(): if self.console.details_viewer_is_visible():
try: try:
self.console.details_close_viewer() self.console.details_close_viewer()
except Exception: except Exception: # pragma: no cover
log.error("Failure when disconnecting from desktop server") log.error("Failure when disconnecting from desktop server")
self.emit("closed") self.emit("closed")
@ -484,7 +484,7 @@ class vmmVMWindow(vmmGObjectUI):
ignore = src ignore = src
try: try:
return self._take_screenshot() return self._take_screenshot()
except Exception as e: except Exception as e: # pragma: no cover
self.err.show_err(_("Error taking screenshot: %s") % str(e)) self.err.show_err(_("Error taking screenshot: %s") % str(e))
def control_vm_usb_redirection(self, src): def control_vm_usb_redirection(self, src):
@ -492,7 +492,7 @@ class vmmVMWindow(vmmGObjectUI):
spice_usbdev_dialog = self.err spice_usbdev_dialog = self.err
spice_usbdev_widget = self.console.details_viewer_get_usb_widget() spice_usbdev_widget = self.console.details_viewer_get_usb_widget()
if not spice_usbdev_widget: if not spice_usbdev_widget: # pragma: no cover
self.err.show_err(_("Error initializing spice USB device widget")) self.err.show_err(_("Error initializing spice USB device widget"))
return return
@ -522,7 +522,7 @@ class vmmVMWindow(vmmGObjectUI):
ret = ret[1] ret = ret[1]
# F24 rawhide, ret[1] is a named tuple with a 'buffer' element... # F24 rawhide, ret[1] is a named tuple with a 'buffer' element...
if hasattr(ret, "buffer"): if hasattr(ret, "buffer"):
ret = ret.buffer ret = ret.buffer # pragma: no cover
import datetime import datetime
now = str(datetime.datetime.now()).split(".")[0].replace(" ", "_") now = str(datetime.datetime.now()).split(".")[0].replace(" ", "_")
@ -557,7 +557,7 @@ class vmmVMWindow(vmmGObjectUI):
try: try:
if self.is_visible(): if self.is_visible():
self.vm.ensure_latest_xml() self.vm.ensure_latest_xml()
except Exception as e: except Exception as e: # pragma: no cover
if self.conn.support.is_libvirt_error_no_domain(e): if self.conn.support.is_libvirt_error_no_domain(e):
self.close() self.close()
return return