Python patches
The following changes since commit c8616fc7670b884de5f74d2767aade224c1c5c3a:
Merge remote-tracking branch 'remotes/philmd/tags/gitlab-ci-20210527' into staging (2021-05-27 16:32:57 +0100)
are available in the Git repository at:
https://gitlab.com/jsnow/qemu.git tags/python-pull-request
for you to fetch changes up to faa40e297406445ab8814844bd9aa532a7538cde:
gitlab: add python linters to CI (2021-05-27 18:11:17 -0400)
----------------------------------------------------------------
Python pull request
Python packaging & CI implementation
Acceptance tests sent w/ Cleber's blessing.
New CI tests send w/ stsquad's RB.
--js
----------------------------------------------------------------
Cleber Rosa (12):
Python: expose QEMUMachine's temporary directory tests/acceptance/virtiofs_submounts.py: add missing accel tag tests/acceptance/virtiofs_submounts.py: evaluate string not length
Python: add utility function for retrieving port redirection Acceptance Tests: move useful ssh methods to base class Acceptance Tests: add port redirection for ssh by default Acceptance Tests: make username/password configurable Acceptance Tests: set up SSH connection by default after boot for
LinuxTest
tests/acceptance/virtiofs_submounts.py: remove launch_vm() Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test tests/acceptance/virtiofs_submounts.py: fix setup of SSH pubkey
John Snow (31):
python/console_socket: avoid one-letter variable python/machine: use subprocess.DEVNULL instead of
open(os.path.devnull)
python/machine: use subprocess.run instead of subprocess.Popen python/console_socket: Add a pylint ignore python/machine: Disable pylint warning for open() in _pre_launch python/machine: disable warning for Popen in _launch() python/machine: Trim line length to below 80 chars iotests/297: add --namespace-packages to mypy arguments
python: create qemu packages
python: add qemu package installer
python: add VERSION file
python: add directory structure README.rst files
python: add MANIFEST.in
python: Add pipenv support
python: add pylint import exceptions
python: move pylintrc into setup.cfg
python: add pylint to pipenv
python: move flake8 config to setup.cfg
python: add excluded dirs to flake8 config
python: Add flake8 to pipenv
python: move mypy.ini into setup.cfg
python: add mypy to pipenv
python: move .isort.cfg into setup.cfg
python/qemu: add isort to pipenv
python/qemu: add qemu package itself to pipenv
python: add devel package requirements to setuptools
python: add avocado-framework and tests
python: add Makefile for some common tasks
python: add .gitignore
python: add tox support
gitlab: add python linters to CI
Willian Rampazzo (1):
acceptance tests: bump Avocado version to 88.1
docs/devel/testing.rst | 26 +++
python/PACKAGE.rst | 43 ++++
python/README.rst | 58 +++++
python/qemu/README.rst | 8 +
python/qemu/machine/README.rst | 9 +
python/qemu/qmp/README.rst | 9 +
python/qemu/utils/README.rst | 7 +
.gitlab-ci.d/containers.yml | 5 +
.gitlab-ci.d/static_checks.yml | 21 ++
python/.gitignore | 16 ++
python/MANIFEST.in | 3 +
python/Makefile | 48 ++++
python/Pipfile | 13 ++
python/Pipfile.lock | 231 ++++++++++++++++++++
python/VERSION | 1 +
python/avocado.cfg | 10 +
python/mypy.ini | 4 -
python/qemu/.flake8 | 2 -
python/qemu/.isort.cfg | 7 -
python/qemu/__init__.py | 11 -
python/qemu/machine/__init__.py | 36 +++
python/qemu/{ => machine}/console_socket.py | 11 +-
python/qemu/{ => machine}/machine.py | 68 ++++--
python/qemu/{ => machine}/qtest.py | 9 +-
python/qemu/pylintrc | 58 -----
python/qemu/{qmp.py => qmp/__init__.py} | 12 +-
python/qemu/utils/__init__.py | 45 ++++
python/qemu/{ => utils}/accel.py | 0
python/setup.cfg | 102 +++++++++
python/setup.py | 23 ++
python/tests/flake8.sh | 2 +
python/tests/isort.sh | 2 +
python/tests/mypy.sh | 2 +
python/tests/pylint.sh | 2 +
tests/acceptance/avocado_qemu/__init__.py | 69 +++++-
tests/acceptance/boot_linux.py | 18 +-
tests/acceptance/hotplug_cpu.py | 37 ++++
tests/acceptance/info_usernet.py | 29 +++
tests/acceptance/linux_ssh_mips_malta.py | 42 +---
tests/acceptance/virtio-gpu.py | 2 +-
tests/acceptance/virtiofs_submounts.py | 71 +-----
tests/docker/dockerfiles/python.docker | 18 ++
tests/qemu-iotests/297 | 1 +
tests/qemu-iotests/300 | 4 +-
tests/qemu-iotests/iotests.py | 4 +-
tests/requirements.txt | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 8 +-
48 files changed, 965 insertions(+), 246 deletions(-)
create mode 100644 python/PACKAGE.rst
create mode 100644 python/README.rst
create mode 100644 python/qemu/README.rst
create mode 100644 python/qemu/machine/README.rst
create mode 100644 python/qemu/qmp/README.rst
create mode 100644 python/qemu/utils/README.rst
create mode 100644 python/.gitignore
create mode 100644 python/MANIFEST.in
create mode 100644 python/Makefile
create mode 100644 python/Pipfile
create mode 100644 python/Pipfile.lock
create mode 100644 python/VERSION
create mode 100644 python/avocado.cfg
delete mode 100644 python/mypy.ini
delete mode 100644 python/qemu/.flake8
delete mode 100644 python/qemu/.isort.cfg
delete mode 100644 python/qemu/__init__.py
create mode 100644 python/qemu/machine/__init__.py
rename python/qemu/{ => machine}/console_socket.py (94%)
rename python/qemu/{ => machine}/machine.py (93%)
rename python/qemu/{ => machine}/qtest.py (95%)
delete mode 100644 python/qemu/pylintrc
rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
create mode 100644 python/qemu/utils/__init__.py
rename python/qemu/{ => utils}/accel.py (100%)
create mode 100644 python/setup.cfg
create mode 100755 python/setup.py
create mode 100755 python/tests/flake8.sh
create mode 100755 python/tests/isort.sh
create mode 100755 python/tests/mypy.sh
create mode 100755 python/tests/pylint.sh
create mode 100644 tests/acceptance/hotplug_cpu.py
create mode 100644 tests/acceptance/info_usernet.py
create mode 100644 tests/docker/dockerfiles/python.dockerSignature · 1 line
2.31.1
[PULL 01/44] Python: expose QEMUMachine's temporary directory
From: Cleber Rosa <[email protected]>
Each instance of qemu.machine.QEMUMachine currently has a "test directory", which may not have any relation to a "test", and it's really a temporary directory.
Users instantiating the QEMUMachine class will be able to set the location of the directory that will *contain* the QEMUMachine unique temporary directory, so that parameter name has been changed from test_dir to base_temp_dir.
A property has been added to allow users to access it without using private attributes, and with that, the directory is created on first use of the property.
Message-Id: <[email protected]>
--- python/qemu/machine.py | 24 ++++++++++++++++-------- python/qemu/qtest.py | 6 +++--- tests/qemu-iotests/iotests.py | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-)
python/qemu/machine.py +16 -8
@@ -84,7 +84,7 @@ def __init__(self, args: Sequence[str] = (), wrapper: Sequence[str] = (), name: Optional[str] = None, - test_dir: str = "/var/tmp", + base_temp_dir: str = "/var/tmp", monitor_address: Optional[SocketAddrT] = None, socket_scm_helper: Optional[str] = None, sock_dir: Optional[str] = None,
@@ -97,10 +97,10 @@ def __init__(self, @param args: list of extra arguments @param wrapper: list of arguments used as prefix to qemu binary @param name: prefix for socket and log file names (default: qemu-PID) - @param test_dir: where to create socket and log file + @param base_temp_dir: default location where temporary files are created @param monitor_address: address for QMP monitor @param socket_scm_helper: helper program, required for send_fd_scm() - @param sock_dir: where to create socket (overrides test_dir for sock) + @param sock_dir: where to create socket (defaults to base_temp_dir) @param drain_console: (optional) True to drain console socket to buffer @param console_log: (optional) path to console log file @note: Qemu process is not started until launch() is used.
@@ -112,8 +112,8 @@ def __init__(self, self._wrapper = wrapper self._name = name or "qemu-%d" % os.getpid() - self._test_dir = test_dir - self._sock_dir = sock_dir or self._test_dir + self._base_temp_dir = base_temp_dir + self._sock_dir = sock_dir or self._base_temp_dir self._socket_scm_helper = socket_scm_helper if monitor_address is not None:
@@ -303,9 +303,7 @@ def _base_args(self) -> List[str]: return args def _pre_launch(self) -> None: - self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-", - dir=self._test_dir) - self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log") + self._qemu_log_path = os.path.join(self.temp_dir, self._name + ".log") self._qemu_log_file = open(self._qemu_log_path, 'wb') if self._console_set:
@@ -744,3 +742,13 @@ def console_socket(self) -> socket.socket: file=self._console_log_path, drain=self._drain_console) return self._console_socket + + @property + def temp_dir(self) -> str: + """ + Returns a temporary directory to be used for this machine + """ + if self._temp_dir is None: + self._temp_dir = tempfile.mkdtemp(prefix="qemu-machine-", + dir=self._base_temp_dir) + return self._temp_dir
python/qemu/qtest.py +3 -3
@@ -112,14 +112,14 @@ def __init__(self, binary: str, args: Sequence[str] = (), name: Optional[str] = None, - test_dir: str = "/var/tmp", + base_temp_dir: str = "/var/tmp", socket_scm_helper: Optional[str] = None, sock_dir: Optional[str] = None): if name is None: name = "qemu-%d" % os.getpid() if sock_dir is None: - sock_dir = test_dir - super().__init__(binary, args, name=name, test_dir=test_dir, + sock_dir = base_temp_dir + super().__init__(binary, args, name=name, base_temp_dir=base_temp_dir, socket_scm_helper=socket_scm_helper, sock_dir=sock_dir) self._qtest: Optional[QEMUQtestProtocol] = None
tests/qemu-iotests/iotests.py +1 -1
@@ -571,7 +571,7 @@ class VM(qtest.QEMUQtestMachine): def __init__(self, path_suffix=''): name = "qemu%s-%d" % (path_suffix, os.getpid()) super().__init__(qemu_prog, qemu_opts, name=name, - test_dir=test_dir, + base_temp_dir=test_dir, socket_scm_helper=socket_scm_helper, sock_dir=sock_dir) self._num_drives = 0
Signature · 1 line
2.31.1
[PULL 04/44] Python: add utility function for retrieving port redirection
In reply to John SnowFrom: Cleber Rosa <[email protected]>
Slightly different versions for the same utility code are currently present on different locations. This unifies them all, giving preference to the version from virtiofs_submounts.py, because of the last tweaks added to it.
While at it, this adds a "qemu.utils" module to host the utility function and a test.
Message-Id: <[email protected]>
--- python/qemu/utils.py | 33 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 +++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------- tests/acceptance/virtiofs_submounts.py | 21 ++++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 76 insertions(+), 30 deletions(-) create mode 100644 python/qemu/utils.py create mode 100644 tests/acceptance/info_usernet.py
python/qemu/utils.py new file +33 -0
@@ -0,0 +1,33 @@ +""" +QEMU utility library + +This offers miscellaneous utility functions, which may not be easily +distinguishable or numerous to be in their own module. +""" + +# Copyright (C) 2021 Red Hat Inc. +# +# Authors: +# Cleber Rosa <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +import re +from typing import Optional + + +def get_info_usernet_hostfwd_port(info_usernet_output: str) -> Optional[int]: + """ + Returns the port given to the hostfwd parameter via info usernet + + :param info_usernet_output: output generated by hmp command "info usernet" + :return: the port number allocated by the hostfwd option + """ + for line in info_usernet_output.split('\r\n'): + regex = r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.' + match = re.search(regex, line) + if match is not None: + return int(match[1]) + return None
tests/acceptance/info_usernet.py new file +29 -0
@@ -0,0 +1,29 @@ +# Test for the hmp command "info usernet" +# +# Copyright (c) 2021 Red Hat, Inc. +# +# Author: +# Cleber Rosa <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from avocado_qemu import Test + +from qemu.utils import get_info_usernet_hostfwd_port + + +class InfoUsernet(Test): + + def test_hostfwd(self): + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22') + self.vm.launch() + res = self.vm.command('human-monitor-command', + command_line='info usernet') + port = get_info_usernet_hostfwd_port(res) + self.assertIsNotNone(port, + ('"info usernet" output content does not seem to ' + 'contain the redirected port')) + self.assertGreater(port, 0, + ('Found a redirected port that is not greater than' + ' zero'))
tests/acceptance/linux_ssh_mips_malta.py +7 -9
@@ -18,6 +18,8 @@ from avocado.utils import archive from avocado.utils import ssh +from qemu.utils import get_info_usernet_hostfwd_port + class LinuxSSH(Test):
@@ -70,18 +72,14 @@ def get_kernel_info(self, endianess, wordsize): def setUp(self): super(LinuxSSH, self).setUp() - def get_portfwd(self): + def ssh_connect(self, username, password): + self.ssh_logger = logging.getLogger('ssh') res = self.vm.command('human-monitor-command', command_line='info usernet') - line = res.split('\r\n')[2] - port = re.split(r'.*TCP.HOST_FORWARD.*127\.0\.0\.1 (\d+)\s+10\..*', - line)[1] + port = get_info_usernet_hostfwd_port(res) + if not port: + self.cancel("Failed to retrieve SSH port") self.log.debug("sshd listening on port:" + port) - return port - - def ssh_connect(self, username, password): - self.ssh_logger = logging.getLogger('ssh') - port = self.get_portfwd() self.ssh_session = ssh.Session(self.VM_IP, port=int(port), user=username, password=password) for i in range(10):
tests/acceptance/virtiofs_submounts.py +5 -16
@@ -9,6 +9,8 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh +from qemu.utils import get_info_usernet_hostfwd_port + def run_cmd(args): subp = subprocess.Popen(args,
@@ -73,27 +75,14 @@ class VirtiofsSubmountsTest(LinuxTest): :avocado: tags=accel:kvm """ - def get_portfwd(self): - port = None - + def ssh_connect(self, username, keyfile): + self.ssh_logger = logging.getLogger('ssh') res = self.vm.command('human-monitor-command', command_line='info usernet') - for line in res.split('\r\n'): - match = \ - re.search(r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.', - line) - if match is not None: - port = int(match[1]) - break - + port = get_info_usernet_hostfwd_port(res) self.assertIsNotNone(port) self.assertGreater(port, 0) self.log.debug('sshd listening on port: %d', port) - return port - - def ssh_connect(self, username, keyfile): - self.ssh_logger = logging.getLogger('ssh') - port = self.get_portfwd() self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, key=keyfile) for i in range(10):
tests/vm/basevm.py +2 -5
@@ -21,6 +21,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu.accel import kvm_available from qemu.machine import QEMUMachine +from qemu.utils import get_info_usernet_hostfwd_port import subprocess import hashlib import argparse
@@ -306,11 +307,7 @@ def boot(self, img, extra_args=[]): self.console_init() usernet_info = guest.qmp("human-monitor-command", command_line="info usernet") - self.ssh_port = None - for l in usernet_info["return"].splitlines(): - fields = l.split() - if "TCP[HOST_FORWARD]" in fields and "22" in fields: - self.ssh_port = l.split()[3] + self.ssh_port = get_info_usernet_hostfwd_port(usernet_info) if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ usernet_info)
Signature · 1 line
2.31.1
[PULL 03/44] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to John SnowFrom: Cleber Rosa <[email protected]>
If the vmlinuz variable is set to anything that evaluates to True, then the respective arguments should be set. If the variable contains an empty string, than it will evaluate to False, and the extra arguments will not be set.
This keeps the same logic, but improves readability a bit.
Message-Id: <[email protected]>
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -251,7 +251,7 @@ def setUp(self): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')
Signature · 1 line
2.31.1
[PULL 05/44] Acceptance Tests: move useful ssh methods to base class
In reply to John SnowFrom: Cleber Rosa <[email protected]>
Both the virtiofs submounts and the linux ssh mips malta tests contains useful methods related to ssh that deserve to be made available to other tests. Let's move them to an auxiliary, mix-in class that will be used on the base LinuxTest class.
The method that helps with setting up an ssh connection will now support both key and password based authentication, defaulting to key based.
Message-Id: <[email protected]>
--- tests/acceptance/avocado_qemu/__init__.py | 48 ++++++++++++++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 40 ++----------------- tests/acceptance/virtiofs_submounts.py | 37 ----------------- 3 files changed, 50 insertions(+), 75 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +47 -1
@@ -20,6 +20,7 @@ from avocado.utils import cloudinit from avocado.utils import datadrainer from avocado.utils import network +from avocado.utils import ssh from avocado.utils import vmimage from avocado.utils.path import find_command
@@ -43,6 +44,8 @@ from qemu.accel import kvm_available from qemu.accel import tcg_available from qemu.machine import QEMUMachine +from qemu.utils import get_info_usernet_hostfwd_port + def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
@@ -253,7 +256,50 @@ def fetch_asset(self, name, cancel_on_missing=cancel_on_missing) -class LinuxTest(Test): +class LinuxSSHMixIn: + """Contains utility methods for interacting with a guest via SSH.""" + + def ssh_connect(self, username, credential, credential_is_key=True): + self.ssh_logger = logging.getLogger('ssh') + res = self.vm.command('human-monitor-command', + command_line='info usernet') + port = get_info_usernet_hostfwd_port(res) + self.assertIsNotNone(port) + self.assertGreater(port, 0) + self.log.debug('sshd listening on port: %d', port) + if credential_is_key: + self.ssh_session = ssh.Session('127.0.0.1', port=port, + user=username, key=credential) + else: + self.ssh_session = ssh.Session('127.0.0.1', port=port, + user=username, password=credential) + for i in range(10): + try: + self.ssh_session.connect() + return + except: + time.sleep(4) + pass + self.fail('ssh connection timeout') + + def ssh_command(self, command): + self.ssh_logger.info(command) + result = self.ssh_session.cmd(command) + stdout_lines = [line.rstrip() for line + in result.stdout_text.splitlines()] + for line in stdout_lines: + self.ssh_logger.info(line) + stderr_lines = [line.rstrip() for line + in result.stderr_text.splitlines()] + for line in stderr_lines: + self.ssh_logger.warning(line) + + self.assertEqual(result.exit_status, 0, + f'Guest command failed: {command}') + return stdout_lines, stderr_lines + + +class LinuxTest(Test, LinuxSSHMixIn): """Facilitates having a cloud-image Linux based available. For tests that indend to interact with guests, this is a better choice
tests/acceptance/linux_ssh_mips_malta.py +3 -37
@@ -12,16 +12,14 @@ import time from avocado import skipUnless -from avocado_qemu import Test +from avocado_qemu import Test, LinuxSSHMixIn from avocado_qemu import wait_for_console_pattern from avocado.utils import process from avocado.utils import archive from avocado.utils import ssh -from qemu.utils import get_info_usernet_hostfwd_port - -class LinuxSSH(Test): +class LinuxSSH(Test, LinuxSSHMixIn): timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg'
@@ -72,41 +70,9 @@ def get_kernel_info(self, endianess, wordsize): def setUp(self): super(LinuxSSH, self).setUp() - def ssh_connect(self, username, password): - self.ssh_logger = logging.getLogger('ssh') - res = self.vm.command('human-monitor-command', - command_line='info usernet') - port = get_info_usernet_hostfwd_port(res) - if not port: - self.cancel("Failed to retrieve SSH port") - self.log.debug("sshd listening on port:" + port) - self.ssh_session = ssh.Session(self.VM_IP, port=int(port), - user=username, password=password) - for i in range(10): - try: - self.ssh_session.connect() - return - except: - time.sleep(4) - pass - self.fail("ssh connection timeout") - def ssh_disconnect_vm(self): self.ssh_session.quit() - def ssh_command(self, command, is_root=True): - self.ssh_logger.info(command) - result = self.ssh_session.cmd(command) - stdout_lines = [line.rstrip() for line - in result.stdout_text.splitlines()] - for line in stdout_lines: - self.ssh_logger.info(line) - stderr_lines = [line.rstrip() for line - in result.stderr_text.splitlines()] - for line in stderr_lines: - self.ssh_logger.warning(line) - return stdout_lines, stderr_lines - def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path): image_url, image_hash = self.get_image_info(endianess) image_path = self.fetch_asset(image_url, asset_hash=image_hash)
@@ -127,7 +93,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path): wait_for_console_pattern(self, console_pattern, 'Oops') self.log.info('sshd ready') - self.ssh_connect('root', 'root') + self.ssh_connect('root', 'root', False) def shutdown_via_ssh(self): self.ssh_command('poweroff')
tests/acceptance/virtiofs_submounts.py +0 -37
@@ -9,8 +9,6 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh -from qemu.utils import get_info_usernet_hostfwd_port - def run_cmd(args): subp = subprocess.Popen(args,
@@ -75,41 +73,6 @@ class VirtiofsSubmountsTest(LinuxTest): :avocado: tags=accel:kvm """ - def ssh_connect(self, username, keyfile): - self.ssh_logger = logging.getLogger('ssh') - res = self.vm.command('human-monitor-command', - command_line='info usernet') - port = get_info_usernet_hostfwd_port(res) - self.assertIsNotNone(port) - self.assertGreater(port, 0) - self.log.debug('sshd listening on port: %d', port) - self.ssh_session = ssh.Session('127.0.0.1', port=port, - user=username, key=keyfile) - for i in range(10): - try: - self.ssh_session.connect() - return - except: - time.sleep(4) - pass - self.fail('ssh connection timeout') - - def ssh_command(self, command): - self.ssh_logger.info(command) - result = self.ssh_session.cmd(command) - stdout_lines = [line.rstrip() for line - in result.stdout_text.splitlines()] - for line in stdout_lines: - self.ssh_logger.info(line) - stderr_lines = [line.rstrip() for line - in result.stderr_text.splitlines()] - for line in stderr_lines: - self.ssh_logger.warning(line) - - self.assertEqual(result.exit_status, 0, - f'Guest command failed: {command}') - return stdout_lines, stderr_lines - def run(self, args, ignore_error=False): stdout, stderr, ret = run_cmd(args)
Signature · 1 line
2.31.1
[PULL 06/44] Acceptance Tests: add port redirection for ssh by default
In reply to John SnowFrom: Cleber Rosa <[email protected]>
For users of the LinuxTest class, let's set up the VM with the port redirection for SSH, instead of requiring each test to set the same arguments.
It also sets the network device, by default, to virtio-net.
Message-Id: <[email protected]>
--- tests/acceptance/avocado_qemu/__init__.py | 5 ++++- tests/acceptance/virtiofs_submounts.py | 4 ---- 2 files changed, 4 insertions(+), 5 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +4 -1
@@ -309,10 +309,13 @@ class LinuxTest(Test, LinuxSSHMixIn): timeout = 900 chksum = None - def setUp(self, ssh_pubkey=None): + def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'): super(LinuxTest, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') + # The following network device allows for SSH connections + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', '%s,netdev=vnet' % network_device_type) self.set_up_boot() if ssh_pubkey is None: ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys()
tests/acceptance/virtiofs_submounts.py +0 -4
@@ -207,10 +207,6 @@ def setUp(self): self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1') - # Allow us to connect to SSH - self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', - '-device', 'virtio-net,netdev=vnet') - self.require_accelerator("kvm") self.vm.add_args('-accel', 'kvm')
Signature · 1 line
2.31.1
[PULL 07/44] Acceptance Tests: make username/password configurable
In reply to John SnowFrom: Cleber Rosa <[email protected]>
This makes the username/password used for authentication configurable, because some guest operating systems may have restrictions on accounts to be used for logins, and it just makes it better documented.
Message-Id: <[email protected]>
--- tests/acceptance/avocado_qemu/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +4 -2
@@ -308,6 +308,8 @@ class LinuxTest(Test, LinuxSSHMixIn): timeout = 900 chksum = None + username = 'root' + password = 'password' def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'): super(LinuxTest, self).setUp()
@@ -371,8 +373,8 @@ def prepare_cloudinit(self, ssh_pubkey=None): with open(ssh_pubkey) as pubkey: pubkey_content = pubkey.read() cloudinit.iso(cloudinit_iso, self.name, - username='root', - password='password', + username=self.username, + password=self.password, # QEMU's hard coded usermode router address phone_home_host='10.0.2.2', phone_home_port=self.phone_home_port,
Signature · 1 line
2.31.1
[PULL 10/44] Acceptance Tests: add basic documentation on LinuxTest base class
In reply to John SnowFrom: Cleber Rosa <[email protected]>
Message-Id: <[email protected]>
--- docs/devel/testing.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
docs/devel/testing.rst +26 -0
@@ -810,6 +810,32 @@ and hypothetical example follows: At test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines shutdown. +The ``avocado_qemu.LinuxTest`` base test class +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``avocado_qemu.LinuxTest`` is further specialization of the +``avocado_qemu.Test`` class, so it contains all the characteristics of +the later plus some extra features. + +First of all, this base class is intended for tests that need to +interact with a fully booted and operational Linux guest. At this +time, it uses a Fedora 31 guest image. The most basic example looks +like this: + +.. code:: + + from avocado_qemu import LinuxTest + + + class SomeTest(LinuxTest): + + def test(self): + self.launch_and_wait() + self.ssh_command('some_command_to_be_run_in_the_guest') + +Please refer to tests that use ``avocado_qemu.LinuxTest`` under +``tests/acceptance`` for more examples. + QEMUMachine ~~~~~~~~~~~
Signature · 1 line
2.31.1
[PULL 02/44] tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to John SnowFrom: Cleber Rosa <[email protected]>
The tag is useful to select tests that depend/use a particular feature.
Message-Id: <[email protected]>
--- tests/acceptance/virtiofs_submounts.py | 1 + 1 file changed, 1 insertion(+)
tests/acceptance/virtiofs_submounts.py +1 -0
@@ -70,6 +70,7 @@ def test_something_that_needs_cmd1_and_cmd2(self): class VirtiofsSubmountsTest(LinuxTest): """ :avocado: tags=arch:x86_64 + :avocado: tags=accel:kvm """ def get_portfwd(self):
Signature · 1 line
2.31.1
[PULL 09/44] tests/acceptance/virtiofs_submounts.py: remove launch_vm()
In reply to John SnowFrom: Cleber Rosa <[email protected]>
The LinuxTest class' launch_and_wait() method now behaves the same way as this test's custom launch_vm(), so let's just use the upper layer (common) method.
Message-Id: <[email protected]>
--- tests/acceptance/virtiofs_submounts.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
tests/acceptance/virtiofs_submounts.py +5 -8
@@ -134,9 +134,6 @@ def set_up_virtiofs(self): '-numa', 'node,memdev=mem') - def launch_vm(self): - self.launch_and_wait() - def set_up_nested_mounts(self): scratch_dir = os.path.join(self.shared_dir, 'scratch') try:
@@ -225,7 +222,7 @@ def test_pre_virtiofsd_set_up(self): self.set_up_nested_mounts() self.set_up_virtiofs() - self.launch_vm() + self.launch_and_wait() self.mount_in_guest() self.check_in_guest()
@@ -235,14 +232,14 @@ def test_pre_launch_set_up(self): self.set_up_nested_mounts() - self.launch_vm() + self.launch_and_wait() self.mount_in_guest() self.check_in_guest() def test_post_launch_set_up(self): self.set_up_shared_dir() self.set_up_virtiofs() - self.launch_vm() + self.launch_and_wait() self.set_up_nested_mounts()
@@ -252,7 +249,7 @@ def test_post_launch_set_up(self): def test_post_mount_set_up(self): self.set_up_shared_dir() self.set_up_virtiofs() - self.launch_vm() + self.launch_and_wait() self.mount_in_guest() self.set_up_nested_mounts()
@@ -265,7 +262,7 @@ def test_two_runs(self): self.set_up_nested_mounts() self.set_up_virtiofs() - self.launch_vm() + self.launch_and_wait() self.mount_in_guest() self.check_in_guest()
Signature · 1 line
2.31.1
[PULL 15/44] python/machine: use subprocess.DEVNULL instead of open(os.path.devnull)
In reply to John SnowOne less file resource to manage, and it helps quiet some pylint >= 2.8.0 warnings about not using a with-context manager for the open call.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/machine.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
python/qemu/machine.py +2 -4
@@ -223,9 +223,8 @@ def send_fd_scm(self, fd: Optional[int] = None, assert fd is not None fd_param.append(str(fd)) - devnull = open(os.path.devnull, 'rb') proc = subprocess.Popen( - fd_param, stdin=devnull, stdout=subprocess.PIPE, + fd_param, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=False ) output = proc.communicate()[0]
@@ -391,7 +390,6 @@ def _launch(self) -> None: """ Launch the VM and establish a QMP connection """ - devnull = open(os.path.devnull, 'rb') self._pre_launch() self._qemu_full_args = tuple( chain(self._wrapper,
@@ -401,7 +399,7 @@ def _launch(self) -> None: ) LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args)) self._popen = subprocess.Popen(self._qemu_full_args, - stdin=devnull, + stdin=subprocess.DEVNULL, stdout=self._qemu_log_file, stderr=subprocess.STDOUT, shell=False,
Signature · 1 line
2.31.1
[PULL 28/44] python: add pylint import exceptions
In reply to John SnowPylint 2.5.x - 2.7.x have regressions that make import checking inconsistent, see:
https://github.com/PyCQA/pylint/issues/3609
https://github.com/PyCQA/pylint/issues/3624
https://github.com/PyCQA/pylint/issues/3651
Pinning to 2.4.4 is worse, because it mandates versions of shared dependencies that are too old for features we want in isort and mypy. Oh well.
Message-id: [email protected]
--- python/qemu/machine/__init__.py | 3 +++ python/qemu/machine/machine.py | 2 +- python/qemu/machine/qtest.py | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
python/qemu/machine/__init__.py +3 -0
@@ -22,6 +22,9 @@ # the COPYING file in the top-level directory. # +# pylint: disable=import-error +# see: https://github.com/PyCQA/pylint/issues/3624 +# see: https://github.com/PyCQA/pylint/issues/3651 from .machine import QEMUMachine from .qtest import QEMUQtestMachine, QEMUQtestProtocol
python/qemu/machine/machine.py +1 -1
@@ -38,7 +38,7 @@ Type, ) -from qemu.qmp import ( +from qemu.qmp import ( # pylint: disable=import-error QEMUMonitorProtocol, QMPMessage, QMPReturnValue,
python/qemu/machine/qtest.py +1 -1
@@ -26,7 +26,7 @@ TextIO, ) -from qemu.qmp import SocketAddrT +from qemu.qmp import SocketAddrT # pylint: disable=import-error from .machine import QEMUMachine
Signature · 1 line
2.31.1
[PULL 08/44] Acceptance Tests: set up SSH connection by default after boot for LinuxTest
In reply to John SnowFrom: Cleber Rosa <[email protected]>
The LinuxTest specifically targets users that need to interact with Linux guests. So, it makes sense to give a connection by default, and avoid requiring it as boiler-plate code.
Message-Id: <[email protected]>
--- tests/acceptance/avocado_qemu/__init__.py | 5 ++++- tests/acceptance/boot_linux.py | 18 +++++++++--------- tests/acceptance/virtiofs_submounts.py | 1 - 3 files changed, 13 insertions(+), 11 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +4 -1
@@ -391,7 +391,7 @@ def set_up_cloudinit(self, ssh_pubkey=None): cloudinit_iso = self.prepare_cloudinit(ssh_pubkey) self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso) - def launch_and_wait(self): + def launch_and_wait(self, set_up_ssh_connection=True): self.vm.set_console() self.vm.launch() console_drainer = datadrainer.LineLogger(self.vm.console_socket.fileno(),
@@ -399,3 +399,6 @@ def launch_and_wait(self): console_drainer.start() self.log.info('VM launched, waiting for boot confirmation from guest') cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), self.name) + if set_up_ssh_connection: + self.log.info('Setting up the SSH connection') + self.ssh_connect(self.username, self.ssh_key)
tests/acceptance/boot_linux.py +9 -9
@@ -29,7 +29,7 @@ def test_pc_i440fx_tcg(self): """ self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) def test_pc_i440fx_kvm(self): """
@@ -38,7 +38,7 @@ def test_pc_i440fx_kvm(self): """ self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) def test_pc_q35_tcg(self): """
@@ -47,7 +47,7 @@ def test_pc_q35_tcg(self): """ self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) def test_pc_q35_kvm(self): """
@@ -56,7 +56,7 @@ def test_pc_q35_kvm(self): """ self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) class BootLinuxAarch64(LinuxTest):
@@ -85,7 +85,7 @@ def test_virt_tcg(self): self.vm.add_args("-cpu", "max") self.vm.add_args("-machine", "virt,gic-version=2") self.add_common_args() - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) def test_virt_kvm_gicv2(self): """
@@ -98,7 +98,7 @@ def test_virt_kvm_gicv2(self): self.vm.add_args("-cpu", "host") self.vm.add_args("-machine", "virt,gic-version=2") self.add_common_args() - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) def test_virt_kvm_gicv3(self): """
@@ -111,7 +111,7 @@ def test_virt_kvm_gicv3(self): self.vm.add_args("-cpu", "host") self.vm.add_args("-machine", "virt,gic-version=3") self.add_common_args() - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) class BootLinuxPPC64(LinuxTest):
@@ -128,7 +128,7 @@ def test_pseries_tcg(self): """ self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False) class BootLinuxS390X(LinuxTest):
@@ -146,4 +146,4 @@ def test_s390_ccw_virtio_tcg(self): """ self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") - self.launch_and_wait() + self.launch_and_wait(set_up_ssh_connection=False)
tests/acceptance/virtiofs_submounts.py +0 -1
@@ -136,7 +136,6 @@ def set_up_virtiofs(self): def launch_vm(self): self.launch_and_wait() - self.ssh_connect('root', self.ssh_key) def set_up_nested_mounts(self): scratch_dir = os.path.join(self.shared_dir, 'scratch')
Signature · 1 line
2.31.1
[PULL 12/44] tests/acceptance/virtiofs_submounts.py: fix setup of SSH pubkey
In reply to John SnowFrom: Cleber Rosa <[email protected]>
The public key argument should be a path to a file, and not the public key data.
Message-Id: <[email protected]>
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -195,7 +195,7 @@ def setUp(self): self.run(('ssh-keygen', '-N', '', '-t', 'ed25519', '-f', self.ssh_key)) - pubkey = open(self.ssh_key + '.pub').read() + pubkey = self.ssh_key + '.pub' super(VirtiofsSubmountsTest, self).setUp(pubkey)
Signature · 1 line
2.31.1
[PULL 17/44] python/console_socket: Add a pylint ignore
In reply to John SnowWe manage cleaning up this resource ourselves. Pylint should shush.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/console_socket.py | 1 + 1 file changed, 1 insertion(+)
python/qemu/console_socket.py +1 -0
@@ -39,6 +39,7 @@ def __init__(self, address: str, file: Optional[str] = None, self.connect(address) self._logfile = None if file: + # pylint: disable=consider-using-with self._logfile = open(file, "bw") self._open = True self._drain_thread = None
Signature · 1 line
2.31.1
[PULL 32/44] python: add excluded dirs to flake8 config
In reply to John SnowInstruct flake8 to avoid certain well-known directories created by python tooling that it ought not check.
Note that at-present, nothing actually creates a ".venv" directory; but it is in such widespread usage as a de-facto location for a developer's virtual environment that it should be excluded anyway. A forthcoming commit canonizes this with a "make venv" command.
Message-id: [email protected]
--- python/setup.cfg | 2 ++ 1 file changed, 2 insertions(+)
python/setup.cfg +2 -0
@@ -24,6 +24,8 @@ packages = [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's +exclude = __pycache__, + .venv, [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You
Signature · 1 line
2.31.1
[PULL 11/44] Acceptance Tests: introduce CPU hotplug test
In reply to John SnowFrom: Cleber Rosa <[email protected]>
Even though there are qtest based tests for hotplugging CPUs (from which this test took some inspiration from), this one adds checks from a Linux guest point of view.
It should also serve as an example for tests that follow a similar pattern and need to interact with QEMU (via qmp) and with the Linux guest via SSH.
Message-Id: <[email protected]>
--- tests/acceptance/hotplug_cpu.py | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/acceptance/hotplug_cpu.py
tests/acceptance/hotplug_cpu.py new file +37 -0
@@ -0,0 +1,37 @@ +# Functional test that hotplugs a CPU and checks it on a Linux guest +# +# Copyright (c) 2021 Red Hat, Inc. +# +# Author: +# Cleber Rosa <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +from avocado_qemu import LinuxTest + + +class HotPlugCPU(LinuxTest): + + def test(self): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:q35 + :avocado: tags=accel:kvm + """ + self.require_accelerator('kvm') + self.vm.add_args('-accel', 'kvm') + self.vm.add_args('-cpu', 'Haswell') + self.vm.add_args('-smp', '1,sockets=1,cores=2,threads=1,maxcpus=2') + self.launch_and_wait() + + self.ssh_command('test -e /sys/devices/system/cpu/cpu0') + with self.assertRaises(AssertionError): + self.ssh_command('test -e /sys/devices/system/cpu/cpu1') + + self.vm.command('device_add', + driver='Haswell-x86_64-cpu', + socket_id=0, + core_id=1, + thread_id=0) + self.ssh_command('test -e /sys/devices/system/cpu/cpu1')
Signature · 1 line
2.31.1
[PULL 13/44] acceptance tests: bump Avocado version to 88.1
In reply to John SnowFrom: Willian Rampazzo <[email protected]>
Besides some internal changes, new features, and bug fixes, on the QEMU side, this version fixes the following message seen when running the acceptance
tests: "Error running method "pre_tests" of plugin "fetchasset": 'bytes' object has no attribute 'encode'".
The release notes are available at
https://avocado-framework.readthedocs.io/en/latest/releases/88_0.html.
Message-Id: <[email protected]>
--- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/requirements.txt +1 -1
@@ -1,5 +1,5 @@ # 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 -avocado-framework==85.0 +avocado-framework==88.1 pycdlib==1.11.0
Signature · 1 line
2.31.1
[PULL 18/44] python/machine: Disable pylint warning for open() in _pre_launch
In reply to John SnowShift the open() call later so that the pylint pragma applies *only* to that one open() call. Add a note that suggests why this is safe: the resource is unconditionally cleaned up in _post_shutdown().
_post_shutdown is called after failed launches (see launch()), and unconditionally after every call to shutdown(), and therefore also on __exit__.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/machine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
python/qemu/machine.py +5 -1
@@ -306,7 +306,6 @@ def _base_args(self) -> List[str]: def _pre_launch(self) -> None: self._qemu_log_path = os.path.join(self.temp_dir, self._name + ".log") - self._qemu_log_file = open(self._qemu_log_path, 'wb') if self._console_set: self._remove_files.append(self._console_address)
@@ -321,6 +320,11 @@ def _pre_launch(self) -> None: nickname=self._name ) + # NOTE: Make sure any opened resources are *definitely* freed in + # _post_shutdown()! + # pylint: disable=consider-using-with + self._qemu_log_file = open(self._qemu_log_path, 'wb') + def _post_launch(self) -> None: if self._qmp_connection: self._qmp.accept()
Signature · 1 line
2.31.1
[PULL 33/44] python: Add flake8 to pipenv
In reply to John Snowflake8 3.5.x does not support the --extend-ignore syntax used in the .flake8 file to gracefully extend default ignores, so 3.6.x is our minimum requirement. There is no known upper bound.
flake8 can be run from the python/ directory with no arguments.
Message-id: [email protected]
--- python/Pipfile | 1 + python/Pipfile.lock | 51 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-)
python/Pipfile +1 -0
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +flake8 = ">=3.6.0" pylint = ">=2.8.0" [packages]
python/Pipfile.lock +50 -1
80 lines not on this page · raw message
Signature · 1 line
2.31.1
[PULL 14/44] python/console_socket: avoid one-letter variable
In reply to John SnowFixes pylint warnings.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/console_socket.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
python/qemu/console_socket.py +5 -5
@@ -46,11 +46,11 @@ def __init__(self, address: str, file: Optional[str] = None, self._drain_thread = self._thread_start() def __repr__(self) -> str: - s = super().__repr__() - s = s.rstrip(">") - s = "%s, logfile=%s, drain_thread=%s>" % (s, self._logfile, - self._drain_thread) - return s + tmp = super().__repr__() + tmp = tmp.rstrip(">") + tmp = "%s, logfile=%s, drain_thread=%s>" % (tmp, self._logfile, + self._drain_thread) + return tmp def _drain_fn(self) -> None: """Drains the socket and runs while the socket is open."""
Signature · 1 line
2.31.1
[PULL 16/44] python/machine: use subprocess.run instead of subprocess.Popen
In reply to John Snowuse run() instead of Popen() -- to assert to pylint that we are not forgetting to close a long-running program.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/machine.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
python/qemu/machine.py +9 -6
@@ -223,13 +223,16 @@ def send_fd_scm(self, fd: Optional[int] = None, assert fd is not None fd_param.append(str(fd)) - proc = subprocess.Popen( - fd_param, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, close_fds=False + proc = subprocess.run( + fd_param, + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + check=False, + close_fds=False, ) - output = proc.communicate()[0] - if output: - LOG.debug(output) + if proc.stdout: + LOG.debug(proc.stdout) return proc.returncode
Signature · 1 line
2.31.1
[PULL 21/44] iotests/297: add --namespace-packages to mypy arguments
In reply to John Snowmypy is kind of weird about how it handles imports. For legacy reasons, it won't load PEP 420 namespaces, because of logic implemented prior to that becoming a standard.
So, if you plan on using any, you have to pass
--namespace-packages. Alright, fine.
Message-id: [email protected]
--- tests/qemu-iotests/297 | 1 + 1 file changed, 1 insertion(+)
tests/qemu-iotests/297 +1 -0
@@ -95,6 +95,7 @@ def run_linters(): '--warn-redundant-casts', '--warn-unused-ignores', '--no-implicit-reexport', + '--namespace-packages', filename), env=env, check=False,
Signature · 1 line
2.31.1
[PULL 41/44] python: add Makefile for some common tasks
In reply to John SnowAdd "make venv" to create the pipenv-managed virtual environment that contains our explicitly pinned dependencies.
Add "make check" to run the python linters [in the host execution environment].
Add "make venv-check" which combines the above two: create/update the venv, then run the linters in that explicitly managed environment.
Add "make develop" which canonizes the runes needed to get both the linting pre-requisites (the "[devel]" part), and the editable live-install (the "-e" part) of these python libraries.
make clean: delete miscellaneous python packaging output possibly created by pipenv, pip, or other python packaging utilities
make distclean: delete the above, the .venv, and the editable "qemu" package forwarder (qemu.egg-info) if there is one.
Message-id: [email protected]
--- python/PACKAGE.rst | 6 ++++++ python/README.rst | 6 ++++++ python/Makefile | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 python/Makefile
python/PACKAGE.rst +6 -0
@@ -35,3 +35,9 @@ the report. Optional packages necessary for running code quality analysis for this package can be installed with the optional dependency group "devel": ``pip install qemu[devel]``. + +``make develop`` can be used to install this package in editable mode +(to the current environment) *and* bring in testing dependencies in one +command. + +``make check`` can be used to run the available tests.
python/README.rst +6 -0
@@ -28,6 +28,9 @@ Installing ".[devel]" instead of "." will additionally pull in required packages for testing this package. They are not runtime requirements, and are not needed to simply use these libraries. +Running ``make develop`` will pull in all testing dependencies and +install QEMU in editable mode to the current environment. + See `Installing packages using pip and virtual environments <https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_ for more information.
@@ -39,6 +42,9 @@ Files in this directory - ``qemu/`` Python package source directory. - ``tests/`` Python package tests directory. - ``avocado.cfg`` Configuration for the Avocado test-runner. + Used by ``make check`` et al. +- ``Makefile`` provides some common testing/installation invocations. + Try ``make help`` to see available targets. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.
python/Makefile new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.31.1
[PULL 20/44] python/machine: Trim line length to below 80 chars
In reply to John SnowOne more little delinting fix that snuck in.
Message-id: [email protected]
--- python/qemu/machine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
python/qemu/machine.py +1 -1
@@ -97,7 +97,7 @@ def __init__(self, @param args: list of extra arguments @param wrapper: list of arguments used as prefix to qemu binary @param name: prefix for socket and log file names (default: qemu-PID) - @param base_temp_dir: default location where temporary files are created + @param base_temp_dir: default location where temp files are created @param monitor_address: address for QMP monitor @param socket_scm_helper: helper program, required for send_fd_scm() @param sock_dir: where to create socket (defaults to base_temp_dir)
Signature · 1 line
2.31.1
[PULL 19/44] python/machine: disable warning for Popen in _launch()
In reply to John SnowWe handle this resource rather meticulously in shutdown/kill/wait/__exit__ et al, through the laborious mechanisms in _do_shutdown().
Quiet this pylint warning here.
Message-id: [email protected]
Message-id: [email protected]
--- python/qemu/machine.py | 3 +++ 1 file changed, 3 insertions(+)
python/qemu/machine.py +3 -0
@@ -405,6 +405,9 @@ def _launch(self) -> None: self._args) ) LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args)) + + # Cleaning up of this subprocess is guaranteed by _do_shutdown. + # pylint: disable=consider-using-with self._popen = subprocess.Popen(self._qemu_full_args, stdin=subprocess.DEVNULL, stdout=self._qemu_log_file,
Signature · 1 line
2.31.1
[PULL 23/44] python: add qemu package installer
In reply to John SnowAdd setup.cfg and setup.py, necessary for installing a package via pip. Add a ReST document (PACKAGE.rst) explaining the basics of what this package is for and who to contact for more information. This document will be used as the landing page for the package on PyPI.
List the subpackages we intend to package by name instead of using find_namespace because find_namespace will naively also packages tests, things it finds in the dist/ folder, etc. I could not figure out how to modify this behavior; adding allow/deny lists to setuptools kept changing the packaged hierarchy. This works, roll with it.
I am not yet using a pyproject.toml style package manifest, because "editable" installs are not defined (yet?) by PEP-517/518.
I consider editable installs crucial for development, though they have (apparently) always been somewhat poorly defined.
Pip now (19.2 and later) now supports editable installs for projects using pyproject.toml manifests, but might require the use of the --no-use-pep517 flag, which somewhat defeats the point. Full support for setup.py-less editable installs was not introduced until pip 21.1.1:
https://github.com/pypa/pip/pull/9547/commits/7a95720e796a5e56481c1cc20b6ce6249c50f357
For now, while the dust settles, stick with the de-facto setup.py/setup.cfg combination supported by setuptools. It will be worth re-evaluating this point again in the future when our supported build platforms all ship a fairly modern pip.
Additional reading on this matter:
https://github.com/pypa/packaging-problems/issues/256
https://github.com/pypa/pip/issues/6334
https://github.com/pypa/pip/issues/6375
https://github.com/pypa/pip/issues/6434
https://github.com/pypa/pip/issues/6438
Message-id: [email protected]
--- python/PACKAGE.rst | 33 +++++++++++++++++++++++++++++++++ python/setup.cfg | 22 ++++++++++++++++++++++ python/setup.py | 23 +++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 python/PACKAGE.rst create mode 100644 python/setup.cfg create mode 100755 python/setup.py
python/PACKAGE.rst new file +33 -0
@@ -0,0 +1,33 @@ +QEMU Python Tooling +=================== + +This package provides QEMU tooling used by the QEMU project to build, +configure, and test QEMU. It is not a fully-fledged SDK and it is subject +to change at any time. + +Usage +----- + +The ``qemu.qmp`` subpackage provides a library for communicating with +QMP servers. The ``qemu.machine`` subpackage offers rudimentary +facilities for launching and managing QEMU processes. Refer to each +package's documentation +(``>>> help(qemu.qmp)``, ``>>> help(qemu.machine)``) +for more information. + +Contributing +------------ + +This package is maintained by John Snow <[email protected]> as part of +the QEMU source tree. Contributions are welcome and follow the `QEMU +patch submission process +<https://wiki.qemu.org/Contribute/SubmitAPatch>`_, which involves +sending patches to the QEMU development mailing list. + +John maintains a `GitLab staging branch +<https://gitlab.com/jsnow/qemu/-/tree/python>`_, and there is an +official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. + +Please report bugs on the `QEMU issue tracker +<https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in +the report.
python/setup.cfg new file +22 -0
@@ -0,0 +1,22 @@ +[metadata] +name = qemu +maintainer = QEMU Developer Team +maintainer_email = [email protected] +url = https://www.qemu.org/ +download_url = https://www.qemu.org/download/ +description = QEMU Python Build, Debug and SDK tooling. +long_description = file:PACKAGE.rst +long_description_content_type = text/x-rst +classifiers = + Development Status :: 3 - Alpha + License :: OSI Approved :: GNU General Public License v2 (GPLv2) + Natural Language :: English + Operating System :: OS Independent + Programming Language :: Python :: 3 :: Only + +[options] +python_requires = >= 3.6 +packages = + qemu.qmp + qemu.machine + qemu.utils
python/setup.py new file +23 -0
@@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +""" +QEMU tooling installer script +Copyright (c) 2020-2021 John Snow for Red Hat, Inc. +""" + +import setuptools +import pkg_resources + + +def main(): + """ + QEMU tooling installer + """ + + # https://medium.com/@daveshawley/safely-using-setup-cfg-for-metadata-1babbe54c108 + pkg_resources.require('setuptools>=39.2') + + setuptools.setup() + + +if __name__ == '__main__': + main()
Signature · 1 line
2.31.1
[PULL 43/44] python: add tox support
In reply to John SnowThis is intended to be a manually run, non-CI script.
Use tox to test the linters against all python versions from 3.6 to 3.10. This will only work if you actually have those versions installed locally, but Fedora makes this easy:
Quoted 1 line
sudo dnf install python3.6 python3.7 python3.8 python3.9 python3.10
Unlike the pipenv tests (make venv-check), this pulls "whichever" versions of the python packages, so they are unpinned and may break as time goes on. In the case that breakages are found, setup.cfg should be amended accordingly to avoid the bad dependant versions, or the code should be amended to work around the issue.
With confidence that the tests pass on 3.6 through 3.10 inclusive, add the appropriate classifiers to setup.cfg to indicate which versions we claim to support.
Tox 3.18.0 or above is required to use the 'allowlist_externals' option.
Message-id: [email protected]
--- python/.gitignore | 1 + python/Makefile | 7 ++++++- python/setup.cfg | 23 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-)
python/.gitignore +1 -0
@@ -13,3 +13,4 @@ qemu.egg-info/ # virtual environments (pipenv et al) .venv/ +.tox/
python/Makefile +6 -1
@@ -16,6 +16,8 @@ help: @echo "" @echo "make check: run linters using the current environment." @echo "" + @echo "make check-tox: run linters using multiple python versions." + @echo "" @echo "make clean: remove package build output." @echo "" @echo "make distclean: remove venv files, qemu package forwarder,"
@@ -36,8 +38,11 @@ develop: check: @avocado --config avocado.cfg run tests/ +check-tox: + @tox + clean: python3 setup.py clean --all distclean: clean - rm -rf qemu.egg-info/ .venv/ dist/ + rm -rf qemu.egg-info/ .venv/ .tox/ dist/
python/setup.cfg +22 -1
@@ -14,6 +14,11 @@ classifiers = Natural Language :: English Operating System :: OS Independent Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 [options] python_requires = >= 3.6
@@ -30,12 +35,13 @@ devel = isort >= 5.1.2 mypy >= 0.770 pylint >= 2.8.0 - + tox >= 3.18.0 [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__, .venv, + .tox, [mypy] strict = True
@@ -79,3 +85,18 @@ include_trailing_comma=True line_length=72 lines_after_imports=2 multi_line_output=3 + +# tox (https://tox.readthedocs.io/) is a tool for running tests in +# multiple virtualenvs. This configuration file will run the test suite +# on all supported python versions. To use it, "pip install tox" and +# then run "tox" from this directory. You will need all of these versions +# of python available on your system to run this test. + +[tox:tox] +envlist = py36, py37, py38, py39, py310 + +[testenv] +allowlist_externals = make +deps = .[devel] +commands = + make check
Signature · 1 line
2.31.1
[PULL 22/44] python: create qemu packages
In reply to John Snowmove python/qemu/*.py to python/qemu/[machine, qmp, utils]/*.py and update import directives across the tree.
This is done to create a PEP420 namespace package, in which we may create subpackages. To do this, the namespace directory ("qemu") should not have any modules in it. Those files will go into new 'machine', 'qmp' and 'utils' subpackages instead.
Implement machine/__init__.py making the top-level classes and functions from its various modules available directly inside the package. Change qmp.py to qmp/__init__.py similarly, such that all of the useful QMP library classes are available directly from "qemu.qmp" instead of "qemu.qmp.qmp".
Message-id: [email protected]
---
python/{qemu => }/.isort.cfg | 0
python/qemu/__init__.py | 11 -------
python/qemu/{ => machine}/.flake8 | 0
python/qemu/machine/__init__.py | 33 +++++++++++++++++++++
python/qemu/{ => machine}/console_socket.py | 0
python/qemu/{ => machine}/machine.py | 16 ++++++----
python/qemu/{ => machine}/pylintrc | 0
python/qemu/{ => machine}/qtest.py | 3 +-
python/qemu/{qmp.py => qmp/__init__.py} | 12 +++++++-
python/qemu/{utils.py => utils/__init__.py} | 18 +++++++++--
python/qemu/{ => utils}/accel.py | 0
tests/acceptance/avocado_qemu/__init__.py | 9 +++---
tests/acceptance/virtio-gpu.py | 2 +-
tests/qemu-iotests/300 | 4 +--
tests/qemu-iotests/iotests.py | 2 +-
tests/vm/aarch64vm.py | 2 +-
tests/vm/basevm.py | 3 +-
17 files changed, 83 insertions(+), 32 deletions(-)
rename python/{qemu => }/.isort.cfg (100%)
delete mode 100644 python/qemu/__init__.py
rename python/qemu/{ => machine}/.flake8 (100%)
create mode 100644 python/qemu/machine/__init__.py
rename python/qemu/{ => machine}/console_socket.py (100%)
rename python/qemu/{ => machine}/machine.py (98%)
rename python/qemu/{ => machine}/pylintrc (100%)
rename python/qemu/{ => machine}/qtest.py (99%)
rename python/qemu/{qmp.py => qmp/__init__.py} (96%)
rename python/qemu/{utils.py => utils/__init__.py} (66%)
rename python/qemu/{ => utils}/accel.py (100%)python/.isort.cfg renamed from python/qemu/.isort.cfg +0 -0
python/qemu/__init__.py deleted +0 -11
@@ -1,11 +0,0 @@ -# QEMU library -# -# Copyright (C) 2015-2016 Red Hat Inc. -# Copyright (C) 2012 IBM Corp. -# -# Authors: -# Fam Zheng <[email protected]> -# -# This work is licensed under the terms of the GNU GPL, version 2. See -# the COPYING file in the top-level directory. -#
python/qemu/machine/.flake8 renamed from python/qemu/.flake8 +0 -0
python/qemu/machine/__init__.py new file +33 -0
@@ -0,0 +1,33 @@ +""" +QEMU development and testing library. + +This library provides a few high-level classes for driving QEMU from a +test suite, not intended for production use. + +- QEMUMachine: Configure and Boot a QEMU VM + - QEMUQtestMachine: VM class, with a qtest socket. + +- QEMUQtestProtocol: Connect to, send/receive qtest messages. +""" + +# Copyright (C) 2020-2021 John Snow for Red Hat Inc. +# Copyright (C) 2015-2016 Red Hat Inc. +# Copyright (C) 2012 IBM Corp. +# +# Authors: +# John Snow <[email protected]> +# Fam Zheng <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +from .machine import QEMUMachine +from .qtest import QEMUQtestMachine, QEMUQtestProtocol + + +__all__ = ( + 'QEMUMachine', + 'QEMUQtestProtocol', + 'QEMUQtestMachine', +)
python/qemu/machine/console_socket.py renamed from python/qemu/console_socket.py +0 -0
python/qemu/machine/machine.py renamed from python/qemu/machine.py +11 -5
@@ -38,8 +38,14 @@ Type, ) -from . import console_socket, qmp -from .qmp import QMPMessage, QMPReturnValue, SocketAddrT +from qemu.qmp import ( + QEMUMonitorProtocol, + QMPMessage, + QMPReturnValue, + SocketAddrT, +) + +from . import console_socket LOG = logging.getLogger(__name__)
@@ -139,7 +145,7 @@ def __init__(self, self._events: List[QMPMessage] = [] self._iolog: Optional[str] = None self._qmp_set = True # Enable QMP monitor by default. - self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] = None + self._qmp_connection: Optional[QEMUMonitorProtocol] = None self._qemu_full_args: Tuple[str, ...] = () self._temp_dir: Optional[str] = None self._launched = False
@@ -314,7 +320,7 @@ def _pre_launch(self) -> None: if self._remove_monitor_sockfile: assert isinstance(self._monitor_address, str) self._remove_files.append(self._monitor_address) - self._qmp_connection = qmp.QEMUMonitorProtocol( + self._qmp_connection = QEMUMonitorProtocol( self._monitor_address, server=True, nickname=self._name
@@ -541,7 +547,7 @@ def set_qmp_monitor(self, enabled: bool = True) -> None: self._qmp_set = enabled @property - def _qmp(self) -> qmp.QEMUMonitorProtocol: + def _qmp(self) -> QEMUMonitorProtocol: if self._qmp_connection is None: raise QEMUMachineError("Attempt to access QMP with no connection") return self._qmp_connection
python/qemu/machine/pylintrc renamed from python/qemu/pylintrc +0 -0
python/qemu/machine/qtest.py renamed from python/qemu/qtest.py +2 -1
@@ -26,8 +26,9 @@ TextIO, ) +from qemu.qmp import SocketAddrT + from .machine import QEMUMachine -from .qmp import SocketAddrT class QEMUQtestProtocol:
python/qemu/qmp/__init__.py renamed from python/qemu/qmp.py +11 -1
@@ -1,4 +1,14 @@ -""" QEMU Monitor Protocol Python class """ +""" +QEMU Monitor Protocol (QMP) development library & tooling. + +This package provides a fairly low-level class for communicating to QMP +protocol servers, as implemented by QEMU, the QEMU Guest Agent, and the +QEMU Storage Daemon. This library is not intended for production use. + +`QEMUMonitorProtocol` is the primary class of interest, and all errors +raised derive from `QMPError`. +""" + # Copyright (C) 2009, 2010 Red Hat Inc. # # Authors:
python/qemu/utils/__init__.py renamed from python/qemu/utils.py +15 -3
@@ -1,13 +1,14 @@ """ -QEMU utility library +QEMU development and testing utilities -This offers miscellaneous utility functions, which may not be easily -distinguishable or numerous to be in their own module. +This package provides a small handful of utilities for performing +various tasks not directly related to the launching of a VM. """ # Copyright (C) 2021 Red Hat Inc. # # Authors: +# John Snow <[email protected]> # Cleber Rosa <[email protected]> # # This work is licensed under the terms of the GNU GPL, version 2. See
@@ -17,6 +18,17 @@ import re from typing import Optional +# pylint: disable=import-error +from .accel import kvm_available, list_accel, tcg_available + + +__all__ = ( + 'get_info_usernet_hostfwd_port', + 'kvm_available', + 'list_accel', + 'tcg_available', +) + def get_info_usernet_hostfwd_port(info_usernet_output: str) -> Optional[int]: """
python/qemu/utils/accel.py renamed from python/qemu/accel.py +0 -0
tests/acceptance/avocado_qemu/__init__.py +5 -4
@@ -41,11 +41,12 @@ sys.path.append(os.path.join(SOURCE_DIR, 'python')) -from qemu.accel import kvm_available -from qemu.accel import tcg_available from qemu.machine import QEMUMachine -from qemu.utils import get_info_usernet_hostfwd_port - +from qemu.utils import ( + get_info_usernet_hostfwd_port, + kvm_available, + tcg_available, +) def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK)
tests/acceptance/virtio-gpu.py +1 -1
@@ -10,7 +10,7 @@ from avocado_qemu import exec_command_and_wait_for_pattern from avocado_qemu import is_readable_executable_file -from qemu.accel import kvm_available +from qemu.utils import kvm_available import os import socket
tests/qemu-iotests/300 +2 -2
@@ -28,7 +28,7 @@ import iotests # Import qemu after iotests.py has amended sys.path # pylint: disable=wrong-import-order -import qemu +from qemu.machine import machine BlockBitmapMapping = List[Dict[str, object]]
@@ -466,7 +466,7 @@ class TestBlockBitmapMappingErrors(TestDirtyBitmapMigration): # the failed migration try: self.vm_b.shutdown() - except qemu.machine.AbnormalShutdown: + except machine.AbnormalShutdown: pass def test_aliased_bitmap_name_too_long(self) -> None:
tests/qemu-iotests/iotests.py +1 -1
@@ -38,7 +38,7 @@ # pylint: disable=import-error, wrong-import-position sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) -from qemu import qtest +from qemu.machine import qtest from qemu.qmp import QMPMessage # Use this logger for logging messages directly from the iotests module
tests/vm/aarch64vm.py +1 -1
@@ -14,7 +14,7 @@ import sys import subprocess import basevm -from qemu.accel import kvm_available +from qemu.utils import kvm_available # This is the config needed for current version of QEMU. # This works for both kvm and tcg.
tests/vm/basevm.py +1 -2
@@ -19,9 +19,8 @@ import time import datetime sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) -from qemu.accel import kvm_available from qemu.machine import QEMUMachine -from qemu.utils import get_info_usernet_hostfwd_port +from qemu.utils import get_info_usernet_hostfwd_port, kvm_available import subprocess import hashlib import argparse
Signature · 1 line
2.31.1
[PULL 26/44] python: add MANIFEST.in
In reply to John SnowWhen creating a source or binary distribution via 'python3 setup.py <sdist|bdist>', the VERSION and PACKAGE.rst files aren't bundled by default. Create a MANIFEST.in file that instructs the build tools to include these so that installation from these files won't fail.
This is required by 'tox', as well as by the tooling needed to upload packages to PyPI.
Exclude the 'README.rst' file -- that's intended as a guidebook to our source tree, not a file that needs to be distributed.
Message-id: [email protected]
--- python/README.rst | 2 ++ python/MANIFEST.in | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 python/MANIFEST.in
python/README.rst +2 -0
@@ -33,6 +33,8 @@ Files in this directory ----------------------- - ``qemu/`` Python package source directory. +- ``MANIFEST.in`` is read by python setuptools, it specifies additional files + that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. - ``README.rst`` you are here! - ``VERSION`` contains the PEP-440 compliant version used to describe
python/MANIFEST.in new file +3 -0
@@ -0,0 +1,3 @@ +include VERSION +include PACKAGE.rst +exclude README.rst
Signature · 1 line
2.31.1
[PULL 29/44] python: move pylintrc into setup.cfg
In reply to John SnowDelete the empty settings now that it's sharing a home with settings for other tools.
pylint can now be run from this folder as "pylint qemu".
Message-id: [email protected]
--- python/qemu/machine/pylintrc | 58 ------------------------------------ python/setup.cfg | 29 ++++++++++++++++++ 2 files changed, 29 insertions(+), 58 deletions(-) delete mode 100644 python/qemu/machine/pylintrc
python/qemu/machine/pylintrc deleted +0 -58
@@ -1,58 +0,0 @@ -[MASTER] - -[MESSAGES CONTROL] - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once). You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use "--disable=all --enable=classes -# --disable=W". -disable=too-many-arguments, - too-many-instance-attributes, - too-many-public-methods, - -[REPORTS] - -[REFACTORING] - -[MISCELLANEOUS] - -[LOGGING] - -[BASIC] - -# Good variable names which should always be accepted, separated by a comma. -good-names=i, - j, - k, - ex, - Run, - _, - fd, - c, -[VARIABLES] - -[STRING] - -[SPELLING] - -[FORMAT] - -[SIMILARITIES] - -# Ignore imports when computing similarities. -ignore-imports=yes - -[TYPECHECK] - -[CLASSES] - -[IMPORTS] - -[DESIGN] - -[EXCEPTIONS]
python/setup.cfg +29 -0
@@ -21,3 +21,32 @@ packages = qemu.qmp qemu.machine qemu.utils + +[pylint.messages control] +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=too-many-arguments, + too-many-instance-attributes, + too-many-public-methods, + +[pylint.basic] +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _, + fd, + c, + +[pylint.similarities] +# Ignore imports when computing similarities. +ignore-imports=yes
Signature · 1 line
2.31.1
[PULL 24/44] python: add VERSION file
In reply to John SnowPython infrastructure as it exists today is not capable reliably of single-sourcing a package version from a parent directory. The authors of pip are working to correct this, but as of today this is not possible.
The problem is that when using pip to build and install a python package, it copies files over to a temporary directory and performs its build there. This loses access to any information in the parent directory, including git itself.
Further, Python versions have a standard (PEP 440) that may or may not follow QEMU's versioning. In general, it does; but naturally QEMU does not follow PEP 440. To avoid any automatically-generated conflict, a manual version file is preferred.
I am proposing:
- Python tooling follows the QEMU version, indirectly, but with a major version of 0 to indicate that the API is not expected to be stable. This would mean version 0.5.2.0, 0.5.1.1, 0.5.3.0, etc.
- In the event that a Python package needs to be updated independently of the QEMU version, a pre-release alpha version should be preferred, but *only* after inclusion to the qemu development or stable branches.
e.g. 0.5.2.0a1, 0.5.2.0a2, and so on should be preferred prior to 5.2.0's release.
- The Python core tooling makes absolutely no version compatibility checks or constraints. It *may* work with releases of QEMU from the past or future, but it is not required to.
i.e., "qemu.machine" will, for now, remain in lock-step with QEMU.
- We reserve the right to split the qemu package into independently versioned subpackages at a later date. This might allow for us to begin versioning QMP independently from QEMU at a later date, if we so choose.
Implement this versioning scheme by adding a VERSION file and setting it to 0.6.0.0a1.
Message-id: [email protected]
--- python/VERSION | 1 + python/setup.cfg | 1 + 2 files changed, 2 insertions(+) create mode 100644 python/VERSION
python/VERSION new file +1 -0
@@ -0,0 +1 @@ +0.6.1.0a1
python/setup.cfg +1 -0
@@ -1,5 +1,6 @@ [metadata] name = qemu +version = file:VERSION maintainer = QEMU Developer Team maintainer_email = [email protected] url = https://www.qemu.org/
Signature · 1 line
2.31.1
[PULL 25/44] python: add directory structure README.rst files
In reply to John SnowAdd short readmes to python/, python/qemu/, python/qemu/machine, python/qemu/qmp, and python/qemu/utils that explain the directory hierarchy. These readmes are visible when browsing the source on e.g. gitlab/github and are designed to help new developers/users quickly make sense of the source tree.
They are not designed for inclusion in a published manual.
Message-id: [email protected]
--- python/README.rst | 41 ++++++++++++++++++++++++++++++++++ python/qemu/README.rst | 8 +++++++ python/qemu/machine/README.rst | 9 ++++++++ python/qemu/qmp/README.rst | 9 ++++++++ python/qemu/utils/README.rst | 7 ++++++ 5 files changed, 74 insertions(+) create mode 100644 python/README.rst create mode 100644 python/qemu/README.rst create mode 100644 python/qemu/machine/README.rst create mode 100644 python/qemu/qmp/README.rst create mode 100644 python/qemu/utils/README.rst
python/README.rst new file +41 -0
@@ -0,0 +1,41 @@ +QEMU Python Tooling +=================== + +This directory houses Python tooling used by the QEMU project to build, +configure, and test QEMU. It is organized by namespace (``qemu``), and +then by package (e.g. ``qemu/machine``, ``qemu/qmp``, etc). + +``setup.py`` is used by ``pip`` to install this tooling to the current +environment. ``setup.cfg`` provides the packaging configuration used by +``setup.py`` in a setuptools specific format. You will generally invoke +it by doing one of the following: + +1. ``pip3 install .`` will install these packages to your current + environment. If you are inside a virtual environment, they will + install there. If you are not, it will attempt to install to the + global environment, which is **not recommended**. + +2. ``pip3 install --user .`` will install these packages to your user's + local python packages. If you are inside of a virtual environment, + this will fail; you likely want the first invocation above. + +If you append the ``-e`` argument, pip will install in "editable" mode; +which installs a version of the package that installs a forwarder +pointing to these files, such that the package always reflects the +latest version in your git tree. + +See `Installing packages using pip and virtual environments +<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_ +for more information. + + +Files in this directory +----------------------- + +- ``qemu/`` Python package source directory. +- ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. +- ``README.rst`` you are here! +- ``VERSION`` contains the PEP-440 compliant version used to describe + this package; it is referenced by ``setup.cfg``. +- ``setup.cfg`` houses setuptools package configuration. +- ``setup.py`` is the setuptools installer used by pip; See above.
python/qemu/README.rst new file +8 -0
@@ -0,0 +1,8 @@ +QEMU Python Namespace +===================== + +This directory serves as the root of a `Python PEP 420 implicit +namespace package <https://www.python.org/dev/peps/pep-0420/>`_. + +Each directory below is assumed to be an installable Python package that +is available under the ``qemu.<package>`` namespace.
python/qemu/machine/README.rst new file +9 -0
@@ -0,0 +1,9 @@ +qemu.machine package +==================== + +This package provides core utilities used for testing and debugging +QEMU. It is used by the iotests, vm tests, acceptance tests, and several +other utilities in the ./scripts directory. It is not a fully-fledged +SDK and it is subject to change at any time. + +See the documentation in ``__init__.py`` for more information.
python/qemu/qmp/README.rst new file +9 -0
@@ -0,0 +1,9 @@ +qemu.qmp package +================ + +This package provides a library used for connecting to and communicating +with QMP servers. It is used extensively by iotests, vm tests, +acceptance tests, and other utilities in the ./scripts directory. It is +not a fully-fledged SDK and is subject to change at any time. + +See the documentation in ``__init__.py`` for more information.
python/qemu/utils/README.rst new file +7 -0
@@ -0,0 +1,7 @@ +qemu.utils package +================== + +This package provides miscellaneous utilities used for testing and +debugging QEMU. It is used primarily by the vm and acceptance tests. + +See the documentation in ``__init__.py`` for more information.
Signature · 1 line
2.31.1
[PULL 31/44] python: move flake8 config to setup.cfg
In reply to John SnowUpdate the comment concerning the flake8 exception to match commit 42c0dd12, whose commit message stated:
A note on the flake8 exception: flake8 will warn on *any* bare except, but pylint's is context-aware and will suppress the warning if you re-raise the exception.
Message-id: [email protected]
--- python/qemu/machine/.flake8 | 2 -- python/setup.cfg | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 python/qemu/machine/.flake8
python/qemu/machine/.flake8 deleted +0 -2
@@ -1,2 +0,0 @@ -[flake8] -extend-ignore = E722 # Pylint handles this, but smarter.
python/setup.cfg +3 -0
@@ -22,6 +22,9 @@ packages = qemu.machine qemu.utils +[flake8] +extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's + [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You # can either give multiple identifiers separated by comma (,) or put this
Signature · 1 line
2.31.1
[PULL 30/44] python: add pylint to pipenv
In reply to John SnowWe are specifying >= pylint 2.8.x for several reasons:
1. For setup.cfg support, added in pylint 2.5.x
2. To specify a version that has incompatibly dropped bad-whitespace checks (2.6.x)
3. 2.7.x fixes "unsubscriptable" warnings in Python 3.9
4. 2.8.x adds a new, incompatible 'consider-using-with' warning that must be disabled in some cases. These pragmas cause warnings themselves in 2.7.x.
Message-id: [email protected]
--- python/Pipfile | 1 + python/Pipfile.lock | 130 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 python/Pipfile.lock
python/Pipfile +1 -0
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] +pylint = ">=2.8.0" [packages]
python/Pipfile.lock new file +130 -0
130 lines not on this page · raw message
Signature · 1 line
2.31.1
[PULL 27/44] python: Add pipenv support
In reply to John Snowpipenv is a tool used for managing virtual environments with pinned, explicit dependencies. It is used for precisely recreating python virtual environments.
pipenv uses two files to do this:
(1) Pipfile, which is similar in purpose and scope to what setup.cfg lists. It specifies the requisite minimum to get a functional environment for using this package.
(2) Pipfile.lock, which is similar in purpose to pip freeze > requirements.txt. It specifies a canonical virtual environment used for deployment or testing. This ensures that all users have repeatable results.
The primary benefit of using this tool is to ensure *rock solid* repeatable CI results with a known set of packages. Although I endeavor to support as many versions as I can, the fluid nature of the Python toolchain often means tailoring code for fairly specific versions.
Note that pipenv is *not* required to install or use this module; this is purely for the sake of repeatable testing by CI or developers.
Here, a "blank" pipfile is added with no dependencies, but specifies Python 3.6 for the virtual environment.
Pipfile will specify our version minimums, while Pipfile.lock specifies an exact loadout of packages that were known to operate correctly. This latter file provides the real value for easy setup of container images and CI environments.
Message-id: [email protected]
--- python/README.rst | 3 +++ python/Pipfile | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 python/Pipfile
python/README.rst +3 -0
@@ -36,6 +36,9 @@ Files in this directory - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org. +- ``Pipfile`` is used by Pipenv to generate ``Pipfile.lock``. +- ``Pipfile.lock`` is a set of pinned package dependencies that this package + is tested under in our CI suite. It is used by ``make venv-check``. - ``README.rst`` you are here! - ``VERSION`` contains the PEP-440 compliant version used to describe this package; it is referenced by ``setup.cfg``.
python/Pipfile new file +11 -0
@@ -0,0 +1,11 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] + +[requires] +python_version = "3.6"
Signature · 1 line
2.31.1
[PULL 34/44] python: move mypy.ini into setup.cfg
In reply to John Snowmypy supports reading its configuration values from a central project configuration file; do so.
Message-id: [email protected]
--- python/mypy.ini | 4 ---- python/setup.cfg | 5 +++++ 2 files changed, 5 insertions(+), 4 deletions(-) delete mode 100644 python/mypy.ini
python/mypy.ini deleted +0 -4
@@ -1,4 +0,0 @@ -[mypy] -strict = True -python_version = 3.6 -warn_unused_configs = True
python/setup.cfg +5 -0
@@ -27,6 +27,11 @@ extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__, .venv, +[mypy] +strict = True +python_version = 3.6 +warn_unused_configs = True + [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You # can either give multiple identifiers separated by comma (,) or put this
Signature · 1 line
2.31.1
[PULL 35/44] python: add mypy to pipenv
In reply to John Snow0.730 appears to be about the oldest version that works with the features we want, including nice human readable output (to make sure iotest 297 passes), and type-parameterized Popen generics.
0.770, however, supports adding 'strict' to the config file, so require at least 0.770.
Now that we are checking a namespace package, we need to tell mypy to allow PEP420 namespaces, so modify the mypy config as part of the move.
mypy can now be run from the python root by typing 'mypy -p qemu'.
A note on mypy invocation: Running it as "mypy qemu/" changes the import path detection mechanisms in mypy slightly, and it will fail. See
https://github.com/python/mypy/issues/8584 for a decent entry point with more breadcrumbs on the various behaviors that contribute to this subtle difference.
Message-id: [email protected]
--- python/Pipfile | 1 + python/Pipfile.lock | 37 ++++++++++++++++++++++++++++++++++++- python/setup.cfg | 1 + 3 files changed, 38 insertions(+), 1 deletion(-)
python/Pipfile +1 -0
@@ -5,6 +5,7 @@ verify_ssl = true [dev-packages] flake8 = ">=3.6.0" +mypy = ">=0.770" pylint = ">=2.8.0" [packages]
python/Pipfile.lock +36 -1
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "3c842ab9c72c40d24d146349aa144e00e4dec1c358c812cfa96489411f5b3f87" + "sha256": "14d171b3d86759e1fdfb9e55f66be4a696b6afa8f627d6c4778f8398c6a66b98" }, "pipfile-spec": 6, "requires": {
@@ -84,6 +84,41 @@ ], "version": "==0.6.1" }, + "mypy": { + "hashes": [ + "sha256:0d0a87c0e7e3a9becdfbe936c981d32e5ee0ccda3e0f07e1ef2c3d1a817cf73e", + "sha256:25adde9b862f8f9aac9d2d11971f226bd4c8fbaa89fb76bdadb267ef22d10064", + "sha256:28fb5479c494b1bab244620685e2eb3c3f988d71fd5d64cc753195e8ed53df7c", + "sha256:2f9b3407c58347a452fc0736861593e105139b905cca7d097e413453a1d650b4", + "sha256:33f159443db0829d16f0a8d83d94df3109bb6dd801975fe86bacb9bf71628e97", + "sha256:3f2aca7f68580dc2508289c729bd49ee929a436208d2b2b6aab15745a70a57df", + "sha256:499c798053cdebcaa916eef8cd733e5584b5909f789de856b482cd7d069bdad8", + "sha256:4eec37370483331d13514c3f55f446fc5248d6373e7029a29ecb7b7494851e7a", + "sha256:552a815579aa1e995f39fd05dde6cd378e191b063f031f2acfe73ce9fb7f9e56", + "sha256:5873888fff1c7cf5b71efbe80e0e73153fe9212fafdf8e44adfe4c20ec9f82d7", + "sha256:61a3d5b97955422964be6b3baf05ff2ce7f26f52c85dd88db11d5e03e146a3a6", + "sha256:674e822aa665b9fd75130c6c5f5ed9564a38c6cea6a6432ce47eafb68ee578c5", + "sha256:7ce3175801d0ae5fdfa79b4f0cfed08807af4d075b402b7e294e6aa72af9aa2a", + "sha256:9743c91088d396c1a5a3c9978354b61b0382b4e3c440ce83cf77994a43e8c521", + "sha256:9f94aac67a2045ec719ffe6111df543bac7874cee01f41928f6969756e030564", + "sha256:a26f8ec704e5a7423c8824d425086705e381b4f1dfdef6e3a1edab7ba174ec49", + "sha256:abf7e0c3cf117c44d9285cc6128856106183938c68fd4944763003decdcfeb66", + "sha256:b09669bcda124e83708f34a94606e01b614fa71931d356c1f1a5297ba11f110a", + "sha256:cd07039aa5df222037005b08fbbfd69b3ab0b0bd7a07d7906de75ae52c4e3119", + "sha256:d23e0ea196702d918b60c8288561e722bf437d82cb7ef2edcd98cfa38905d506", + "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c", + "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb" + ], + "index": "pypi", + "version": "==0.812" + }, + "mypy-extensions": { + "hashes": [ + "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", + "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" + ], + "version": "==0.4.3" + }, "pycodestyle": { "hashes": [ "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068",
python/setup.cfg +1 -0
@@ -31,6 +31,7 @@ exclude = __pycache__, strict = True python_version = 3.6 warn_unused_configs = True +namespace_packages = True [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You
Signature · 1 line
2.31.1
[PULL 37/44] python/qemu: add isort to pipenv
In reply to John Snowisort 5.0.0 through 5.0.4 has a bug that causes it to misinterpret certain "from ..." clauses that are not related to imports.
isort < 5.1.1 has a bug where it does not handle comments near import statements correctly.
Require 5.1.2 or greater.
isort can be run (in "check" mode) with 'isort -c qemu' from the python root. isort can also be used to fix/rewrite import order automatically by using 'isort qemu'.
Message-id: [email protected]
--- python/Pipfile | 1 + python/Pipfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
python/Pipfile +1 -0
@@ -5,6 +5,7 @@ verify_ssl = true [dev-packages] flake8 = ">=3.6.0" +isort = ">=5.1.2" mypy = ">=0.770" pylint = ">=2.8.0"
python/Pipfile.lock +2 -2
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "14d171b3d86759e1fdfb9e55f66be4a696b6afa8f627d6c4778f8398c6a66b98" + "sha256": "8173290ad57aab0b722c9b4f109519de4e0dd7cd1bad1e16806b78bb169bce08" }, "pipfile-spec": 6, "requires": {
@@ -46,7 +46,7 @@ "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" ], - "markers": "python_version >= '3.6' and python_version < '4.0'", + "index": "pypi", "version": "==5.8.0" }, "lazy-object-proxy": {
Signature · 1 line
2.31.1
[PULL 40/44] python: add avocado-framework and tests
In reply to John SnowTry using avocado to manage our various tests; even though right now they're only invoking shell scripts and not really running any python-native code.
Create tests/, and add shell scripts which call out to mypy, flake8, pylint and isort to enforce the standards in this directory.
Add avocado-framework to the setup.cfg development dependencies, and add avocado.cfg to store some preferences for how we'd like the test output to look.
Finally, add avocado-framework to the Pipfile environment and lock the new dependencies. We are using avocado >= 87.0 here to take advantage of some features that Cleber has helpfully added to make the test output here *very* friendly and easy to read for developers that might chance upon the output in Gitlab CI.
[Note: ALL of the dependencies get updated to the most modern versions that exist at the time of this writing. No way around it that I have seen. Not ideal, but so it goes.]
Provided you have the right development dependencies (mypy, flake8, isort, pylint, and now avocado-framework) You should be able to run "avocado --config avocado.cfg run tests/" from the python folder to run all of these linters with the correct arguments.
(A forthcoming commit adds the much easier 'make check'.)
Message-id: [email protected]
--- python/README.rst | 2 ++ python/Pipfile.lock | 8 ++++++++ python/avocado.cfg | 10 ++++++++++ python/setup.cfg | 1 + python/tests/flake8.sh | 2 ++ python/tests/isort.sh | 2 ++ python/tests/mypy.sh | 2 ++ python/tests/pylint.sh | 2 ++ 8 files changed, 29 insertions(+) create mode 100644 python/avocado.cfg create mode 100755 python/tests/flake8.sh create mode 100755 python/tests/isort.sh create mode 100755 python/tests/mypy.sh create mode 100755 python/tests/pylint.sh
python/README.rst +2 -0
@@ -37,6 +37,8 @@ Files in this directory ----------------------- - ``qemu/`` Python package source directory. +- ``tests/`` Python package tests directory. +- ``avocado.cfg`` Configuration for the Avocado test-runner. - ``MANIFEST.in`` is read by python setuptools, it specifies additional files that should be included by a source distribution. - ``PACKAGE.rst`` is used as the README file that is visible on PyPI.org.
python/Pipfile.lock +8 -0
@@ -30,6 +30,14 @@ "markers": "python_version ~= '3.6'", "version": "==2.5.6" }, + "avocado-framework": { + "hashes": [ + "sha256:42aa7962df98d6b78d4efd9afa2177226dc630f3d83a2a7d5baf7a0a7da7fa1b", + "sha256:d96ae343abf890e1ef3b3a6af5ce49e35f6bded0715770c4acb325bca555c515" + ], + "markers": "python_version >= '3.6'", + "version": "==88.1" + }, "flake8": { "hashes": [ "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b",
python/avocado.cfg new file +10 -0
@@ -0,0 +1,10 @@ +[simpletests] +# Don't show stdout/stderr in the test *summary* +status.failure_fields = ['status'] + +[job] +# Don't show the full debug.log output; only select stdout/stderr. +output.testlogs.logfiles = ['stdout', 'stderr'] + +# Show full stdout/stderr only on tests that FAIL +output.testlogs.statuses = ['FAIL']
python/setup.cfg +1 -0
@@ -25,6 +25,7 @@ packages = [options.extras_require] # Run `pipenv lock --dev` when changing these requirements. devel = + avocado-framework >= 87.0 flake8 >= 3.6.0 isort >= 5.1.2 mypy >= 0.770
python/tests/flake8.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m flake8
python/tests/isort.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m isort -c qemu/
python/tests/mypy.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m mypy -p qemu
python/tests/pylint.sh new file +2 -0
@@ -0,0 +1,2 @@ +#!/bin/sh -e +python3 -m pylint qemu/
Signature · 1 line
2.31.1
[PULL 36/44] python: move .isort.cfg into setup.cfg
In reply to John SnowMessage-id: [email protected]
--- python/.isort.cfg | 7 ------- python/setup.cfg | 8 ++++++++ 2 files changed, 8 insertions(+), 7 deletions(-) delete mode 100644 python/.isort.cfg
python/.isort.cfg deleted +0 -7
@@ -1,7 +0,0 @@ -[settings] -force_grid_wrap=4 -force_sort_within_sections=True -include_trailing_comma=True -line_length=72 -lines_after_imports=2 -multi_line_output=3
python/setup.cfg +8 -0
@@ -61,3 +61,11 @@ good-names=i, [pylint.similarities] # Ignore imports when computing similarities. ignore-imports=yes + +[isort] +force_grid_wrap=4 +force_sort_within_sections=True +include_trailing_comma=True +line_length=72 +lines_after_imports=2 +multi_line_output=3
Signature · 1 line
2.31.1
[PULL 38/44] python/qemu: add qemu package itself to pipenv
In reply to John SnowThis adds the python qemu packages themselves to the pipenv manifest. 'pipenv sync' will create a virtual environment sufficient to use the SDK. 'pipenv sync --dev' will create a virtual environment sufficient to use and test the SDK (with pylint, mypy, isort, flake8, etc.)
The qemu packages are installed in 'editable' mode; all changes made to the python package inside the git tree will be reflected in the installed package without reinstallation. This includes changes made via git pull and so on.
Message-id: [email protected]
--- python/Pipfile | 1 + python/Pipfile.lock | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
python/Pipfile +1 -0
@@ -10,6 +10,7 @@ mypy = ">=0.770" pylint = ">=2.8.0" [packages] +qemu = {editable = true,path = "."} [requires] python_version = "3.6"
python/Pipfile.lock +7 -2
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8173290ad57aab0b722c9b4f109519de4e0dd7cd1bad1e16806b78bb169bce08" + "sha256": "7c74cc4c2db3a75c954a6686411cda6fd60e464620bb6d5f1ed9a54be61db4cc" }, "pipfile-spec": 6, "requires": {
@@ -15,7 +15,12 @@ } ] }, - "default": {}, + "default": { + "qemu": { + "editable": true, + "path": "." + } + }, "develop": { "astroid": { "hashes": [
Signature · 1 line
2.31.1
[PULL 42/44] python: add .gitignore
In reply to John SnowIgnore *Python* build and package output (build, dist, qemu.egg-info); these files are not created as part of a QEMU build. They are created by running the commands 'python3 setup.py <sdist|bdist>' when preparing tarballs to upload to e.g. PyPI.
Ignore miscellaneous cached python confetti (mypy, pylint, et al)
Ignore .idea (pycharm) .vscode, and .venv (pipenv et al).
Message-id: [email protected]
--- python/.gitignore | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 python/.gitignore
python/.gitignore new file +15 -0
@@ -0,0 +1,15 @@ +# linter/tooling cache +.mypy_cache/ +.cache/ + +# python packaging +build/ +dist/ +qemu.egg-info/ + +# editor config +.idea/ +.vscode/ + +# virtual environments (pipenv et al) +.venv/
Signature · 1 line
2.31.1
[PULL 44/44] gitlab: add python linters to CI
In reply to John SnowAdd a Python container that has just enough juice for us to run the Python code quality analysis tools. Base this container on Fedora, because Fedora has very convenient packaging for testing multiple Python versions.
We need python3, pip (for pulling packages), pipenv and virtualenv for creating virtual environments, and tox for running tests. make is needed for running 'make check-tox' and 'make venv-check' targets. Python3.10 is needed explicitly because the tox package only pulls in 3.6-3.9, but we wish to test the forthcoming release of Python as well to help predict any problems. Lastly, we need gcc to compile PyPI packages that may not have a binary distribution available.
Add two tests:
check-python-pipenv uses pipenv to test a frozen, very explicit set of packages against our minimum supported python version, Python 3.6. This test is not allowed to fail. The dependencies this test uses do not change unless python/Pipfile.lock is changed.
check-python-tox uses tox to install the latest versions of required python dependencies against a wide array of Python versions from 3.6 to 3.9, even including the yet-to-be-released Python 3.10. This test is allowed to fail with a warning.
Message-id: [email protected]
--- .gitlab-ci.d/containers.yml | 5 +++++ .gitlab-ci.d/static_checks.yml | 21 +++++++++++++++++++++ tests/docker/dockerfiles/python.docker | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 tests/docker/dockerfiles/python.docker
.gitlab-ci.d/containers.yml +5 -0
@@ -43,3 +43,8 @@ amd64-opensuse-leap-container: extends: .container_job_template variables: NAME: opensuse-leap + +python-container: + extends: .container_job_template + variables: + NAME: python
.gitlab-ci.d/static_checks.yml +21 -0
@@ -24,3 +24,24 @@ check-dco: - if: '$CI_PROJECT_NAMESPACE == "qemu-project" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' when: never - when: on_success + +check-python-pipenv: + stage: test + image: $CI_REGISTRY_IMAGE/qemu/python:latest + script: + - make -C python venv-check + variables: + GIT_DEPTH: 1 + needs: + job: python-container + +check-python-tox: + stage: test + image: $CI_REGISTRY_IMAGE/qemu/python:latest + script: + - make -C python check-tox + variables: + GIT_DEPTH: 1 + needs: + job: python-container + allow_failure: true
tests/docker/dockerfiles/python.docker new file +18 -0
@@ -0,0 +1,18 @@ +# Python library testing environment + +FROM fedora:latest +MAINTAINER John Snow <[email protected]> + +# Please keep this list sorted alphabetically +ENV PACKAGES \ + gcc \ + make \ + pipenv \ + python3 \ + python3-pip \ + python3-tox \ + python3-virtualenv \ + python3.10 + +RUN dnf install -y $PACKAGES +RUN rpm -q $PACKAGES | sort > /packages.txt
Signature · 1 line
2.31.1
[PULL 39/44] python: add devel package requirements to setuptools
In reply to John Snowsetuptools doesn't have a formal understanding of development requires, but it has an optional feataures section. Fine; add a "devel" feature and add the requirements to it.
To avoid duplication, we can modify pipenv to install qemu[devel] instead. This enables us to run invocations like "pip install -e .[devel]" and test the package on bleeding-edge packages beyond those specified in Pipfile.lock.
Importantly, this also allows us to install the qemu development packages in a non-networked mode: pip3 install --no-index -e .[devel] will now fail if the proper development dependencies are not already met. This can be useful for automated build scripts where fetching network packages may be undesirable.
Message-id: [email protected]
--- python/PACKAGE.rst | 4 ++++ python/README.rst | 4 ++++ python/Pipfile | 5 +---- python/Pipfile.lock | 14 +++++++++----- python/setup.cfg | 9 +++++++++ 5 files changed, 27 insertions(+), 9 deletions(-)
python/PACKAGE.rst +4 -0
@@ -31,3 +31,7 @@ official `GitLab mirror <https://gitlab.com/qemu-project/qemu>`_. Please report bugs on the `QEMU issue tracker <https://gitlab.com/qemu-project/qemu/-/issues>`_ and tag ``@jsnow`` in the report. + +Optional packages necessary for running code quality analysis for this +package can be installed with the optional dependency group "devel": +``pip install qemu[devel]``.
python/README.rst +4 -0
@@ -24,6 +24,10 @@ which installs a version of the package that installs a forwarder pointing to these files, such that the package always reflects the latest version in your git tree. +Installing ".[devel]" instead of "." will additionally pull in required +packages for testing this package. They are not runtime requirements, +and are not needed to simply use these libraries. + See `Installing packages using pip and virtual environments <https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>`_ for more information.
python/Pipfile +1 -4
@@ -4,10 +4,7 @@ url = "https://pypi.org/simple" verify_ssl = true [dev-packages] -flake8 = ">=3.6.0" -isort = ">=5.1.2" -mypy = ">=0.770" -pylint = ">=2.8.0" +qemu = {editable = true, extras = ["devel"], path = "."} [packages] qemu = {editable = true,path = "."}
python/Pipfile.lock +9 -5
@@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7c74cc4c2db3a75c954a6686411cda6fd60e464620bb6d5f1ed9a54be61db4cc" + "sha256": "eff562a688ebc6f3ffe67494dbb804b883e2159ad81c4d55d96da9f7aec13e91" }, "pipfile-spec": 6, "requires": {
@@ -35,7 +35,7 @@ "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b", "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907" ], - "index": "pypi", + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==3.9.2" }, "importlib-metadata": {
@@ -51,7 +51,7 @@ "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" ], - "index": "pypi", + "markers": "python_version >= '3.6' and python_version < '4.0'", "version": "==5.8.0" }, "lazy-object-proxy": {
@@ -114,7 +114,7 @@ "sha256:d65cc1df038ef55a99e617431f0553cd77763869eebdf9042403e16089fe746c", "sha256:d7da2e1d5f558c37d6e8c1246f1aec1e7349e4913d8fb3cb289a35de573fe2eb" ], - "index": "pypi", + "markers": "python_version >= '3.5'", "version": "==0.812" }, "mypy-extensions": {
@@ -145,9 +145,13 @@ "sha256:586d8fa9b1891f4b725f587ef267abe2a1bad89d6b184520c7f07a253dd6e217", "sha256:f7e2072654a6b6afdf5e2fb38147d3e2d2d43c89f648637baab63e026481279b" ], - "index": "pypi", + "markers": "python_version ~= '3.6'", "version": "==2.8.2" }, + "qemu": { + "editable": true, + "path": "." + }, "toml": { "hashes": [ "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
python/setup.cfg +9 -0
@@ -22,6 +22,15 @@ packages = qemu.machine qemu.utils +[options.extras_require] +# Run `pipenv lock --dev` when changing these requirements. +devel = + flake8 >= 3.6.0 + isort >= 5.1.2 + mypy >= 0.770 + pylint >= 2.8.0 + + [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's exclude = __pycache__,
Signature · 1 line
2.31.1
Quoted 16 lines · John Snow
The following changes since commit
c8616fc7670b884de5f74d2767aade224c1c5c3a:Merge remote-tracking branch 'remotes/philmd/tags/gitlab-ci-20210527' into staging (2021-05-27 16:32:57 +0100)
are available in the Git repository at:
https://gitlab.com/jsnow/qemu.git tags/python-pull-request
for you to fetch changes up to
faa40e297406445ab8814844bd9aa532a7538cde:gitlab: add python linters to CI (2021-05-27 18:11:17 -0400)
----------------------------------------------------------------
Python pull request
Quoted 7 lines
Python packaging & CI implementation
Acceptance tests sent w/ Cleber's blessing.
New CI tests send w/ stsquad's RB.--js
----------------------------------------------------------------
Fails to build on my machine that runs the BSD VMs, apparently before it gets to the point of launching the VM:
make: Entering directory '/home/peter.maydell/qemu-freebsd/build' /usr/bin/python3 -B /home/peter.maydell/qemu-freebsd/meson/meson.py introspect --targets --tests --benchmarks | /usr/bin/python3 -B scripts/mtest2make.py > Makefile.mtest
{ \
echo 'ninja-targets = \'; \
/usr/bin/ninja -t targets all | sed 's/:.*//; $!s/$/ \\/'; \
echo 'build-files = \'; \
/usr/bin/ninja -t query build.ninja | sed -n '1,/^ input:/d; /^
outputs:/q; s/$/ \\/p'; \
} > Makefile.ninja.tmp && mv Makefile.ninja.tmp Makefile.ninja (GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)
(GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)/usr/bin/python3 -B /home/peter.maydell/qemu-freebsd/tests/vm/freebsd
--debug --genisoimage /usr/bin/genisoimage --image
"/home/peter.maydell/.cache/qemu-vm/images/freebsd.img" --force --build-image /home/peter.maydell/.cache/qemu-vm/images/freebsd.img Traceback (most recent call last):
File "/home/peter.maydell/qemu-freebsd/tests/vm/freebsd", line 21, in <module>
import basevm
File "/home/peter.maydell/qemu-freebsd/tests/vm/basevm.py", line 22,
in <module>
from qemu.machine import QEMUMachine
ImportError: bad magic number in 'qemu': b'\x03\xf3\r\n' /home/peter.maydell/qemu-freebsd/tests/vm/Makefile.include:79: recipe for target '/home/peter.maydell/.cache/qemu-vm/images/freebsd.img' failed
make: *** [/home/peter.maydell/.cache/qemu-vm/images/freebsd.img] Error 1
make: Leaving directory '/home/peter.maydell/qemu-freebsd/build'
thanks
-- PMM
Quoted 62 lines · Peter Maydell
Quoted 16 lines · John Snow
The following changes since commit
c8616fc7670b884de5f74d2767aade224c1c5c3a:Merge remote-tracking branch 'remotes/philmd/tags/gitlab-ci-20210527' into staging (2021-05-27 16:32:57 +0100)are available in the Git repository at:
https://gitlab.com/jsnow/qemu.git tags/python-pull-request
for you to fetch changes up to
faa40e297406445ab8814844bd9aa532a7538cde:gitlab: add python linters to CI (2021-05-27 18:11:17 -0400)
----------------------------------------------------------------
Python pull requestQuoted 7 lines
Python packaging & CI implementation
Acceptance tests sent w/ Cleber's blessing.
New CI tests send w/ stsquad's RB.--js
----------------------------------------------------------------
Fails to build on my machine that runs the BSD VMs, apparently before it gets to the point of launching the VM:
make: Entering directory '
/home/peter.maydell/qemu-freebsd/build'/usr/bin/python3-B/home/peter.maydell/qemu-freebsd/meson/meson.pyintrospect --targets --tests --benchmarks |/usr/bin/python3-Bscripts/mtest2make.py> Makefile.mtest{ \ echo 'ninja-targets = \'; \ /usr/bin/ninja -t targets all | sed 's/:.*//; $!s/$/ \\/'; \ echo 'build-files = \'; \ /usr/bin/ninja -t query build.ninja | sed -n '1,/^ input:/d; /^outputs:/q; s/$/ \\/p'; \
} > Makefile.ninja.tmp && mv Makefile.ninja.tmp Makefile.ninja (GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)
(GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)/usr/bin/python3-B/home/peter.maydell/qemu-freebsd/tests/vm/freebsd
--debug --genisoimage/usr/bin/genisoimage--image
"/home/peter.maydell/.cache/qemu-vm/images/freebsd.img" --force --build-image/home/peter.maydell/.cache/qemu-vm/images/freebsd.imgTraceback (most recent call last):
File "/home/peter.maydell/qemu-freebsd/tests/vm/freebsd", line 21, in <module>
import basevm
File "/home/peter.maydell/qemu-freebsd/tests/vm/basevm.py", line 22,
in <module>
from qemu.machine import QEMUMachine
ImportError: bad magic number in 'qemu': b'\x03\xf3\r\n'/home/peter.maydell/qemu-freebsd/tests/vm/Makefile.include:79: recipe for target '/home/peter.maydell/.cache/qemu-vm/images/freebsd.img' failed
make: *** [/home/peter.maydell/.cache/qemu-vm/images/freebsd.img] Error 1
make: Leaving directory '/home/peter.maydell/qemu-freebsd/build'
Quoted 3 lines
thanks
-- PMM
Hmm ...
When I have seen this error message in the past, it has been because of using a new Python version and it gets confused reading stale cached information generated from an older interpreter.
None of these patches *should* have affected what version of python is used during the build, only the locations of some of the files. I don't immediately know why this PR would affect the QEMU build at all, actually.
Can you do me a favor and delete any __pycache__ folders and/or any *.pyc files that might be hiding in your tree and/or build folders and try running it again?
(If it helps, I can see about amending 'make clean' to try and clean up stale Python cache, which is the best solution I can think of for right now.)
In case that doesn't fix it, can you tell me what version of Python your BSD setup uses? (And what version of FreeBSD you use?) -- I'll try to set up a VM and see if I can reproduce the problem.
--js
Quoted 39 lines · John Snow
Quoted 29 lines · Peter Maydell
Fails to build on my machine that runs the BSD VMs, apparently before it gets to the point of launching the VM:
make: Entering directory '
/home/peter.maydell/qemu-freebsd/build'/usr/bin/python3-B/home/peter.maydell/qemu-freebsd/meson/meson.pyintrospect --targets --tests --benchmarks |/usr/bin/python3-Bscripts/mtest2make.py> Makefile.mtest
{ \
echo 'ninja-targets = \'; \
/usr/bin/ninja-t targets all | sed 's/:.*//; $!s/$/ \\/'; \
echo 'build-files = \'; \
/usr/bin/ninja-t query build.ninja | sed -n '1,/^ input:/d; /^ outputs:/q; s/$/ \\/p'; \
} > Makefile.ninja.tmp && mv Makefile.ninja.tmp Makefile.ninja (GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)
(GIT="git" "/home/peter.maydell/qemu-freebsd/scripts/git-submodule.sh" update ui/keycodemapdb meson tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp)/usr/bin/python3-B/home/peter.maydell/qemu-freebsd/tests/vm/freebsd--debug --genisoimage /usr/bin/genisoimage --image "/home/peter.maydell/.cache/qemu-vm/images/freebsd.img" --force --build-image/home/peter.maydell/.cache/qemu-vm/images/freebsd.imgTraceback (most recent call last):
File "/home/peter.maydell/qemu-freebsd/tests/vm/freebsd", line 21, in <module>
import basevm
File "/home/peter.maydell/qemu-freebsd/tests/vm/basevm.py", line 22,Quoted 8 lines
in <module>
from qemu.machine import QEMUMachine
ImportError: bad magic number in 'qemu': b'\x03\xf3\r\n'/home/peter.maydell/qemu-freebsd/tests/vm/Makefile.include:79: recipe for target '/home/peter.maydell/.cache/qemu-vm/images/freebsd.img' failed
make: *** [/home/peter.maydell/.cache/qemu-vm/images/freebsd.img] Error 1
make: Leaving directory '/home/peter.maydell/qemu-freebsd/build'
Quoted 3 lines
In case that doesn't fix it, can you tell me what version of Python your BSD setup uses? (And what version of FreeBSD you use?) -- I'll try to set up a VM and see if I can reproduce the problem.
IIUC correctly this is on the host (likely Linux); no BSD VM could be launched yet.
Quoted 8 lines · John Snow
Quoted 2 lines · Peter Maydell
Fails to build on my machine that runs the BSD VMs, apparently before it gets to the point of launching the VM:
When I have seen this error message in the past, it has been because of using a new Python version and it gets confused reading stale cached information generated from an older interpreter.
This seems like a bug in Python...
Quoted 3 lines
Can you do me a favor and delete any
__pycache__folders and/or any *.pyc files that might be hiding in your tree and/or build folders and try running it again?
I tried that, and it does seem to make more progress. It now fails with:
### Booting installer ...
DEBUG:root:QEMU args: -nodefaults -m 4G -cpu max,sse4.2=off -netdev user,id=vnet,hostfwd=:127.0.0.1:0-:22 -device
virtio-net-pci,netdev=vnet -vnc 127.0.0.1:0,to=20 -smp 18 -enable-kvm
-drive file=/home/peter.maydell/.cache/qemu-vm/images/freebsd.img.tmp,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -bios
pc-bios/bios-256k.bin -machine graphics=off -device VGA -cdrom /home/peter.maydell/.cache/qemu-vm/images/freebsd.img.install.iso DEBUG:qemu.machine.machine:VM launch command: 'qemu-system-x86_64
-display none -vga none -chardev
socket,id=mon,path=/var/tmp/qemu-13084-monitor.sock -mon
chardev=mon,mode=control -machine pc -chardev socket,id=console,path=/var/tmp/qemu-13084-console.sock,server=on,wait=off
-serial chardev:console -nodefaults -m 4G -cpu max,sse4.2=off -netdev user,id=vnet,hostfwd=:127.0.0.1:0-:22 -device
virtio-net-pci,netdev=vnet -vnc 127.0.0.1:0,to=20 -smp 18 -enable-kvm
-drive file=/home/peter.maydell/.cache/qemu-vm/images/freebsd.img.tmp,if=none,id=drive0,cache=writeback -device virtio-blk,drive=drive0,bootindex=0 -bios
pc-bios/bios-256k.bin -machine graphics=off -device VGA -cdrom /home/peter.maydell/.cache/qemu-vm/images/freebsd.img.install.iso' DEBUG:QMP.qemu-13084:>>> {'execute': 'qmp_capabilities'}
DEBUG:QMP.qemu-13084:<<< {'return': {}}
DEBUG:QMP.qemu-13084:>>> {'execute': 'human-monitor-command',
'arguments': {'command-line': 'info usernet'}}
DEBUG:QMP.qemu-13084:<<< {'return': 'Hub -1 (vnet):\r\n
Protocol[State] FD Source Address Port Dest. Address Port
RecvQ SendQ\r\n TCP[HOST_FORWARD] 15 127.0.0.1 38577
10.0.2.15 22 0 0\r\n'}
Failed to prepare guest environment
Traceback (most recent call last):
File "/home/peter.maydell/qemu-freebsd/tests/vm/basevm.py", line 630, in main
return vm.build_image(args.image)
File "/home/peter.maydell/qemu-freebsd/tests/vm/freebsd", line 103,
in build_image
"-cdrom", iso
File "/home/peter.maydell/qemu-freebsd/tests/vm/basevm.py", line 309, in boot
self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)
File "/home/peter.maydell/qemu-freebsd/tests/vm/../../python/qemu/utils/__init__.py",
line 40, in get_info_usernet_hostfwd_port
for line in info_usernet_output.split('\r\n'):
AttributeError: 'dict' object has no attribute 'split' DEBUG:QMP.qemu-13084:>>> {'execute': 'quit'}
DEBUG:QMP.qemu-13084:<<< {'return': {}} /home/peter.maydell/qemu-freebsd/tests/vm/Makefile.include:79: recipe
for target '/home/peter.maydell/.cache/qemu-vm/images/freebsd.img'
failed
make: *** [/home/peter.maydell/.cache/qemu-vm/images/freebsd.img] Error 2
make: Leaving directory '/home/peter.maydell/qemu-freebsd/build'
thanks
-- PMM
Quoted 12 lines · Peter Maydell
Quoted 8 lines · John Snow
Quoted 2 lines · Peter Maydell
Fails to build on my machine that runs the BSD VMs, apparently before it gets to the point of launching the VM:
When I have seen this error message in the past, it has been because of using a new Python version and it gets confused reading stale cached information generated from an older interpreter.
This seems like a bug in Python...
Yes. I don't know why it's like that either...
Quoted 7 lines
Quoted 3 lines
Can you do me a favor and delete any
__pycache__folders and/or any *.pyc files that might be hiding in your tree and/or build folders and try running it again?I tried that, and it does seem to make more progress. It now fails with:
One of the acceptance test patches causes this, I've squashed in a fixup and have re-sent the PR.
Thanks,
--js
cover VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
In reply to John SnowThe utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
The issue can be replicated with (and verified the fix) with make vm-build-freebsd.
Cleber Rosa (1):
VM tests: account for changes in
qemu.utils.get_info_usernet_hostfwd_port()
tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.4
PATCH 1/1 VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
The utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
--- tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/vm/basevm.py +2 -2
@@ -227,7 +227,7 @@ def _ssh_do(self, user, cmd, check): "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout={}".format(self._config["ssh_timeout"]), - "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] + "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:
@@ -305,7 +305,7 @@ def boot(self, img, extra_args=[]): # Init console so we can start consuming the chars. self.console_init() usernet_info = guest.qmp("human-monitor-command", - command_line="info usernet") + command_line="info usernet").get("return") self.ssh_port = get_info_usernet_hostfwd_port(usernet_info) if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \
Signature · 1 line
2.25.4
Re: [PATCH 1/1] VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
Quoted 25 lines · Cleber Rosa
The utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
Signed-off-by John Snow <[email protected]>Signed-off-by Cleber Rosa <[email protected]>--- tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tests/vm/basevm.py +1
-1@@ -227,7 +227,7 @@ def _ssh_do(self, user, cmd, check): "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout={}".format(self._config["ssh_timeout"]), - "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] + "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:
tests/vm/basevm.py def boot(self, img, extra_args=[]): · line 309
Quoted 6 lines
tests/vm/basevm.py +1
-1@@ -305,7 +305,7 @@ def boot(self, img, extra_args=[]): # Init console so we can start consuming the chars. self.console_init() usernet_info = guest.qmp("human-monitor-command", - command_line="info usernet") + command_line="info usernet").get("return") self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)
From here, your file differs from the upstream and your patch does not work. I'm trying on commit 52848929b70dcf92a68aedcfd90207be81ba3274.
Quoted 5 lines
tests/vm/basevm.py +0
-1if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ --2.25.4
John Snow
Reviewed-by Wainer dos Santos Moschetta Reviewed-by Eric Auger Reviewed-by Willian RampazzoRe: [PATCH 1/1] VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
Quoted 27 lines · Willian Rampazzo
Quoted 26 lines · Cleber Rosa
The utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
Signed-off-by John Snow <[email protected]>Signed-off-by Cleber Rosa <[email protected]>--- tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tests/vm/basevm.py +1
-1@@ -227,7 +227,7 @@ def _ssh_do(self, user, cmd, check): "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout={}".format(self._config["ssh_timeout"]), - "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] + "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:@@ -305,7 +305,7 @@ def boot(self, img, extra_args=[]): # Init console so we can start consuming the chars.
Quoted 9 lines
tests/vm/basevm.py def boot(self, img, extra_args=[]): · line 309
Quoted 5 lines
tests/vm/basevm.py +1
-1self.console_init() usernet_info = guest.qmp("human-monitor-command", - command_line="info usernet") + command_line="info usernet").get("return") self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)From here, your file differs from the upstream and your patch does not
work. I'm trying on commit52848929b70dcf92a68aedcfd90207be81ba3274.
Cleber is patching against my pull request -- I'll be squashing it into (from PR tree) 0739780d621f8fd4163ce6969a183e59113245aa -- just waiting on some tests to finish running before I move ahead with it.
commit 0739780d621f8fd4163ce6969a183e59113245aa
Author: Cleber Rosa <[email protected]> Date: Mon Apr 12 00:46:36 2021 -0400
Python: add utility function for retrieving port redirection
Slightly different versions for the same utility code are currently present on different locations. This unifies them all, giving preference to the version from virtiofs_submounts.py, because of the last tweaks added to it.
While at it, this adds a "qemu.utils" module to host the utility function and a test.
Message-Id: <[email protected]>
Quoted 6 lines
Quoted 5 lines
tests/vm/basevm.py +0
-1if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ --2.25.4
thanks,
--js
Re: [PATCH 1/1] VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
In reply to Willian RampazzoQuoted 28 lines · Willian Rampazzo
Quoted 26 lines · Cleber Rosa
The utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
Signed-off-by John Snow <[email protected]>Signed-off-by Cleber Rosa <[email protected]>--- tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tests/vm/basevm.py +1
-1@@ -227,7 +227,7 @@ def _ssh_do(self, user, cmd, check): "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout={}".format(self._config["ssh_timeout"]), - "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] + "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:@@ -305,7 +305,7 @@ def boot(self, img, extra_args=[]): # Init console so we can start consuming the chars.
Quoted 8 lines
tests/vm/basevm.py def boot(self, img, extra_args=[]): · line 309
Quoted 5 lines
tests/vm/basevm.py +1
-1self.console_init() usernet_info = guest.qmp("human-monitor-command", - command_line="info usernet") + command_line="info usernet").get("return") self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)From here, your file differs from the upstream and your patch does not work. I'm trying on commit
52848929b70dcf92a68aedcfd90207be81ba3274.
Talking to Cleber he mentioned he submitted In-reply-to John's PR, but Gmail did not show it for me.
On top of John's PR
(https://patchew.org/QEMU/[email protected]/):
Quoted 6 lines
Quoted 6 lines
tests/vm/basevm.py +0
-1if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ --2.25.4
Re: [PATCH 1/1] VM tests: account for changes in qemu.utils.get_info_usernet_hostfwd_port()
Quoted 38 lines · Willian Rampazzo
Quoted 28 lines · Willian Rampazzo
Quoted 26 lines · Cleber Rosa
The utility function actually accepts a string, and not the raw dictionary response from QMP. Also, it returns (optionally) an integer, so that must also be accounted for.
Signed-off-by John Snow <[email protected]>Signed-off-by Cleber Rosa <[email protected]>--- tests/vm/basevm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)tests/vm/basevm.py +1
-1@@ -227,7 +227,7 @@ def _ssh_do(self, user, cmd, check): "-o", "UserKnownHostsFile=" + os.devnull, "-o", "ConnectTimeout={}".format(self._config["ssh_timeout"]), - "-p", self.ssh_port, "-i", self._ssh_tmp_key_file] + "-p", str(self.ssh_port), "-i", self._ssh_tmp_key_file] # If not in debug mode, set ssh to quiet mode to # avoid printing the results of commands. if not self.debug:@@ -305,7 +305,7 @@ def boot(self, img, extra_args=[]): # Init console so we can start consuming the chars.Quoted 8 lines
tests/vm/basevm.py def boot(self, img, extra_args=[]): · line 309
Quoted 5 lines
tests/vm/basevm.py +1
-1self.console_init() usernet_info = guest.qmp("human-monitor-command", - command_line="info usernet") + command_line="info usernet").get("return") self.ssh_port = get_info_usernet_hostfwd_port(usernet_info)From here, your file differs from the upstream and your patch does not work. I'm trying on commit
52848929b70dcf92a68aedcfd90207be81ba3274.
Quoted 1 line
Talking to Cleber he mentioned he submitted In-reply-to
Please don't, as the series end up buried in the other email thread.
Quoted 5 lines
John's PR, but
Gmail did not show it for me.On top of John's PR
(https://patchew.org/QEMU/[email protected]/):
The syntax is:
Based-on: [email protected]
https://wiki.qemu.org/Contribute/SubmitAPatch#Base_patches_against_current_git_master
Quoted 11 lines
Tested-by Willian Rampazzo <[email protected]>Reviewed-by Willian Rampazzo <[email protected]>Quoted 6 lines
Quoted 6 lines
tests/vm/basevm.py +0
-1if not self.ssh_port: raise Exception("Cannot find ssh port from 'info usernet':\n%s" % \ --2.25.4