From nobody Thu May 16 11:00:49 2024 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; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1573567259; cv=none; d=zoho.com; s=zohoarc; b=JRpcvI7H575p9MwkWUN2SDueJojV38nLTBsz00n2r+XiXvs6RIII1MqeBw5MHgibDtKko53vKGhLW9YC6YZVxi8oRkHSUmyZBKJ/xZrbscnqFSxPkMn8CdhkJrskFnXYbA9ucuuhLLvi0IJe4OMSC+n69yocsBP+VdJQJvRd0DQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573567259; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=fadKMt1uXOBeY5f+UjsFOSxOwqtaSYhrsqw/L3DyzmU=; b=neXLEIWrU19t2vLKuCFFzqnPutf4PiDfpYiOBgUHOLJfSb5g6T+EQptVyg61qqerW/HjLR3bXZBUM2ZtBcjTZQ6BEIkOruaG1Bfo3JXW8cNAUiBwSaj+jSm2pf+kPIjTtt6Tzd08SNRgJrLxOz322UyLRVGtsLUzukhrxJwqJck= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573567259013711.6385871636106; Tue, 12 Nov 2019 06:00:59 -0800 (PST) Received: from localhost ([::1]:35344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUWiz-0000kD-KL for importer@patchew.org; Tue, 12 Nov 2019 09:00:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53631) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUWhX-0008I8-Rx for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUWhT-00051o-UG for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:21 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43478 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUWhT-00051X-Oq for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-82-naXEbdssPsKOFOzMFeoDFg-1; Tue, 12 Nov 2019 08:58:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DCD9DB60 for ; Tue, 12 Nov 2019 13:58:11 +0000 (UTC) Received: from virtlab501.virt.lab.eng.bos.redhat.com (virtlab501.virt.lab.eng.bos.redhat.com [10.19.152.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A6FA100EBAC; Tue, 12 Nov 2019 13:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573567159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fadKMt1uXOBeY5f+UjsFOSxOwqtaSYhrsqw/L3DyzmU=; b=CXONlNDAiVvIaSakZ9Og6NWKyxgFN1BMnodPcoq8GxDDnVxirPiKjjzxsM6yaQOS25FUGS CSGdXzz+7pR5vT2uJuDa/MeXA37i9O5KrSfbFYJ3yuj/WTuFm8zSWTmBNTG5z8IxpmEtI4 wZETAJlKRJ+VA1Seh5oYjqXQtyjTTZY= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 1/2] python/qemu: Add set_qmp_monitor() to QEMUMachine Date: Tue, 12 Nov 2019 08:58:00 -0500 Message-Id: <20191112135801.854-2-wainersm@redhat.com> In-Reply-To: <20191112135801.854-1-wainersm@redhat.com> References: <20191112135801.854-1-wainersm@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: naXEbdssPsKOFOzMFeoDFg-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The QEMUMachine VM has a monitor setup on which an QMP connection is always attempted on _post_launch() (executed by launch()). In case the QEMU process immediatly exits then the qmp.accept() (used to establish the connection) stalls until it reaches timeout and consequently an exception raises. That behavior is undesirable when, for instance, it needs to gather information from the QEMU binary ($ qemu -cpu list) or a test which launches the VM expecting its failure. This patch adds the set_qmp_monitor() method to QEMUMachine that allows turn off the creation of the monitor machinery on VM launch. Signed-off-by: Wainer dos Santos Moschetta --- python/qemu/machine.py | 68 ++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index a4631d6934..04ee86e1ba 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -104,6 +104,7 @@ class QEMUMachine(object): self._events =3D [] self._iolog =3D None self._socket_scm_helper =3D socket_scm_helper + self._qmp_set =3D True # Enable QMP monitor by default. self._qmp =3D None self._qemu_full_args =3D None self._test_dir =3D test_dir @@ -228,15 +229,16 @@ class QEMUMachine(object): self._iolog =3D iolog.read() =20 def _base_args(self): - if isinstance(self._monitor_address, tuple): - moncdev =3D "socket,id=3Dmon,host=3D%s,port=3D%s" % ( + args =3D ['-display', 'none', '-vga', 'none'] + if self._qmp_set: + if isinstance(self._monitor_address, tuple): + moncdev =3D "socket,id=3Dmon,host=3D%s,port=3D%s" % ( self._monitor_address[0], self._monitor_address[1]) - else: - moncdev =3D 'socket,id=3Dmon,path=3D%s' % self._vm_monitor - args =3D ['-chardev', moncdev, - '-mon', 'chardev=3Dmon,mode=3Dcontrol', - '-display', 'none', '-vga', 'none'] + else: + moncdev =3D 'socket,id=3Dmon,path=3D%s' % self._vm_monitor + args.extend(['-chardev', moncdev, '-mon', + 'chardev=3Dmon,mode=3Dcontrol']) if self._machine is not None: args.extend(['-machine', self._machine]) if self._console_set: @@ -255,20 +257,21 @@ class QEMUMachine(object): =20 def _pre_launch(self): self._temp_dir =3D tempfile.mkdtemp(dir=3Dself._test_dir) - if self._monitor_address is not None: - self._vm_monitor =3D self._monitor_address - else: - self._vm_monitor =3D os.path.join(self._sock_dir, - self._name + "-monitor.sock") - self._remove_files.append(self._vm_monitor) self._qemu_log_path =3D os.path.join(self._temp_dir, self._name + = ".log") self._qemu_log_file =3D open(self._qemu_log_path, 'wb') =20 - self._qmp =3D qmp.QEMUMonitorProtocol(self._vm_monitor, - server=3DTrue) + if self._qmp_set: + if self._monitor_address is not None: + self._vm_monitor =3D self._monitor_address + else: + self._vm_monitor =3D os.path.join(self._sock_dir, + self._name + "-monitor.soc= k") + self._remove_files.append(self._vm_monitor) + self._qmp =3D qmp.QEMUMonitorProtocol(self._vm_monitor, server= =3DTrue) =20 def _post_launch(self): - self._qmp.accept() + if self._qmp: + self._qmp.accept() =20 def _post_shutdown(self): if self._qemu_log_file is not None: @@ -330,7 +333,8 @@ class QEMUMachine(object): Wait for the VM to power off """ self._popen.wait() - self._qmp.close() + if self._qmp: + self._qmp.close() self._load_io_log() self._post_shutdown() =20 @@ -346,12 +350,13 @@ class QEMUMachine(object): self._console_socket =3D None =20 if self.is_running(): - try: - if not has_quit: - self._qmp.cmd('quit') - self._qmp.close() - except: - self._popen.kill() + if self._qmp: + try: + if not has_quit: + self._qmp.cmd('quit') + self._qmp.close() + except: + self._popen.kill() self._popen.wait() =20 self._load_io_log() @@ -368,6 +373,23 @@ class QEMUMachine(object): =20 self._launched =3D False =20 + def set_qmp_monitor(self, disabled=3DFalse, monitor_address=3DNone): + """ + Set the QMP monitor. + + @param disabled: if True, qmp monitor options will be removed from= the + base arguments of the resulting QEMU command line. + @param monitor_address: address for the QMP monitor. + @note: call this function before launch(). + """ + if disabled: + self._qmp_set =3D False + self._qmp =3D None + else: + self._qmp_set =3D True + if monitor_address: + self._monitor_address =3D monitor_address + def qmp(self, cmd, conv_keys=3DTrue, **args): """ Invoke a QMP command and return the response dict --=20 2.18.1 From nobody Thu May 16 11:00:49 2024 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; dkim=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1573567259; cv=none; d=zoho.com; s=zohoarc; b=UxzW1Osx4/MFMLM9s1Fa5q/8RJtrOA5uxd/6xy82uZ04ppkTBziKy1qW58ia0xWipxbEQVuqzkSnLFgp4WE7KPdfhKhDoNy12NVK2nITy/8OgyTtV8pM95ur+h3MoLdTmEz7v4keQk0W112NnWd9frH0PBqLANq2j3kdUVDkgVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573567259; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=twVqRx4Sja+DfqjSaz8u0cWY+m3+byf5RH+2bJlobTY=; b=FA7iTq8XDH1k4KK+R4rAvBmzeqgSmrrjTfyBCqbtCO/3KHfTlrEb9EOARUH60S7IbWklisJFdyc0Oq5cbSNfMgEnQnYg11LCzLzstoaZTv5p1tp3qWHowdfNQxIqRZZkX3jx8gkYSgkzE//1oa5fIrApwQgiINSeoOZjnsqYZEY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1573567259013612.403796030661; Tue, 12 Nov 2019 06:00:59 -0800 (PST) Received: from localhost ([::1]:35342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUWiy-0000jv-GO for importer@patchew.org; Tue, 12 Nov 2019 09:00:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53655) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iUWhX-0008IH-U6 for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iUWhW-00057o-PN for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:23 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:56399 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iUWhW-00057P-Lk for qemu-devel@nongnu.org; Tue, 12 Nov 2019 08:59:22 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-89-0pC-nGahPhGGzMtCWMAQDQ-1; Tue, 12 Nov 2019 08:58:12 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 237F41800D63 for ; Tue, 12 Nov 2019 13:58:12 +0000 (UTC) Received: from virtlab501.virt.lab.eng.bos.redhat.com (virtlab501.virt.lab.eng.bos.redhat.com [10.19.152.162]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E32F100EBAC; Tue, 12 Nov 2019 13:58:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573567162; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=twVqRx4Sja+DfqjSaz8u0cWY+m3+byf5RH+2bJlobTY=; b=TyWxLDZgTvNeHWNqjUulCouE3UC1FHEV+Of+fX5ieHp2BUwowpYD+8OXqd8RvgdCc/Vs0F K3nv+Xd7+dbt4ejK0ssfvWve/KOhcRlF4DmEGVBBc6d99tePxPjIu4qu7uJBY3K5J8FVSw WZLzH00tV6Fuo6LyBxUKrBtu/ccJXu0= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 2/2] tests/acceptance: Makes linux_initrd and empty_cpu_model use QEMUMachine Date: Tue, 12 Nov 2019 08:58:01 -0500 Message-Id: <20191112135801.854-3-wainersm@redhat.com> In-Reply-To: <20191112135801.854-1-wainersm@redhat.com> References: <20191112135801.854-1-wainersm@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-MC-Unique: 0pC-nGahPhGGzMtCWMAQDQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: philmd@redhat.com, ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On linux_initrd and empty_cpu_model tests the same effect of calling QEMU through run() to inspect the terminated process is achieved with a sequence of set_qmp_monitor() / launch() / wait() commands on an QEMUMachine object. This patch changes those tests to use QEMUMachine instead, so they follow the same pattern to launch QEMU found on other acceptance tests. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa --- tests/acceptance/empty_cpu_model.py | 13 +++++++------ tests/acceptance/linux_initrd.py | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/acceptance/empty_cpu_model.py b/tests/acceptance/empty_c= pu_model.py index 3f4f663582..8c20a4ef4a 100644 --- a/tests/acceptance/empty_cpu_model.py +++ b/tests/acceptance/empty_cpu_model.py @@ -7,13 +7,14 @@ # # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -import subprocess from avocado_qemu import Test =20 class EmptyCPUModel(Test): def test(self): - cmd =3D [self.qemu_bin, '-S', '-display', 'none', '-machine', 'non= e', '-cpu', ''] - r =3D subprocess.run(cmd, stderr=3Dsubprocess.PIPE, stdout=3Dsubpr= ocess.PIPE) - self.assertEquals(r.returncode, 1, "QEMU exit code should be 1") - self.assertEquals(r.stdout, b'', "QEMU stdout should be empty") - self.assertNotEquals(r.stderr, b'', "QEMU stderr shouldn't be empt= y") + self.vm.add_args('-S', '-display', 'none', '-machine', 'none', + '-cpu', '') + self.vm.set_qmp_monitor(disabled=3DTrue) + self.vm.launch() + self.vm.wait() + self.assertEquals(self.vm.exitcode(), 1, "QEMU exit code should be= 1") + self.assertRegex(self.vm.get_log(), r'-cpu option cannot be empty') diff --git a/tests/acceptance/linux_initrd.py b/tests/acceptance/linux_init= rd.py index c61d9826a4..158ec4d46c 100644 --- a/tests/acceptance/linux_initrd.py +++ b/tests/acceptance/linux_initrd.py @@ -10,7 +10,6 @@ =20 import logging import tempfile -from avocado.utils.process import run =20 from avocado_qemu import Test =20 @@ -41,13 +40,15 @@ class LinuxInitrd(Test): initrd.seek(max_size) initrd.write(b'\0') initrd.flush() - cmd =3D "%s -kernel %s -initrd %s -m 4096" % ( - self.qemu_bin, kernel_path, initrd.name) - res =3D run(cmd, ignore_status=3DTrue) - self.assertEqual(res.exit_status, 1) + self.vm.add_args('-kernel', kernel_path, '-initrd', initrd.nam= e, + '-m', '4096') + self.vm.set_qmp_monitor(disabled=3DTrue) + self.vm.launch() + self.vm.wait() + self.assertEqual(self.vm.exitcode(), 1) expected_msg =3D r'.*initrd is too large.*max: \d+, need %s.*'= % ( max_size + 1) - self.assertRegex(res.stderr_text, expected_msg) + self.assertRegex(self.vm.get_log(), expected_msg) =20 def test_with_2gib_file_should_work_with_linux_v4_16(self): """ --=20 2.18.1