qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: John Snow <jsnow@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	Daniel Berrange <berrange@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH v2 2/6] iotests: add warning for rogue 'qemu' packages
Date: Thu, 23 Sep 2021 21:32:26 +0300	[thread overview]
Message-ID: <d9c1be2a-e927-49a1-b30e-f99d48946928@virtuozzo.com> (raw)
In-Reply-To: <20210923180715.4168522-3-jsnow@redhat.com>

23.09.2021 21:07, John Snow wrote:
> Add a warning for when 'iotests' runs against a qemu namespace that
> isn't the one in the source tree. This might occur if you have
> (accidentally) installed the Python namespace package to your local
> packages.
> 
> (I'm not going to say that this is because I bit myself with this,
> but you can fill in the blanks.)
> 
> In the future, we will pivot to always preferring a specific installed
> instance of qemu python packages managed directly by iotests. For now
> simply warn if there is an ambiguity over which instance that iotests
> might use.
> 
> Example: If a user has navigated to ~/src/qemu/python and executed
> `pip install .`, you will see output like this when running `./check`:
> 
> WARNING: 'qemu' python packages will be imported from outside the source tree ('/home/jsnow/src/qemu/python')
>           Importing instead from '/home/jsnow/.local/lib/python3.9/site-packages/qemu'
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>   tests/qemu-iotests/testenv.py | 24 ++++++++++++++++++++++++
>   1 file changed, 24 insertions(+)
> 
> diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
> index 99a57a69f3a..1c0f6358538 100644
> --- a/tests/qemu-iotests/testenv.py
> +++ b/tests/qemu-iotests/testenv.py
> @@ -16,6 +16,8 @@
>   # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>   #
>   
> +import importlib.util
> +import logging
>   import os
>   import sys
>   import tempfile
> @@ -112,6 +114,27 @@ def init_directories(self) -> None:
>           # Path where qemu goodies live in this source tree.
>           qemu_srctree_path = Path(__file__, '../../../python').resolve()
>   
> +        # Warn if we happen to be able to find qemu namespace packages
> +        # (using qemu.qmp as a bellwether) from an unexpected location.
> +        # i.e. the package is already installed in the user's environment.
> +        try:
> +            qemu_spec = importlib.util.find_spec('qemu.qmp')
> +        except ModuleNotFoundError:
> +            qemu_spec = None
> +
> +        if qemu_spec and qemu_spec.origin:
> +            spec_path = Path(qemu_spec.origin)
> +            try:
> +                _ = spec_path.relative_to(qemu_srctree_path)

It took some time and looking at specification trying to understand what's going on here :)

Could we just use:

if not Path(qemu_spec.origin).is_relative_to(qemu_srctree_path):
    ... logging ...


> +            except ValueError:
> +                self._logger.warning(
> +                    "WARNING: 'qemu' python packages will be imported from"
> +                    " outside the source tree ('%s')",
> +                    qemu_srctree_path)
> +                self._logger.warning(
> +                    "         Importing instead from '%s'",
> +                    spec_path.parents[1])
> +

Also, I'd move this new chunk of code to a separate function (may be even out of class, as the only usage of self is self._logger, which you introduce with this patch. Still a method would be OK too). And then, just call it from __init__(). Just to keep init_directories() simpler. And with this new code we don't init any directories to pass to further test execution, it's just a check for runtime environment.

>           self.pythonpath = os.pathsep.join(filter(None, (
>               self.source_iotests,
>               str(qemu_srctree_path),
> @@ -230,6 +253,7 @@ def __init__(self, imgfmt: str, imgproto: str, aiomode: str,
>   
>           self.build_root = os.path.join(self.build_iotests, '..', '..')
>   
> +        self._logger = logging.getLogger('qemu.iotests')
>           self.init_directories()
>           self.init_binaries()
>   
> 


-- 
Best regards,
Vladimir


  reply	other threads:[~2021-09-23 18:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 18:07 [PATCH v2 0/6] iotests: update environment and linting configuration John Snow
2021-09-23 18:07 ` [PATCH v2 1/6] iotests: add 'qemu' package location to PYTHONPATH in testenv John Snow
2021-09-23 18:07 ` [PATCH v2 2/6] iotests: add warning for rogue 'qemu' packages John Snow
2021-09-23 18:32   ` Vladimir Sementsov-Ogievskiy [this message]
2021-09-23 18:44     ` John Snow
2021-09-23 20:27       ` Vladimir Sementsov-Ogievskiy
2021-09-24 18:11         ` John Snow
2021-09-23 18:07 ` [PATCH v2 3/6] iotests/linters: check mypy files all at once John Snow
2021-09-23 18:07 ` [PATCH v2 4/6] iotests/mirror-top-perms: Adjust imports John Snow
2021-09-23 18:07 ` [PATCH v2 5/6] iotests/migrate-bitmaps-test: delint John Snow
2021-09-23 18:07 ` [PATCH v2 6/6] iotests: Update for pylint 2.11.1 John Snow
2021-09-24 18:13 ` [PATCH v2 0/6] iotests: update environment and linting configuration John Snow
2021-09-27  9:31   ` Kevin Wolf

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=d9c1be2a-e927-49a1-b30e-f99d48946928@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=berrange@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).