diff options
author | Nicholas Piggin <npiggin@gmail.com> | 2025-03-12 23:00:01 +1000 |
---|---|---|
committer | Thomas Huth <thuth@redhat.com> | 2025-03-12 18:20:50 +0100 |
commit | 7524e1b33679dc1356e8bb4efdd18e83fc50f5cc (patch) | |
tree | 83ca60dae44fa1c87e25a1275764a852828b0fae | |
parent | a5e8299d1a119b9d757ae28a57612f633894d2f6 (diff) | |
download | qemu-7524e1b33679dc1356e8bb4efdd18e83fc50f5cc.zip qemu-7524e1b33679dc1356e8bb4efdd18e83fc50f5cc.tar.gz qemu-7524e1b33679dc1356e8bb4efdd18e83fc50f5cc.tar.bz2 |
tests/functional/asset: Verify downloaded size
If the server provides a Content-Length header, use that to verify the
size of the downloaded file. This catches cases where the connection
terminates early, and gives the opportunity to retry. Without this, the
checksum will likely mismatch and fail without retry.
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-ID: <20250312130002.945508-3-npiggin@gmail.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
-rw-r--r-- | tests/functional/qemu_test/asset.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py index 27dd839..6bbfb9e 100644 --- a/tests/functional/qemu_test/asset.py +++ b/tests/functional/qemu_test/asset.py @@ -121,6 +121,20 @@ class Asset: with tmp_cache_file.open("xb") as dst: with urllib.request.urlopen(self.url) as resp: copyfileobj(resp, dst) + length_hdr = resp.getheader("Content-Length") + + # Verify downloaded file size against length metadata, if + # available. + if length_hdr is not None: + length = int(length_hdr) + fsize = tmp_cache_file.stat().st_size + if fsize != length: + self.log.error("Unable to download %s: " + "connection closed before " + "transfer complete (%d/%d)", + self.url, fsize, length) + tmp_cache_file.unlink() + continue break except FileExistsError: self.log.debug("%s already exists, " |