qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: qemu-block@nongnu.org, jsnow@redhat.com, qemu-devel@nongnu.org,
	mreitz@redhat.com, den@openvz.org
Subject: Re: [PATCH v8 2/5] iotests: add testenv.py
Date: Tue, 26 Jan 2021 11:13:43 +0100	[thread overview]
Message-ID: <20210126101343.GB4385@merkur.fritz.box> (raw)
In-Reply-To: <1d2e022a-68d7-9fcb-cbcd-837b3089d4b2@virtuozzo.com>

Am 26.01.2021 um 11:08 hat Vladimir Sementsov-Ogievskiy geschrieben:
> 26.01.2021 12:45, Kevin Wolf wrote:
> > Am 26.01.2021 um 09:28 hat Vladimir Sementsov-Ogievskiy geschrieben:
> > > 26.01.2021 01:05, Kevin Wolf wrote:
> > > > Am 23.01.2021 um 22:04 hat Vladimir Sementsov-Ogievskiy geschrieben:
> > > > > Add TestEnv class, which will handle test environment in a new python
> > > > > iotests running framework.
> > > > > 
> > > > > Don't add compat=1.1 for qcow2 IMGOPTS, as v3 is default anyway.
> > > > > 
> > > > > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> > > > > ---
> > > > >    tests/qemu-iotests/testenv.py | 278 ++++++++++++++++++++++++++++++++++
> > > > >    1 file changed, 278 insertions(+)
> > > > >    create mode 100644 tests/qemu-iotests/testenv.py
> > > > > 
> > > > > diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
> > > > > new file mode 100644
> > > > > index 0000000000..348af593e9
> > > > > --- /dev/null
> > > > > +++ b/tests/qemu-iotests/testenv.py
> > > > > @@ -0,0 +1,278 @@
> > > > > +# TestEnv class to manage test environment variables.
> > > > > +#
> > > > > +# Copyright (c) 2020-2021 Virtuozzo International GmbH
> > > > > +#
> > > > > +# This program is free software; you can redistribute it and/or modify
> > > > > +# it under the terms of the GNU General Public License as published by
> > > > > +# the Free Software Foundation; either version 2 of the License, or
> > > > > +# (at your option) any later version.
> > > > > +#
> > > > > +# This program is distributed in the hope that it will be useful,
> > > > > +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > > > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > > > +# GNU General Public License for more details.
> > > > > +#
> > > > > +# You should have received a copy of the GNU General Public License
> > > > > +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> > > > > +#
> > > > > +
> > > > > +import os
> > > > > +import sys
> > > > > +import tempfile
> > > > > +from pathlib import Path
> > > > > +import shutil
> > > > > +import collections
> > > > > +import random
> > > > > +import subprocess
> > > > > +import glob
> > > > > +from contextlib import AbstractContextManager
> > > > > +from typing import Dict, Any, Optional
> > > > > +
> > > > > +
> > > > > +def get_default_machine(qemu_prog: str) -> str:
> > > > > +    outp = subprocess.run([qemu_prog, '-machine', 'help'], check=True,
> > > > > +                          universal_newlines=True,
> > > > > +                          stdout=subprocess.PIPE).stdout
> > > > > +
> > > > > +    machines = outp.split('\n')
> > > > > +    default_machine = next(m for m in machines if m.endswith(' (default)'))
> > > > > +    default_machine = default_machine.split(' ', 1)[0]
> > > > > +
> > > > > +    alias_suf = ' (alias of {})'.format(default_machine)
> > > > > +    alias = next((m for m in machines if m.endswith(alias_suf)), None)
> > > > > +    if alias is not None:
> > > > > +        default_machine = alias.split(' ', 1)[0]
> > > > > +
> > > > > +    return default_machine
> > > > > +
> > > > > +
> > > > > +class TestEnv(AbstractContextManager['TestEnv']):
> > > > 
> > > > I'm getting CI failures here:
> > > > 
> > > > Traceback (most recent call last):
> > > >     File "./check", line 23, in <module>
> > > >       from testenv import TestEnv
> > > >     File "/builds/.../qemu/tests/qemu-iotests/testenv.py", line 49, in <module>
> > > >       class TestEnv(AbstractContextManager['TestEnv']):
> > > > TypeError: 'ABCMeta' object is not subscriptable
> > > > 
> > > > On the other hand, if I make it just AbstractContextManager without
> > > > giving the type parameter, mypy complains:
> > > > 
> > > > testenv.py:49: error: Missing type parameters for generic type "ContextManager"
> > > > 
> > > > I guess I need to have another look into this tomorrow.
> > > 
> > > It may help to use typing.ContextManager instead of
> > > AbstractContextManager. mypy is OK with it, probably CI will be OK
> > > too..
> > 
> > Okay, I'm trying now if this change works (on top of v9, of course). If
> > it does, I'll just squash it in. I also silenced some of the mypy
> > warnings, so that I'm not testing with the following patch squashed in.
> > 
> > Kevin
> > 
> > 
> > diff --git a/tests/qemu-iotests/testenv.py b/tests/qemu-iotests/testenv.py
> > index ca9cab531b..becea1bb7d 100644
> > --- a/tests/qemu-iotests/testenv.py
> > +++ b/tests/qemu-iotests/testenv.py
> > @@ -25,8 +25,7 @@ import collections
> >   import random
> >   import subprocess
> >   import glob
> > -from contextlib import AbstractContextManager
> > -from typing import Dict, Any, Optional
> > +from typing import ContextManager, Dict, Any, Optional
> > 
> > 
> >   def isxfile(path: str) -> bool:
> > @@ -50,7 +49,7 @@ def get_default_machine(qemu_prog: str) -> str:
> >       return default_machine
> > 
> > 
> > -class TestEnv(AbstractContextManager['TestEnv']):
> > +class TestEnv(ContextManager['TestEnv']):
> >       """
> >       Manage system environment for running tests
> > 
> > @@ -81,7 +80,7 @@ class TestEnv(AbstractContextManager['TestEnv']):
> > 
> >           return env
> > 
> > -    def init_directories(self):
> > +    def init_directories(self) -> None:
> >           """Init directory variables:
> >                PYTHONPATH
> >                TEST_DIR
> > @@ -114,7 +113,7 @@ class TestEnv(AbstractContextManager['TestEnv']):
> > 
> >           self.output_dir = os.getcwd()  # OUTPUT_DIR
> > 
> > -    def init_binaries(self):
> > +    def init_binaries(self) -> None:
> >           """Init binary path variables:
> >                PYTHON (for bash tests)
> >                QEMU_PROG, QEMU_IMG_PROG, QEMU_IO_PROG, QEMU_NBD_PROG, QSD_PROG
> > @@ -122,7 +121,7 @@ class TestEnv(AbstractContextManager['TestEnv']):
> >           """
> >           self.python = sys.executable
> > 
> > -        def root(*names):
> > +        def root(*names: str) -> str:
> >               return os.path.join(self.build_root, *names)
> > 
> >           arch = os.uname().machine
> 
> Strange, that CI doesn't complain AbstractContextManager['...'] in
> testrunner.py.. Anyway, I think we should consistently use
> typing.ContextManager, if it works.

Ah, it probably does. The runs just take so long that I haven't got
results yet. So I'll probably have to start another run.

Kevin



  reply	other threads:[~2021-01-26 10:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23 21:04 [PATCH v8 0/5] Rework iotests/check Vladimir Sementsov-Ogievskiy
2021-01-23 21:04 ` [PATCH v8 1/5] iotests: add findtests.py Vladimir Sementsov-Ogievskiy
2021-01-23 21:04 ` [PATCH v8 2/5] iotests: add testenv.py Vladimir Sementsov-Ogievskiy
2021-01-25 12:32   ` Vladimir Sementsov-Ogievskiy
2021-01-25 22:05   ` Kevin Wolf
2021-01-26  8:28     ` Vladimir Sementsov-Ogievskiy
2021-01-26  9:45       ` Kevin Wolf
2021-01-26 10:08         ` Vladimir Sementsov-Ogievskiy
2021-01-26 10:13           ` Kevin Wolf [this message]
2021-01-23 21:04 ` [PATCH v8 3/5] iotests: add testrunner.py Vladimir Sementsov-Ogievskiy
2021-01-23 21:04 ` [PATCH v8 4/5] iotests: rewrite check into python Vladimir Sementsov-Ogievskiy
2021-01-23 21:04 ` [PATCH v8 5/5] iotests: rename and move 169 and 199 tests Vladimir Sementsov-Ogievskiy
2021-01-25 16:08 ` [PATCH v8 0/5] Rework iotests/check Kevin Wolf
2021-01-25 16:23   ` Vladimir Sementsov-Ogievskiy
2021-01-25 16:36   ` Vladimir Sementsov-Ogievskiy
2021-01-25 16:50     ` 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=20210126101343.GB4385@merkur.fritz.box \
    --to=kwolf@redhat.com \
    --cc=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).