tests/functional: Fix problems in asset.py reported by pylint

The "raise" without an Exception was a real problem, the other
spots are rather cosmetics.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20251015095454.1575318-2-thuth@redhat.com>
This commit is contained in:
Thomas Huth 2025-10-13 15:38:03 +02:00
parent 41a6620c91
commit 1a6ccf45eb

View file

@ -112,7 +112,7 @@ class Asset:
return False
self.log.debug("Time out while waiting for %s!", tmp_cache_file)
raise
raise TimeoutError(f"Time out while waiting for {tmp_cache_file}")
def _save_time_stamp(self):
'''
@ -141,7 +141,7 @@ class Asset:
self.log.info("Downloading %s to %s...", self.url, self.cache_file)
tmp_cache_file = self.cache_file.with_suffix(".download")
for retries in range(3):
for _retries in range(3):
try:
with tmp_cache_file.open("xb") as dst:
with urllib.request.urlopen(self.url) as resp:
@ -181,7 +181,7 @@ class Asset:
# server or networking problem
if e.code == 404:
raise AssetError(self, "Unable to download: "
"HTTP error %d" % e.code)
"HTTP error %d" % e.code) from e
continue
except URLError as e:
# This is typically a network/service level error
@ -190,7 +190,7 @@ class Asset:
self.log.error("Unable to download %s: URL error %s",
self.url, e.reason)
raise AssetError(self, "Unable to download: URL error %s" %
e.reason, transient=True)
e.reason, transient=True) from e
except ConnectionError as e:
# A socket connection failure, such as dropped conn
# or refused conn
@ -201,7 +201,7 @@ class Asset:
except Exception as e:
tmp_cache_file.unlink()
raise AssetError(self, "Unable to download: %s" % e,
transient=True)
transient=True) from e
if not os.path.exists(tmp_cache_file):
raise AssetError(self, "Download retries exceeded", transient=True)
@ -214,7 +214,6 @@ class Asset:
self.hash.encode('utf8'))
except Exception as e:
self.log.debug("Unable to set xattr on %s: %s", tmp_cache_file, e)
pass
if not self._check(tmp_cache_file):
tmp_cache_file.unlink()
@ -224,9 +223,10 @@ class Asset:
# Remove write perms to stop tests accidentally modifying them
os.chmod(self.cache_file, stat.S_IRUSR | stat.S_IRGRP)
self.log.info("Cached %s at %s" % (self.url, self.cache_file))
self.log.info("Cached %s at %s", self.url, self.cache_file)
return str(self.cache_file)
@staticmethod
def precache_test(test):
log = logging.getLogger('qemu-test')
log.setLevel(logging.DEBUG)
@ -237,16 +237,17 @@ class Asset:
handler.setFormatter(formatter)
log.addHandler(handler)
for name, asset in vars(test.__class__).items():
if name.startswith("ASSET_") and type(asset) == Asset:
if name.startswith("ASSET_") and isinstance(asset, Asset):
try:
asset.fetch()
except AssetError as e:
if not e.transient:
raise
log.error("%s: skipping asset precache" % e)
log.error("%s: skipping asset precache", e)
log.removeHandler(handler)
@staticmethod
def precache_suite(suite):
for test in suite:
if isinstance(test, unittest.TestSuite):
@ -254,9 +255,10 @@ class Asset:
elif isinstance(test, unittest.TestCase):
Asset.precache_test(test)
def precache_suites(path, cacheTstamp):
@staticmethod
def precache_suites(path, cache_tstamp):
loader = unittest.loader.defaultTestLoader
tests = loader.loadTestsFromNames([path], None)
with open(cacheTstamp, "w") as fh:
with open(cache_tstamp, "w", encoding='utf-8'):
Asset.precache_suite(tests)