From nobody Mon Apr 29 00:55:44 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 1501003090165947.6049132297575; Tue, 25 Jul 2017 10:18:10 -0700 (PDT) Received: from localhost ([::1]:33757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3TD-0003EW-LJ for importer@patchew.org; Tue, 25 Jul 2017 13:18:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48426) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3SN-0002wB-Vd for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:17:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3SJ-0007kK-Ub for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:17:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3SJ-0007iv-M3 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:17:11 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7291481245; Tue, 25 Jul 2017 17:11:53 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 975D09653E; Tue, 25 Jul 2017 17:11:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7291481245 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:09 +0200 Message-Id: <20170725171014.25193-2-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 17:11:53 +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 v5 1/6] qemu.py: make 'args' public 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" Let's make args public so users can extend it in instances without feeling like abusing the internal API. Signed-off-by: Amador Pahim --- scripts/qemu.py | 14 +++++++------- tests/qemu-iotests/iotests.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8219..59ed5270f8 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -33,7 +33,7 @@ class QEMUMachine(object): self._qemu_log_path =3D os.path.join(test_dir, name + ".log") self._popen =3D None self._binary =3D binary - self._args =3D list(args) # Force copy args in case we modify them + self.args =3D list(args) # Force copy args in case we modify them self._wrapper =3D wrapper self._events =3D [] self._iolog =3D None @@ -43,8 +43,8 @@ class QEMUMachine(object): # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): args =3D 'tcp:%s:%d,server,nowait,telnet' % (ip, port) - self._args.append('-monitor') - self._args.append(args) + self.args.append('-monitor') + self.args.append(args) =20 def add_fd(self, fd, fdset, opaque, opts=3D''): '''Pass a file descriptor to the VM''' @@ -54,8 +54,8 @@ class QEMUMachine(object): if opts: options.append(opts) =20 - self._args.append('-add-fd') - self._args.append(','.join(options)) + self.args.append('-add-fd') + self.args.append(','.join(options)) return self =20 def send_fd_scm(self, fd_file_path): @@ -131,7 +131,7 @@ class QEMUMachine(object): qemulog =3D open(self._qemu_log_path, 'wb') try: self._pre_launch() - args =3D self._wrapper + [self._binary] + self._base_args() + = self._args + 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._post_launch() @@ -154,7 +154,7 @@ 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))) + sys.stderr.write('qemu received signal %i: %s\n' % (-exitc= ode, ' '.join(self.args))) self._load_io_log() self._post_shutdown() =20 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index abcf3c10e2..6925d8841e 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -150,13 +150,13 @@ class VM(qtest.QEMUQtestMachine): self._num_drives =3D 0 =20 def add_device(self, opts): - self._args.append('-device') - self._args.append(opts) + self.args.append('-device') + self.args.append(opts) return self =20 def add_drive_raw(self, opts): - self._args.append('-drive') - self._args.append(opts) + self.args.append('-drive') + self.args.append(opts) return self =20 def add_drive(self, path, opts=3D'', interface=3D'virtio', format=3Dim= gfmt): @@ -172,17 +172,17 @@ class VM(qtest.QEMUQtestMachine): if opts: options.append(opts) =20 - self._args.append('-drive') - self._args.append(','.join(options)) + self.args.append('-drive') + self.args.append(','.join(options)) self._num_drives +=3D 1 return self =20 def add_blockdev(self, opts): - self._args.append('-blockdev') + self.args.append('-blockdev') if isinstance(opts, str): - self._args.append(opts) + self.args.append(opts) else: - self._args.append(','.join(opts)) + self.args.append(','.join(opts)) return self =20 def pause_drive(self, drive, event=3DNone): --=20 2.13.3 From nobody Mon Apr 29 00:55:44 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 1501003305340701.0184823828696; Tue, 25 Jul 2017 10:21:45 -0700 (PDT) Received: from localhost ([::1]:33769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3Wg-0004xq-Ia for importer@patchew.org; Tue, 25 Jul 2017 13:21:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48932) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3VA-00043m-3w for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3V6-0001QJ-3S for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20744) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3V5-0001Pq-TY for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5759361B82; Tue, 25 Jul 2017 17:12:00 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA84295A67; Tue, 25 Jul 2017 17:11:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5759361B82 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=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:10 +0200 Message-Id: <20170725171014.25193-3-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 25 Jul 2017 17:12: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 v5 2/6] 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, if any. Signed-off-by: Amador Pahim Reviewed-by: Stefan Hajnoczi --- scripts/qemu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 59ed5270f8..f37e2fe58e 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -86,12 +86,12 @@ class QEMUMachine(object): raise =20 def is_running(self): - return self._popen and (self._popen.returncode is None) + return self._popen 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(): --=20 2.13.3 From nobody Mon Apr 29 00:55:44 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 1501003562553578.1434405328552; Tue, 25 Jul 2017 10:26:02 -0700 (PDT) Received: from localhost ([::1]:33789 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3aq-0008OT-VC for importer@patchew.org; Tue, 25 Jul 2017 13:26:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3WI-0004vt-1A for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:21:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3WE-00025x-1R for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:21:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44292) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3WD-00025e-RL for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:21:13 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB82B7C846; Tue, 25 Jul 2017 17:12:11 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8EAC95A67; Tue, 25 Jul 2017 17:12:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AB82B7C846 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:11 +0200 Message-Id: <20170725171014.25193-4-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 25 Jul 2017 17:12:11 +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 v5 3/6] qemu.py: cleanup 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 message contains the self._args, which has only part of the options used in the qemu command line and is not representative enough to figure out what happened to the process. This patch drops the self._args part of the message. Signed-off-by: Amador Pahim Reviewed-by: Stefan Hajnoczi --- scripts/qemu.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index f37e2fe58e..56142ed59b 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -154,7 +154,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))) + sys.stderr.write('qemu received signal %i\n' % -exitcode) + self._load_io_log() self._post_shutdown() =20 --=20 2.13.3 From nobody Mon Apr 29 00:55:44 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 1501003424836870.0212036883518; Tue, 25 Jul 2017 10:23:44 -0700 (PDT) Received: from localhost ([::1]:33778 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3Yd-0006T1-GQ for importer@patchew.org; Tue, 25 Jul 2017 13:23:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3XC-0005aj-Bz for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:22:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3X8-0002Ox-Ak for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:22:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3X8-0002Of-1f for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:22:10 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4358F8E3D5; Tue, 25 Jul 2017 17:12:15 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DB6B95A67; Tue, 25 Jul 2017 17:12:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4358F8E3D5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:12 +0200 Message-Id: <20170725171014.25193-5-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 17:12:15 +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 v5 4/6] qemu.py: cleanup 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" launch() is currently taking care of a number of flows, each one if its own exception treatment, depending on the VM state and the files creation state. This patch makes launch() more resilient, off-loading the core calls to the new _launch() and calling shutdown() if any exception is raised by _launch(), making sure VM will be terminated and cleaned up. Signed-off-by: Amador Pahim --- scripts/qemu.py | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 56142ed59b..45a63e8e9d 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -99,8 +99,11 @@ 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() + 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): @@ -126,23 +129,28 @@ class QEMUMachine(object): self._remove_if_exists(self._qemu_log_path) =20 def launch(self): - '''Launch the VM and establish a QMP connection''' - devnull =3D open('/dev/null', 'rb') - qemulog =3D open(self._qemu_log_path, 'wb') + ''' + Try to launch the VM and make sure we cleanup on exception. + ''' + if self.is_running(): + return + 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._post_launch() + self._launch() except: - if self.is_running(): - self._popen.kill() - self._popen.wait() - self._load_io_log() - self._post_shutdown() + self.shutdown() raise =20 + def _launch(self): + '''Launch the VM and establish a QMP connection.''' + devnull =3D open('/dev/null', 'rb') + qemulog =3D open(self._qemu_log_path, 'wb') + self._pre_launch() + args =3D self._wrapper + [self._binary] + self._base_args() + self= ._args + self._popen =3D subprocess.Popen(args, stdin=3Ddevnull, stdout=3Dq= emulog, + stderr=3Dsubprocess.STDOUT, shell= =3DFalse) + self._post_launch() + def shutdown(self): '''Terminate the VM and clean up''' if self.is_running(): @@ -156,8 +164,8 @@ class QEMUMachine(object): if exitcode < 0: sys.stderr.write('qemu received signal %i\n' % -exitcode) =20 - 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.3 From nobody Mon Apr 29 00:55:44 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 1501003350420634.8352457508181; Tue, 25 Jul 2017 10:22:30 -0700 (PDT) Received: from localhost ([::1]:33771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3XQ-0005Ve-Rj for importer@patchew.org; Tue, 25 Jul 2017 13:22:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3VA-00043n-3s for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3V6-0001QW-5G for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3V5-0001Pr-VJ for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD4FB61D11; Tue, 25 Jul 2017 17:12:21 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C80396533; Tue, 25 Jul 2017 17:12:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BD4FB61D11 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=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:13 +0200 Message-Id: <20170725171014.25193-6-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 25 Jul 2017 17:12: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 v5 5/6] qemu.py: make sure shutdown() is called before launching again 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 launch() is called twice or if the VM is terminated not using shutdown(), the new call to launch() will fail due to the dirty environment, with files from the previous instance laying around. This patch add to launch() the ability to check whether shutdown() was called after a previous launch(), calling it when applies. 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 45a63e8e9d..e18e8ec657 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -39,6 +39,7 @@ class QEMUMachine(object): self._iolog =3D None self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug + self._shutdown_pending =3D False =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -135,8 +136,14 @@ class QEMUMachine(object): if self.is_running(): return =20 + if self._shutdown_pending: + sys.stderr.write('shutdown() was not called after previous ' + 'launch(). Calling now.\n') + self.shutdown() + try: self._launch() + self._shutdown_pending =3D True except: self.shutdown() raise @@ -166,6 +173,7 @@ class QEMUMachine(object): =20 self._load_io_log() self._post_shutdown() + self._shutdown_pending =3D False =20 underscore_to_dash =3D string.maketrans('_', '-') def qmp(self, cmd, conv_keys=3DTrue, **args): --=20 2.13.3 From nobody Mon Apr 29 00:55:44 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 1501003475919513.2652542757244; Tue, 25 Jul 2017 10:24:35 -0700 (PDT) Received: from localhost ([::1]:33780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3ZS-0007MG-Kp for importer@patchew.org; Tue, 25 Jul 2017 13:24:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da3VC-000463-03 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da3V6-0001QR-4P for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33490) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da3V5-0001Pt-UR for qemu-devel@nongnu.org; Tue, 25 Jul 2017 13:20:04 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 147A661E48; Tue, 25 Jul 2017 17:12:28 +0000 (UTC) Received: from t460p.pahim.org.com (ovpn-204-234.brq.redhat.com [10.40.204.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19F1995A67; Tue, 25 Jul 2017 17:12:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 147A661E48 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=pass smtp.mailfrom=apahim@redhat.com From: Amador Pahim To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 19:10:14 +0200 Message-Id: <20170725171014.25193-7-apahim@redhat.com> In-Reply-To: <20170725171014.25193-1-apahim@redhat.com> References: <20170725171014.25193-1-apahim@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 25 Jul 2017 17:12: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 v5 6/6] qemu.py: include qemu command line and output 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 is useful to see the qemu command line that was executed and the output of that command. Signed-off-by: Amador Pahim --- scripts/qemu.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index e18e8ec657..abfa3eebe9 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -131,7 +131,8 @@ class QEMUMachine(object): =20 def launch(self): ''' - Try to launch the VM and make sure we cleanup on exception. + Try to launch the VM and make sure we cleanup and expose the + command line/output in case of exception. ''' if self.is_running(): return @@ -142,18 +143,24 @@ class QEMUMachine(object): self.shutdown() =20 try: - self._launch() + args =3D None + args =3D self._wrapper + [self._binary] + self._base_args() + = self._args + self._launch(args) self._shutdown_pending =3D True except: self.shutdown() + sys.stderr.write('Error launching VM.\n%s%s' % + ('Command:\n%s\n' % + ' '.join(args) if args else '', + 'Output:\n%s\n' % + ''.join(self._iolog) if self._iolog else '')) raise =20 - def _launch(self): + def _launch(self, args): '''Launch the VM and establish a QMP connection.''' devnull =3D open('/dev/null', 'rb') qemulog =3D open(self._qemu_log_path, 'wb') self._pre_launch() - args =3D self._wrapper + [self._binary] + self._base_args() + self= ._args self._popen =3D subprocess.Popen(args, stdin=3Ddevnull, stdout=3Dq= emulog, stderr=3Dsubprocess.STDOUT, shell= =3DFalse) self._post_launch() --=20 2.13.3