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 <[email protected]> > > > > > --- > > > > > 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
