Acceptance Test: introduce base class for Linux based tests
PATCH 3/22 Acceptance Tests: remove unnecessary tag from documentation example
In reply to Cleber RosaThe ":avocado: enable" is not necessary and was removed in 9531d26c, so let's remove from the docs.
--- docs/devel/testing.rst | 3 --- 1 file changed, 3 deletions(-)
docs/devel/testing.rst +0 -3
@@ -765,9 +765,6 @@ and hypothetical example follows: class MultipleMachines(Test): - """ - :avocado: enable - """ def test_multiple_machines(self): first_machine = self.get_vm() second_machine = self.get_vm()
Signature · 1 line
2.25.4
PATCH 5/22 tests/acceptance/virtiofs_submounts.py: do not ask for ssh key password
In reply to Cleber RosaTests are supposed to be non-interactive, and ssh-keygen is asking for a password when creating a key. Let's set an empty key, which prevents ssh-keygen for asking for a password.
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -235,7 +235,7 @@ class VirtiofsSubmountsTest(BootLinux): self.ssh_key = os.path.join(self.workdir, 'id_ed25519') - self.run(('ssh-keygen', '-t', 'ed25519', '-f', self.ssh_key)) + self.run(('ssh-keygen', '-N', '', '-t', 'ed25519', '-f', self.ssh_key)) pubkey = open(self.ssh_key + '.pub').read()
Signature · 1 line
2.25.4
PATCH 8/22 tests/acceptance/virtiofs_submounts.py: standardize port as integer
In reply to Cleber RosaInstead of having to cast it whenever it's going to be used, let's standardize it as an integer, which is the data type that will be used most often.
Given that the regex will only match digits, it's safe that we'll end up getting a integer, but, it could as well be a zero.
--- tests/acceptance/virtiofs_submounts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tests/acceptance/virtiofs_submounts.py +4 -3
@@ -86,17 +86,18 @@ class VirtiofsSubmountsTest(BootLinux): re.search(r'TCP.HOST_FORWARD.*127\.0\.0\.1\s*(\d+)\s+10\.', line) if match is not None: - port = match[1] + port = int(match[1]) break self.assertIsNotNone(port) - self.log.debug('sshd listening on port: ' + 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=int(port), + self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, key=keyfile) for i in range(10): try:
Signature · 1 line
2.25.4
cover Acceptance Test: introduce base class for Linux based tests
This introduces a base class for tests that need to interact with a Linux guest. It generalizes the "boot_linux.py" code, already been used by the "virtiofs_submounts.py" and also SSH related code being used by that and "linux_ssh_mips_malta.py".
While at it, a number of fixes on hopeful improvements to those tests were added.
Cleber Rosa (22):
tests/acceptance/boot_linux.py: fix typo on cloudinit error message tests/acceptance/boot_linux.py: rename misleading cloudinit method Acceptance Tests: remove unnecessary tag from documentation example tests/acceptance/virtiofs_submounts.py: use workdir property tests/acceptance/virtiofs_submounts.py: do not ask for ssh key
password
tests/acceptance/virtiofs_submounts.py: use a virtio-net device
instead
tests/acceptance/virtiofs_submounts.py: evaluate string not length tests/acceptance/virtiofs_submounts.py: standardize port as integer tests/acceptance/virtiofs_submounts.py: required space between IP and
port
Python: add utility function for retrieving port redirection tests/acceptance/linux_ssh_mips_malta.py: standardize port as integer Acceptance tests: clarify ssh connection failure reason tests/acceptance/virtiofs_submounts.py: add missing accel tag Acceptance Tests: introduce LinuxTest base class Acceptance Tests: move useful ssh methods to base class Acceptance Tests: introduce method for requiring an accelerator Acceptance Tests: fix population of public key in cloudinit image Acceptance Tests: set up existing ssh keys by default Acceptance Tests: add port redirection for ssh by default Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test
[NOTFORMERGE] Bump Avocado version to latest master
docs/devel/testing.rst | 29 +++- python/qemu/utils.py | 35 +++++ tests/acceptance/avocado_qemu/__init__.py | 176 ++++++++++++++++++++++ tests/acceptance/boot_linux.py | 128 ++-------------- tests/acceptance/hotplug_cpu.py | 38 +++++ tests/acceptance/info_usernet.py | 29 ++++ tests/acceptance/linux_ssh_mips_malta.py | 44 +----- tests/acceptance/virtiofs_submounts.py | 73 +-------- tests/requirements.txt | 2 +- tests/vm/basevm.py | 7 +- 10 files changed, 334 insertions(+), 227 deletions(-) create mode 100644 python/qemu/utils.py create mode 100644 tests/acceptance/hotplug_cpu.py create mode 100644 tests/acceptance/info_usernet.py
Signature · 1 line
2.25.4
PATCH 9/22 tests/acceptance/virtiofs_submounts.py: required space between IP and port
AFAICT, there should not be a situation where IP and port do not have at least one whitespace character separating them.
This may be true for other '\s*' patterns in the same regex too.
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -83,7 +83,7 @@ class VirtiofsSubmountsTest(BootLinux): 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\.', + re.search(r'TCP.HOST_FORWARD.*127\.0\.0\.1\s+(\d+)\s+10\.', line) if match is not None: port = int(match[1])
Signature · 1 line
2.25.4
PATCH 11/22 tests/acceptance/linux_ssh_mips_malta.py: standardize port as integer
In reply to Cleber Rosa--- tests/acceptance/linux_ssh_mips_malta.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tests/acceptance/linux_ssh_mips_malta.py +2 -2
@@ -79,8 +79,8 @@ class LinuxSSH(Test): 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), + self.log.debug("sshd listening on port: %d", port) + self.ssh_session = ssh.Session(self.VM_IP, port=port, user=username, password=password) for i in range(10): try:
Signature · 1 line
2.25.4
PATCH 16/22 Acceptance Tests: introduce method for requiring an accelerator
In reply to Cleber RosaSome tests explicitly require a QEMU accelerator to be available. Given that this depends on some runtime aspects not known before the test is started, such as the currently set QEMU binary, it's left to be checked also at runtime.
--- tests/acceptance/avocado_qemu/__init__.py | 24 ++++++++++++++++ tests/acceptance/boot_linux.py | 34 ++++++----------------- tests/acceptance/virtiofs_submounts.py | 5 +--- 3 files changed, 34 insertions(+), 29 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +24 -0
@@ -41,6 +41,8 @@ else: 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
@@ -166,6 +168,28 @@ class Test(avocado.Test): return vals.pop() return None + def require_accelerator(self, accelerator): + """ + Requires an accelerator to be available for the test to continue + + It takes into account the currently set qemu binary. + + If the check fails, the test is canceled. If the check itself + for the given accelerator is not available, the test is also + canceled. + + :param accelerator: name of the accelerator, such as "kvm" or "tcg" + :type accelerator: str + """ + checker = {'tcg': tcg_available, + 'kvm': kvm_available}.get(accelerator) + if checker is None: + self.cancel("Don't know how to check for the presence " + "of accelerator %s" % accelerator) + if not checker(qemu_bin=self.qemu_bin): + self.cancel("%s accelerator does not seem to be " + "available" % accelerator) + def setUp(self): self._vms = {}
tests/acceptance/boot_linux.py +9 -25
@@ -12,15 +12,8 @@ import os from avocado_qemu import LinuxTest, BUILD_DIR -from qemu.accel import kvm_available -from qemu.accel import tcg_available - from avocado import skipIf -ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available" -KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM" -TCG_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "TCG" - class BootLinuxX8664(LinuxTest): """
@@ -34,8 +27,7 @@ class BootLinuxX8664(LinuxTest): :avocado: tags=machine:pc :avocado: tags=accel:tcg """ - if not tcg_available(self.qemu_bin): - self.cancel(TCG_NOT_AVAILABLE) + self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") self.launch_and_wait()
@@ -44,8 +36,7 @@ class BootLinuxX8664(LinuxTest): :avocado: tags=machine:pc :avocado: tags=accel:kvm """ - if not kvm_available(self.arch, self.qemu_bin): - self.cancel(KVM_NOT_AVAILABLE) + self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") self.launch_and_wait()
@@ -54,8 +45,7 @@ class BootLinuxX8664(LinuxTest): :avocado: tags=machine:q35 :avocado: tags=accel:tcg """ - if not tcg_available(self.qemu_bin): - self.cancel(TCG_NOT_AVAILABLE) + self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") self.launch_and_wait()
@@ -64,8 +54,7 @@ class BootLinuxX8664(LinuxTest): :avocado: tags=machine:q35 :avocado: tags=accel:kvm """ - if not kvm_available(self.arch, self.qemu_bin): - self.cancel(KVM_NOT_AVAILABLE) + self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") self.launch_and_wait()
@@ -91,8 +80,7 @@ class BootLinuxAarch64(LinuxTest): :avocado: tags=accel:tcg :avocado: tags=cpu:max """ - if not tcg_available(self.qemu_bin): - self.cancel(TCG_NOT_AVAILABLE) + self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") self.vm.add_args("-cpu", "max") self.vm.add_args("-machine", "virt,gic-version=2")
@@ -105,8 +93,7 @@ class BootLinuxAarch64(LinuxTest): :avocado: tags=cpu:host :avocado: tags=device:gicv2 """ - if not kvm_available(self.arch, self.qemu_bin): - self.cancel(KVM_NOT_AVAILABLE) + self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") self.vm.add_args("-cpu", "host") self.vm.add_args("-machine", "virt,gic-version=2")
@@ -119,8 +106,7 @@ class BootLinuxAarch64(LinuxTest): :avocado: tags=cpu:host :avocado: tags=device:gicv3 """ - if not kvm_available(self.arch, self.qemu_bin): - self.cancel(KVM_NOT_AVAILABLE) + self.require_accelerator("kvm") self.vm.add_args("-accel", "kvm") self.vm.add_args("-cpu", "host") self.vm.add_args("-machine", "virt,gic-version=3")
@@ -140,8 +126,7 @@ class BootLinuxPPC64(LinuxTest): :avocado: tags=machine:pseries :avocado: tags=accel:tcg """ - if not tcg_available(self.qemu_bin): - self.cancel(TCG_NOT_AVAILABLE) + self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") self.launch_and_wait()
@@ -159,7 +144,6 @@ class BootLinuxS390X(LinuxTest): :avocado: tags=machine:s390-ccw-virtio :avocado: tags=accel:tcg """ - if not tcg_available(self.qemu_bin): - self.cancel(TCG_NOT_AVAILABLE) + self.require_accelerator("tcg") self.vm.add_args("-accel", "tcg") self.launch_and_wait()
tests/acceptance/virtiofs_submounts.py +1 -4
@@ -9,8 +9,6 @@ from avocado_qemu import LinuxTest, BUILD_DIR from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh -from qemu.accel import kvm_available - def run_cmd(args): subp = subprocess.Popen(args,
@@ -201,8 +199,7 @@ class VirtiofsSubmountsTest(LinuxTest): self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', '-device', 'virtio-net,netdev=vnet') - if not kvm_available(self.arch, self.qemu_bin): - self.cancel(KVM_NOT_AVAILABLE) + self.require_accelerator("kvm") self.vm.add_args('-accel', 'kvm') def tearDown(self):
Signature · 1 line
2.25.4
PATCH 17/22 Acceptance Tests: fix population of public key in cloudinit image
In reply to Cleber RosaCurrently the path of the ssh public key is being set, but its content is obviously what's needed.
--- tests/acceptance/avocado_qemu/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tests/acceptance/avocado_qemu/__init__.py +3 -1
@@ -337,13 +337,15 @@ class LinuxTest(Test, LinuxSSHMixIn): try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') self.phone_home_port = network.find_free_port() + with open(ssh_pubkey) as pubkey: + pubkey_content = pubkey.read() cloudinit.iso(cloudinit_iso, self.name, username='root', password='password', # QEMU's hard coded usermode router address phone_home_host='10.0.2.2', phone_home_port=self.phone_home_port, - authorized_key=ssh_pubkey) + authorized_key=pubkey_content) except Exception: self.cancel('Failed to prepare the cloudinit image') return cloudinit_iso
Signature · 1 line
2.25.4
PATCH 13/22 tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to Cleber RosaWhich is useful to select tests that depend/use a particular feature.
--- tests/acceptance/virtiofs_submounts.py | 1 + 1 file changed, 1 insertion(+)
tests/acceptance/virtiofs_submounts.py +1 -0
@@ -75,6 +75,7 @@ def has_cmds(*cmds): class VirtiofsSubmountsTest(BootLinux): """ :avocado: tags=arch:x86_64 + :avocado: tags=accel:kvm """ def ssh_connect(self, username, keyfile):
Signature · 1 line
2.25.4
PATCH 22/22 Bump Avocado version to latest master
In reply to Cleber RosaThis is intende to be replaced by a bump to Avocado 85.0, to be released by Feb 8 2021.
Latest master contains an improvement to "avocado.utils.vmimage" that let's it download older Fedora images from the archive locations. That allows the currently set Fedora 31 images to continue being used.
Reference: https://github.com/avocado-framework/avocado/milestone/11
Reference: https://github.com/avocado-framework/avocado/commit/e4d67e96ee9563436dcf7dd83902723576657d29
--- 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==83.0 +git+https://github.com/avocado-framework/avocado@9b372adeec6dceaba276ca4729f2e5a2fcccaa4c#egg=avocado_framework pycdlib==1.11.0
Signature · 1 line
2.25.4
PATCH 2/22 tests/acceptance/boot_linux.py: rename misleading cloudinit method
In reply to Cleber RosaThere's no downloading happening on that method, so let's call it "prepare" instead. While at it, and because of it, the current "prepare_boot" and "prepare_cloudinit" are also renamed.
The reasoning here is that "prepare_" methods will just work on the images, while "set_up_" will make them effective to the VM that will be launched. Inspiration comes from the "virtiofs_submounts.py" tests, which this expects to converge more into.
--- tests/acceptance/boot_linux.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tests/acceptance/boot_linux.py +6 -6
@@ -57,7 +57,7 @@ class BootLinuxBase(Test): self.cancel('Failed to download/prepare boot image') return boot.path - def download_cloudinit(self, ssh_pubkey=None): + def prepare_cloudinit(self, ssh_pubkey=None): self.log.info('Preparing cloudinit image') try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso')
@@ -85,15 +85,15 @@ class BootLinux(BootLinuxBase): super(BootLinux, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') - self.prepare_boot() - self.prepare_cloudinit(ssh_pubkey) + self.set_up_boot() + self.set_up_cloudinit(ssh_pubkey) - def prepare_boot(self): + def set_up_boot(self): path = self.download_boot() self.vm.add_args('-drive', 'file=%s' % path) - def prepare_cloudinit(self, ssh_pubkey=None): - cloudinit_iso = self.download_cloudinit(ssh_pubkey) + 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):
Signature · 1 line
2.25.4
PATCH 19/22 Acceptance Tests: add port redirection for ssh by default
In reply to Cleber RosaFor 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.
--- tests/acceptance/avocado_qemu/__init__.py | 2 ++ tests/acceptance/virtiofs_submounts.py | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +2 -0
@@ -301,6 +301,8 @@ class LinuxTest(Test, LinuxSSHMixIn): super(LinuxTest, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', 'virtio-net,netdev=vnet') 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
@@ -195,10 +195,6 @@ class VirtiofsSubmountsTest(LinuxTest): 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.25.4
PATCH 12/22 Acceptance tests: clarify ssh connection failure reason
In reply to Cleber RosaIf the connection to the ssh server fails, it may indeed be a "sshd" issue, but it may also not be that. Let's state what we know: the establishment of the connection from the client side was not possible.
--- tests/acceptance/linux_ssh_mips_malta.py | 2 +- tests/acceptance/virtiofs_submounts.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tests/acceptance/linux_ssh_mips_malta.py +1 -1
@@ -89,7 +89,7 @@ class LinuxSSH(Test): except: time.sleep(4) pass - self.fail("sshd timeout") + self.fail("ssh connection timeout") def ssh_disconnect_vm(self): self.ssh_session.quit()
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -94,7 +94,7 @@ class VirtiofsSubmountsTest(BootLinux): except: time.sleep(4) pass - self.fail('sshd timeout') + self.fail('ssh connection timeout') def ssh_command(self, command): self.ssh_logger.info(command)
Signature · 1 line
2.25.4
PATCH 10/22 Python: add utility function for retrieving port redirection
In reply to Cleber RosaSlightly 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.util" module to host the utility function and a test.
--- python/qemu/utils.py | 35 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------ tests/acceptance/virtiofs_submounts.py | 20 +++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 python/qemu/utils.py create mode 100644 tests/acceptance/info_usernet.py
python/qemu/utils.py new file +35 -0
@@ -0,0 +1,35 @@ +""" +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" + :param info_usernet_output: str + :return: the port number allocated by the hostfwd option + :rtype: int + """ + 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 process 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 @@ class LinuxSSH(Test): 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 +4 -16
@@ -10,6 +10,7 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available +from qemu.utils import get_info_usernet_hostfwd_port from boot_linux import BootLinux
@@ -76,27 +77,14 @@ class VirtiofsSubmountsTest(BootLinux): :avocado: tags=arch:x86_64 """ - 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 @@ 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 import subprocess import hashlib import argparse
@@ -306,11 +307,7 @@ class BaseVM(object): 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.25.4
PATCH 20/22 Acceptance Tests: add basic documentation on LinuxTest base class
In reply to Cleber Rosa--- docs/devel/testing.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
docs/devel/testing.rst +26 -0
@@ -790,6 +790,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. 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_connect('root', self.ssh_key) + 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.25.4
Re: [PATCH 03/22] Acceptance Tests: remove unnecessary tag from documentation example
In reply to Cleber RosaQuoted 7 lines · Cleber Rosa
The ":avocado: enable" is not necessary and was removed in
9531d26c, so let's remove from the docs.Signed-off-by Cleber Rosa <[email protected]>--- docs/devel/testing.rst | 3 --- 1 file changed, 3 deletions(-)
PATCH 1/22 tests/acceptance/boot_linux.py: fix typo on cloudinit error message
In reply to Cleber Rosa--- tests/acceptance/boot_linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/boot_linux.py +1 -1
@@ -70,7 +70,7 @@ class BootLinuxBase(Test): phone_home_port=self.phone_home_port, authorized_key=ssh_pubkey) except Exception: - self.cancel('Failed to prepared cloudinit image') + self.cancel('Failed to prepare the cloudinit image') return cloudinit_iso class BootLinux(BootLinuxBase):
Signature · 1 line
2.25.4
PATCH 21/22 Acceptance Tests: introduce CPU hotplug test
In reply to Cleber RosaEven 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.
--- tests/acceptance/hotplug_cpu.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/acceptance/hotplug_cpu.py
tests/acceptance/hotplug_cpu.py new file +38 -0
@@ -0,0 +1,38 @@ +# 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_connect('root', self.ssh_key) + 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.25.4
Re: [PATCH 01/22] tests/acceptance/boot_linux.py: fix typo on cloudinit error message
In reply to Cleber RosaQuoted 4 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/boot_linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
PATCH 6/22 tests/acceptance/virtiofs_submounts.py: use a virtio-net device instead
In reply to Cleber RosaIn a virtiofs based tests, it seems safe to assume that the guest will be capable of a virtio-net device.
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -247,7 +247,7 @@ class VirtiofsSubmountsTest(BootLinux): # Allow us to connect to SSH self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', - '-device', 'e1000,netdev=vnet') + '-device', 'virtio-net,netdev=vnet') if not kvm_available(self.arch, self.qemu_bin): self.cancel(KVM_NOT_AVAILABLE)
Signature · 1 line
2.25.4
PATCH 4/22 tests/acceptance/virtiofs_submounts.py: use workdir property
In reply to Cleber RosaFor Avocado Instrumented based tests, it's a better idea to just use the property. The environment variable is a fall back for tests not written using that Python API.
Reference: https://avocado-framework.readthedocs.io/en/84.0/api/test/avocado.html#avocado.Test.workdir
--- tests/acceptance/virtiofs_submounts.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
tests/acceptance/virtiofs_submounts.py +2 -4
@@ -136,8 +136,7 @@ class VirtiofsSubmountsTest(BootLinux): return (stdout, stderr, ret) def set_up_shared_dir(self): - atwd = os.getenv('AVOCADO_TEST_WORKDIR') - self.shared_dir = os.path.join(atwd, 'virtiofs-shared') + self.shared_dir = os.path.join(self.workdir, 'virtiofs-shared') os.mkdir(self.shared_dir)
@@ -234,8 +233,7 @@ class VirtiofsSubmountsTest(BootLinux): self.seed = self.params.get('seed') - atwd = os.getenv('AVOCADO_TEST_WORKDIR') - self.ssh_key = os.path.join(atwd, 'id_ed25519') + self.ssh_key = os.path.join(self.workdir, 'id_ed25519') self.run(('ssh-keygen', '-t', 'ed25519', '-f', self.ssh_key))
Signature · 1 line
2.25.4
Re: [PATCH 12/22] Acceptance tests: clarify ssh connection failure reason
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
If the connection to the ssh server fails, it may indeed be a "sshd" issue, but it may also not be that. Let's state what we know: the establishment of the connection from the client side was not possible.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/linux_ssh_mips_malta.py | 2 +- tests/acceptance/virtiofs_submounts.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
PATCH 14/22 Acceptance Tests: introduce LinuxTest base class
In reply to Cleber RosaThis is basically the infrastructure around "boot_linux.py" tests, but now made into a base class for general use.
--- tests/acceptance/avocado_qemu/__init__.py | 87 +++++++++++++++++++++ tests/acceptance/boot_linux.py | 94 ++--------------------- tests/acceptance/virtiofs_submounts.py | 6 +- 3 files changed, 94 insertions(+), 93 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +87 -0
@@ -16,6 +16,13 @@ import tempfile import avocado +from avocado.utils import cloudinit +from avocado.utils import datadrainer +from avocado.utils import network +from avocado.utils import vmimage +from avocado.utils.path import find_command + + #: The QEMU build root directory. It may also be the source directory #: if building from the source dir, but it's safer to use BUILD_DIR for #: that purpose. Be aware that if this code is moved outside of a source
@@ -206,3 +213,83 @@ class Test(avocado.Test): expire=expire, find_only=find_only, cancel_on_missing=cancel_on_missing) + + +class LinuxTest(Test): + """Facilitates having a cloud-image Linux based available. + + For tests that indend to interact with guests, this is a better choice + to start with than the more vanilla `Test` class. + """ + + timeout = 900 + chksum = None + + def setUp(self, ssh_pubkey=None): + super(LinuxTest, self).setUp() + self.vm.add_args('-smp', '2') + self.vm.add_args('-m', '1024') + self.set_up_boot() + self.set_up_cloudinit(ssh_pubkey) + + def download_boot(self): + self.log.debug('Looking for and selecting a qemu-img binary to be ' + 'used to create the bootable snapshot image') + # If qemu-img has been built, use it, otherwise the system wide one + # will be used. If none is available, the test will cancel. + qemu_img = os.path.join(BUILD_DIR, 'qemu-img') + if not os.path.exists(qemu_img): + qemu_img = find_command('qemu-img', False) + if qemu_img is False: + self.cancel('Could not find "qemu-img", which is required to ' + 'create the bootable image') + vmimage.QEMU_IMG = qemu_img + + self.log.info('Downloading/preparing boot image') + # Fedora 31 only provides ppc64le images + image_arch = self.arch + if image_arch == 'ppc64': + image_arch = 'ppc64le' + try: + boot = vmimage.get( + 'fedora', arch=image_arch, version='31', + checksum=self.chksum, + algorithm='sha256', + cache_dir=self.cache_dirs[0], + snapshot_dir=self.workdir) + except: + self.cancel('Failed to download/prepare boot image') + return boot.path + + def prepare_cloudinit(self, ssh_pubkey=None): + self.log.info('Preparing cloudinit image') + try: + cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') + self.phone_home_port = network.find_free_port() + cloudinit.iso(cloudinit_iso, self.name, + username='root', + password='password', + # QEMU's hard coded usermode router address + phone_home_host='10.0.2.2', + phone_home_port=self.phone_home_port, + authorized_key=ssh_pubkey) + except Exception: + self.cancel('Failed to prepare the cloudinit image') + return cloudinit_iso + + def set_up_boot(self): + path = self.download_boot() + self.vm.add_args('-drive', 'file=%s' % path) + + 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): + self.vm.set_console() + self.vm.launch() + console_drainer = datadrainer.LineLogger(self.vm.console_socket.fileno(), + logger=self.log.getChild('console')) + 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)
tests/acceptance/boot_linux.py +5 -89
128 lines not on this page · raw message
tests/acceptance/virtiofs_submounts.py +2 -4
@@ -5,15 +5,13 @@ import subprocess import time from avocado import skipUnless -from avocado_qemu import Test, BUILD_DIR +from avocado_qemu import LinuxTest, BUILD_DIR from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available from qemu.utils import get_info_usernet_hostfwd_port -from boot_linux import BootLinux - def run_cmd(args): subp = subprocess.Popen(args,
@@ -72,7 +70,7 @@ def has_cmds(*cmds): return (True, '') -class VirtiofsSubmountsTest(BootLinux): +class VirtiofsSubmountsTest(LinuxTest): """ :avocado: tags=arch:x86_64 :avocado: tags=accel:kvm
Signature · 1 line
2.25.4
PATCH 15/22 Acceptance Tests: move useful ssh methods to base class
In reply to Cleber RosaBoth 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 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.
--- tests/acceptance/avocado_qemu/__init__.py | 49 ++++++++++++++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 38 ++---------------- tests/acceptance/virtiofs_submounts.py | 36 ----------------- 3 files changed, 51 insertions(+), 72 deletions(-)
tests/acceptance/avocado_qemu/__init__.py +48 -1
@@ -10,6 +10,7 @@ import logging import os +import re import sys import uuid import tempfile
@@ -19,6 +20,7 @@ import avocado 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
@@ -40,6 +42,8 @@ else: sys.path.append(os.path.join(SOURCE_DIR, 'python')) 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)
@@ -215,7 +219,50 @@ class Test(avocado.Test): 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 -35
@@ -12,7 +12,7 @@ import logging 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
@@ -21,7 +21,7 @@ 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 +72,9 @@ class LinuxSSH(Test): 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: %d", port) - self.ssh_session = ssh.Session(self.VM_IP, port=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 +95,7 @@ class LinuxSSH(Test): 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 -36
@@ -10,7 +10,6 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available -from qemu.utils import get_info_usernet_hostfwd_port def run_cmd(args):
@@ -76,41 +75,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.25.4
PATCH 7/22 tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Cleber RosaIf 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.
--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/acceptance/virtiofs_submounts.py +1 -1
@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): 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.25.4
PATCH 18/22 Acceptance Tests: set up existing ssh keys by default
In reply to Cleber RosaIt's questionable wether it's necessary to create one brand new pair for each test. It's not questionable that it takes less time and resources to just use the keys available at "tests/keys" that exist for that exact reason.
If a location for the public key is not given explicitly, the LinuxTest will now set up the existing pair of keys as the default. This removes the need for a lot of boiler plate code.
To avoid the ssh client from erroring on permission issues, a directory with restricive permissions is created for the private key. This should still be a lot cheaper than creating a new key.
--- tests/acceptance/avocado_qemu/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
tests/acceptance/avocado_qemu/__init__.py +14 -0
@@ -11,6 +11,7 @@ import logging import os import re +import shutil import sys import uuid import tempfile
@@ -301,8 +302,21 @@ class LinuxTest(Test, LinuxSSHMixIn): self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') self.set_up_boot() + if ssh_pubkey is None: + ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys() self.set_up_cloudinit(ssh_pubkey) + def set_up_existing_ssh_keys(self): + ssh_public_key = os.path.join(SOURCE_DIR, 'tests', 'keys', 'id_rsa.pub') + source_private_key = os.path.join(SOURCE_DIR, 'tests', 'keys', 'id_rsa') + ssh_dir = os.path.join(self.workdir, '.ssh') + os.mkdir(ssh_dir, mode=0o700) + ssh_private_key = os.path.join(ssh_dir, + os.path.basename(source_private_key)) + shutil.copyfile(source_private_key, ssh_private_key) + os.chmod(ssh_private_key, 0o600) + return (ssh_public_key, ssh_private_key) + def download_boot(self): self.log.debug('Looking for and selecting a qemu-img binary to be ' 'used to create the bootable snapshot image')
Signature · 1 line
2.25.4
Re: [PATCH 19/22] Acceptance Tests: add port redirection for ssh by default
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 2 ++ tests/acceptance/virtiofs_submounts.py | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 13 lines
tests/acceptance/avocado_qemu/__init__.py class LinuxTest(Test, LinuxSSHMixIn): · line 305
Quoted 10 lines
tests/acceptance/avocado_qemu/__init__.py +2
-0@@ -301,6 +301,8 @@ class LinuxTest(Test, LinuxSSHMixIn): super(LinuxTest, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', 'virtio-net,netdev=vnet')You need a machine with a virtio-bus to be able to plug a virtio device, not all provide one.
Alternatively you could provide a network_device_type argument to setUp() which has to be explicitly set (since the tests would be pointless without network access).
Re: [PATCH 19/22] Acceptance Tests: add port redirection for ssh by default
In reply to Cleber RosaQuoted 15 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 2 ++ tests/acceptance/virtiofs_submounts.py | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-)tests/acceptance/avocado_qemu/__init__.py +0
-0
tests/acceptance/avocado_qemu/__init__.py class LinuxTest(Test, LinuxSSHMixIn): · line 305
Quoted 5 lines
tests/acceptance/avocado_qemu/__init__.py +2
-0@@ -301,6 +301,8 @@ class LinuxTest(Test, LinuxSSHMixIn): super(LinuxTest, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', 'virtio-net,netdev=vnet')
You need a machine with a virtio-bus to be able to plug a virtio device, not all provide one.
Re: [PATCH 02/22] tests/acceptance/boot_linux.py: rename misleading cloudinit method
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
There's no downloading happening on that method, so let's call it "prepare" instead. While at it, and because of it, the current "
prepare_boot" and "prepare_cloudinit" are also renamed.The reasoning here is that "
prepare_" methods will just work on the images, while "set_up_" will make them effective to the VM that will be launched. Inspiration comes from the "virtiofs_submounts.py" tests, which this expects to converge more into.
Quoted 4 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/boot_linux.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Re: [PATCH 01/22] tests/acceptance/boot_linux.py: fix typo on cloudinit error message
In reply to Cleber RosaQuoted 1 line · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 01/22] tests/acceptance/boot_linux.py: fix typo on cloudinit error message
In reply to Cleber RosaQuoted 4 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/boot_linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH 02/22] tests/acceptance/boot_linux.py: rename misleading cloudinit method
In reply to Cleber RosaQuoted 10 lines · Cleber Rosa
There's no downloading happening on that method, so let's call it "prepare" instead. While at it, and because of it, the current "
prepare_boot" and "prepare_cloudinit" are also renamed.The reasoning here is that "
prepare_" methods will just work on the images, while "set_up_" will make them effective to the VM that will be launched. Inspiration comes from the "virtiofs_submounts.py" tests, which this expects to converge more into.Signed-off-by Cleber Rosa <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 03/22] Acceptance Tests: remove unnecessary tag from documentation example
In reply to Cleber RosaQuoted 4 lines · Cleber Rosa
The ":avocado: enable" is not necessary and was removed in
9531d26c, so let's remove from the docs.Signed-off-by Cleber Rosa <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 02/22] tests/acceptance/boot_linux.py: rename misleading cloudinit method
In reply to Cleber RosaQuoted 51 lines · Cleber Rosa
There's no downloading happening on that method, so let's call it "prepare" instead. While at it, and because of it, the current "
prepare_boot" and "prepare_cloudinit" are also renamed.The reasoning here is that "
prepare_" methods will just work on the images, while "set_up_" will make them effective to the VM that will be launched. Inspiration comes from the "virtiofs_submounts.py" tests, which this expects to converge more into.Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/boot_linux.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)tests/acceptance/boot_linux.py +6
-6@@ -57,7 +57,7 @@ class BootLinuxBase(Test): self.cancel('Failed to download/prepare boot image') return boot.path - def download_cloudinit(self, ssh_pubkey=None): + def prepare_cloudinit(self, ssh_pubkey=None): self.log.info('Preparing cloudinit image') try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso')@@ -85,15 +85,15 @@ class BootLinux(BootLinuxBase): super(BootLinux, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') - self.prepare_boot() - self.prepare_cloudinit(ssh_pubkey) + self.set_up_boot() + self.set_up_cloudinit(ssh_pubkey) - def prepare_boot(self): + def set_up_boot(self): path = self.download_boot() self.vm.add_args('-drive', 'file=%s' % path) - def prepare_cloudinit(self, ssh_pubkey=None): - cloudinit_iso = self.download_cloudinit(ssh_pubkey) + 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):Signature · 1 line
2.25.4
Re: [PATCH 04/22] tests/acceptance/virtiofs_submounts.py: use workdir property
In reply to Cleber RosaQuoted 6 lines · Cleber Rosa
For Avocado Instrumented based tests, it's a better idea to just use the property. The environment variable is a fall back for tests not written using that Python API.
Reference: https://avocado-framework.readthedocs.io/en/84.0/api/test/avocado.html#avocado.Test.workdir
Signed-off-by Cleber Rosa <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 04/22] tests/acceptance/virtiofs_submounts.py: use workdir property
In reply to Cleber RosaQuoted 37 lines · Cleber Rosa
For Avocado Instrumented based tests, it's a better idea to just use the property. The environment variable is a fall back for tests not written using that Python API.
Reference: https://avocado-framework.readthedocs.io/en/84.0/api/test/avocado.html#avocado.Test.workdir
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)tests/acceptance/virtiofs_submounts.py +2
-4@@ -136,8 +136,7 @@ class VirtiofsSubmountsTest(BootLinux): return (stdout, stderr, ret) def set_up_shared_dir(self): - atwd = os.getenv('AVOCADO_TEST_WORKDIR') - self.shared_dir = os.path.join(atwd, 'virtiofs-shared') + self.shared_dir = os.path.join(self.workdir, 'virtiofs-shared') os.mkdir(self.shared_dir)@@ -234,8 +233,7 @@ class VirtiofsSubmountsTest(BootLinux): self.seed = self.params.get('seed') - atwd = os.getenv('AVOCADO_TEST_WORKDIR') - self.ssh_key = os.path.join(atwd, 'id_ed25519') + self.ssh_key = os.path.join(self.workdir, 'id_ed25519') self.run(('ssh-keygen', '-t', 'ed25519', '-f', self.ssh_key))Signature · 1 line
2.25.4
Re: [PATCH 05/22] tests/acceptance/virtiofs_submounts.py: do not ask for ssh key password
In reply to Cleber RosaQuoted 25 lines · Cleber Rosa
Tests are supposed to be non-interactive, and ssh-keygen is asking for a password when creating a key. Let's set an empty key, which prevents ssh-keygen for asking for a password.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +1
-1@@ -235,7 +235,7 @@ class VirtiofsSubmountsTest(BootLinux): self.ssh_key = os.path.join(self.workdir, 'id_ed25519') - self.run(('ssh-keygen', '-t', 'ed25519', '-f', self.ssh_key)) + self.run(('ssh-keygen', '-N', '', '-t', 'ed25519', '-f', self.ssh_key)) pubkey = open(self.ssh_key + '.pub').read()Signature · 1 line
2.25.4
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Cleber RosaQuoted 28 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): 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.25.4
Re: [PATCH 05/22] tests/acceptance/virtiofs_submounts.py: do not ask for ssh key password
In reply to Cleber RosaQuoted 3 lines · Cleber Rosa
Tests are supposed to be non-interactive, and ssh-keygen is asking for a password when creating a key. Let's set an empty key, which prevents ssh-keygen for asking for a password.
We are not generating an empty key, just one that isn't protected by a passphrase. So:
Tests are supposed to be non-interactive, and ssh-keygen is asking for a passphrase when creating a key. Let's set an empty passphrase to avoid the prompt.
Otherwise:
Signature · 1 line
Alex Bennée
Re: [PATCH 08/22] tests/acceptance/virtiofs_submounts.py: standardize port as integer
In reply to Cleber RosaQuoted 41 lines · Cleber Rosa
Instead of having to cast it whenever it's going to be used, let's standardize it as an integer, which is the data type that will be used most often.
Given that the regex will only match digits, it's safe that we'll end up getting a integer, but, it could as well be a zero.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)tests/acceptance/virtiofs_submounts.py +4
-3@@ -86,17 +86,18 @@ class VirtiofsSubmountsTest(BootLinux): re.search(r'TCP.HOST_FORWARD.*127\.0\.0\.1\s*(\d+)\s+10\.', line) if match is not None: - port = match[1] + port = int(match[1]) break self.assertIsNotNone(port) - self.log.debug('sshd listening on port: ' + 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=int(port), + self.ssh_session = ssh.Session('127.0.0.1', port=port, user=username, key=keyfile) for i in range(10): try:Signature · 1 line
2.25.4
Re: [PATCH 16/22] Acceptance Tests: introduce method for requiring an accelerator
In reply to Cleber RosaQuoted 11 lines · Cleber Rosa
Some tests explicitly require a QEMU accelerator to be available. Given that this depends on some runtime aspects not known before the test is started, such as the currently set QEMU binary, it's left to be checked also at runtime.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 24 ++++++++++++++++ tests/acceptance/boot_linux.py | 34 ++++++----------------- tests/acceptance/virtiofs_submounts.py | 5 +--- 3 files changed, 34 insertions(+), 29 deletions(-)
Re: [PATCH 06/22] tests/acceptance/virtiofs_submounts.py: use a virtio-net device instead
In reply to Cleber RosaQuoted 4 lines · Cleber Rosa
In a virtiofs based tests, it seems safe to assume that the guest will be capable of a virtio-net device.
Signed-off-by Cleber Rosa <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Cleber RosaQuoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0
tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')
And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run ./tests/acceptance/virtiofs_submounts.py
JOB ID : b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG : /home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 s
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are. FWIW I also had the following locally applied to workaround the fact the losetup and mkfs.xfs binaries aren't visible to normal users.
modified tests/acceptance/virtiofs_submounts.py
@@ -173,7 +173,10 @@ class VirtiofsSubmountsTest(LinuxTest):
self.run(('bash', self.get_data('cleanup.sh'), scratch_dir))
@skipUnless(*has_cmds(('sudo -n', ('sudo', '-n', 'true')),
- 'ssh-keygen', 'bash', 'losetup', 'mkfs.xfs', 'mount'))
+ 'ssh-keygen', 'bash',
+ ('losetup', ('sudo', '-n', 'losetup')),
+ ('mkfs.xfs', ('sudo', '-n', 'which', 'mkfs.xfs')),
+ 'mount')) def setUp(self):
vmlinuz = self.params.get('vmlinuz')
if vmlinuz is None:
Signature · 1 line
Alex Bennée
Re: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to Cleber RosaQuoted 8 lines · Cleber Rosa
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.util" module to host the utility function and a test.
qemu.utils, with the s!
And, OK, this makes me feel less weird about creating a qemu.utils package, actually.
ACK (but not reviewed, tested or linted) for the new code heading into python/qemu/.
--js
Quoted 35 lines
Signed-off-by Cleber Rosa <[email protected]>--- python/qemu/utils.py | 35 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------ tests/acceptance/virtiofs_submounts.py | 20 +++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 77 insertions(+), 30 deletions(-)create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/info_usernet.pypython/qemu/utils.py new file +18
-0@@ -0,0 +1,35 @@ +""" +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
python/qemu/utils.py line 28
Quoted 10 lines
python/qemu/utils.py new file +10
-0+ + +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" + :param info_usernet_output: str + :return: the port number allocated by the hostfwd option + :rtype: int
We can probably delete the :rtype: field, can't we? Annotations should handle this information now.
(Unless some tool needs it for compatibility reasons, but we don't use this field anywhere else in ./python/ yet.)
Re: [PATCH 09/22] tests/acceptance/virtiofs_submounts.py: required space between IP and port
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
AFAICT, there should not be a situation where IP and port do not have at least one whitespace character separating them.
This may be true for other '\s*' patterns in the same regex too.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [PATCH 13/22] tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to Cleber RosaQuoted 1 line · Cleber Rosa
Which is useful to select tests that depend/use a particular feature.
Is that a question?
Why keep this last in your series?
Quoted 18 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 1 + 1 file changed, 1 insertion(+)tests/acceptance/virtiofs_submounts.py +1
-0@@ -75,6 +75,7 @@ def has_cmds(*cmds): class VirtiofsSubmountsTest(BootLinux): """ :avocado: tags=arch:x86_64 + :avocado: tags=accel:kvm """ def ssh_connect(self, username, keyfile):
Re: [PATCH 11/22] tests/acceptance/linux_ssh_mips_malta.py: standardize port as integer
In reply to Cleber RosaQuoted 4 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/linux_ssh_mips_malta.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 35 lines · Cleber Rosa
This introduces a base class for tests that need to interact with a Linux guest. It generalizes the "
boot_linux.py" code, already been used by the "virtiofs_submounts.py" and also SSH related code being used by that and "linux_ssh_mips_malta.py".While at it, a number of fixes on hopeful improvements to those tests were added.
Cleber Rosa (22):
tests/acceptance/boot_linux.py: fix typo on cloudinit error messagetests/acceptance/boot_linux.py: rename misleading cloudinit method Acceptance Tests: remove unnecessary tag from documentation exampletests/acceptance/virtiofs_submounts.py: use workdir propertytests/acceptance/virtiofs_submounts.py: do not ask for ssh key
password
tests/acceptance/virtiofs_submounts.py: use a virtio-net device
instead
tests/acceptance/virtiofs_submounts.py: evaluate string not lengthtests/acceptance/virtiofs_submounts.py: standardize port as integertests/acceptance/virtiofs_submounts.py: required space between IP and
port
Python: add utility function for retrieving port redirectiontests/acceptance/linux_ssh_mips_malta.py: standardize port as integer Acceptance tests: clarify ssh connection failure reasontests/acceptance/virtiofs_submounts.py: add missing accel tag Acceptance Tests: introduce LinuxTest base class Acceptance Tests: move useful ssh methods to base class Acceptance Tests: introduce method for requiring an accelerator Acceptance Tests: fix population of public key in cloudinit image Acceptance Tests: set up existing ssh keys by default Acceptance Tests: add port redirection for ssh by default Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test
[NOTFORMERGE] Bump Avocado version to latest master
Quoted 14 lines
docs/devel/testing.rst | 29 +++- python/qemu/utils.py | 35 +++++ tests/acceptance/avocado_qemu/__init__.py | 176 ++++++++++++++++++++++ tests/acceptance/boot_linux.py | 128 ++-------------- tests/acceptance/hotplug_cpu.py | 38 +++++ tests/acceptance/info_usernet.py | 29 ++++ tests/acceptance/linux_ssh_mips_malta.py | 44 +----- tests/acceptance/virtiofs_submounts.py | 73 +-------- tests/requirements.txt | 2 +- tests/vm/basevm.py | 7 +- 10 files changed, 334 insertions(+), 227 deletions(-) create mode 100644 python/qemu/utils.py create mode 100644 tests/acceptance/hotplug_cpu.py create mode 100644 tests/acceptance/info_usernet.py
Patches 1-6, 8-9 & 12 queued.
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Alex BennéeQuoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 s
Quoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case “-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or
“-p vmlinuz=''”.
Ideally, vmlinuz='' would be the default, but there’s a problem with that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).
Using vmlinuz='' you can test it with the kernel that is part of the cloud image. Once that kernel is sufficiently new (i.e., >=5.10), we can make that the default.
Max
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
Quoted 57 lines · Max Reitz
Quoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 sQuoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case
“-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or “-p vmlinuz=''”.
Quoted 5 lines
Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).
This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself. At the least it would be worth pointing to a part of our docs on how to build such an image.
Quoted 3 lines
Using vmlinuz='' you can test it with the kernel that is part of the cloud image. Once that kernel is sufficiently new (i.e., >=5.10), we can make that the default.
Good.
Quoted 2 lines
Max
Signature · 1 line
Alex Bennée
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
Quoted 60 lines · Alex Bennée
Quoted 57 lines · Max Reitz
Quoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 sQuoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case
“-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or “-p vmlinuz=''”.
Quoted 8 lines
Quoted 5 lines
Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself.
Yes, but there’s nothing I can do apart from just not having the test as part of qemu, which I don’t find better than to just cancel it when not run with the necessary parameters.
Or, well, I could let the test download and compile the Linux sources, but I don’t think that’s a viable alternative.
Quoted 2 lines
At the least it would be worth pointing to a part of our docs on how to build such an image.
Well, I could perhaps come up with a comprehensive kernel configuration that works, but I really don’t think that’s valuable for people who just want to run the acceptance tests and don’t care about this test in particular. I just don’t think they’re actually going to build a Linux kernel just for it.
(Alternatively, I could just build a Linux kernel here on my machine, upload the binary and point to it somewhere, e.g. in the cancel message.
That would be OK for me, and perhaps something I could imagine someone
might actually use.)
I’d rather just wait until the test image contains a kernel that’s sufficiently new (should be the case once Fedora 34 is out), so we can make -p vmlinuz='' the default. Until then I personally find it completely reasonable to have this test just be cancelled.
Max
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
Quoted 67 lines · Max Reitz
Quoted 66 lines · Alex Bennée
Quoted 62 lines · Max Reitz
Quoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 sQuoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case
“-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or “-p vmlinuz=''”.Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).
Quoted 6 lines
Quoted 2 lines
This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself.
Yes, but there’s nothing I can do apart from just not having the test as part of qemu, which I don’t find better than to just cancel it when not run with the necessary parameters.
No I agree having the tests is useful.
Quoted 3 lines
Or, well, I could let the test download and compile the Linux sources, but I don’t think that’s a viable alternative.
There has been discussion before but I agree it's not viable given the compile times for such things.
Quoted 8 lines
Quoted 2 lines
At the least it would be worth pointing to a part of our docs on how to build such an image.
Well, I could perhaps come up with a comprehensive kernel configuration that works, but I really don’t think that’s valuable for people who just want to run the acceptance tests and don’t care about this test in particular. I just don’t think they’re actually going to build a Linux kernel just for it.
Sure - but I was trying to review the series and as part of my review I generally like to run the things I review. Hence why I stopped as I couldn't get things running.
Quoted 4 lines
(Alternatively, I could just build a Linux kernel here on my machine, upload the binary and point to it somewhere, e.g. in the cancel message.
That would be OK for me, and perhaps something I could imagine someone
might actually use.)
I've actually done this with some Xen patches I'm working on at the moment. I'll probably decorate the test with:
@skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
with a comment explaining what's waiting to be upstreamed. Once there are upstream binaries I plan on transitioning the test to those.
Quoted 6 lines
I’d rather just wait until the test image contains a kernel that’s sufficiently new (should be the case once Fedora 34 is out), so we can make -p vmlinuz='' the default. Until then I personally find it completely reasonable to have this test just be cancelled.
Max
Signature · 1 line
Alex Bennée
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
Quoted 104 lines · Alex Bennée
Quoted 67 lines · Max Reitz
Quoted 66 lines · Alex Bennée
Quoted 62 lines · Max Reitz
Quoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 sQuoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case
“-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or “-p vmlinuz=''”.Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).Quoted 6 lines
Quoted 2 lines
This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself.
Yes, but there’s nothing I can do apart from just not having the test as part of qemu, which I don’t find better than to just cancel it when not run with the necessary parameters.
No I agree having the tests is useful.
Quoted 3 lines
Or, well, I could let the test download and compile the Linux sources, but I don’t think that’s a viable alternative.
There has been discussion before but I agree it's not viable given the compile times for such things.
Quoted 8 lines
Quoted 2 lines
At the least it would be worth pointing to a part of our docs on how to build such an image.
Well, I could perhaps come up with a comprehensive kernel configuration that works, but I really don’t think that’s valuable for people who just want to run the acceptance tests and don’t care about this test in particular. I just don’t think they’re actually going to build a Linux kernel just for it.
Sure - but I was trying to review the series and as part of my review I generally like to run the things I review. Hence why I stopped as I couldn't get things running.
Quoted 4 lines
(Alternatively, I could just build a Linux kernel here on my machine, upload the binary and point to it somewhere, e.g. in the cancel message.
That would be OK for me, and perhaps something I could imagine someone
might actually use.)
Quoted 7 lines
I've actually done this with some Xen patches I'm working on at the moment. I'll probably decorate the test with:
@skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
with a comment explaining what's waiting to be upstreamed. Once there are upstream binaries I plan on transitioning the test to those.
Oh, so you’d be fine with an in-code comment that explains why the parameter is required right now, but will be optional in the future? If so, sounds good to me.
Max
Re: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to Cleber RosaHi,
Quoted 16 lines · Cleber Rosa
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.util" module to host the utility function and a test.
Signed-off-by Cleber Rosa <[email protected]>--- python/qemu/utils.py | 35 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------ tests/acceptance/virtiofs_submounts.py | 20 +++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 77 insertions(+), 30 deletions(-)
Quoted 2 lines
create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/info_usernet.py
I've a few suggestions:
- IMHO "utils" is too broad, people may start throwing random stuffs there. Maybe call it "net". I am sure there will be more net-related code to be clustered on that module in the future.
- Rename the method to "get_hostfwd_port()" because the parameter's name already implies it is expected an "info usernet" output.
- Drop the InfoUsernet Test. It is too simple, and the same functionality is tested indirectly by other tests.
Quoted 95 lines
python/qemu/utils.py new file +35
-0@@ -0,0 +1,35 @@ +""" +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" + :param info_usernet_output: str + :return: the port number allocated by the hostfwd option + :rtype: int + """ + 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 Nonetests/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 +2
-1@@ -18,6 +18,8 @@ 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):@@ -70,18 +72,14 @@ class LinuxSSH(Test): def setUp(self): super(LinuxSSH, self).setUp() - def get_portfwd(self):
tests/acceptance/linux_ssh_mips_malta.py class LinuxSSH(Test): · line 81
Quoted 10 lines
tests/acceptance/linux_ssh_mips_malta.py +5
-3+ 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")
Here I think it should assert not none, otherwise there is a bug somewhere.
- Wainer
Quoted 77 lines
tests/acceptance/linux_ssh_mips_malta.py +0
-5self.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 +4
-16@@ -10,6 +10,7 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available +from qemu.utils import get_info_usernet_hostfwd_port from boot_linux import BootLinux@@ -76,27 +77,14 @@ class VirtiofsSubmountsTest(BootLinux): :avocado: tags=arch:x86_64 """ - 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 @@ 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 import subprocess import hashlib import argparse@@ -306,11 +307,7 @@ class BaseVM(object): 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)
Re: [PATCH 13/22] tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to Cleber RosaQuoted 6 lines · Cleber Rosa
Which is useful to select tests that depend/use a particular feature.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
tests/acceptance/virtiofs_submounts.py +1
-0@@ -75,6 +75,7 @@ def has_cmds(*cmds): class VirtiofsSubmountsTest(BootLinux): """ :avocado: tags=arch:x86_64 + :avocado: tags=accel:kvm """ def ssh_connect(self, username, keyfile):
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Max ReitzQuoted 108 lines · Max Reitz
Quoted 107 lines · Alex Bennée
Quoted 67 lines · Max Reitz
Quoted 66 lines · Alex Bennée
Quoted 62 lines · Max Reitz
Quoted 42 lines · Alex Bennée
Quoted 17 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/acceptance/virtiofs_submounts.py +0
-0tests/acceptance/virtiofs_submounts.py class VirtiofsSubmountsTest(BootLinux): · line 246
Quoted 7 lines
tests/acceptance/virtiofs_submounts.py +1
-1@@ -241,7 +241,7 @@ class VirtiofsSubmountsTest(BootLinux): super(VirtiofsSubmountsTest, self).setUp(pubkey) - if len(vmlinuz) > 0: + if vmlinuz: self.vm.add_args('-kernel', vmlinuz, '-append', 'console=ttyS0 root=/dev/sda1')And this is were I gave up because I can't see how to run the test:
./tests/venv/bin/avocado run
./tests/acceptance/virtiofs_submounts.py
JOB ID :b3d9bfcfcd603189a471bec7d770fca3b50a81ee
JOB LOG :/home/alex/avocado/job-results/job-2021-02-04T13.21-b3d9bfc/job.log
(1/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (2/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (3/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_launch_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary
to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
(4/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_post_mount_set_up: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s) (5/5) ./tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_two_runs: CANCEL: vmlinuz parameter not set; you must point it to a Linux kernel binary to test (to run this test with the on-image kernel, set it to an empty string) (0.00 s)
RESULTS : PASS 0 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 5
JOB TIME : 0.56 sQuoted 3 lines
Given the test seems to make assumptions about an environment being setup for it I think we need some documentation somewhere about what those pre-requisites are.
I find the cancel message pretty clear, but then again it was me who wrote it...
Either you point the vmlinuz parameter to some Linux kernel you built yourself, or you set it to the empty string to just use the kernel that’s part of the image. Setting Avocado parameters is done via -p, i.e. “-p key=value”. So in this case
“-p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage”, or “-p vmlinuz=''”.Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).Quoted 6 lines
Quoted 2 lines
This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself.
Yes, but there’s nothing I can do apart from just not having the test as part of qemu, which I don’t find better than to just cancel it when not run with the necessary parameters.
No I agree having the tests is useful.
Quoted 3 lines
Or, well, I could let the test download and compile the Linux sources, but I don’t think that’s a viable alternative.
There has been discussion before but I agree it's not viable given the compile times for such things.
Quoted 8 lines
Quoted 2 lines
At the least it would be worth pointing to a part of our docs on how to build such an image.
Well, I could perhaps come up with a comprehensive kernel configuration that works, but I really don’t think that’s valuable for people who just want to run the acceptance tests and don’t care about this test in particular. I just don’t think they’re actually going to build a Linux kernel just for it.
Sure - but I was trying to review the series and as part of my review I generally like to run the things I review. Hence why I stopped as I couldn't get things running.
Quoted 4 lines
(Alternatively, I could just build a Linux kernel here on my machine, upload the binary and point to it somewhere, e.g. in the cancel message.
That would be OK for me, and perhaps something I could imagine someone
might actually use.)I've actually done this with some Xen patches I'm working on at the moment. I'll probably decorate the test with:
Quoted 8 lines
Quoted 4 lines
@skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
with a comment explaining what's waiting to be upstreamed. Once there are upstream binaries I plan on transitioning the test to those.
Oh, so you’d be fine with an in-code comment that explains why the parameter is required right now, but will be optional in the future? If so, sounds good to me.
Yes that would be great ;-)
Signature · 1 line
Alex Bennée
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Alex BennéeQuoted 6 lines · Alex Bennée
Quoted 5 lines · Max Reitz
Quoted 4 lines · Alex Bennée
Quoted 3 lines · Max Reitz
Quoted 2 lines · Alex Bennée
Cleber Rosa <[email protected]> writes:
...
Quoted 40 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Ideally, vmlinuz='' would be the default, but there’s a problem with
that: I submitted this test along with the patches that added the required feature to the Linux kernel, so at that point that feature was not part of Linux. That’s why you generally have to point it to a Linux kernel binary you built yourself that has this feature (5.10 does).Quoted 6 lines
Quoted 2 lines
This is where it deviates from the rest of the check-acceptance tests. Generally I don't have to worry about finding the right image myself.
Yes, but there’s nothing I can do apart from just not having the test as part of qemu, which I don’t find better than to just cancel it when not run with the necessary parameters.
No I agree having the tests is useful.
Quoted 3 lines
Or, well, I could let the test download and compile the Linux sources, but I don’t think that’s a viable alternative.
There has been discussion before but I agree it's not viable given the compile times for such things.
Quoted 8 lines
Quoted 2 lines
At the least it would be worth pointing to a part of our docs on how to build such an image.
Well, I could perhaps come up with a comprehensive kernel configuration that works, but I really don’t think that’s valuable for people who just want to run the acceptance tests and don’t care about this test in particular. I just don’t think they’re actually going to build a Linux kernel just for it.
Sure - but I was trying to review the series and as part of my review I generally like to run the things I review. Hence why I stopped as I couldn't get things running.
Quoted 4 lines
(Alternatively, I could just build a Linux kernel here on my machine, upload the binary and point to it somewhere, e.g. in the cancel message.
That would be OK for me, and perhaps something I could imagine someone
might actually use.)
Quoted 7 lines
I've actually done this with some Xen patches I'm working on at the moment. I'll probably decorate the test with:
@skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
with a comment explaining what's waiting to be upstreamed. Once there are upstream binaries I plan on transitioning the test to those.
Instead of a binary AVOCADO_ALLOW_UNTRUSTED_CODE variable, we could have a list allowed domains/namespaces, that can be increased on the tester discretion.
For example these are assumed trusted:
. archives.fedoraproject.org
. archive.debian.org
. cdn.netbsd.org
. github.com/torvalds
. people.debian.org/~aurel32
. snapshot.debian.org
. storage.kernelci.org
. www.qemu-advent-calendar.org
Then personally interested in testing ARM boards I'd amend:
. apt.armbian.com
. github.com/philmd
. github.com/groeck
. github.com/hskinnemoen
. github.com/pbatard
and Max's repo since I'm interested in testing virtiofs_submounts.
Re: [PATCH 14/22] Acceptance Tests: introduce LinuxTest base class
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
This is basically the infrastructure around "
boot_linux.py" tests, but now made into a base class for general use.Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 87 +++++++++++++++++++++ tests/acceptance/boot_linux.py | 94 ++--------------------- tests/acceptance/virtiofs_submounts.py | 6 +- 3 files changed, 94 insertions(+), 93 deletions(-)
Quoted 270 lines
tests/acceptance/avocado_qemu/__init__.py +87
-0@@ -16,6 +16,13 @@ import tempfile import avocado +from avocado.utils import cloudinit +from avocado.utils import datadrainer +from avocado.utils import network +from avocado.utils import vmimage +from avocado.utils.path import find_command + + #: The QEMU build root directory. It may also be the source directory #: if building from the source dir, but it's safer to use BUILD_DIR for #: that purpose. Be aware that if this code is moved outside of a source@@ -206,3 +213,83 @@ class Test(avocado.Test): expire=expire, find_only=find_only, cancel_on_missing=cancel_on_missing) + + +class LinuxTest(Test): + """Facilitates having a cloud-image Linux based available. + + For tests that indend to interact with guests, this is a better choice + to start with than the more vanilla `Test` class. + """ + + timeout = 900 + chksum = None + + def setUp(self, ssh_pubkey=None): + super(LinuxTest, self).setUp() + self.vm.add_args('-smp', '2') + self.vm.add_args('-m', '1024') + self.set_up_boot() + self.set_up_cloudinit(ssh_pubkey) + + def download_boot(self): + self.log.debug('Looking for and selecting a qemu-img binary to be ' + 'used to create the bootable snapshot image') + # If qemu-img has been built, use it, otherwise the system wide one + # will be used. If none is available, the test will cancel. + qemu_img = os.path.join(BUILD_DIR, 'qemu-img') + if not os.path.exists(qemu_img): + qemu_img = find_command('qemu-img', False) + if qemu_img is False: + self.cancel('Could not find "qemu-img", which is required to ' + 'create the bootable image') + vmimage.QEMU_IMG = qemu_img + + self.log.info('Downloading/preparing boot image') + # Fedora 31 only provides ppc64le images + image_arch = self.arch + if image_arch == 'ppc64': + image_arch = 'ppc64le' + try: + boot = vmimage.get( + 'fedora', arch=image_arch, version='31', + checksum=self.chksum, + algorithm='sha256', + cache_dir=self.cache_dirs[0], + snapshot_dir=self.workdir) + except: + self.cancel('Failed to download/prepare boot image') + return boot.path + + def prepare_cloudinit(self, ssh_pubkey=None): + self.log.info('Preparing cloudinit image') + try: + cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') + self.phone_home_port = network.find_free_port() + cloudinit.iso(cloudinit_iso, self.name, + username='root', + password='password', + # QEMU's hard coded usermode router address + phone_home_host='10.0.2.2', + phone_home_port=self.phone_home_port, + authorized_key=ssh_pubkey) + except Exception: + self.cancel('Failed to prepare the cloudinit image') + return cloudinit_iso + + def set_up_boot(self): + path = self.download_boot() + self.vm.add_args('-drive', 'file=%s' % path) + + 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): + self.vm.set_console() + self.vm.launch() + console_drainer = datadrainer.LineLogger(self.vm.console_socket.fileno(), + logger=self.log.getChild('console')) + 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)tests/acceptance/boot_linux.py +5
-89@@ -10,16 +10,11 @@ import os -from avocado_qemu import Test, BUILD_DIR +from avocado_qemu import LinuxTest, BUILD_DIR from qemu.accel import kvm_available from qemu.accel import tcg_available -from avocado.utils import cloudinit -from avocado.utils import network -from avocado.utils import vmimage -from avocado.utils import datadrainer -from avocado.utils.path import find_command from avocado import skipIf ACCEL_NOT_AVAILABLE_FMT = "%s accelerator does not seem to be available"@@ -27,86 +22,7 @@ KVM_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "KVM" TCG_NOT_AVAILABLE = ACCEL_NOT_AVAILABLE_FMT % "TCG" -class BootLinuxBase(Test): - def download_boot(self): - self.log.debug('Looking for and selecting a qemu-img binary to be ' - 'used to create the bootable snapshot image') - # If qemu-img has been built, use it, otherwise the system wide one - # will be used. If none is available, the test will cancel. - qemu_img = os.path.join(BUILD_DIR, 'qemu-img') - if not os.path.exists(qemu_img): - qemu_img = find_command('qemu-img', False) - if qemu_img is False: - self.cancel('Could not find "qemu-img", which is required to ' - 'create the bootable image') - vmimage.QEMU_IMG = qemu_img - - self.log.info('Downloading/preparing boot image') - # Fedora 31 only provides ppc64le images - image_arch = self.arch - if image_arch == 'ppc64': - image_arch = 'ppc64le' - try: - boot = vmimage.get( - 'fedora', arch=image_arch, version='31', - checksum=self.chksum, - algorithm='sha256', - cache_dir=self.cache_dirs[0], - snapshot_dir=self.workdir) - except: - self.cancel('Failed to download/prepare boot image') - return boot.path - - def prepare_cloudinit(self, ssh_pubkey=None): - self.log.info('Preparing cloudinit image') - try: - cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') - self.phone_home_port = network.find_free_port() - cloudinit.iso(cloudinit_iso, self.name, - username='root', - password='password', - # QEMU's hard coded usermode router address - phone_home_host='10.0.2.2', - phone_home_port=self.phone_home_port, - authorized_key=ssh_pubkey) - except Exception: - self.cancel('Failed to prepare the cloudinit image') - return cloudinit_iso - -class BootLinux(BootLinuxBase): - """ - Boots a Linux system, checking for a successful initialization - """ - - timeout = 900 - chksum = None - - def setUp(self, ssh_pubkey=None): - super(BootLinux, self).setUp() - self.vm.add_args('-smp', '2') - self.vm.add_args('-m', '1024') - self.set_up_boot() - self.set_up_cloudinit(ssh_pubkey) - - def set_up_boot(self): - path = self.download_boot() - self.vm.add_args('-drive', 'file=%s' % path) - - 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): - self.vm.set_console() - self.vm.launch() - console_drainer = datadrainer.LineLogger(self.vm.console_socket.fileno(), - logger=self.log.getChild('console')) - 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) - - -class BootLinuxX8664(BootLinux): +class BootLinuxX8664(LinuxTest): """ :avocado: tags=arch:x86_64 """@@ -154,7 +70,7 @@ class BootLinuxX8664(BootLinux): self.launch_and_wait() -class BootLinuxAarch64(BootLinux): +class BootLinuxAarch64(LinuxTest): """ :avocado: tags=arch:aarch64 :avocado: tags=machine:virt@@ -212,7 +128,7 @@ class BootLinuxAarch64(BootLinux): self.launch_and_wait() -class BootLinuxPPC64(BootLinux): +class BootLinuxPPC64(LinuxTest): """ :avocado: tags=arch:ppc64 """@@ -230,7 +146,7 @@ class BootLinuxPPC64(BootLinux): self.launch_and_wait() -class BootLinuxS390X(BootLinux): +class BootLinuxS390X(LinuxTest): """ :avocado: tags=arch:s390x """tests/acceptance/virtiofs_submounts.py +2
-4@@ -5,15 +5,13 @@ import subprocess import time from avocado import skipUnless -from avocado_qemu import Test, BUILD_DIR +from avocado_qemu import LinuxTest, BUILD_DIR from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available from qemu.utils import get_info_usernet_hostfwd_port -from boot_linux import BootLinux - def run_cmd(args): subp = subprocess.Popen(args,@@ -72,7 +70,7 @@ def has_cmds(*cmds): return (True, '') -class VirtiofsSubmountsTest(BootLinux): +class VirtiofsSubmountsTest(LinuxTest): """ :avocado: tags=arch:x86_64 :avocado: tags=accel:kvm
Re: [PATCH 15/22] Acceptance Tests: move useful ssh methods to base class
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
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 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.
Quoted 6 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 49 ++++++++++++++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 38 ++---------------- tests/acceptance/virtiofs_submounts.py | 36 ----------------- 3 files changed, 51 insertions(+), 72 deletions(-)
Quoted 209 lines
tests/acceptance/avocado_qemu/__init__.py +48
-1@@ -10,6 +10,7 @@ import logging import os +import re import sys import uuid import tempfile@@ -19,6 +20,7 @@ import avocado 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@@ -40,6 +42,8 @@ else: sys.path.append(os.path.join(SOURCE_DIR, 'python')) 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)@@ -215,7 +219,50 @@ class Test(avocado.Test): 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 choicetests/acceptance/linux_ssh_mips_malta.py +3
-35@@ -12,7 +12,7 @@ import logging 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@@ -21,7 +21,7 @@ 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 +72,9 @@ class LinuxSSH(Test): 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: %d", port) - self.ssh_session = ssh.Session(self.VM_IP, port=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 +95,7 @@ class LinuxSSH(Test): 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
-36@@ -10,7 +10,6 @@ from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh from qemu.accel import kvm_available -from qemu.utils import get_info_usernet_hostfwd_port def run_cmd(args):@@ -76,41 +75,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)
Re: [PATCH 17/22] Acceptance Tests: fix population of public key in cloudinit image
In reply to Cleber RosaQuoted 5 lines · Cleber Rosa
Currently the path of the ssh public key is being set, but its content is obviously what's needed.
Signed-off-by Cleber Rosa <[email protected]>
Quoted 29 lines
--- tests/acceptance/avocado_qemu/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tests/acceptance/avocado_qemu/__init__.py +3
-2@@ -337,13 +337,15 @@ class LinuxTest(Test, LinuxSSHMixIn): try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') self.phone_home_port = network.find_free_port() + with open(ssh_pubkey) as pubkey: + pubkey_content = pubkey.read() cloudinit.iso(cloudinit_iso, self.name, username='root', password='password', # QEMU's hard coded usermode router address phone_home_host='10.0.2.2', phone_home_port=self.phone_home_port, - authorized_key=ssh_pubkey) + authorized_key=pubkey_content) except Exception: self.cancel('Failed to prepare the cloudinit image') return cloudinit_iso --2.25.4
Signature · 1 line
Marc-André Lureau
Re: [PATCH 20/22] Acceptance Tests: add basic documentation on LinuxTest base class
In reply to Cleber RosaQuoted 2 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>
Quoted 45 lines
--- docs/devel/testing.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)docs/devel/testing.rst +26
-1@@ -790,6 +790,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. 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_connect('root', self.ssh_key) + 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 ~~~~~~~~~~~ --2.25.4
Signature · 1 line
Marc-André Lureau
Re: [PATCH 18/22] Acceptance Tests: set up existing ssh keys by default
In reply to Cleber RosaHi
Quoted 2 lines · Cleber Rosa
It's questionable wether it's necessary to create one brand new pair
whether
Quoted 7 lines
for each test. It's not questionable that it takes less time and resources to just use the keys available at "tests/keys" that exist for that exact reason.
If a location for the public key is not given explicitly, the LinuxTest will now set up the existing pair of keys as the default. This removes the need for a lot of boiler plate code.
boilerplate
Quoted 3 lines
To avoid the ssh client from erroring on permission issues, a directory with restricive permissions is created for the private key.
restrictive
Quoted 3 lines
This should still be a lot cheaper than creating a new key.
Signed-off-by Cleber Rosa <[email protected]>
Quoted 42 lines
--- tests/acceptance/avocado_qemu/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)tests/acceptance/avocado_qemu/__init__.py +14
-1@@ -11,6 +11,7 @@ import logging import os import re +import shutil import sys import uuid import tempfile@@ -301,8 +302,21 @@ class LinuxTest(Test, LinuxSSHMixIn): self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') self.set_up_boot() + if ssh_pubkey is None: + ssh_pubkey, self.ssh_key = self.set_up_existing_ssh_keys() self.set_up_cloudinit(ssh_pubkey) + def set_up_existing_ssh_keys(self): + ssh_public_key = os.path.join(SOURCE_DIR, 'tests', 'keys', 'id_rsa.pub') + source_private_key = os.path.join(SOURCE_DIR, 'tests', 'keys', 'id_rsa') + ssh_dir = os.path.join(self.workdir, '.ssh') + os.mkdir(ssh_dir, mode=0o700) + ssh_private_key = os.path.join(ssh_dir, + os.path.basename(source_private_key)) + shutil.copyfile(source_private_key, ssh_private_key) + os.chmod(ssh_private_key, 0o600) + return (ssh_public_key, ssh_private_key) + def download_boot(self): self.log.debug('Looking for and selecting a qemu-img binary to be ' 'used to create the bootable snapshot image') --2.25.4
Signature · 1 line
Marc-André Lureau
Re: [PATCH 21/22] Acceptance Tests: introduce CPU hotplug test
In reply to Cleber RosaQuoted 10 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>
Quoted 53 lines
--- tests/acceptance/hotplug_cpu.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/acceptance/hotplug_cpu.pytests/acceptance/hotplug_cpu.py new file +38
-1@@ -0,0 +1,38 @@ +# 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_connect('root', self.ssh_key) + 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') --2.25.4
Signature · 1 line
Marc-André Lureau
Re: [PATCH 22/22] [NOTFORMERGE] Bump Avocado version to latest master
In reply to Cleber RosaHi
Quoted 11 lines · Cleber Rosa
This is intende to be replaced by a bump to Avocado 85.0, to be released by Feb 8 2021.
Latest master contains an improvement to "avocado.utils.vmimage" that let's it download older Fedora images from the archive locations. That allows the currently set Fedora 31 images to continue being used.
Reference: https://github.com/avocado-framework/avocado/milestone/11
Reference: https://github.com/avocado-framework/avocado/commit/e4d67e96ee9563436dcf7dd83902723576657d29Signed-off-by Cleber Rosa <[email protected]>
Although it's not a panacea to use its API, you may consider using osinfo in the future. I gave it a 5min try to have:
import gigi.require_version('Libosinfo', '1.0')
from gi.repository import Libosinfo
l = Libosinfo.Loader.new()l.process_system_path()
db = l.get_db()
os = db.get_os_list().get_elements()
for o in os:
for l in o.get_image_list().get_elements():
print(l.get_url())
Quoted 19 lines
--- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/requirements.txt +1
-2@@ -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==83.0 +git+https://github.com/avocado-framework/avocado@9b372adeec6dceaba276ca4729f2e5a2fcccaa4c#egg=avocado_framework pycdlib==1.11.0 --2.25.4
Signature · 1 line
Marc-André Lureau
Re: [PATCH 20/22] Acceptance Tests: add basic documentation on LinuxTest base class
In reply to Cleber RosaQuoted 6 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>--- docs/devel/testing.rst | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
Re: [PATCH 17/22] Acceptance Tests: fix population of public key in cloudinit image
In reply to Cleber RosaQuoted 7 lines · Cleber Rosa
Currently the path of the ssh public key is being set, but its content is obviously what's needed.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 22 lines
tests/acceptance/avocado_qemu/__init__.py +3
-1@@ -337,13 +337,15 @@ class LinuxTest(Test, LinuxSSHMixIn): try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') self.phone_home_port = network.find_free_port() + with open(ssh_pubkey) as pubkey: + pubkey_content = pubkey.read() cloudinit.iso(cloudinit_iso, self.name, username='root', password='password', # QEMU's hard coded usermode router address phone_home_host='10.0.2.2', phone_home_port=self.phone_home_port, - authorized_key=ssh_pubkey) + authorized_key=pubkey_content) except Exception: self.cancel('Failed to prepare the cloudinit image') return cloudinit_iso
Hi,
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 46 lines · Cleber Rosa
This introduces a base class for tests that need to interact with a Linux guest. It generalizes the "
boot_linux.py" code, already been used by the "virtiofs_submounts.py" and also SSH related code being used by that and "linux_ssh_mips_malta.py".While at it, a number of fixes on hopeful improvements to those tests were added.
Cleber Rosa (22):
tests/acceptance/boot_linux.py: fix typo on cloudinit error messagetests/acceptance/boot_linux.py: rename misleading cloudinit method Acceptance Tests: remove unnecessary tag from documentation exampletests/acceptance/virtiofs_submounts.py: use workdir propertytests/acceptance/virtiofs_submounts.py: do not ask for ssh key
password
tests/acceptance/virtiofs_submounts.py: use a virtio-net device
instead
tests/acceptance/virtiofs_submounts.py: evaluate string not lengthtests/acceptance/virtiofs_submounts.py: standardize port as integertests/acceptance/virtiofs_submounts.py: required space between IP and
port
Python: add utility function for retrieving port redirectiontests/acceptance/linux_ssh_mips_malta.py: standardize port as integer Acceptance tests: clarify ssh connection failure reasontests/acceptance/virtiofs_submounts.py: add missing accel tag Acceptance Tests: introduce LinuxTest base class Acceptance Tests: move useful ssh methods to base class Acceptance Tests: introduce method for requiring an accelerator Acceptance Tests: fix population of public key in cloudinit image Acceptance Tests: set up existing ssh keys by default Acceptance Tests: add port redirection for ssh by default Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test [NOTFORMERGE] Bump Avocado version to latest masterdocs/devel/testing.rst | 29 +++- python/qemu/utils.py | 35 +++++ tests/acceptance/avocado_qemu/__init__.py | 176 ++++++++++++++++++++++ tests/acceptance/boot_linux.py | 128 ++-------------- tests/acceptance/hotplug_cpu.py | 38 +++++ tests/acceptance/info_usernet.py | 29 ++++ tests/acceptance/linux_ssh_mips_malta.py | 44 +----- tests/acceptance/virtiofs_submounts.py | 73 +-------- tests/requirements.txt | 2 +- tests/vm/basevm.py | 7 +- 10 files changed, 334 insertions(+), 227 deletions(-)Quoted 3 lines
create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/hotplug_cpu.pycreate mode 100644tests/acceptance/info_usernet.py
Quoted 1 line
Patches 1-6, 8-9 & 12 queued.
Those are merged. Most of the remaining patches got at least one review, so could you (Cleber or Philippe) open a pull request for them as well? Telling it because there are many series in flight for the acceptance tests, and to avoid conflicts with future series...
Thanks!
- Wainer
Quoted 2 lines
Quoted 53 lines · Wainer dos Santos Moschetta
Hi,
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 49 lines · Cleber Rosa
This introduces a base class for tests that need to interact with a Linux guest. It generalizes the "
boot_linux.py" code, already been used by the "virtiofs_submounts.py" and also SSH related code being used by that and "linux_ssh_mips_malta.py".While at it, a number of fixes on hopeful improvements to those tests were added.
Cleber Rosa (22):
tests/acceptance/boot_linux.py: fix typo on cloudinit error messagetests/acceptance/boot_linux.py: rename misleading cloudinit method Acceptance Tests: remove unnecessary tag from documentation exampletests/acceptance/virtiofs_submounts.py: use workdir propertytests/acceptance/virtiofs_submounts.py: do not ask for ssh key password
tests/acceptance/virtiofs_submounts.py: use a virtio-net device instead
tests/acceptance/virtiofs_submounts.py: evaluate string not lengthtests/acceptance/virtiofs_submounts.py: standardize port as integertests/acceptance/virtiofs_submounts.py: required space between IP and port
Python: add utility function for retrieving port redirectiontests/acceptance/linux_ssh_mips_malta.py: standardize port as integer Acceptance tests: clarify ssh connection failure reasontests/acceptance/virtiofs_submounts.py: add missing accel tag Acceptance Tests: introduce LinuxTest base class Acceptance Tests: move useful ssh methods to base class Acceptance Tests: introduce method for requiring an accelerator Acceptance Tests: fix population of public key in cloudinit image Acceptance Tests: set up existing ssh keys by default Acceptance Tests: add port redirection for ssh by default Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test [NOTFORMERGE] Bump Avocado version to latest masterdocs/devel/testing.rst | 29 +++- python/qemu/utils.py | 35 +++++
tests/acceptance/avocado_qemu/__init__.py| 176 ++++++++++++++++++++++ tests/acceptance/boot_linux.py | 128 ++-------------- tests/acceptance/hotplug_cpu.py | 38 +++++ tests/acceptance/info_usernet.py | 29 ++++ tests/acceptance/linux_ssh_mips_malta.py | 44 +----- tests/acceptance/virtiofs_submounts.py | 73 +-------- tests/requirements.txt | 2 +- tests/vm/basevm.py | 7 +-10 files changed, 334 insertions(+), 227 deletions(-)create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/hotplug_cpu.pycreate mode 100644tests/acceptance/info_usernet.py
Quoted 7 lines
Quoted 1 line
Patches 1-6, 8-9 & 12 queued.
Those are merged. Most of the remaining patches got at least one review, so could you (Cleber or Philippe) open a pull request for them as well? Telling it because there are many series in flight for the acceptance tests, and to avoid conflicts with future series...
I asked a question to Cleber in patch 13 and am waiting what he meant before queuing the series (fixing the typo Marc-André noticed).
Regards,
Phil.
Re: [PATCH 13/22] tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to Philippe Mathieu-DaudéQuoted 5 lines · Philippe Mathieu-Daudé
Quoted 1 line · Cleber Rosa
Which is useful to select tests that depend/use a particular feature.
Is that a question?
No, it's not a question.
I meant: "add a tag which is useful to select tests...". I guess this statement followed a similar previous broken approach of mine, reusing the commit title to give it meaning.
I'll try to keep avoid that in the future, thanks for asking about it.
Quoted 2 lines
Why keep this last in your series?
No reason... it doesn't impact any pre or post patches in the series AFAICT.
Cheers,
- Cleber.
Re: [PATCH 07/22] tests/acceptance/virtiofs_submounts.py: evaluate string not length
In reply to Philippe Mathieu-DaudéQuoted 26 lines · Philippe Mathieu-Daudé
Quoted 8 lines
I've actually done this with some Xen patches I'm working on at the moment. I'll probably decorate the test with:
@skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
with a comment explaining what's waiting to be upstreamed. Once there are upstream binaries I plan on transitioning the test to those.
Instead of a binary
AVOCADO_ALLOW_UNTRUSTED_CODEvariable, we could have a list allowed domains/namespaces, that can be increased on the tester discretion.For example these are assumed trusted:
. archives.fedoraproject.org
. archive.debian.org
. cdn.netbsd.org
. github.com/torvalds
. people.debian.org/~aurel32
. snapshot.debian.org
. storage.kernelci.org
. www.qemu-advent-calendar.orgThen personally interested in testing ARM boards I'd amend:
Quoted 8 lines
. apt.armbian.com
. github.com/philmd
. github.com/groeck
. github.com/hskinnemoen
. github.com/pbatardand Max's repo since I'm interested in testing
virtiofs_submounts.
Hi Phil,
I think I follow your idea, but I see two issues here:
1) Functional area (subsystem / architecture / machine type, etc)
2) Trustfulness of the code
WRT 1, the domains do not contain meaning onto themselves, so a secondary mapping of subsystem/architecture/machine to the domain would be needed. Also, wouldn't it be common to end up needing a N:N mapping between domains and subsystem/architecture/machine?
WRT 2, while limiting download from a number of domains can add some protection, the ultimate trust is achieved by setting a hash to the exact code we will download/run.
If those points seem valid, then I believe it's better to continue thinking of subsystem/architecture/machine because of the usability aspects, and possibly improve the perceived level of trust/stability of the assets by adding a "tier" classification. That one, one could pick, say:
* board|machine_type == "foo" AND
* tier == 1
And exclude what is considered inferior tiers. How does that sound?
Regards,
- Cleber.
Re: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to Wainer dos Santos MoschettaQuoted 22 lines · Wainer dos Santos Moschetta
Hi,
Quoted 16 lines · Cleber Rosa
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.util" module to host the utility function and a test.
Signed-off-by Cleber Rosa <[email protected]>--- python/qemu/utils.py | 35 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------ tests/acceptance/virtiofs_submounts.py | 20 +++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 77 insertions(+), 30 deletions(-)Quoted 2 lines
create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/info_usernet.py
Quoted 6 lines
I've a few suggestions:
- IMHO "utils" is too broad, people may start throwing random stuffs there. Maybe call it "net". I am sure there will be more net-related code to be clustered on that module in the future.
It's hard to find the right balance here. If you take a look at what John is proposing wrt the packaging the "qemu" Python libs, I believe one module is a good compromise at this point. I really to expect that it will grow and that more modules will be created.
Quoted 3 lines
- Rename the method to "
get_hostfwd_port()" because the parameter's name already implies it is expected an "info usernet" output.
I thought about the method name, and decided to keep the more verbose name because this method is *not* about retrieving the "hostfwd port" from a running QEMU, but rather from the output that should be produced by a "info usernet" command. It may become the foundation of a method on the QEMUMachine class that is called "get_hostfwd_port()" as you suggested, that includes getting the data (that is, issuing a "info usernet" command).
Anyway, I tend to favor "explicit is better than implicit" approach, but I recognize that I can be too verbose at times. Let's see if other people chip in with naming suggestions.
Quoted 3 lines
- Drop the InfoUsernet Test. It is too simple, and the same functionality is tested indirectly by other tests.
I find "too simple" is a typical case of "famous last words" :D. Now, as a functional test to cover the utility function, it's indeed a bit of overkill. It'd probably be less necessary if there were unittests for those (and there will hopefully be some soon).
Now, testing *directly* was indeed the intention here. I see a few reasons for that, including saving a good amount of debugging time:
such a test failing would provide *direct* indication of where the regression is. These simpler tests can also be run with targets other than the ones really connecting into guests at this moment (while it's debatable wether such a regression would appear only on such targets).
Quoted 104 lines
Quoted 91 lines
python/qemu/utils.py new file +35
-0@@ -0,0 +1,35 @@ +""" +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" + :param info_usernet_output: str + :return: the port number allocated by the hostfwd option + :rtype: int + """ + 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 Nonetests/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 +2
-1@@ -18,6 +18,8 @@ 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):@@ -70,18 +72,14 @@ class LinuxSSH(Test): def setUp(self): super(LinuxSSH, self).setUp() - def get_portfwd(self):tests/acceptance/linux_ssh_mips_malta.py class LinuxSSH(Test): · line 80
Quoted 10 lines
tests/acceptance/linux_ssh_mips_malta.py +5
-3+ 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")Here I think it should assert not none, otherwise there is a bug somewhere.
Quoted 1 line
- Wainer
I'm trying to be careful and conservative with adding assertions, because IMO those belong to test writers. IMO the expectation of a user writing a test using "ssh_connect()" as a framework utility, would be more aligned with the framework bailing out, than blatantly setting a test failure.
It's similar to what happens if a "vmimage" snapshot can not be created... there's an issue somewhere, but it'd be a bit unfair, and confusing, to set a assertion error (and thus test failure). But, I think this is the kind of design decision that will evolve with (more) time here.
Let me know if my explanations make sense and change your mind any bit :).
Thanks for the review!
- Cleber.
Re: [PATCH 11/22] tests/acceptance/linux_ssh_mips_malta.py: standardize port as integer
In reply to Cleber RosaQuoted 6 lines · Cleber Rosa
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/linux_ssh_mips_malta.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Re: [PATCH 14/22] Acceptance Tests: introduce LinuxTest base class
In reply to Cleber Rosatests/acceptance/avocado_qemu/__init__.py
Quoted 15 lines · Cleber Rosa
This is basically the infrastructure around "
boot_linux.py" tests, but now made into a base class for general use.Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 87 +++++++++++++++++++++ tests/acceptance/boot_linux.py | 94 ++--------------------- tests/acceptance/virtiofs_submounts.py | 6 +- 3 files changed, 94 insertions(+), 93 deletions(-)tests/acceptance/avocado_qemu/__init__.py +0
-0
I found it not so intuitive to have the base class defined here. I see the number of base classes for the tests growing in the future. A common place for base classes for tests would be better, just like the qemu.utils you are defining somewhere else. Anyway, this is a design decision that can be changed later, so
Re: [PATCH 15/22] Acceptance Tests: move useful ssh methods to base class
In reply to Cleber RosaQuoted 10 lines · Cleber Rosa
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 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.
Quoted 7 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 49 ++++++++++++++++++++++- tests/acceptance/linux_ssh_mips_malta.py | 38 ++---------------- tests/acceptance/virtiofs_submounts.py | 36 ----------------- 3 files changed, 51 insertions(+), 72 deletions(-)
Here I bring back my comment from patch 14, having a common place for test specific classes would bring a better organization to the code. Anyway,
Re: [PATCH 16/22] Acceptance Tests: introduce method for requiring an accelerator
In reply to Cleber RosaQuoted 6 lines · Cleber Rosa
Some tests explicitly require a QEMU accelerator to be available. Given that this depends on some runtime aspects not known before the test is started, such as the currently set QEMU binary, it's left to be checked also at runtime.
Quoted 7 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 24 ++++++++++++++++ tests/acceptance/boot_linux.py | 34 ++++++----------------- tests/acceptance/virtiofs_submounts.py | 5 +--- 3 files changed, 34 insertions(+), 29 deletions(-)
Re: [PATCH 17/22] Acceptance Tests: fix population of public key in cloudinit image
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
Currently the path of the ssh public key is being set, but its content is obviously what's needed.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Re: [PATCH 18/22] Acceptance Tests: set up existing ssh keys by default
In reply to Cleber RosaQuoted 10 lines · Cleber Rosa
It's questionable wether it's necessary to create one brand new pair for each test. It's not questionable that it takes less time and resources to just use the keys available at "tests/keys" that exist for that exact reason.
If a location for the public key is not given explicitly, the LinuxTest will now set up the existing pair of keys as the default. This removes the need for a lot of boiler plate code.
Quoted 9 lines
To avoid the ssh client from erroring on permission issues, a directory with restricive permissions is created for the private key. This should still be a lot cheaper than creating a new key.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Re: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to Cleber RosaQuoted 5 lines · Cleber Rosa
It's hard to find the right balance here. If you take a look at what John is proposing wrt the packaging the "qemu" Python libs, I believe one module is a good compromise at this point. I really to expect that it will grow and that more modules will be created.
Yeah. We have a "qmp" package and a "machine" package, and these seem very well-defined.
Then we have everything else which is mostly a few random bits and pieces (at the moment: just accel.py). Over time those bits and pieces might take shape as something more important/meaningful, but for now it's pretty nebulous.
An emerging pattern I see is that these functions are "environment analysis" helpers; things designed to help interrogate the local environment to choose appropriate QEMU flags, or otherwise "QEMU output analysis", things designed to make better sense of the output received from QEMU.
accel.py is the former, this patch targets the latter.
I suspect accel.py will want to belong to "smart" tools for booting up an arbitrary VM (interrogate, decide on config, launch) whereas this patch fits into a class of API-esque tools designed for making sense of I/O information.
It's meant to digest HMP, though -- is this evidence that we need a better QMP command? We shouldn't be using HMP for machine driven testing. (I know we have to sometimes, but we should be working towards eliminating it.)
-js
Re: [PATCH 21/22] Acceptance Tests: introduce CPU hotplug test
In reply to Cleber RosaQuoted 9 lines · Cleber Rosa
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.
Quoted 6 lines
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/hotplug_cpu.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/acceptance/hotplug_cpu.py
Re: [PATCH 13/22] tests/acceptance/virtiofs_submounts.py: add missing accel tag
In reply to Cleber RosaQuoted 8 lines · Cleber Rosa
Which is useful to select tests that depend/use a particular feature.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/virtiofs_submounts.py | 1 + 1 file changed, 1 insertion(+)
Wainer dos Santos Moschetta
Reviewed-byRe: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to Cleber RosaQuoted 55 lines · Cleber Rosa
Quoted 21 lines · Wainer dos Santos Moschetta
Hi,
Quoted 16 lines · Cleber Rosa
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.util" module to host the utility function and a test.
Signed-off-by Cleber Rosa <[email protected]>--- python/qemu/utils.py | 35 ++++++++++++++++++++++++ tests/acceptance/info_usernet.py | 29 ++++++++++++++++++++ tests/acceptance/linux_ssh_mips_malta.py | 16 +++++------ tests/acceptance/virtiofs_submounts.py | 20 +++----------- tests/vm/basevm.py | 7 ++--- 5 files changed, 77 insertions(+), 30 deletions(-)Quoted 2 lines
create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/info_usernet.pyQuoted 6 lines
I've a few suggestions:
- IMHO "utils" is too broad, people may start throwing random stuffs there. Maybe call it "net". I am sure there will be more net-related code to be clustered on that module in the future.
It's hard to find the right balance here. If you take a look at what John is proposing wrt the packaging the "qemu" Python libs, I believe one module is a good compromise at this point. I really to expect that it will grow and that more modules will be created.
Quoted 3 lines
- Rename the method to "
get_hostfwd_port()" because the parameter's name already implies it is expected an "info usernet" output.I thought about the method name, and decided to keep the more verbose name because this method is *not* about retrieving the "hostfwd port" from a running QEMU, but rather from the output that should be produced by a "info usernet" command. It may become the foundation of a method on the QEMUMachine class that is called "
get_hostfwd_port()" as you suggested, that includes getting the data (that is, issuing a "info usernet" command).Anyway, I tend to favor "explicit is better than implicit" approach, but I recognize that I can be too verbose at times. Let's see if other people chip in with naming suggestions.
Quoted 3 lines
- Drop the InfoUsernet Test. It is too simple, and the same functionality is tested indirectly by other tests.
I find "too simple" is a typical case of "famous last words" :D. Now, as a functional test to cover the utility function, it's indeed a bit of overkill. It'd probably be less necessary if there were unittests for those (and there will hopefully be some soon).
Quoted 6 lines
Now, testing *directly* was indeed the intention here. I see a few reasons for that, including saving a good amount of debugging time:
such a test failing would provide *direct* indication of where the regression is. These simpler tests can also be run with targets other than the ones really connecting into guests at this moment (while it's debatable wether such a regression would appear only on such targets).
I confess I was thinking on the impact of many small/simple tests on CI if that become a trend. Time to run a job should be manageable. In this case, having unittests for the utilities is all we need and would save some minutes on CI.
On the absence of unittests, I'm not opposed to merge this test.
Quoted 110 lines
Quoted 103 lines
Quoted 91 lines
python/qemu/utils.py new file +35
-0@@ -0,0 +1,35 @@ +""" +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" + :param info_usernet_output: str + :return: the port number allocated by the hostfwd option + :rtype: int + """ + 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 Nonetests/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 +2
-1@@ -18,6 +18,8 @@ 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):@@ -70,18 +72,14 @@ class LinuxSSH(Test): def setUp(self): super(LinuxSSH, self).setUp() - def get_portfwd(self):tests/acceptance/linux_ssh_mips_malta.py class LinuxSSH(Test): · line 80
Quoted 10 lines
tests/acceptance/linux_ssh_mips_malta.py +5
-3+ 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")Here I think it should assert not none, otherwise there is a bug somewhere.
Quoted 1 line
- Wainer
I'm trying to be careful and conservative with adding assertions, because IMO those belong to test writers. IMO the expectation of a user writing a test using "
ssh_connect()" as a framework utility, would be more aligned with the framework bailing out, than blatantly setting a test failure.
Quoted 5 lines
It's similar to what happens if a "vmimage" snapshot can not be created... there's an issue somewhere, but it'd be a bit unfair, and confusing, to set a assertion error (and thus test failure). But, I think this is the kind of design decision that will evolve with (more) time here.
I see. I agree with that design, I will keep it in mind when reviewing patches and submitting changes.
Quoted 3 lines
Let me know if my explanations make sense and change your mind any bit :).
Sure, thanks for the explanations. As I mentioned in my first reply, they were just suggestions. So,
Quoted 3 lines
Thanks for the review!
- Cleber.
Re: [PATCH 14/22] Acceptance Tests: introduce LinuxTest base class
In reply to Willian RampazzoQuoted 12 lines · Willian Rampazzo
Quoted 11 lines · Cleber Rosa
This is basically the infrastructure around "
boot_linux.py" tests, but now made into a base class for general use.Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 87 +++++++++++++++++++++ tests/acceptance/boot_linux.py | 94 ++--------------------- tests/acceptance/virtiofs_submounts.py | 6 +- 3 files changed, 94 insertions(+), 93 deletions(-)
Quoted 11 lines
tests/acceptance/avocado_qemu/__init__.py
Quoted 4 lines
tests/acceptance/avocado_qemu/__init__.py +0
-0I found it not so intuitive to have the base class defined here. I see the number of base classes for the tests growing in the future. A common place for base classes for tests would be better, just like the
qemu.utilsyou are defining somewhere else. Anyway, this is a design decision that can be changed later, so
Hi Willian,
I tend to agree, and my medium/long term vision is similar. What I expect to be able to do soon (this is connected to John's work) is to have "avocado_qemu" as something like "qemu.testing.functional" which describe its Avocado (and other) dependencies.
A "qemu.test.other" could describe its own dependencies (which may not include Avocado).
Quoted 3 lines
Reviewed-by Willian Rampazzo <[email protected]>
Thanks for the review,
- Cleber.
Re: [PATCH 18/22] Acceptance Tests: set up existing ssh keys by default
In reply to Marc-André LureauQuoted 8 lines · Marc-André Lureau
Hi
Quoted 2 lines · Cleber Rosa
It's questionable wether it's necessary to create one brand new pair
whether
Yep, thanks!
Quoted 10 lines
Quoted 7 lines
for each test. It's not questionable that it takes less time and resources to just use the keys available at "tests/keys" that exist for that exact reason.
If a location for the public key is not given explicitly, the LinuxTest will now set up the existing pair of keys as the default. This removes the need for a lot of boiler plate code.
boilerplate
You're right again.
Quoted 6 lines
Quoted 3 lines
To avoid the ssh client from erroring on permission issues, a directory with restricive permissions is created for the private key.
restrictive
OK.
Quoted 6 lines
Quoted 3 lines
This should still be a lot cheaper than creating a new key.
Signed-off-by Cleber Rosa <[email protected]>Reviewed-by Marc-André Lureau <[email protected]>
Thanks for the review,
- Cleber.
Quoted 62 lines · Philippe Mathieu-Daudé
Quoted 53 lines · Wainer dos Santos Moschetta
Hi,
Quoted 50 lines · Philippe Mathieu-Daudé
Quoted 49 lines · Cleber Rosa
This introduces a base class for tests that need to interact with a Linux guest. It generalizes the "
boot_linux.py" code, already been used by the "virtiofs_submounts.py" and also SSH related code being used by that and "linux_ssh_mips_malta.py".While at it, a number of fixes on hopeful improvements to those tests were added.
Cleber Rosa (22):
tests/acceptance/boot_linux.py: fix typo on cloudinit error messagetests/acceptance/boot_linux.py: rename misleading cloudinit method Acceptance Tests: remove unnecessary tag from documentation exampletests/acceptance/virtiofs_submounts.py: use workdir propertytests/acceptance/virtiofs_submounts.py: do not ask for ssh key password
tests/acceptance/virtiofs_submounts.py: use a virtio-net device instead
tests/acceptance/virtiofs_submounts.py: evaluate string not lengthtests/acceptance/virtiofs_submounts.py: standardize port as integertests/acceptance/virtiofs_submounts.py: required space between IP and port
Python: add utility function for retrieving port redirectiontests/acceptance/linux_ssh_mips_malta.py: standardize port as integer Acceptance tests: clarify ssh connection failure reasontests/acceptance/virtiofs_submounts.py: add missing accel tag Acceptance Tests: introduce LinuxTest base class Acceptance Tests: move useful ssh methods to base class Acceptance Tests: introduce method for requiring an accelerator Acceptance Tests: fix population of public key in cloudinit image Acceptance Tests: set up existing ssh keys by default Acceptance Tests: add port redirection for ssh by default Acceptance Tests: add basic documentation on LinuxTest base class Acceptance Tests: introduce CPU hotplug test [NOTFORMERGE] Bump Avocado version to latest masterdocs/devel/testing.rst | 29 +++- python/qemu/utils.py | 35 +++++
tests/acceptance/avocado_qemu/__init__.py| 176 ++++++++++++++++++++++ tests/acceptance/boot_linux.py | 128 ++-------------- tests/acceptance/hotplug_cpu.py | 38 +++++ tests/acceptance/info_usernet.py | 29 ++++ tests/acceptance/linux_ssh_mips_malta.py | 44 +----- tests/acceptance/virtiofs_submounts.py | 73 +-------- tests/requirements.txt | 2 +- tests/vm/basevm.py | 7 +-10 files changed, 334 insertions(+), 227 deletions(-)create mode 100644
python/qemu/utils.pycreate mode 100644tests/acceptance/hotplug_cpu.pycreate mode 100644tests/acceptance/info_usernet.pyQuoted 7 lines
Quoted 1 line
Patches 1-6, 8-9 & 12 queued.
Those are merged. Most of the remaining patches got at least one review, so could you (Cleber or Philippe) open a pull request for them as well? Telling it because there are many series in flight for the acceptance tests, and to avoid conflicts with future series...
Quoted 7 lines
I asked a question to Cleber in patch 13 and am waiting what he meant before queuing the series (fixing the typo Marc-André noticed).
Regards,
Phil.
Hi Phil,
Thanks for taking the previous patches, and thanks for the willingness to take (and tweak) some more. I only saw this comment now, and I have a bunch of these ready to fire a PR.
I guess I also provided an answer to the question you're referring to.
If my tree passes CI, then I should be sending a PR within the next few hours.
Best,
- Cleber.
Re: [PATCH 10/22] Python: add utility function for retrieving port redirection
In reply to John SnowQuoted 6 lines · John Snow
Quoted 5 lines · Cleber Rosa
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.
Quoted 6 lines
Quoted 3 lines
While at it, this adds a "qemu.util" module to host the utility function and a test.
qemu.utils, with the s!
Nice catch, thanks!
- Cleber.
Re: [PATCH 19/22] Acceptance Tests: add port redirection for ssh by default
In reply to Philippe Mathieu-DaudéQuoted 12 lines · Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Cleber Rosa
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.
Signed-off-by Cleber Rosa <[email protected]>--- tests/acceptance/avocado_qemu/__init__.py | 2 ++ tests/acceptance/virtiofs_submounts.py | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-)
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
tests/acceptance/avocado_qemu/__init__.py +0
-0@@ -301,6 +301,8 @@ class LinuxTest(Test, LinuxSSHMixIn):Quoted 8 lines
tests/acceptance/avocado_qemu/__init__.py class LinuxTest(Test, LinuxSSHMixIn): · line 305
Quoted 5 lines
tests/acceptance/avocado_qemu/__init__.py +2
-0super(LinuxTest, self).setUp() self.vm.add_args('-smp', '2') self.vm.add_args('-m', '1024') + self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22', + '-device', 'virtio-net,netdev=vnet')You need a machine with a virtio-bus to be able to plug a virtio device, not all provide one.
Very true.
Quoted 4 lines
Alternatively you could provide a
network_device_typeargument tosetUp()which has to be explicitly set (since the tests would be pointless without network access).
Sure, I'll add the capability to configure the device type on v2.
Thanks!
- Cleber.