From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, "Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 2/7] tests/functional/qemu_test: Split huge fetch() function in asset.py
Date: Mon, 30 Mar 2026 12:28:10 +0200 [thread overview]
Message-ID: <20260330102815.6759-3-thuth@redhat.com> (raw)
In-Reply-To: <20260330102815.6759-1-thuth@redhat.com>
From: Thomas Huth <thuth@redhat.com>
The fetch() function has become really huge and pylint complains about
that. Extract the internal retry-three-times-download loop into a
separate function to make it a little bit more readable and to make
pylint happy about this file again.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-ID: <20260324163543.55503-4-thuth@redhat.com>
---
tests/functional/qemu_test/asset.py | 43 ++++++++++++++++-------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py
index 1cd03c2a9a9..51a434b2b70 100644
--- a/tests/functional/qemu_test/asset.py
+++ b/tests/functional/qemu_test/asset.py
@@ -133,24 +133,7 @@ def _save_time_stamp(self):
'''
self.cache_file.with_suffix(".stamp").write_text(f"{int(time.time())}")
- def fetch(self):
- '''Download the asset from the internet'''
- if not self.cache_dir.exists():
- self.cache_dir.mkdir(parents=True, exist_ok=True)
-
- if self.valid():
- self.log.debug("Using cached asset %s for %s",
- self.cache_file, self.url)
- self._save_time_stamp()
- return str(self.cache_file)
-
- if not self.fetchable():
- raise AssetError(self,
- "Asset cache is invalid and downloads disabled")
-
- self.log.info("Downloading %s to %s...", self.url, self.cache_file)
- tmp_cache_file = self.cache_file.with_suffix(".download")
-
+ def _try_to_fetch(self, tmp_cache_file):
for _retries in range(3):
try:
with tmp_cache_file.open("xb") as dst:
@@ -176,7 +159,7 @@ def fetch(self):
"waiting for other thread to finish...",
tmp_cache_file)
if self._wait_for_other_download(tmp_cache_file):
- return str(self.cache_file)
+ return True
self.log.debug("%s seems to be stale, "
"deleting and retrying download...",
tmp_cache_file)
@@ -213,6 +196,28 @@ def fetch(self):
tmp_cache_file.unlink()
raise AssetError(self, f"Unable to download: {e}",
transient=True) from e
+ return False
+
+ def fetch(self):
+ '''Download the asset from the internet'''
+ if not self.cache_dir.exists():
+ self.cache_dir.mkdir(parents=True, exist_ok=True)
+
+ if self.valid():
+ self.log.debug("Using cached asset %s for %s",
+ self.cache_file, self.url)
+ self._save_time_stamp()
+ return str(self.cache_file)
+
+ if not self.fetchable():
+ raise AssetError(self,
+ "Asset cache is invalid and downloads disabled")
+
+ self.log.info("Downloading %s to %s...", self.url, self.cache_file)
+ tmp_cache_file = self.cache_file.with_suffix(".download")
+
+ if self._try_to_fetch(tmp_cache_file):
+ return str(self.cache_file)
if not os.path.exists(tmp_cache_file):
raise AssetError(self, "Download retries exceeded", transient=True)
--
2.53.0
next prev parent reply other threads:[~2026-03-30 10:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 10:28 [PULL 0/7] Fixes for QEMU v11.0-rc2 Thomas Huth
2026-03-30 10:28 ` [PULL 1/7] tests/functional/qemu_test: Silence (most) warnings from pylint in asset.py Thomas Huth
2026-03-30 10:28 ` Thomas Huth [this message]
2026-03-30 10:28 ` [PULL 3/7] tests/functional/qemu_test: Silence warnings from pylint in config.py Thomas Huth
2026-03-30 10:28 ` [PULL 4/7] hw/display/vga-isa: Fix migration of the isa-vga device Thomas Huth
2026-03-30 10:28 ` [PULL 5/7] hw/display/cirrus_vga_isa: Disable global_vmstate by default for new machines Thomas Huth
2026-03-30 10:28 ` [PULL 6/7] pc-bios: remove obsolete linuxboot.bin prebuilt blob Thomas Huth
2026-03-30 10:28 ` [PULL 7/7] tests/functional/migration.py: Skip migration_with_exec() if socat is not available Thomas Huth
2026-03-30 12:54 ` [PULL 0/7] Fixes for QEMU v11.0-rc2 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260330102815.6759-3-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.