Am 09.11.26 um 17:14 schrieb Peter Maydell:
The Asset() implementation only works with HTTP URLs because it assumes that the object it gets back from urllib.request.urlopen() has a getheader() method. This is only true for the HTTPResponse object that HTTP URLs produce, not for the urllib.request.addinfourl object that file, data and FTP URLs produce.File URLs are obviously not useful for public QEMU tests, but they can be helpful for iterating locally on the asset to be used by a test before putting the final asset image up somewhere public. Get the Content-Length header with resp.headers.get(), which works on both object types, and matches how the urllib documentation suggests getting headers. Fixes: 7524e1b33679dc13 ("tests/functional/asset: Verify downloaded size") Signed-off-by: Peter Maydell <[email protected]> --- tests/functional/qemu_test/asset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py index 0abd89e0a38..780b995b703 100644 --- a/tests/functional/qemu_test/asset.py +++ b/tests/functional/qemu_test/asset.py @@ -139,7 +139,7 @@ def _try_to_fetch(self, tmp_cache_file): 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") + length_hdr = resp.headers.get("Content-Length")# Verify downloaded file size against length metadata, if# available.
Reviewed-by: Thomas Huth <[email protected]>
