From patchwork Mon Jul 11 23:01:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914346 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5508C43334 for ; Mon, 11 Jul 2022 23:09:40 +0000 (UTC) Received: from localhost ([::1]:38368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2X5-0001gP-Ii for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:09:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Px-0000zr-LT for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53939) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pn-00024m-TN for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Hpl9Hcmja7wCqA/6pHrgfp7z/GTa2UgFHuwdaUlLYz0=; b=RXtJrP0bUkJj3Fdh1bSujUgQqbUilsquFtFoZOqgmp/YIgHOSAhREq5pD93V20V3yjUuY9 21qU3ZA+aWQYbw/Uo0aN73LDxOTbw8QLdSvg/pekZfnouGHKaWU8lFJ7scNlBZ2ChGlN5G X5328U/jZ9m82Typsw2jjKWbMKFJ8PQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-82-YaLRLi9JOuWG_NSDB_JWiQ-1; Mon, 11 Jul 2022 19:01:58 -0400 X-MC-Unique: YaLRLi9JOuWG_NSDB_JWiQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 625D080029D; Mon, 11 Jul 2022 23:01:57 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id C19D72166B26; Mon, 11 Jul 2022 23:01:56 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 1/7] tests: create optional tests/venv dependency groups Date: Mon, 11 Jul 2022 19:01:49 -0400 Message-Id: <20220711230155.953788-2-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch uses a dummy package and setup.cfg/setup.py files to manage optional dependency groups for the test venv specification. Now, there's a core set of dependencies which for now includes just "qemu" (but soon, qemu.qmp) and a separate, optional 'avocado' group that includes avocado-framework and pycdlib. Practical upshot: We install only a minimum of things for the majority of check-* targets, but allow optional add-ons to be processed when running avocado tests. This will spare downstreams from having to add more dependencies than is necessary as a build dependencies when invoking "make check". (We also keep both sets of dependencies in one file, which is helpful for review to ensure that different option groups don't conflict with one another.) NOTE: There is a non-fatal caveat introduced by this patch on Ubuntu 20.04 systems; see the subsequent commit "tests: Remove spurious pip warnings on Ubuntu20.04" for more information. Signed-off-by: John Snow --- tests/Makefile.include | 21 ++++++++++++++------- tests/requirements.txt | 6 ------ tests/setup.cfg | 20 ++++++++++++++++++++ tests/setup.py | 16 ++++++++++++++++ 4 files changed, 50 insertions(+), 13 deletions(-) delete mode 100644 tests/requirements.txt create mode 100644 tests/setup.cfg create mode 100644 tests/setup.py diff --git a/tests/Makefile.include b/tests/Makefile.include index 3accb83b132..82c697230e0 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -81,13 +81,13 @@ clean-tcg: $(CLEAN_TCG_TARGET_RULES) # Python venv for running tests -.PHONY: check-venv check-avocado check-acceptance check-acceptance-deprecated-warning +.PHONY: check-venv check-venv-avocado check-avocado check-acceptance \ + check-acceptance-deprecated-warning # Build up our target list from the filtered list of ninja targets TARGETS=$(patsubst libqemu-%.fa, %, $(filter libqemu-%.fa, $(ninja-targets))) TESTS_VENV_DIR=$(BUILD_DIR)/tests/venv -TESTS_VENV_REQ=$(SRC_PATH)/tests/requirements.txt TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results TESTS_PYTHON=$(TESTS_VENV_DIR)/bin/python3 ifndef AVOCADO_TESTS @@ -108,10 +108,16 @@ quiet-venv-pip = $(quiet-@)$(call quiet-command-run, \ $(TESTS_PYTHON) -m pip -q --disable-pip-version-check $1, \ "VENVPIP","$1") -$(TESTS_VENV_DIR): $(TESTS_VENV_REQ) +# Core dependencies for tests/venv +$(TESTS_VENV_DIR): $(SRC_PATH)/tests/setup.cfg $(SRC_PATH)/python/setup.cfg $(call quiet-command, $(PYTHON) -m venv $@, VENV, $@) $(call quiet-venv-pip,install -e "$(SRC_PATH)/python/") - $(call quiet-venv-pip,install -r $(TESTS_VENV_REQ)) + $(call quiet-venv-pip,install "$(SRC_PATH)/tests/") + $(call quiet-command, touch $@) + +# Optional avocado dependencies for tests/venv +$(TESTS_VENV_DIR)/avocado: $(TESTS_VENV_DIR) + $(call quiet-venv-pip,install "$(SRC_PATH)/tests/[avocado]") $(call quiet-command, touch $@) $(TESTS_RESULTS_DIR): @@ -119,6 +125,7 @@ $(TESTS_RESULTS_DIR): MKDIR, $@) check-venv: $(TESTS_VENV_DIR) +check-venv-avocado: $(TESTS_VENV_DIR)/avocado FEDORA_31_ARCHES_TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGETS))) FEDORA_31_ARCHES_CANDIDATES=$(patsubst ppc64,ppc64le,$(FEDORA_31_ARCHES_TARGETS)) @@ -126,16 +133,16 @@ FEDORA_31_ARCHES := x86_64 aarch64 ppc64le s390x FEDORA_31_DOWNLOAD=$(filter $(FEDORA_31_ARCHES),$(FEDORA_31_ARCHES_CANDIDATES)) # download one specific Fedora 31 image -get-vm-image-fedora-31-%: check-venv +get-vm-image-fedora-31-%: check-venv-avocado $(call quiet-command, \ $(TESTS_PYTHON) -m avocado vmimage get \ --distro=fedora --distro-version=31 --arch=$*, \ "AVOCADO", "Downloading avocado tests VM image for $*") # download all vm images, according to defined targets -get-vm-images: check-venv $(patsubst %,get-vm-image-fedora-31-%, $(FEDORA_31_DOWNLOAD)) +get-vm-images: check-venv-avocado $(patsubst %,get-vm-image-fedora-31-%, $(FEDORA_31_DOWNLOAD)) -check-avocado: check-venv $(TESTS_RESULTS_DIR) get-vm-images +check-avocado: check-venv-avocado $(TESTS_RESULTS_DIR) get-vm-images $(call quiet-command, \ $(TESTS_PYTHON) -m avocado \ --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \ diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 0ba561b6bdf..00000000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -# Add Python module requirements, one per line, to be installed -# in the tests/venv Python virtual environment. For more info, -# refer to: https://pip.pypa.io/en/stable/user_guide/#id1 -# Note that qemu.git/python/ is always implicitly installed. -avocado-framework==88.1 -pycdlib==1.11.0 diff --git a/tests/setup.cfg b/tests/setup.cfg new file mode 100644 index 00000000000..263a5de01af --- /dev/null +++ b/tests/setup.cfg @@ -0,0 +1,20 @@ +# This file represents a "dummy" package that expresses +# the dependencies necessary to run the various python-based +# test suites in the qemu.git tree. +[metadata] +name = qemu.dummy_tests +version = 0.0.0 +description = qemu.git testing dummy package + +[options] +packages = +python_requires = >= 3.6 +install_requires = + qemu # Note: A special setup script will always install 'qemu' from + # qemu.git/python. It doesn't have a meaningful/real version. + +[options.extras_require] +# Extra dependencies required by the avocado tests. +avocado = + avocado-framework<89.0,>=88.1 + pycdlib<2.0,>=1.11.0 diff --git a/tests/setup.py b/tests/setup.py new file mode 100644 index 00000000000..c99fe5d1725 --- /dev/null +++ b/tests/setup.py @@ -0,0 +1,16 @@ +# This setup file is just-enough-config to allow pip to bootstrap a +# testing environment. It is not meant to be executed directly. +# See also: setup.cfg + +import setuptools +import pkg_resources + + +def main(): + # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108 + pkg_resources.require('setuptools>=39.2') + setuptools.setup() + + +if __name__ == '__main__': + main() From patchwork Mon Jul 11 23:01:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8111EC43334 for ; Mon, 11 Jul 2022 23:04:50 +0000 (UTC) Received: from localhost ([::1]:56470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2SP-0003Av-FQ for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pn-0000go-W5 for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55207) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pi-00022f-Sk for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=anYhfcvgMMDENUPqkU/tUzCABSO9Egx8LCG3jbKLIcY=; b=ej0QNFhmLEUonC2Djh/oA3vPFdrq1LAWN3jNnCc0Medfr+pEs5r43loRrX9ZDYtrzFV4iV 319daXWZWKetRfzOWaaPrnLwPmpv+JieHMk+N5w07Esid7WQWRZVM2RdBUSjcSScd5UcuO eLVezW3B8SkmKpvW5liWkPZ7h3A8isM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-112-JOT-ivUvO0KrHNUgMH7Tgw-1; Mon, 11 Jul 2022 19:01:58 -0400 X-MC-Unique: JOT-ivUvO0KrHNUgMH7Tgw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 143A585A585; Mon, 11 Jul 2022 23:01:58 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71B982166B26; Mon, 11 Jul 2022 23:01:57 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 2/7] tests: pythonize test venv creation Date: Mon, 11 Jul 2022 19:01:50 -0400 Message-Id: <20220711230155.953788-3-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This splits the venv creation logic out of the Makefile and into a Python script. One reason for doing this is to be able to call the venv bootstrapper from places outside of the Makefile, e.g. configure and iotests. Another reason is to be able to add "offline" logic to modify the behavior of the script in certain circumstances. RFC: I don't like how I have an entire "enter_venv" function here, and by the end of the series, completely separate logic for entering a venv in testenv.py -- but they both operate in different ways: this patch offers a method that alters the current ENV immediately, whereas the testenv.py method alters a copied ENV that is explicitly passed to subprocesses. Still, there's a bit more boilerplate than I'd like, but it's probably fine and it probably won't need to be updated much, but... less code is usually better. But, even if I did write it more generically here; iotests wouldn't be able to use it anyway, because importing it would mean more sys.path hacking. So... eh? Signed-off-by: John Snow --- tests/Makefile.include | 16 ++-- tests/mkvenv.py | 186 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 tests/mkvenv.py diff --git a/tests/Makefile.include b/tests/Makefile.include index 82c697230e0..d8af6a38112 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -104,21 +104,17 @@ else AVOCADO_CMDLINE_TAGS=$(addprefix -t , $(AVOCADO_TAGS)) endif -quiet-venv-pip = $(quiet-@)$(call quiet-command-run, \ - $(TESTS_PYTHON) -m pip -q --disable-pip-version-check $1, \ - "VENVPIP","$1") - # Core dependencies for tests/venv $(TESTS_VENV_DIR): $(SRC_PATH)/tests/setup.cfg $(SRC_PATH)/python/setup.cfg - $(call quiet-command, $(PYTHON) -m venv $@, VENV, $@) - $(call quiet-venv-pip,install -e "$(SRC_PATH)/python/") - $(call quiet-venv-pip,install "$(SRC_PATH)/tests/") - $(call quiet-command, touch $@) + $(call quiet-command, \ + $(PYTHON) "$(SRC_PATH)/tests/mkvenv.py" "$@", \ + MKVENV, $@) # Optional avocado dependencies for tests/venv $(TESTS_VENV_DIR)/avocado: $(TESTS_VENV_DIR) - $(call quiet-venv-pip,install "$(SRC_PATH)/tests/[avocado]") - $(call quiet-command, touch $@) + $(call quiet-command, \ + $(PYTHON) "$(SRC_PATH)/tests/mkvenv.py" --opt avocado "$<", \ + MKVENV, $@) $(TESTS_RESULTS_DIR): $(call quiet-command, mkdir -p $@, \ diff --git a/tests/mkvenv.py b/tests/mkvenv.py new file mode 100644 index 00000000000..0667106d6aa --- /dev/null +++ b/tests/mkvenv.py @@ -0,0 +1,186 @@ +""" +mkvenv - QEMU venv bootstrapping utility + +usage: mkvenv.py [-h] [--offline] [--opt OPT] target + +Bootstrap QEMU testing venv. + +positional arguments: + target Target directory to install virtual environment into. + +optional arguments: + -h, --help show this help message and exit + --offline Use system packages and work entirely offline. + --opt OPT Install an optional dependency group. +""" + +# Copyright (C) 2022 Red Hat, Inc. +# +# Authors: +# John Snow +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +# Do not add any dependencies from outside the stdlib: +# This script must be usable on its own! + +import argparse +from contextlib import contextmanager +import logging +import os +from pathlib import Path +import subprocess +import sys +from typing import Iterable, Iterator, Union +import venv + + +def make_venv( + venv_path: Union[str, Path], + system_site_packages: bool = False +) -> None: + """ + Create a venv using the python3 'venv' module. + + Identical to: + ``python3 -m venv --clear [--system-site-packages] {venv_path}`` + + :param venv_path: The target directory + :param system_site_packages: If True, allow system packages in venv. + """ + logging.debug("%s: make_venv(venv_path=%s, system_site_packages=%s)", + __file__, str(venv_path), system_site_packages) + venv.create( + str(venv_path), + clear=True, + symlinks=os.name != "nt", # Same as venv CLI's default. + with_pip=True, + system_site_packages=system_site_packages, + ) + + +@contextmanager +def enter_venv(venv_dir: Union[str, Path]) -> Iterator[None]: + """Scoped activation of an existing venv.""" + venv_keys = ('PATH', 'PYTHONHOME', 'VIRTUAL_ENV') + old = {k: v for k, v in os.environ.items() if k in venv_keys} + vdir = Path(venv_dir).resolve() + + def _delete_keys() -> None: + for k in venv_keys: + try: + del os.environ[k] + except KeyError: + pass + + try: + _delete_keys() + + os.environ['VIRTUAL_ENV'] = str(vdir) + os.environ['PATH'] = os.pathsep.join([ + str(vdir / "bin/"), + old['PATH'], + ]) + + logging.debug("PATH => %s", os.environ['PATH']) + logging.debug("VIRTUAL_ENV => %s", os.environ['VIRTUAL_ENV']) + + yield + + finally: + _delete_keys() + for key, val in old.items(): + os.environ[key] = val + + +def install(*args: str, offline: bool = False) -> None: + """Shorthand for pip install; expected to be used under a venv.""" + cli_args = ['pip3', '--disable-pip-version-check', '-q', 'install'] + if offline: + cli_args.append('--no-index') + cli_args += args + print(f" VENVPIP install {' '.join(args)}") + logging.debug(' '.join(cli_args)) + subprocess.run(cli_args, check=True) + + +def make_qemu_venv( + venv_dir: str, + options: Iterable[str], + offline: bool = False +) -> None: + """ + Make and initialize a qemu testing venv. + + Forcibly re-creates the venv if it already exists, unless optional + dependency groups are specified - in which case, just install the + extra dependency groups. + + :param venv_dir: The target directory to install to. + :param options: + Optional dependency groups of the testing package to install. + (e.g. 'avocado'.) + :param offline: + If true, force offline mode. System packages will be usable from + the venv and dependencies will not be fetched from PyPI. + """ + venv_path = Path(venv_dir).resolve() + src_root = Path(__file__).joinpath('../..') + pysrc_path = src_root.joinpath('python/').resolve() + test_src_path = src_root.joinpath('tests/').resolve() + + logging.debug("make_qemu_venv(%s)", venv_dir) + logging.debug("sys.executable: %s", sys.executable) + logging.debug("resolved: %s", str(Path(sys.executable).resolve())) + logging.debug("venv_dir: %s", str(venv_path)) + logging.debug("python source: %s", str(pysrc_path)) + logging.debug("tests source: %s", str(test_src_path)) + + do_initialize = not venv_path.exists() or not options + if do_initialize: + make_venv(venv_path, system_site_packages=offline) + + with enter_venv(venv_path): + if do_initialize: + install("-e", str(pysrc_path), offline=offline) + install(str(test_src_path), offline=offline) + venv_path.touch() + + for option in options: + dummy = venv_path / option + install(f"{test_src_path!s}/[{option}]", offline=offline) + dummy.touch() + + +def main() -> int: + """CLI interface to make_qemu_venv. See module docstring.""" + if os.environ.get('DEBUG'): + logging.basicConfig(level=logging.DEBUG) + + parser = argparse.ArgumentParser( + description="Bootstrap QEMU testing venv.") + parser.add_argument( + '--offline', + action='store_true', + help="Use system packages and work entirely offline.", + ) + parser.add_argument( + '--opt', + type=str, + action='append', + help="Install an optional dependency group.", + ) + parser.add_argument( + 'target', + type=str, + action='store', + help="Target directory to install virtual environment into.", + ) + args = parser.parse_args() + make_qemu_venv(args.target, args.opt or (), args.offline) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) From patchwork Mon Jul 11 23:01:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914344 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 63432C43334 for ; Mon, 11 Jul 2022 23:07:25 +0000 (UTC) Received: from localhost ([::1]:34100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2Uu-0007D0-Gs for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:07:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Ps-0000nh-AJ for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:21209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pp-00025Q-PD for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=STX+HDAQ+qzf8HD6UcpV60/VFSD4Vcst0FqCUJoq2SM=; b=NSQzWUkS7VM90vdVqGiwbaTJL4ubtqq9dhn36+z3LSM1l88ezMuCslWGtER+nfbUe0VlvO UyjprTGPUhlw98l1YF01C2wCefin2bz6zVLkT7OJNhUh1E6VUag7whT3r3HTVDUAw+0XRi RYYvep0F2VykQn6JzjRSW0N1Bm71dQk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-446-UMq_Ehh4OBeTiTFKT6Zt5A-1; Mon, 11 Jul 2022 19:01:59 -0400 X-MC-Unique: UMq_Ehh4OBeTiTFKT6Zt5A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B813D804184; Mon, 11 Jul 2022 23:01:58 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20B172166B26; Mon, 11 Jul 2022 23:01:58 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 3/7] tests: Remove spurious pip warnings on Ubuntu20.04 Date: Mon, 11 Jul 2022 19:01:51 -0400 Message-Id: <20220711230155.953788-4-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The version of pip ("20.0.2") that ships with Ubuntu 20.04 has a bug where it will try to attempt building a wheel even if the "wheel" python package that enables it to do so is not installed. Even though pip continues gracefully from source, The result is a lot of irrelevant failure output. Upstream pip 20.0.2 does not have this problem, and pip 20.1 introduces a new info message that informs a user that wheel building is being skipped. On this version, the output can be silenced by passing --no-binary to coax pip into skipping that step to begin with. Note, this error does not seem to show up for the "qemu" package because we install that package in editable mode. (I think, but did not test, that installing an empty package in editable mode caused more problems than it fixed.) Signed-off-by: John Snow --- tests/mkvenv.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/mkvenv.py b/tests/mkvenv.py index 0667106d6aa..78f8d0382e0 100644 --- a/tests/mkvenv.py +++ b/tests/mkvenv.py @@ -144,7 +144,8 @@ def make_qemu_venv( with enter_venv(venv_path): if do_initialize: install("-e", str(pysrc_path), offline=offline) - install(str(test_src_path), offline=offline) + install("--no-binary", "qemu.dummy-tests", + str(test_src_path), offline=offline) venv_path.touch() for option in options: From patchwork Mon Jul 11 23:01:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02D5EC43334 for ; Mon, 11 Jul 2022 23:07:21 +0000 (UTC) Received: from localhost ([::1]:33912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2Ur-00074I-5B for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pq-0000h9-B9 for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pn-00022s-M4 for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZVW9wb/Sy6wFZiPqp05CpN1WWQfMiHBMfVd1UK0Fho=; b=HmlP1XyWbvfi+bx3tHFMFu2Mej/QICZNChmf5CThT7iBj57IDC5szhl+SzJ6d8gKC3O+Q1 dw2IwqsotRPqys9sNMvjbxsirc4PSPXvdCXbidxOpfUmW0iutriMOW6DLlPP3LQTw5a2RH lGZ0ZKiEy7LZQKEacqZN8q9K6OXWy9k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-427-Owg9gEGoMk6XOjNEwp2VHg-1; Mon, 11 Jul 2022 19:02:00 -0400 X-MC-Unique: Owg9gEGoMk6XOjNEwp2VHg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6856F101AA48; Mon, 11 Jul 2022 23:01:59 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id C681F2166B26; Mon, 11 Jul 2022 23:01:58 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 4/7] tests/vm: add venv pre-requisites to VM building recipes Date: Mon, 11 Jul 2022 19:01:52 -0400 Message-Id: <20220711230155.953788-5-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" NetBSD needs "py37-pip" in order to create virtual environments. Signed-off-by: John Snow --- tests/vm/netbsd | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/vm/netbsd b/tests/vm/netbsd index 45aa9a7fda7..53fe508e487 100755 --- a/tests/vm/netbsd +++ b/tests/vm/netbsd @@ -31,6 +31,7 @@ class NetBSDVM(basevm.BaseVM): "pkgconf", "xz", "python37", + "py37-pip", "ninja-build", # gnu tools From patchwork Mon Jul 11 23:01:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3AB6C433EF for ; Mon, 11 Jul 2022 23:12:13 +0000 (UTC) Received: from localhost ([::1]:42016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2ZY-0004GP-Qv for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:12:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pt-0000q0-7H for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:46346) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pq-00025T-JN for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bjWxx+HtDYkpHG8IIiAqT8hxb/16pFET6uQ6IklA3os=; b=GcINsKRucnosGhe7u68GdNf9P3ASmifE+LcIlj/rF4LMtDIE8hcevazEoMjSniaT24evgX 7N/Mbz1EDh1J/1EpgKRS4LUVdsIOaNKZd7aVnngjHQhvUpBLFjsxD/x17XvvPw1s/yQhwk VwQp1GArATLOuIKa4JQU3LtQ4rJ9fOE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-656-ng3-Hu3JPleRE_NZBL_20A-1; Mon, 11 Jul 2022 19:02:00 -0400 X-MC-Unique: ng3-Hu3JPleRE_NZBL_20A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1C2658032FB; Mon, 11 Jul 2022 23:02:00 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76AB02166B26; Mon, 11 Jul 2022 23:01:59 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 5/7] tests: add 'check-venv' as a dependency of 'make check' Date: Mon, 11 Jul 2022 19:01:53 -0400 Message-Id: <20220711230155.953788-6-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This patch adds the 'check-venv' target as a requisite of all meson driven check-* targets. As of this commit, it will only install the "qemu" namespace package from the source tree, and nothing else. In the future, the "qemu" namespace package in qemu.git will begin to require an external qemu.qmp package, and this would be installed into this environment as well. The avocado test dependencies will *not* be pulled into this venv by default, but they may be added in at a later point in time by running 'make check-avocado' or, without running the tests, 'make check-venv-avocado'. Signed-off-by: John Snow --- tests/Makefile.include | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Makefile.include b/tests/Makefile.include index d8af6a38112..d484a335be5 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -155,6 +155,9 @@ check-acceptance-deprecated-warning: check-acceptance: check-acceptance-deprecated-warning | check-avocado +# The do-meson-check and do-meson-bench targets are defined in Makefile.mtest +do-meson-check do-meson-bench: check-venv + # Consolidated targets .PHONY: check check-clean get-vm-images From patchwork Mon Jul 11 23:01:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 365BAC43334 for ; Mon, 11 Jul 2022 23:04:58 +0000 (UTC) Received: from localhost ([::1]:56590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2SX-0003Fj-1l for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:04:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pr-0000hL-17 for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44773) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pn-00023B-MB for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=62eiebJ4CRcXipkHxKOY6aVMeIBXkh9jFMURuOSkro4=; b=ZCPQSIpkurk2sqtZkLGICFXV2T2Kf6KX4BpMbI8+WepS5uJtlYc0JYsEy9PqWxVBdj3AfG +jQaPc1ruf+F9gd2TzvzBHouOVUJ3zRwZyOP5J6WJLjvEItORXez2854N/Mmxjjq2C/B8x fih71RWAL9dB4ZWH9ikzarg48ChQiBQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-202-Gu9El7cbNWWaaJF3JEaEzg-1; Mon, 11 Jul 2022 19:02:01 -0400 X-MC-Unique: Gu9El7cbNWWaaJF3JEaEzg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C022F802D2C; Mon, 11 Jul 2022 23:02:00 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 299AD2166B26; Mon, 11 Jul 2022 23:02:00 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 6/7] iotests: use tests/venv for running tests Date: Mon, 11 Jul 2022 19:01:54 -0400 Message-Id: <20220711230155.953788-7-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Essentially, the changes to testenv.py here mimic the changes that occur when you "source venv/bin/activate.fish" or similar. (1) update iotest's internal notion of which python binary to use, (2) export the VIRTUAL_ENV variable, (3) front-load the venv/bin directory to PATH. If the venv directory isn't found, raise a friendly exception that tries to give the human operator a friendly clue as to what's gone wrong. The subsequent commit attempts to address this shortcoming by teaching iotests how to invoke the venv bootstrapper in this circumstance instead. Signed-off-by: John Snow --- tests/qemu-iotests/testenv.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py index a864c74b123..29404ac94be 100644 --- a/tests/qemu-iotests/testenv.py +++ b/tests/qemu-iotests/testenv.py @@ -65,8 +65,9 @@ class TestEnv(ContextManager['TestEnv']): # lot of them. Silence pylint: # pylint: disable=too-many-instance-attributes - env_variables = ['PYTHONPATH', 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR', - 'PYTHON', 'QEMU_PROG', 'QEMU_IMG_PROG', + env_variables = ['PYTHONPATH', 'VIRTUAL_ENV', 'PYTHON', 'PATH', + 'TEST_DIR', 'SOCK_DIR', 'SAMPLE_IMG_DIR', + 'QEMU_PROG', 'QEMU_IMG_PROG', 'QEMU_IO_PROG', 'QEMU_NBD_PROG', 'QSD_PROG', 'QEMU_OPTIONS', 'QEMU_IMG_OPTIONS', 'QEMU_IO_OPTIONS', 'QEMU_IO_OPTIONS_NO_FMT', @@ -102,18 +103,29 @@ def get_env(self) -> Dict[str, str]: def init_directories(self) -> None: """Init directory variables: + VIRTUAL_ENV + PATH PYTHONPATH TEST_DIR SOCK_DIR SAMPLE_IMG_DIR """ + venv_path = Path(self.build_root, 'tests/venv/') + if not venv_path.exists(): + raise FileNotFoundError( + f"Virtual environment \"{venv_path!s}\" isn't found." + " (Maybe you need to run 'make check-venv'" + " from the build dir?)" + ) + self.virtual_env: str = str(venv_path) - # Path where qemu goodies live in this source tree. - qemu_srctree_path = Path(__file__, '../../../python').resolve() + self.path = os.pathsep.join(( + str(venv_path / 'bin'), + os.environ['PATH'], + )) self.pythonpath = os.pathsep.join(filter(None, ( self.source_iotests, - str(qemu_srctree_path), os.getenv('PYTHONPATH'), ))) @@ -138,7 +150,7 @@ def init_binaries(self) -> None: PYTHON (for bash tests) QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG """ - self.python = sys.executable + self.python: str = os.path.join(self.virtual_env, 'bin', 'python3') def root(*names: str) -> str: return os.path.join(self.build_root, *names) @@ -300,6 +312,7 @@ def print_env(self, prefix: str = '') -> None: {prefix}GDB_OPTIONS -- {GDB_OPTIONS} {prefix}VALGRIND_QEMU -- {VALGRIND_QEMU} {prefix}PRINT_QEMU_OUTPUT -- {PRINT_QEMU} +{prefix}VIRTUAL_ENV -- {VIRTUAL_ENV} {prefix}""" args = collections.defaultdict(str, self.get_env()) From patchwork Mon Jul 11 23:01:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 12914347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 60765C433EF for ; Mon, 11 Jul 2022 23:09:44 +0000 (UTC) Received: from localhost ([::1]:38528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB2X9-0001mf-9e for qemu-devel@archiver.kernel.org; Mon, 11 Jul 2022 19:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pq-0000iz-He for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB2Pn-00023P-O8 for qemu-devel@nongnu.org; Mon, 11 Jul 2022 19:02:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657580525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0f3qVSnmvQZOUE7GmzmLW3QsKQrZDOm39K1IEFxZUeU=; b=UqFzoiJ/LbO061pAO1HrIOHAk+47mrQ48Ep7Rpvyln+d8HitfMuDPOb4fLXxRZtiwuGG+E 8NrG6wquxHXZg4LiRMQ8e51rH+zFnbTTo964vSIjUBUMJ5gNOZTn3UulbQ9wath447Vh9Z CB/gEKZIavyADmnXW8GL3gBt4UcQ63U= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-272-yZ0K2dzuMmeNC_bwA1Vw9Q-1; Mon, 11 Jul 2022 19:02:01 -0400 X-MC-Unique: yZ0K2dzuMmeNC_bwA1Vw9Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76DC91C06EC7; Mon, 11 Jul 2022 23:02:01 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE80D2166B26; Mon, 11 Jul 2022 23:02:00 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Daniel Berrange , Kevin Wolf , Beraldo Leal , John Snow , =?utf-8?q?Al?= =?utf-8?q?ex_Benn=C3=A9e?= , Thomas Huth , Wainer dos Santos Moschetta , Kyle Evans , Warner Losh , qemu-block@nongnu.org, Paolo Bonzini , Cleber Rosa , Michael Tsirkin , Ani Sinha , Hanna Reitz , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= Subject: [RFC PATCH v3 7/7] iotests: self-bootstrap testing venv Date: Mon, 11 Jul 2022 19:01:55 -0400 Message-Id: <20220711230155.953788-8-jsnow@redhat.com> In-Reply-To: <20220711230155.953788-1-jsnow@redhat.com> References: <20220711230155.953788-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When iotests are invoked manually from e.g. $build/tests/qemu-iotests/check, it is not necessarily guaranteed that we'll have run 'check-venv' yet. With this patch, teach testenv.py how to create its own environment. Note: this self-bootstrapping is fairly rudimentary and will miss certain triggers to refresh the venv. It will miss when new dependencies are added to either python/setup.cfg or tests/setup.cfg. It can be coaxed into updating by running 'make check', 'make check-block', 'make check-venv', etc. Signed-off-by: John Snow --- tests/qemu-iotests/testenv.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py index 29404ac94be..e985eaf3e97 100644 --- a/tests/qemu-iotests/testenv.py +++ b/tests/qemu-iotests/testenv.py @@ -112,10 +112,10 @@ def init_directories(self) -> None: """ venv_path = Path(self.build_root, 'tests/venv/') if not venv_path.exists(): - raise FileNotFoundError( - f"Virtual environment \"{venv_path!s}\" isn't found." - " (Maybe you need to run 'make check-venv'" - " from the build dir?)" + mkvenv = Path(self.source_iotests, '../mkvenv.py') + subprocess.run( + (sys.executable, str(mkvenv), str(venv_path)), + check=True, ) self.virtual_env: str = str(venv_path)