From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503077102925864.9143565795666; Fri, 18 Aug 2017 10:25:02 -0700 (PDT) Received: from localhost ([::1]:42950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dil13-00028K-Nc for importer@patchew.org; Fri, 18 Aug 2017 13:25:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42408) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikq7-0000a6-UR for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikq7-00066C-0R for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikq6-00065x-R0 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:42 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 913E7883C7; Fri, 18 Aug 2017 17:06:00 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E7BC6BC2C; Fri, 18 Aug 2017 17:05:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 913E7883C7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:16 +0200 Message-Id: <20170818170526.13496-2-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Aug 2017 17:06:00 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 01/11] qemu.py: fix is_running() return before first launch() 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" is_running() returns None when called before the first time we call launch(): >>> import qemu >>> vm =3D qemu.QEMUMachine('qemu-system-x86_64') >>> vm.is_running() >>> It should return False instead. This patch fixes that. For consistence, this patch removes the parenthesis from the second clause as it's not really needed. Signed-off-by: Amador Pahim --- scripts/qemu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8219..0ae5d39414 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -86,7 +86,7 @@ class QEMUMachine(object): raise =20 def is_running(self): - return self._popen and (self._popen.returncode is None) + return self._popen is not None and self._popen.returncode is None =20 def exitcode(self): if self._popen is None: --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076830078563.0217651045275; Fri, 18 Aug 2017 10:20:30 -0700 (PDT) Received: from localhost ([::1]:42485 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikwe-0006AR-PM for importer@patchew.org; Fri, 18 Aug 2017 13:20:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikoj-0007ei-7w for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikog-0005iT-6e for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikof-0005iB-U4 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44A06356E8; Fri, 18 Aug 2017 17:06:04 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id E742E6BC24; Fri, 18 Aug 2017 17:06:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44A06356E8 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:17 +0200 Message-Id: <20170818170526.13496-3-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Aug 2017 17:06:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 02/11] qemu.py: avoid writing to stdout/stderr 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This module should not write directly to stdout/stderr. Instead, it should either raise exceptions or just log the messages and let the callers handle them and decide what to do. For example, scripts could choose to send the log messages stderr or/and write them to a file if verbose or debugging mode is enabled. This patch replaces the writes to stderr by an exception in the send_fd_scm() when _socket_scm_helper is not set or not present. In the same method, the subprocess Popen will now redirect the stdout/stderr to logging.debug instead of writing to system stderr. As consequence, since the Popen.communicate() is now used (in order to get the stdout), the further call to wait() became redundant and was replaced by Popen.returncode. The shutdown() message on negative exit code will now be logged to logging.debug instead of written to system stderr. Signed-off-by: Amador Pahim --- scripts/qemu.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 0ae5d39414..ef531bb23b 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -13,6 +13,7 @@ # =20 import errno +import logging import string import os import sys @@ -20,6 +21,15 @@ import subprocess import qmp.qmp =20 =20 +LOG =3D logging.getLogger(__name__) + + +class QEMUMachineError(Exception): + """ + Exception called when an error in QEMUMachine happens. + """ + + class QEMUMachine(object): '''A QEMU VM''' =20 @@ -62,18 +72,20 @@ class QEMUMachine(object): # In iotest.py, the qmp should always use unix socket. assert self._qmp.is_scm_available() if self._socket_scm_helper is None: - print >>sys.stderr, "No path to socket_scm_helper set" - return -1 + raise QEMUMachineError("No path to socket_scm_helper set") if os.path.exists(self._socket_scm_helper) =3D=3D False: - print >>sys.stderr, "%s does not exist" % self._socket_scm_hel= per - return -1 + raise QEMUMachineError("%s does not exist" % self._socket_scm_= helper) fd_param =3D ["%s" % self._socket_scm_helper, "%d" % self._qmp.get_sock_fd(), "%s" % fd_file_path] devnull =3D open('/dev/null', 'rb') - p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsys.std= out, - stderr=3Dsys.stderr) - return p.wait() + p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsubproc= ess.PIPE, + stderr=3Dsubprocess.STDOUT) + output =3D p.communicate()[0] + if output: + LOG.debug(output) + + return p.returncode =20 @staticmethod def _remove_if_exists(path): @@ -154,7 +166,8 @@ class QEMUMachine(object): =20 exitcode =3D self._popen.wait() if exitcode < 0: - sys.stderr.write('qemu received signal %i: %s\n' % (-exitc= ode, ' '.join(self._args))) + LOG.debug('qemu received signal %i: %s', -exitcode, + ' '.join(self._args)) self._load_io_log() self._post_shutdown() =20 --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503077151011563.8604216823776; Fri, 18 Aug 2017 10:25:51 -0700 (PDT) Received: from localhost ([::1]:42983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dil1p-0002sM-Rt for importer@patchew.org; Fri, 18 Aug 2017 13:25:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikqX-0000xZ-Tj for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:14:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikqW-0006DR-W5 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:14:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikqW-0006D3-Pm for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:14:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F8F2C0587E8; Fri, 18 Aug 2017 17:06:07 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E4B860468; Fri, 18 Aug 2017 17:06:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6F8F2C0587E8 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:18 +0200 Message-Id: <20170818170526.13496-4-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 18 Aug 2017 17:06:07 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 03/11] qemu.py: use os.path.null instead of /dev/null 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For increased portability, let's use os.path.devnull. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index ef531bb23b..51545f7f97 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -78,7 +78,7 @@ class QEMUMachine(object): fd_param =3D ["%s" % self._socket_scm_helper, "%d" % self._qmp.get_sock_fd(), "%s" % fd_file_path] - devnull =3D open('/dev/null', 'rb') + devnull =3D open(os.path.devnull, 'rb') p =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsubproc= ess.PIPE, stderr=3Dsubprocess.STDOUT) output =3D p.communicate()[0] @@ -139,7 +139,7 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' - devnull =3D open('/dev/null', 'rb') + devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076952384392.4254581114195; Fri, 18 Aug 2017 10:22:32 -0700 (PDT) Received: from localhost ([::1]:42679 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikyd-0008CF-69 for importer@patchew.org; Fri, 18 Aug 2017 13:22:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42233) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikpl-0000Df-7P for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikpi-0005yA-2P for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48200) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikph-0005xp-Rr for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB90A20274; Fri, 18 Aug 2017 17:06:12 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id C88FF60468; Fri, 18 Aug 2017 17:06:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB90A20274 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:19 +0200 Message-Id: <20170818170526.13496-5-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 17:06:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 04/11] qemu.py: use poll() instead of 'returncode' 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 'returncode' Popen attribute is not guaranteed to be updated. It actually depends on a call to either poll(), wait() or communicate(). On the other hand, poll() will: "Check if child process has terminated. Set and return returncode attribute." Let's use the poll() to check whether the process is running and also to get the updated process exit code, when the process is finished. As consequence, the shutdown() calls to self._load_io_log() self._post_shutdown() are now always executed to make sure we cleanup even if VM is not running when the shutdown() is called. Signed-off-by: Amador Pahim --- scripts/qemu.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 51545f7f97..774f971f69 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -98,12 +98,12 @@ class QEMUMachine(object): raise =20 def is_running(self): - return self._popen is not None and self._popen.returncode is None + return self._popen is not None and self._popen.poll() is None =20 def exitcode(self): if self._popen is None: return None - return self._popen.returncode + return self._popen.poll() =20 def get_pid(self): if not self.is_running(): @@ -111,8 +111,15 @@ class QEMUMachine(object): return self._popen.pid =20 def _load_io_log(self): - with open(self._qemu_log_path, "r") as fh: - self._iolog =3D fh.read() + ''' + Load the Qemu log file content (if available) into the proper + instance variable + ''' + try: + with open(self._qemu_log_path, "r") as fh: + self._iolog =3D fh.read() + except IOError: + pass =20 def _base_args(self): if isinstance(self._monitor_address, tuple): @@ -168,8 +175,8 @@ class QEMUMachine(object): if exitcode < 0: LOG.debug('qemu received signal %i: %s', -exitcode, ' '.join(self._args)) - self._load_io_log() - self._post_shutdown() + self._load_io_log() + self._post_shutdown() =20 underscore_to_dash =3D string.maketrans('_', '-') def qmp(self, cmd, conv_keys=3DTrue, **args): --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076452380236.4322713376706; Fri, 18 Aug 2017 10:14:12 -0700 (PDT) Received: from localhost ([::1]:42353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikqZ-0000a5-5l for importer@patchew.org; Fri, 18 Aug 2017 13:14:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikoj-0007ek-8S for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikog-0005iN-2c for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikof-0005iA-Sn for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 117CA356E6; Fri, 18 Aug 2017 17:06:18 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AFCC60468; Fri, 18 Aug 2017 17:06:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 117CA356E6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:20 +0200 Message-Id: <20170818170526.13496-6-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Aug 2017 17:06:18 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 05/11] qemu.py: cleanup redundant calls in launch() 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Now that shutdown() is guaranteed to always execute self._load_io_log() and self._post_shutdown(), their calls in 'except' became redundant and we can safely replace it by a call to shutdown(). Signed-off-by: Amador Pahim --- scripts/qemu.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 774f971f69..902d4c6c78 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -155,11 +155,7 @@ class QEMUMachine(object): stderr=3Dsubprocess.STDOUT, she= ll=3DFalse) self._post_launch() except: - if self.is_running(): - self._popen.kill() - self._popen.wait() - self._load_io_log() - self._post_shutdown() + self.shutdown() raise =20 def shutdown(self): --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076655320556.1073148520966; Fri, 18 Aug 2017 10:17:35 -0700 (PDT) Received: from localhost ([::1]:42434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diktp-0003cm-9v for importer@patchew.org; Fri, 18 Aug 2017 13:17:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikoV-0007SQ-7S for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikoS-0005fb-2g for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikoR-0005fP-Qe for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:12:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D81A5D687; Fri, 18 Aug 2017 17:06:21 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 736806BC24; Fri, 18 Aug 2017 17:06:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5D81A5D687 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:21 +0200 Message-Id: <20170818170526.13496-7-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 18 Aug 2017 17:06:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 06/11] qemu.py: improve message on negative exit code 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The current message shows 'self._args', which contains only part of the options used in the Qemu command line. This patch makes the qemu full args list an instance variable and then uses it in the negative exit code message. Message was moved outside the 'if is_running' block to make sure it will be logged if the VM finishes before the call to shutdown(). Signed-off-by: Amador Pahim --- scripts/qemu.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 902d4c6c78..0bcec4b3b1 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -49,6 +49,7 @@ class QEMUMachine(object): self._iolog =3D None self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug + self._qemu_full_args =3D None =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -146,13 +147,18 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' + self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() - args =3D self._wrapper + [self._binary] + self._base_args() + = self._args - self._popen =3D subprocess.Popen(args, stdin=3Ddevnull, stdout= =3Dqemulog, - stderr=3Dsubprocess.STDOUT, she= ll=3DFalse) + self._qemu_full_args =3D (self._wrapper + [self._binary] + + self._base_args() + self._args) + self._popen =3D subprocess.Popen(self._qemu_full_args, + stdin=3Ddevnull, + stdout=3Dqemulog, + stderr=3Dsubprocess.STDOUT, + shell=3DFalse) self._post_launch() except: self.shutdown() @@ -166,11 +172,17 @@ class QEMUMachine(object): self._qmp.close() except: self._popen.kill() + self._popen.wait() + + exitcode =3D self.exitcode() + if exitcode is not None and exitcode < 0: + msg =3D 'qemu received signal -%i: %s' + if self._qemu_full_args: + command =3D ' '.join(self._qemu_full_args) + else: + command =3D '' + LOG.debug(msg, exitcode, command) =20 - exitcode =3D self._popen.wait() - if exitcode < 0: - LOG.debug('qemu received signal %i: %s', -exitcode, - ' '.join(self._args)) self._load_io_log() self._post_shutdown() =20 --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076489465802.4022903860254; Fri, 18 Aug 2017 10:14:49 -0700 (PDT) Received: from localhost ([::1]:42355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikrA-00017n-2k for importer@patchew.org; Fri, 18 Aug 2017 13:14:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diko7-00077E-4J for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diko3-0005R0-Tp for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49688) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diko3-0005OB-Nr for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B79664A6EB; Fri, 18 Aug 2017 17:06:24 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8D116BC24; Fri, 18 Aug 2017 17:06:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B79664A6EB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:22 +0200 Message-Id: <20170818170526.13496-8-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 Aug 2017 17:06:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 07/11] qemu.py: include debug information on launch error 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When launching a VM, if an exception happens and the VM is not initiated, it might be useful to see the qemu command line and the qemu command output. This patch creates that message. Notice that self._iolog needs to be cleaned up in the beginning of the launch() to make sure we will not expose the qemu log from a previous launch if the current one fails. Signed-off-by: Amador Pahim --- scripts/qemu.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 0bcec4b3b1..29fd2469f9 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -147,6 +147,7 @@ class QEMUMachine(object): =20 def launch(self): '''Launch the VM and establish a QMP connection''' + self._iolog =3D None self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') qemulog =3D open(self._qemu_log_path, 'wb') @@ -162,6 +163,13 @@ class QEMUMachine(object): self._post_launch() except: self.shutdown() + + LOG.debug('Error launching VM') + if self._qemu_full_args: + LOG.debug('Command: %r', ' '.join(self._qemu_full_args)) + if self._iolog: + LOG.debug('Output: %r', self._iolog) + raise =20 def shutdown(self): --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076841106318.5847399944578; Fri, 18 Aug 2017 10:20:41 -0700 (PDT) Received: from localhost ([::1]:42490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikwp-0006MJ-Op for importer@patchew.org; Fri, 18 Aug 2017 13:20:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikpl-0000Di-8E for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikpi-0005yI-52 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikph-0005xq-Ru for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A4FE37EEF; Fri, 18 Aug 2017 17:06:28 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22AFC6BC2A; Fri, 18 Aug 2017 17:06:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A4FE37EEF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:23 +0200 Message-Id: <20170818170526.13496-9-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 17:06:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 08/11] qemu.py: make sure we only remove files we create 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To launch a VM, we need to create basically two files: the monitor socket (if it's a UNIX socket) and the qemu log file. For the qemu log file, we currently just open the path, which will create the file if it does not exist or overwrite the file if it does exist. For the monitor socket, if it already exists, we are currently removing it, even if it's not created by us. This patch moves to pre_launch() the responsibility to make sure we only create files that are not pre-existent and to populate a list of controlled files. This list will then be used as the reference of files to remove during the cleanup (post_shutdown()). Signed-off-by: Amador Pahim --- scripts/qemu.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 29fd2469f9..9ae65e454e 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -41,6 +41,7 @@ class QEMUMachine(object): monitor_address =3D os.path.join(test_dir, name + "-monitor.so= ck") self._monitor_address =3D monitor_address self._qemu_log_path =3D os.path.join(test_dir, name + ".log") + self._qemu_log_fd =3D None self._popen =3D None self._binary =3D binary self._args =3D list(args) # Force copy args in case we modify them @@ -50,6 +51,7 @@ class QEMUMachine(object): self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug self._qemu_full_args =3D None + self._created_files =3D [] =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -134,30 +136,47 @@ class QEMUMachine(object): '-display', 'none', '-vga', 'none'] =20 def _pre_launch(self): - self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_address, s= erver=3DTrue, - debug=3Dself._debug) + try: + self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_addres= s, + server=3DTrue, + debug=3Dself._debug) + except: + raise + else: + if not isinstance(self._monitor_address, tuple): + self._created_files.append(self._monitor_address) + + try: + flags =3D os.O_CREAT | os.O_EXCL | os.O_WRONLY + os.open(self._qemu_log_path, flags) + except: + raise + else: + self._created_files.append(self._qemu_log_path) + self._qemu_log_fd =3D open(self._qemu_log_path, 'wb') =20 def _post_launch(self): self._qmp.accept() =20 def _post_shutdown(self): - if not isinstance(self._monitor_address, tuple): - self._remove_if_exists(self._monitor_address) - self._remove_if_exists(self._qemu_log_path) + if self._qemu_log_fd is not None: + self._qemu_log_fd.close() + + while self._created_files: + self._remove_if_exists(self._created_files.pop()) =20 def launch(self): '''Launch the VM and establish a QMP connection''' self._iolog =3D None self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') - qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() self._qemu_full_args =3D (self._wrapper + [self._binary] + self._base_args() + self._args) self._popen =3D subprocess.Popen(self._qemu_full_args, stdin=3Ddevnull, - stdout=3Dqemulog, + stdout=3Dself._qemu_log_fd, stderr=3Dsubprocess.STDOUT, shell=3DFalse) self._post_launch() --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15030770068911022.7351111203451; Fri, 18 Aug 2017 10:23:26 -0700 (PDT) Received: from localhost ([::1]:42773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikzV-0000UX-Cl for importer@patchew.org; Fri, 18 Aug 2017 13:23:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikq3-0000Vf-94 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikq0-00063u-1N for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikpz-00063f-Qq for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6F1FC047B61; Fri, 18 Aug 2017 17:06:35 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE8EA6BC2A; Fri, 18 Aug 2017 17:06:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6F1FC047B61 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:24 +0200 Message-Id: <20170818170526.13496-10-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 18 Aug 2017 17:06:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 09/11] qemu.py: launch vm only if it's not running 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" A new call to launch() with a running VM will fall in exception and consequently call shutdown(). This patch makes launch() to raise an exception when it's called with VM already running. Signed-off-by: Amador Pahim Reviewed-by: Fam Zheng --- scripts/qemu.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 9ae65e454e..46e8ff3232 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -170,6 +170,9 @@ class QEMUMachine(object): self._iolog =3D None self._qemu_full_args =3D None devnull =3D open(os.path.devnull, 'rb') + if self.is_running(): + raise QEMULaunchError('VM already running') + try: self._pre_launch() self._qemu_full_args =3D (self._wrapper + [self._binary] + --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150307651236998.81008073871476; Fri, 18 Aug 2017 10:15:12 -0700 (PDT) Received: from localhost ([::1]:42357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikrX-0001RZ-4f for importer@patchew.org; Fri, 18 Aug 2017 13:15:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikoK-0007IP-6o for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikoH-0005cn-24 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikoG-0005cc-Sb for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:11:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3CF18046A; Fri, 18 Aug 2017 17:06:38 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31A9C60468; Fri, 18 Aug 2017 17:06:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F3CF18046A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:25 +0200 Message-Id: <20170818170526.13496-11-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 18 Aug 2017 17:06:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 10/11] qemu.py: don't launch again before shutdown() 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If a VM is launched, files are created and a cleanup is required before a new launch. This cleanup is executed by shutdown(), so shutdown() must be called even if the VM is manually terminated (i.e. using kill). This patch creates a control to make sure launch() will not be executed again if shutdown() is not called after the previous launch(). Signed-off-by: Amador Pahim --- scripts/qemu.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/qemu.py b/scripts/qemu.py index 46e8ff3232..2bd81afcf2 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -52,6 +52,7 @@ class QEMUMachine(object): self._debug =3D debug self._qemu_full_args =3D None self._created_files =3D [] + self._pending_shutdown =3D False =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -173,6 +174,9 @@ class QEMUMachine(object): if self.is_running(): raise QEMULaunchError('VM already running') =20 + if self._pending_shutdown: + raise QEMULaunchError('Shutdown pending after previous launch') + try: self._pre_launch() self._qemu_full_args =3D (self._wrapper + [self._binary] + @@ -183,6 +187,7 @@ class QEMUMachine(object): stderr=3Dsubprocess.STDOUT, shell=3DFalse) self._post_launch() + self._pending_shutdown =3D True except: self.shutdown() =20 @@ -215,6 +220,7 @@ class QEMUMachine(object): =20 self._load_io_log() self._post_shutdown() + self._pending_shutdown =3D False =20 underscore_to_dash =3D string.maketrans('_', '-') def qmp(self, cmd, conv_keys=3DTrue, **args): --=20 2.13.5 From nobody Tue Apr 30 00:03:20 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503076623925458.3858080176864; Fri, 18 Aug 2017 10:17:03 -0700 (PDT) Received: from localhost ([::1]:42433 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diktK-0003GD-M3 for importer@patchew.org; Fri, 18 Aug 2017 13:17:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dikpl-0000Dg-7V for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dikpi-0005yJ-50 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dikph-0005xr-SA for qemu-devel@nongnu.org; Fri, 18 Aug 2017 13:13:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 27C51461FE; Fri, 18 Aug 2017 17:06:42 +0000 (UTC) Received: from t460p.pahim.org.com (unknown [10.40.205.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 590616BC2C; Fri, 18 Aug 2017 17:06:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27C51461FE Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 19:05:26 +0200 Message-Id: <20170818170526.13496-12-apahim@redhat.com> In-Reply-To: <20170818170526.13496-1-apahim@redhat.com> References: <20170818170526.13496-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 17:06:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v7 11/11] qemu.py: refactor launch() 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: kwolf@redhat.com, ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, stefanha@gmail.com, Amador Pahim , armbru@redhat.com, mreitz@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is just an refactor to separate the exception handler from the actual launch procedure, improving the readability and making future maintenances in this piece of code easier. Signed-off-by: Amador Pahim --- scripts/qemu.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 2bd81afcf2..7f890ff8e5 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -167,10 +167,10 @@ class QEMUMachine(object): self._remove_if_exists(self._created_files.pop()) =20 def launch(self): - '''Launch the VM and establish a QMP connection''' - self._iolog =3D None - self._qemu_full_args =3D None - devnull =3D open(os.path.devnull, 'rb') + ''' + Try to launch the VM and make sure we cleanup and expose the + command line/output in case of exception. + ''' if self.is_running(): raise QEMULaunchError('VM already running') =20 @@ -178,15 +178,7 @@ class QEMUMachine(object): raise QEMULaunchError('Shutdown pending after previous launch') =20 try: - self._pre_launch() - self._qemu_full_args =3D (self._wrapper + [self._binary] + - self._base_args() + self._args) - self._popen =3D subprocess.Popen(self._qemu_full_args, - stdin=3Ddevnull, - stdout=3Dself._qemu_log_fd, - stderr=3Dsubprocess.STDOUT, - shell=3DFalse) - self._post_launch() + self._launch() self._pending_shutdown =3D True except: self.shutdown() @@ -199,6 +191,21 @@ class QEMUMachine(object): =20 raise =20 + def _launch(self): + '''Launch the VM and establish a QMP connection''' + self._iolog =3D None + self._qemu_full_args =3D None + devnull =3D open(os.path.devnull, 'rb') + self._pre_launch() + self._qemu_full_args =3D (self._wrapper + [self._binary] + + self._base_args() + self._args) + self._popen =3D subprocess.Popen(self._qemu_full_args, + stdin=3Ddevnull, + stdout=3Dself._qemu_log_fd, + stderr=3Dsubprocess.STDOUT, + shell=3DFalse) + self._post_launch() + def shutdown(self): '''Terminate the VM and clean up''' if self.is_running(): --=20 2.13.5