From nobody Fri Nov 7 15:25:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548698634691284.7444588010193; Mon, 28 Jan 2019 10:03:54 -0800 (PST) Received: from localhost ([127.0.0.1]:36229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBG6-0004cg-Qf for importer@patchew.org; Mon, 28 Jan 2019 13:03:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBDg-0003Db-KF for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goBAL-00070n-70 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:57:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42890) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1goBAK-0006yC-VC for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:57:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDDBFC067831 for ; Mon, 28 Jan 2019 17:47:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-55.gru2.redhat.com [10.97.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4FF61786; Mon, 28 Jan 2019 17:47:35 +0000 (UTC) From: Caio Carrara To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 15:47:24 -0200 Message-Id: <20190128174725.8809-2-ccarrara@redhat.com> In-Reply-To: <20190128174725.8809-1-ccarrara@redhat.com> References: <20190128174725.8809-1-ccarrara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 28 Jan 2019 17:47:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/2] tests.acceptance: adds multi vm capability for acceptance tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Caio Carrara , philmd@redhat.com, ehabkost@redhat.com, wainersm@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This change adds the possibility to write acceptance tests with multi virtual machine support. It's done keeping the virtual machines objects stored in a test attribute (dictionary). This dictionary shouldn't be accessed directly but through the new method added `get_vm`. This new method accept a list of args (that will be added as virtual machine arguments) and an optional name argument. The name is the key that identify a single virtual machine along the test machines available. If a name without a machine is informed a new machine will be instantiated. The current usage of vm in tests will not be broken by this change since it keeps a property called vm in the base test class. This property only calls the new method `get_vm` with default parameters (no args and 'default' as machine name). Signed-off-by: Caio Carrara --- docs/devel/testing.rst | 40 ++++++++++++++++++++++- tests/acceptance/avocado_qemu/__init__.py | 25 +++++++++++--- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index 18e2c0868a..b97c0368bc 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -634,7 +634,45 @@ instance, available at ``self.vm``. Because many test= s will tweak the QEMU command line, launching the QEMUMachine (by using ``self.vm.launch()`= `) is left to the test writer. =20 -At test "tear down", ``avocado_qemu.Test`` handles the QEMUMachine +The base test class has also support for tests with more than one +QEMUMachine. The way to get machines is through the ``self.get_vm()`` +method which will return a QEMUMachine instance. The ``self.get_vm()`` +method also accepts an optional `name` attribute so you can identify a +specific machine and get it more than once through the tests methods. A +simple and hypothetical example follows: + +.. code:: + + from avocado_qemu import Test + + + class MultipleMachines(Test): + """ + :avocado: enable + """ + def test_multiple_machines(self): + first_machine =3D self.get_vm() + second_machine =3D self.get_vm() + self.get_vm(name=3D'third_machine').launch() + + first_machine.launch() + second_machine.launch() + + first_res =3D first_machine.command( + 'human-monitor-command', + command_line=3D'info version') + + second_res =3D second_machine.command( + 'human-monitor-command', + command_line=3D'info version') + + third_res =3D self.get_vm(name=3D'third_machine').command( + 'human-monitor-command', + command_line=3D'info version') + + self.assertEquals(first_res, second_res, third_res) + +At test "tear down", ``avocado_qemu.Test`` handles all the QEMUMachines shutdown. =20 QEMUMachine diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index 1e54fd5932..4c9e27feda 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -10,6 +10,7 @@ =20 import os import sys +import uuid =20 import avocado =20 @@ -42,13 +43,29 @@ def pick_default_qemu_bin(): =20 class Test(avocado.Test): def setUp(self): - self.vm =3D None + self._vms =3D {} self.qemu_bin =3D self.params.get('qemu_bin', default=3Dpick_default_qemu_bin()) if self.qemu_bin is None: self.cancel("No QEMU binary defined or found in the source tre= e") - self.vm =3D QEMUMachine(self.qemu_bin) + + def _new_vm(self, *args): + vm =3D QEMUMachine(self.qemu_bin) + if args: + vm.add_args(*args) + return vm + + @property + def vm(self): + return self.get_vm(name=3D'default') + + def get_vm(self, *args, name=3DNone): + if not name: + name =3D str(uuid.uuid4()) + if self._vms.get(name) is None: + self._vms[name] =3D self._new_vm(*args) + return self._vms[name] =20 def tearDown(self): - if self.vm is not None: - self.vm.shutdown() + for vm in self._vms.values(): + vm.shutdown() --=20 2.20.1 From nobody Fri Nov 7 15:25:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548700285857815.143552360574; Mon, 28 Jan 2019 10:31:25 -0800 (PST) Received: from localhost ([127.0.0.1]:36662 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBgl-0002Ja-QV for importer@patchew.org; Mon, 28 Jan 2019 13:31:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEs-0003dP-Uu for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:02:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB0j-0001RK-5a for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:47:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47272) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1goB0i-0001LY-VR for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:47:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2C93C04BD46 for ; Mon, 28 Jan 2019 17:47:38 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-55.gru2.redhat.com [10.97.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54F126148F; Mon, 28 Jan 2019 17:47:37 +0000 (UTC) From: Caio Carrara To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 15:47:25 -0200 Message-Id: <20190128174725.8809-3-ccarrara@redhat.com> In-Reply-To: <20190128174725.8809-1-ccarrara@redhat.com> References: <20190128174725.8809-1-ccarrara@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 28 Jan 2019 17:47:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/2] Acceptance tests: add simple migration test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: philmd@redhat.com, ehabkost@redhat.com, wainersm@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Cleber Rosa This is the simplest possible migration test, exercising the multi VM capabilities of the test class. Signed-off-by: Cleber Rosa --- tests/acceptance/migration.py | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/acceptance/migration.py diff --git a/tests/acceptance/migration.py b/tests/acceptance/migration.py new file mode 100644 index 0000000000..973ae0ab4b --- /dev/null +++ b/tests/acceptance/migration.py @@ -0,0 +1,45 @@ +# Migration test +# +# Copyright (c) 2019 Red Hat, Inc. +# +# Author: +# Cleber Rosa +# +# 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 avocado.utils import network +from avocado.utils import wait + + +class Migration(Test): + """ + :avocado: enable + """ + + timeout =3D 10 + + @staticmethod + def migration_completed(vm): + cmd_result =3D vm.qmp('query-migrate') + if cmd_result is not None: + result =3D cmd_result.get('return') + if result is not None: + return result.get('status') =3D=3D 'completed' + return False + + def test_tcp(self): + source =3D self.get_vm() + port =3D network.find_free_port() + if port is None: + self.cancel('Failed to find a free port') + dest_uri =3D 'tcp:localhost:%u' % port + dest =3D self.get_vm('-incoming', dest_uri) + dest.launch() + source.launch() + source.qmp('migrate', uri=3Ddest_uri) + wait.wait_for(self.migration_completed, timeout=3Dself.timeout, + step=3D0.1, args=3D(source,)) --=20 2.20.1