Skip to content

Commit 7524e1b

Browse files
npigginhuth
authored andcommitted
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é <[email protected]> Signed-off-by: Nicholas Piggin <[email protected]> Message-ID: <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent a5e8299 commit 7524e1b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/functional/qemu_test/asset.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ def fetch(self):
121121
with tmp_cache_file.open("xb") as dst:
122122
with urllib.request.urlopen(self.url) as resp:
123123
copyfileobj(resp, dst)
124+
length_hdr = resp.getheader("Content-Length")
125+
126+
# Verify downloaded file size against length metadata, if
127+
# available.
128+
if length_hdr is not None:
129+
length = int(length_hdr)
130+
fsize = tmp_cache_file.stat().st_size
131+
if fsize != length:
132+
self.log.error("Unable to download %s: "
133+
"connection closed before "
134+
"transfer complete (%d/%d)",
135+
self.url, fsize, length)
136+
tmp_cache_file.unlink()
137+
continue
124138
break
125139
except FileExistsError:
126140
self.log.debug("%s already exists, "

0 commit comments

Comments
 (0)