qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Thomas Huth" <thuth@redhat.com>,
	qemu-devel@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Richard Henderson <richard.henderson@linaro.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: Re: [PULL 15/42] tests/functional: enable pre-emptive caching of assets
Date: Tue, 26 Nov 2024 17:44:29 +0100	[thread overview]
Message-ID: <66bf4784-f1e4-479f-83db-2d4f91c10e48@linaro.org> (raw)
In-Reply-To: <20240904103923.451847-16-thuth@redhat.com>

Hi,

On 4/9/24 12:38, Thomas Huth wrote:
> From: Daniel P. Berrangé <berrange@redhat.com>
> 
> Many tests need to access assets stored on remote sites. We don't want
> to download these during test execution when run by meson, since this
> risks hitting test timeouts when data transfers are slow.
> 
> Add support for pre-emptive caching of assets by setting the env var
> QEMU_TEST_PRECACHE to point to a timestamp file. When this is set,
> instead of running the test, the assets will be downloaded and saved
> to the cache, then the timestamp file created.
> 
> A meson custom target is created as a dependency of each test suite
> to trigger the pre-emptive caching logic before the test runs.
> 
> When run in caching mode, it will locate assets by looking for class
> level variables with a name prefix "ASSET_", and type "Asset".
> 
> At the ninja level
> 
>     ninja test --suite functional
> 
> will speculatively download any assets that are not already cached,
> so it is advisable to set a timeout multiplier.
> 
>     QEMU_TEST_NO_DOWNLOAD=1 ninja test --suite functional
> 
> will fail the test if a required asset is not already cached
> 
>     ninja precache-functional
> 
> will download and cache all assets required by the functional
> tests
> 
> At the make level, precaching is always done by
> 
>     make check-functional
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> Tested-by: Richard Henderson <richard.henderson@linaro.org>
> [thuth: Remove the duplicated "path = os.path.basename(...)" line]
> Message-ID: <20240830133841.142644-16-thuth@redhat.com>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   tests/Makefile.include                 |  3 ++-
>   tests/functional/meson.build           | 33 +++++++++++++++++++++++--
>   tests/functional/qemu_test/asset.py    | 34 ++++++++++++++++++++++++++
>   tests/functional/qemu_test/testcase.py |  7 ++++++
>   4 files changed, 74 insertions(+), 3 deletions(-)


> diff --git a/tests/functional/qemu_test/asset.py b/tests/functional/qemu_test/asset.py
> index c0e675d847..b329ab7dbe 100644
> --- a/tests/functional/qemu_test/asset.py
> +++ b/tests/functional/qemu_test/asset.py
> @@ -9,6 +9,8 @@
>   import logging
>   import os
>   import subprocess
> +import sys
> +import unittest
>   import urllib.request
>   from pathlib import Path
>   from shutil import copyfileobj
> @@ -62,6 +64,9 @@ def fetch(self):
>                              self.cache_file, self.url)
>               return str(self.cache_file)
>   
> +        if os.environ.get("QEMU_TEST_NO_DOWNLOAD", False):
> +            raise Exception("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")
>   
> @@ -95,3 +100,32 @@ def fetch(self):
>   
>           self.log.info("Cached %s at %s" % (self.url, self.cache_file))
>           return str(self.cache_file)
> +
> +    def precache_test(test):
> +        log = logging.getLogger('qemu-test')
> +        log.setLevel(logging.DEBUG)
> +        handler = logging.StreamHandler(sys.stdout)
> +        handler.setLevel(logging.DEBUG)
> +        formatter = logging.Formatter(
> +            '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
> +        handler.setFormatter(formatter)
> +        log.addHandler(handler)
> +        for name, asset in vars(test.__class__).items():
> +            if name.startswith("ASSET_") and type(asset) == Asset:
> +                log.info("Attempting to cache '%s'" % asset)
> +                asset.fetch()

fetch() can fail [*] (see previous patch, various Exceptions returned).

What should we do in this case? If we ignore a missing artifact,
the tests will eventually fail. Better bail out early and save
credit minutes?

> +        log.removeHandler(handler)
> +
> +    def precache_suite(suite):
> +        for test in suite:
> +            if isinstance(test, unittest.TestSuite):
> +                Asset.precache_suite(test)
> +            elif isinstance(test, unittest.TestCase):
> +                Asset.precache_test(test)
> +
> +    def precache_suites(path, cacheTstamp):
> +        loader = unittest.loader.defaultTestLoader
> +        tests = loader.loadTestsFromNames([path], None)
> +
> +        with open(cacheTstamp, "w") as fh:
> +            Asset.precache_suite(tests)
> diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py
> index b2dd863c6e..18314be9d1 100644
> --- a/tests/functional/qemu_test/testcase.py
> +++ b/tests/functional/qemu_test/testcase.py
> @@ -21,6 +21,7 @@
>   from qemu.machine import QEMUMachine
>   from qemu.utils import kvm_available, tcg_available
>   
> +from .asset import Asset
>   from .cmd import run_cmd
>   from .config import BUILD_DIR
>   
> @@ -58,6 +59,12 @@ def tearDown(self):
>   
>       def main():
>           path = os.path.basename(sys.argv[0])[:-3]
> +
> +        cache = os.environ.get("QEMU_TEST_PRECACHE", None)
> +        if cache is not None:
> +            Asset.precache_suites(path, cache)
> +            return
> +
>           tr = pycotap.TAPTestRunner(message_log = pycotap.LogMode.LogToError,
>                                      test_output_log = pycotap.LogMode.LogToError)
>           unittest.main(module = None, testRunner = tr, argv=["__dummy__", path])

[*] Peter reported the following CI failure:

   https://gitlab.com/qemu-project/qemu/-/jobs/8474928266

2024-11-26 14:58:53,170 - qemu-test - ERROR - Unable to download 
https://apt.armbian.com/pool/main/l/linux-6.6.16/linux-image-current-sunxi_24.2.1_armhf__6.6.16-Seb3e-D6b4a-P2359-Ce96bHfe66-HK01ba-V014b-B067e-R448a.deb: 
HTTP Error 418:
Traceback (most recent call last):
   File "/builds/qemu-project/qemu/tests/functional/test_arm_bpim2u.py", 
line 186, in <module>
     LinuxKernelTest.main()
   File 
"/builds/qemu-project/qemu/tests/functional/qemu_test/testcase.py", line 
76, in main
     Asset.precache_suites(path, cache)
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 180, in precache_suites
     Asset.precache_suite(tests)
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 171, in precache_suite
     Asset.precache_suite(test)
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 171, in precache_suite
     Asset.precache_suite(test)
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 173, in precache_suite
     Asset.precache_test(test)
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 165, in precache_test
     asset.fetch()
   File "/builds/qemu-project/qemu/tests/functional/qemu_test/asset.py", 
line 113, in fetch
     with urllib.request.urlopen(self.url) as resp:
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
     return opener.open(url, data, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 525, in open
     response = meth(req, response)
                ^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 634, in http_response
     response = self.parent.error(
                ^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 557, in error
     result = self._call_chain(*args)
              ^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
     result = func(*args)
              ^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 749, in http_error_302
     return self.parent.open(new, timeout=req.timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 525, in open
     response = meth(req, response)
                ^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 634, in http_response
     response = self.parent.error(
                ^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 563, in error
     return self._call_chain(*args)
            ^^^^^^^^^^^^^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
     result = func(*args)
              ^^^^^^^^^^^
   File "/usr/lib/python3.11/urllib/request.py", line 643, in 
http_error_default
     raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 418:
ninja: build stopped: subcommand failed.



  reply	other threads:[~2024-11-26 16:45 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-04 10:38 [PULL 00/42] Introduce new functional test framework Thomas Huth
2024-09-04 10:38 ` [PULL 01/42] tests/avocado: machine aarch64: standardize location and RO access Thomas Huth
2024-09-04 10:38 ` [PULL 02/42] tests/avocado/boot_xen.py: fetch kernel during test setUp() Thomas Huth
2024-09-04 10:38 ` [PULL 03/42] tests/avocado/machine_aarch64_sbsaref.py: allow for rw usage of image Thomas Huth
2024-09-04 10:38 ` [PULL 04/42] Bump avocado to 103.0 Thomas Huth
2024-09-04 10:38 ` [PULL 05/42] tests/avocado/avocado_qemu: Fix the "from" statements in linuxtest.py Thomas Huth
2024-09-04 10:38 ` [PULL 06/42] tests/avocado/boot_linux_console: Remove the s390x subtest Thomas Huth
2024-09-04 10:38 ` [PULL 07/42] python: Install pycotap in our venv if necessary Thomas Huth
2024-09-04 10:38 ` [PULL 08/42] tests/functional: Add base classes for the upcoming pytest-based tests Thomas Huth
2024-09-04 10:38 ` [PULL 09/42] tests/functional: Set up logging Thomas Huth
2024-09-04 10:38 ` [PULL 10/42] tests/Makefile.include: Increase the level of indentation in the help text Thomas Huth
2024-09-04 10:38 ` [PULL 11/42] tests/functional: Prepare the meson build system for the functional tests Thomas Huth
2024-09-04 10:38 ` [PULL 12/42] tests/functional: Convert simple avocado tests into standalone python tests Thomas Huth
2024-09-04 10:38 ` [PULL 13/42] tests/functional: Convert avocado tests that just need a small adjustment Thomas Huth
2024-09-04 10:38 ` [PULL 14/42] tests/functional: add a module for handling asset download & caching Thomas Huth
2024-09-04 10:38 ` [PULL 15/42] tests/functional: enable pre-emptive caching of assets Thomas Huth
2024-11-26 16:44   ` Philippe Mathieu-Daudé [this message]
2024-11-26 16:45     ` Peter Maydell
2024-11-26 17:26       ` Daniel P. Berrangé
2024-11-26 17:31     ` Daniel P. Berrangé
2024-11-26 17:46       ` Peter Maydell
2024-11-26 17:52         ` Thomas Huth
2024-11-26 17:56           ` Daniel P. Berrangé
2024-11-26 21:17             ` Peter Maydell
2024-11-26 22:54           ` Richard Henderson
2024-11-27  6:29             ` Thomas Huth
2024-11-27 18:02               ` Richard Henderson
2024-11-28  9:54                 ` Thomas Huth
2024-11-28  9:58                   ` Daniel P. Berrangé
2024-11-27  9:06             ` Daniel P. Berrangé
2024-11-27 18:31               ` Pierrick Bouvier
2024-11-28  9:34                 ` Daniel P. Berrangé
2024-11-28 17:25                   ` Pierrick Bouvier
2024-11-28 17:57                     ` Daniel P. Berrangé
2024-09-04 10:38 ` [PULL 16/42] tests/functional: Allow asset downloading with concurrent threads Thomas Huth
2024-09-04 10:38 ` [PULL 17/42] tests/functional: Convert some tests that download files via fetch_asset() Thomas Huth
2024-09-04 10:38 ` [PULL 18/42] tests/functional: Add a function for extracting files from an archive Thomas Huth
2024-09-04 10:38 ` [PULL 19/42] tests/functional: Convert some avocado tests that needed avocado.utils.archive Thomas Huth
2024-09-04 10:38 ` [PULL 20/42] tests/functional: Convert the s390x avocado tests into standalone tests Thomas Huth
2024-09-04 10:38 ` [PULL 21/42] tests/functional: Convert the x86_cpu_model_versions test Thomas Huth
2024-09-04 10:38 ` [PULL 22/42] tests/functional: Convert the microblaze avocado tests into standalone tests Thomas Huth
2024-09-04 10:38 ` [PULL 23/42] tests/functional: Convert the virtio_gpu avocado test into a standalone test Thomas Huth
2024-09-04 10:38 ` [PULL 24/42] tests/functional: Convert most ppc avocado tests into standalone tests Thomas Huth
2024-09-04 10:39 ` [PULL 25/42] tests/functional: Convert the ppc_amiga avocado test into a standalone test Thomas Huth
2024-09-04 10:39 ` [PULL 26/42] tests/functional: Convert the ppc_hv " Thomas Huth
2024-09-04 10:39 ` [PULL 27/42] tests/functional: Convert the m68k nextcube test with tesseract Thomas Huth
2024-09-04 10:39 ` [PULL 28/42] tests/functional: Convert the acpi-bits test into a standalone test Thomas Huth
2024-09-04 10:39 ` [PULL 29/42] tests/functional: Convert the rx_gdbsim avocado " Thomas Huth
2024-09-04 10:39 ` [PULL 30/42] tests/functional: Convert the linux_initrd " Thomas Huth
2024-09-04 10:39 ` [PULL 31/42] tests/functional: Convert ARM Integrator/CP avocado tests Thomas Huth
2024-09-04 10:39 ` [PULL 32/42] tests/functional: Convert Aarch64 SBSA-Ref " Thomas Huth
2024-09-04 10:39 ` [PULL 33/42] tests/functional: Convert Aarch64 Virt machine " Thomas Huth
2024-09-04 10:39 ` [PULL 34/42] tests/functional: Convert mips64el Fuloong2e avocado test (1/2) Thomas Huth
2024-09-04 10:39 ` [PULL 35/42] tests/functional: Add QemuUserTest class Thomas Huth
2024-09-04 10:39 ` [PULL 36/42] tests/functional: Convert ARM bFLT linux-user avocado test Thomas Huth
2024-09-04 10:39 ` [PULL 37/42] tests/avocado: Remove unused QemuUserTest class Thomas Huth
2024-09-04 10:39 ` [PULL 38/42] gitlab-ci: Add "check-functional" to the build tests Thomas Huth
2024-09-04 10:39 ` [PULL 39/42] docs/devel: Split testing docs from the build docs and move to separate folder Thomas Huth
2024-09-04 10:39 ` [PULL 40/42] docs/devel/testing: Split the Avocado documentation into a separate file Thomas Huth
2024-09-04 10:39 ` [PULL 41/42] docs/devel/testing: Rename avocado_qemu.Test class Thomas Huth
2024-09-04 10:39 ` [PULL 42/42] docs/devel/testing: Add documentation for functional tests Thomas Huth
2024-09-06 11:32 ` [PULL 00/42] Introduce new functional test framework 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=66bf4784-f1e4-479f-83db-2d4f91c10e48@linaro.org \
    --to=philmd@linaro.org \
    --cc=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@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).