From patchwork Wed Dec 11 18:55:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wainer dos Santos Moschetta X-Patchwork-Id: 1207850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="IpMT+5Qi"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Y5nY6v2wz9sPh for ; Thu, 12 Dec 2019 05:59:13 +1100 (AEDT) Received: from localhost ([::1]:47974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if7CD-000206-Ov for incoming@patchwork.ozlabs.org; Wed, 11 Dec 2019 13:58:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44616) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if79I-00086F-9s for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1if79G-0006UW-21 for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:47 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:55728 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 1if79F-0006TO-Ts for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576090545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3bSEH2MNBHb9zRWEcSfzytTWqVdg55a5Y7VZz2LuXXQ=; b=IpMT+5QiVh5Lv1u2vmb8J2LHHwMvFDb9nzAHkTvYJyXiDXZz4lzzXB1sgkoagm/3y7QRu8 NGHaXvB2omuYDoc2EkwWp00AG02aGZScf+nrmTeEVBK7WlKKfP8Nqr6ITI1LWGcZcDREMA MOxY7CgQU69TLT2gsfx0HdIyirx/EJ4= 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-114-RpaXykCiMrmnlXuYoIjfwQ-1; Wed, 11 Dec 2019 13:55:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 482D0DB20 for ; Wed, 11 Dec 2019 18:55:41 +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 A15875D6AE; Wed, 11 Dec 2019 18:55:40 +0000 (UTC) From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] python/qemu: Add set_qmp_monitor() to QEMUMachine Date: Wed, 11 Dec 2019 13:55:35 -0500 Message-Id: <20191211185536.16962-2-wainersm@redhat.com> In-Reply-To: <20191211185536.16962-1-wainersm@redhat.com> References: <20191211185536.16962-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: RpaXykCiMrmnlXuYoIjfwQ-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Cleber Rosa --- python/qemu/machine.py | 66 +++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index a4631d6934..7d4d621a42 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -104,6 +104,7 @@ class QEMUMachine(object): self._events = [] self._iolog = None self._socket_scm_helper = socket_scm_helper + self._qmp_set = True # Enable QMP monitor by default. self._qmp = None self._qemu_full_args = None self._test_dir = test_dir @@ -228,15 +229,16 @@ class QEMUMachine(object): self._iolog = iolog.read() def _base_args(self): - if isinstance(self._monitor_address, tuple): - moncdev = "socket,id=mon,host=%s,port=%s" % ( + args = ['-display', 'none', '-vga', 'none'] + if self._qmp_set: + if isinstance(self._monitor_address, tuple): + moncdev = "socket,id=mon,host=%s,port=%s" % ( self._monitor_address[0], self._monitor_address[1]) - else: - moncdev = 'socket,id=mon,path=%s' % self._vm_monitor - args = ['-chardev', moncdev, - '-mon', 'chardev=mon,mode=control', - '-display', 'none', '-vga', 'none'] + else: + moncdev = 'socket,id=mon,path=%s' % self._vm_monitor + args.extend(['-chardev', moncdev, '-mon', + 'chardev=mon,mode=control']) if self._machine is not None: args.extend(['-machine', self._machine]) if self._console_set: @@ -255,20 +257,21 @@ class QEMUMachine(object): def _pre_launch(self): self._temp_dir = tempfile.mkdtemp(dir=self._test_dir) - if self._monitor_address is not None: - self._vm_monitor = self._monitor_address - else: - self._vm_monitor = os.path.join(self._sock_dir, - self._name + "-monitor.sock") - self._remove_files.append(self._vm_monitor) self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log") self._qemu_log_file = open(self._qemu_log_path, 'wb') - self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor, - server=True) + if self._qmp_set: + if self._monitor_address is not None: + self._vm_monitor = self._monitor_address + else: + self._vm_monitor = os.path.join(self._sock_dir, + self._name + "-monitor.sock") + self._remove_files.append(self._vm_monitor) + self._qmp = qmp.QEMUMonitorProtocol(self._vm_monitor, server=True) def _post_launch(self): - self._qmp.accept() + if self._qmp: + self._qmp.accept() 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() @@ -346,12 +350,13 @@ class QEMUMachine(object): self._console_socket = None 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() self._load_io_log() @@ -368,6 +373,21 @@ class QEMUMachine(object): self._launched = False + def set_qmp_monitor(self, enabled=True): + """ + Set the QMP monitor. + + @param enabled: if False, qmp monitor options will be removed from + the base arguments of the resulting QEMU command + line. Default is True. + @note: call this function before launch(). + """ + if enabled: + self._qmp_set = True + else: + self._qmp_set = False + self._qmp = None + def qmp(self, cmd, conv_keys=True, **args): """ Invoke a QMP command and return the response dict From patchwork Wed Dec 11 18:55:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wainer dos Santos Moschetta X-Patchwork-Id: 1207848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="K4zGoDUd"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Y5kC6W9cz9sNH for ; Thu, 12 Dec 2019 05:56:18 +1100 (AEDT) Received: from localhost ([::1]:47952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if79g-00086X-2I for incoming@patchwork.ozlabs.org; Wed, 11 Dec 2019 13:56:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44429) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1if79I-00086A-9m for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1if79F-0006T6-6J for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:46 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26217 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 1if79F-0006RY-0e for qemu-devel@nongnu.org; Wed, 11 Dec 2019 13:55:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576090544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C027+qP+Ucd9AjIY+dJd9HmyMJGJbuHv6eZml/KFFFY=; b=K4zGoDUdtXQj9umxNspdvy9918KE0DiKy/xacLJk1j6k5ByDFIkO8m8DgLb7l+4CUM6Oga tAuS0PjQliC28WLLsb5A6qi4PR1nDbPM6JDitwiEV/l+Fy0OWMHj0/Q19DVHc0rLpzm/Z4 5F3TI3j/lEJleof6r1W8jFcdb9zbpWk= 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-396-3W6x3mDQO_uApiHMUkTPsw-1; Wed, 11 Dec 2019 13:55:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 089E3800D53 for ; Wed, 11 Dec 2019 18:55:42 +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 679565D6AE; Wed, 11 Dec 2019 18:55:41 +0000 (UTC) From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] tests/acceptance: Makes linux_initrd and empty_cpu_model use QEMUMachine Date: Wed, 11 Dec 2019 13:55:36 -0500 Message-Id: <20191211185536.16962-3-wainersm@redhat.com> In-Reply-To: <20191211185536.16962-1-wainersm@redhat.com> References: <20191211185536.16962-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 3W6x3mDQO_uApiHMUkTPsw-1 X-Mimecast-Spam-Score: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 | 12 ++++++------ tests/acceptance/linux_initrd.py | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/acceptance/empty_cpu_model.py b/tests/acceptance/empty_cpu_model.py index 3f4f663582..a1e59e45e4 100644 --- a/tests/acceptance/empty_cpu_model.py +++ b/tests/acceptance/empty_cpu_model.py @@ -7,13 +7,13 @@ # # 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 class EmptyCPUModel(Test): def test(self): - cmd = [self.qemu_bin, '-S', '-display', 'none', '-machine', 'none', '-cpu', ''] - r = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.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 empty") + self.vm.add_args('-S', '-display', 'none', '-machine', 'none', '-cpu', '') + self.vm.set_qmp_monitor(enabled=False) + 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_initrd.py index c61d9826a4..aaa4eb9698 100644 --- a/tests/acceptance/linux_initrd.py +++ b/tests/acceptance/linux_initrd.py @@ -10,7 +10,6 @@ import logging import tempfile -from avocado.utils.process import run from avocado_qemu import Test @@ -41,13 +40,15 @@ class LinuxInitrd(Test): initrd.seek(max_size) initrd.write(b'\0') initrd.flush() - cmd = "%s -kernel %s -initrd %s -m 4096" % ( - self.qemu_bin, kernel_path, initrd.name) - res = run(cmd, ignore_status=True) - self.assertEqual(res.exit_status, 1) + self.vm.add_args('-kernel', kernel_path, '-initrd', initrd.name, + '-m', '4096') + self.vm.set_qmp_monitor(enabled=False) + self.vm.launch() + self.vm.wait() + self.assertEqual(self.vm.exitcode(), 1) expected_msg = 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) def test_with_2gib_file_should_work_with_linux_v4_16(self): """