From 7a63fb95ec74b057218bbfce275edc64fc250546 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sat, 22 Aug 2020 15:04:01 -0400 Subject: [PATCH] object: Finish off non-domain code coverage Signed-off-by: Cole Robinson --- virtManager/object/libvirtobject.py | 8 +++--- virtManager/object/nodedev.py | 43 ++++++----------------------- virtManager/object/storagepool.py | 6 ++-- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/virtManager/object/libvirtobject.py b/virtManager/object/libvirtobject.py index 1b94ca6f..ef561c8a 100644 --- a/virtManager/object/libvirtobject.py +++ b/virtManager/object/libvirtobject.py @@ -117,7 +117,7 @@ class vmmLibvirtObject(vmmGObject): self.ensure_latest_xml() xmlobj = self._make_xmlobj_to_define() if xmlobj.name == newname: - return + return # pragma: no cover log.debug("Changing %s name from %s to %s", self, oldname, newname) @@ -155,11 +155,11 @@ class vmmLibvirtObject(vmmGObject): def _get_backend_status(self): raise NotImplementedError() - def _define(self, xml): + def _define(self, xml): # pragma: no cover ignore = xml return - def delete(self, force=True): + def delete(self, force=True): # pragma: no cover ignore = force def get_name(self): @@ -183,7 +183,7 @@ class vmmLibvirtObject(vmmGObject): a new object appears. """ if self.__initialized: - return + return # pragma: no cover initialize_failed = False try: diff --git a/virtManager/object/nodedev.py b/virtManager/object/nodedev.py index 2877d85b..8f49df06 100644 --- a/virtManager/object/nodedev.py +++ b/virtManager/object/nodedev.py @@ -10,44 +10,19 @@ from .libvirtobject import vmmLibvirtObject def _usb_pretty_name(xmlobj): - # Hypervisor may return a rather sparse structure, missing - # some ol all stringular descriptions of the device altogether. - # Do our best to help user identify the device. - - # Certain devices pad their vendor with trailing spaces, - # such as "LENOVO ". It does not look well. - product = str(xmlobj.product_name).strip() - vendor = str(xmlobj.vendor_name).strip() - - if product == "": - product = str(xmlobj.product_id) - if vendor == "": - # No stringular descriptions altogether - vendor = str(xmlobj.vendor_id) - devstr = "%s:%s" % (vendor, product) - else: - # Only the vendor is known - devstr = "%s %s" % (vendor, product) - else: - if vendor == "": - # Sometimes vendor is left out empty, but product is - # already descriptive enough or contains the vendor string: - # "Lenovo USB Laser Mouse" - devstr = product - else: - # We know everything. Perfect. - devstr = "%s %s" % (vendor, product) - + # product/vendor name fields can be messy, this tries to cope + product = str(xmlobj.product_name or "").strip() + vendor = str(xmlobj.vendor_name or "").strip() + product = product or str(xmlobj.product_id or "") + vendor = vendor or str(xmlobj.vendor_id or "") busstr = "%.3d:%.3d" % (int(xmlobj.bus), int(xmlobj.device)) - desc = "%s %s" % (busstr, devstr) + desc = "%s %s %s" % (busstr, vendor, product) return desc def _pretty_name(xmlobj): if xmlobj.device_type == "net": - if xmlobj.interface: - return _("Interface %s") % xmlobj.interface - return xmlobj.name + return _("Interface %s") % xmlobj.interface or xmlobj.name if xmlobj.device_type == "pci": devstr = "%.4X:%.2X:%.2X:%X" % (int(xmlobj.domain), @@ -64,7 +39,7 @@ def _pretty_name(xmlobj): xmlobj.conn, xmlobj.parent) return "%s (%s)" % (_pretty_name(parent), xmlobj.drm_type) - return xmlobj.name + return xmlobj.name # pragma: no cover class vmmNodeDevice(vmmLibvirtObject): @@ -72,7 +47,7 @@ class vmmNodeDevice(vmmLibvirtObject): vmmLibvirtObject.__init__(self, conn, backend, key, NodeDevice) def _conn_tick_poll_param(self): - return "pollnodedev" + return "pollnodedev" # pragma: no cover def class_name(self): return "nodedev" diff --git a/virtManager/object/storagepool.py b/virtManager/object/storagepool.py index e7bdf27e..d59057d2 100644 --- a/virtManager/object/storagepool.py +++ b/virtManager/object/storagepool.py @@ -47,9 +47,9 @@ class vmmStorageVolume(vmmLibvirtObject): ########################## def _conn_tick_poll_param(self): - return None + return None # pragma: no cover def class_name(self): - return "volume" + return "volume" # pragma: no cover def _XMLDesc(self, flags): try: @@ -289,5 +289,3 @@ class vmmStoragePool(vmmLibvirtObject): return _pretty_bytes(self.get_allocation()) def get_pretty_available(self): return _pretty_bytes(self.get_available()) - def get_pretty_capacity(self): - return _pretty_bytes(self.get_capacity())