qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Nicholas Piggin" <npiggin@gmail.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 6/8] tests/functional/asset: Verify downloaded size
Date: Thu, 13 Mar 2025 09:01:30 +0100	[thread overview]
Message-ID: <20250313080132.1467625-7-thuth@redhat.com> (raw)
In-Reply-To: <20250313080132.1467625-1-thuth@redhat.com>

From: Nicholas Piggin <npiggin@gmail.com>

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>
---
 tests/functional/qemu_test/asset.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py
index 27dd839e705..6bbfb9e1cad 100644
--- a/tests/functional/qemu_test/asset.py
+++ b/tests/functional/qemu_test/asset.py
@@ -121,6 +121,20 @@ def fetch(self):
                 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, "
-- 
2.48.1



  parent reply	other threads:[~2025-03-13  8:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13  8:01 [PULL 0/8] Fixes for functional tests Thomas Huth
2025-03-13  8:01 ` [PULL 1/8] docs: Rename default-configs to configs Thomas Huth
2025-03-13  8:01 ` [PULL 2/8] tests/functional: Require 'user' netdev for ppc64 e500 test Thomas Huth
2025-03-13  8:01 ` [PULL 3/8] tests/functional: Bump up arm_replay timeout Thomas Huth
2025-03-13  8:01 ` [PULL 4/8] docs/system: Fix the information on how to run certain functional tests Thomas Huth
2025-03-13  8:01 ` [PULL 5/8] tests/functional/asset: Fail assert fetch when retries are exceeded Thomas Huth
2025-03-13  8:01 ` Thomas Huth [this message]
2025-03-13  8:01 ` [PULL 7/8] tests/functional/asset: Add AssetError exception class Thomas Huth
2025-03-13  8:01 ` [PULL 8/8] tests/functional: skip vulkan test if missing vulkaninfo Thomas Huth
2025-03-14  4:46 ` [PULL 0/8] Fixes for functional tests Stefan Hajnoczi

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=20250313080132.1467625-7-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=berrange@redhat.com \
    --cc=npiggin@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).