Fix pylint raise-missing-from

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-15 12:33:31 -04:00
parent 3238594028
commit 9fdbccec2b
9 changed files with 31 additions and 34 deletions

View File

@ -299,6 +299,7 @@ class Command(object):
dom = conn.defineXML(domxml)
dom.undefine()
except Exception as e:
# pylint: disable=raise-missing-from
raise AssertionError("Bad XML:\n%s\n\nError was: %s: %s" %
(domxml, e.__class__.__name__, str(e)))

View File

@ -207,6 +207,7 @@ def test_create(testconn, xml, define_func="defineXML"):
func = getattr(testconn, define_func)
obj = func(xml)
except Exception as e:
# pylint: disable=raise-missing-from
raise RuntimeError(str(e) + "\n" + xml)
try:

View File

@ -593,7 +593,7 @@ class vmmConnection(vmmGObject):
"origerror": str(renameerr),
"recovererror": str(fixerr),
}
raise RuntimeError(msg)
raise RuntimeError(msg) from None
raise
finally:
if newobj:

View File

@ -144,7 +144,7 @@ def setupLogging(appname, debug_stdout, do_quiet, cli_app=True):
os.makedirs(vi_dir, 0o751)
except IOError as e:
raise RuntimeError("Could not create directory %s: %s" %
(vi_dir, e))
(vi_dir, e)) from None
if (logfile and
os.path.exists(logfile) and
@ -1116,8 +1116,8 @@ class _VirtCLIArgument(object):
if self.propname:
xmlutil.get_prop_path(inst, self.propname)
except AttributeError: # pragma: no cover
raise xmlutil.DevError(
"obj=%s does not have member=%s" % (inst, self.propname))
msg = "obj=%s does not have member=%s" % (inst, self.propname)
raise xmlutil.DevError(msg) from None
if self._virtarg.cb:
self._virtarg.cb(parser, inst, self.val, self)

View File

@ -41,11 +41,9 @@ def _replace_vm(conn, name):
log.debug("Undefining guest '%s'", name)
vm.undefine()
except libvirt.libvirtError as e: # pragma: no cover
raise RuntimeError(
_("Could not remove old vm '%(vm)s': %(error)s") % {
"vm": name,
"error": str(e),
})
msg = (_("Could not remove old vm '%(vm)s': %(error)s") % {
"vm": name, "error": str(e)})
raise RuntimeError(msg) from None
def _generate_clone_name(conn, basename):
@ -485,7 +483,8 @@ class Cloner(object):
check_collision=not self._replace,
validate=False)
except ValueError as e:
raise ValueError(_("Invalid name for new guest: %s") % e)
msg = _("Invalid name for new guest: %s") % e
raise ValueError(msg) from None
for diskinfo in self.get_nonshare_diskinfos():
orig_disk = diskinfo.disk

View File

@ -619,12 +619,13 @@ class CloneStorageCreator(_StorageCreator):
if i < size_bytes:
meter.update(i)
except OSError as e: # pragma: no cover
log.debug("Error while cloning", exc_info=True)
msg = (_("Error cloning diskimage "
"%(inputpath)s to %(outputpath)s: %(error)s") %
{"inputpath": self._input_path,
"outputpath": self._output_path,
"error": str(e)})
raise RuntimeError(msg)
raise RuntimeError(msg) from None
finally:
if src_fd is not None:
os.close(src_fd)

View File

@ -66,11 +66,9 @@ class InstallerTreeMedia(object):
"like HTTP, or manually mount the NFS share and install "
"from the local directory mount point.")
raise ValueError(
_("Validating install media '%(media)s' failed: %(error)s") % {
"media": str(path),
"error": str(e),
})
msg = (_("Validating install media '%(media)s' failed: %(error)s") %
{"media": str(path), "error": str(e)})
raise ValueError(msg) from None
@staticmethod
def get_system_scratchdir(guest):

View File

@ -65,11 +65,9 @@ class _URLFetcher(object):
try:
urlobj, size = self._grabber(url)
except Exception as e:
raise ValueError(
_("Couldn't acquire file %(url)s: %(error)s") % {
"url": url,
"error": str(e),
})
msg = (_("Couldn't acquire file %(url)s: %(error)s") % {
"url": url, "error": str(e)})
raise ValueError(msg) from None
log.debug("Fetching URI: %s", url)
self.meter.start(
@ -245,11 +243,9 @@ class _FTPURLFetcher(_URLFetcher):
# Force binary mode
self._ftp.voidcmd("TYPE I")
except Exception as e: # pragma: no cover
raise ValueError(
_("Opening URL %(url)s failed: %(error)s") % {
"url": self.location,
"error": str(e),
})
msg = (_("Opening URL %(url)s failed: %(error)s") % {
"url": self.location, "error": str(e)})
raise ValueError(msg) from None
def _grabber(self, url):
"""

View File

@ -162,11 +162,10 @@ class StoragePool(_StorageObject):
defpool.install(build=True, create=True, autostart=True)
return defpool
except Exception as e: # pragma: no cover
raise RuntimeError(
_("Couldn't create default storage pool '%(path)s': %(error)s") % {
"path": path,
"error": str(e),
})
log.debug("Error building default pool", exc_info=True)
msg = (_("Couldn't create default storage pool '%(path)s': %(error)s") %
{"path": path, "error": str(e)})
raise RuntimeError(msg) from None
@staticmethod
def lookup_pool_by_path(conn, path):
@ -386,7 +385,8 @@ class StoragePool(_StorageObject):
try:
pool = self.conn.storagePoolDefineXML(xml, 0)
except Exception as e: # pragma: no cover
raise RuntimeError(_("Could not define storage pool: %s") % str(e))
msg = _("Could not define storage pool: %s") % str(e)
raise RuntimeError(msg) from None
errmsg = None
if build:
@ -706,8 +706,9 @@ class StorageVolume(_StorageObject):
return vol
except Exception as e:
log.debug("Error creating storage volume", exc_info=True)
raise RuntimeError("Couldn't create storage volume "
"'%s': '%s'" % (self.name, str(e)))
msg = ("Couldn't create storage volume '%s': '%s'" % (
self.name, str(e)))
raise RuntimeError(msg) from None
finally:
event.set()
t.join()