From nobody Mon Apr 29 22:21:15 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 1503066774220441.5737434723967; Fri, 18 Aug 2017 07:32:54 -0700 (PDT) Received: from localhost ([::1]:58002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiKT-0005Fl-0F for importer@patchew.org; Fri, 18 Aug 2017 10:32:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiEh-00005O-0L for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEd-00077r-OW for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:26:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEd-000764-Et for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:26:51 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E31D80F6D; Fri, 18 Aug 2017 14:26:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9614E66D76; Fri, 18 Aug 2017 14:26:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E31D80F6D 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=fail smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:04 +0200 Message-Id: <20170818142613.32394-2-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 18 Aug 2017 14:26:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 01/10] qemu.py: Pylint/style fixes 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No actual code changes, just several pylint/style fixes and docstring clarifications. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Stefan Hajnoczi Reviewed-by: Cleber Rosa --- scripts/qemu.py | 73 +++++++++++++++++++++++++++++++++++++++++++----------= ---- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8..dd679f1 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -23,8 +23,22 @@ import qmp.qmp class QEMUMachine(object): '''A QEMU VM''' =20 - def __init__(self, binary, args=3D[], wrapper=3D[], name=3DNone, test_= dir=3D"/var/tmp", - monitor_address=3DNone, socket_scm_helper=3DNone, debug= =3DFalse): + def __init__(self, binary, args=3D[], wrapper=3D[], name=3DNone, + test_dir=3D"/var/tmp", monitor_address=3DNone, + socket_scm_helper=3DNone, debug=3DFalse): + ''' + Initialize a QEMUMachine + + @param binary: path to the qemu binary + @param args: list of extra arguments + @param wrapper: list of arguments used as prefix to qemu binary + @param name: prefix for socket and log file names (default: qemu-P= ID) + @param test_dir: where to create socket and log file + @param monitor_address: address for QMP monitor + @param socket_scm_helper: helper program, required for send_fd_scm= ()" + @param debug: enable debug mode + @note: Qemu process is not started until launch() is used. + ''' if name is None: name =3D "qemu-%d" % os.getpid() if monitor_address is None: @@ -33,12 +47,13 @@ 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 self._socket_scm_helper =3D socket_scm_helper self._debug =3D debug + self._qmp =3D None =20 # This can be used to add an unused monitor instance. def add_monitor_telnet(self, ip, port): @@ -64,16 +79,16 @@ class QEMUMachine(object): if self._socket_scm_helper is None: print >>sys.stderr, "No path to socket_scm_helper set" return -1 - if os.path.exists(self._socket_scm_helper) =3D=3D False: + if not os.path.exists(self._socket_scm_helper): print >>sys.stderr, "%s does not exist" % self._socket_scm_hel= per return -1 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() + proc =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsys.= stdout, + stderr=3Dsys.stderr) + return proc.wait() =20 @staticmethod def _remove_if_exists(path): @@ -99,8 +114,8 @@ 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() + with open(self._qemu_log_path, "r") as iolog: + self._iolog =3D iolog.read() =20 def _base_args(self): if isinstance(self._monitor_address, tuple): @@ -114,7 +129,8 @@ class QEMUMachine(object): '-display', 'none', '-vga', 'none'] =20 def _pre_launch(self): - self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_address, s= erver=3DTrue, + self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_address, + server=3DTrue, debug=3Dself._debug) =20 def _post_launch(self): @@ -131,9 +147,11 @@ 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) + stderr=3Dsubprocess.STDOUT, + shell=3DFalse) self._post_launch() except: if self.is_running(): @@ -154,23 +172,30 @@ 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' + % (-exitcode, ' '.join(self._args))) self._load_io_log() self._post_shutdown() =20 underscore_to_dash =3D string.maketrans('_', '-') + def qmp(self, cmd, conv_keys=3DTrue, **args): - '''Invoke a QMP command and return the result dict''' + '''Invoke a QMP command and return the response dict''' qmp_args =3D dict() - for k in args.keys(): + for key in args.keys(): if conv_keys: - qmp_args[k.translate(self.underscore_to_dash)] =3D args[k] + qmp_args[key.translate(self.underscore_to_dash)] =3D args[= key] else: - qmp_args[k] =3D args[k] + qmp_args[key] =3D args[key] =20 return self._qmp.cmd(cmd, args=3Dqmp_args) =20 def command(self, cmd, conv_keys=3DTrue, **args): + ''' + Invoke a QMP command. + On success return the response dict. + On failure raise an exception. + ''' reply =3D self.qmp(cmd, conv_keys, **args) if reply is None: raise Exception("Monitor is closed") @@ -193,7 +218,15 @@ class QEMUMachine(object): return events =20 def event_wait(self, name, timeout=3D60.0, match=3DNone): - # Test if 'match' is a recursive subset of 'event' + ''' + Wait for specified timeout on named event in QMP; optionally filter + results by match. + + The 'match' is checked to be a recursive subset of the 'event'; sk= ips + branch processing on match's value None + {"foo": {"bar": 1}} matches {"foo": None} + {"foo": {"bar": 1}} does not matches {"foo": {"baz": None}} + ''' def event_match(event, match=3DNone): if match is None: return True @@ -226,4 +259,8 @@ class QEMUMachine(object): return None =20 def get_log(self): + ''' + After self.shutdown or failed qemu execution, this returns the out= put + of the qemu process. + ''' return self._iolog --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066686519812.4175206288753; Fri, 18 Aug 2017 07:31:26 -0700 (PDT) Received: from localhost ([::1]:57995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiJ2-00041t-Vf for importer@patchew.org; Fri, 18 Aug 2017 10:31:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiEl-0000AZ-D3 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEk-0007ac-BU for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:26:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39348) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEk-0007Wc-4x for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:26:58 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E8FB883C7; Fri, 18 Aug 2017 14:26:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADA5566D76; Fri, 18 Aug 2017 14:26:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2E8FB883C7 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:05 +0200 Message-Id: <20170818142613.32394-3-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Aug 2017 14:26:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 02/10] qemu|qtest: Avoid dangerous arguments 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The list object is mutable in python and potentially might modify other object's arguments when used as default argument. Reproducer: >>> vm1 =3D QEMUMachine("qemu") >>> vm2 =3D QEMUMachine("qemu") >>> vm1._wrapper.append("foo") >>> print vm2._wrapper ['foo'] In this case the `args` is actually copied so it would be safe to keep it, but it's not a good practice to keep it. The same issue applies in inherited qtest module. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Cleber Rosa --- scripts/qemu.py | 6 +++++- scripts/qtest.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index dd679f1..5d09de4 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -23,7 +23,7 @@ import qmp.qmp class QEMUMachine(object): '''A QEMU VM''' =20 - def __init__(self, binary, args=3D[], wrapper=3D[], name=3DNone, + def __init__(self, binary, args=3DNone, wrapper=3DNone, name=3DNone, test_dir=3D"/var/tmp", monitor_address=3DNone, socket_scm_helper=3DNone, debug=3DFalse): ''' @@ -39,6 +39,10 @@ class QEMUMachine(object): @param debug: enable debug mode @note: Qemu process is not started until launch() is used. ''' + if args is None: + args =3D [] + if wrapper is None: + wrapper =3D [] if name is None: name =3D "qemu-%d" % os.getpid() if monitor_address is None: diff --git a/scripts/qtest.py b/scripts/qtest.py index d5aecb5..ab183c0 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -79,7 +79,7 @@ class QEMUQtestProtocol(object): class QEMUQtestMachine(qemu.QEMUMachine): '''A QEMU VM''' =20 - def __init__(self, binary, args=3D[], name=3DNone, test_dir=3D"/var/tm= p", + def __init__(self, binary, args=3DNone, name=3DNone, test_dir=3D"/var/= tmp", socket_scm_helper=3DNone): if name is None: name =3D "qemu-%d" % os.getpid() --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066724679468.9760648899412; Fri, 18 Aug 2017 07:32:04 -0700 (PDT) Received: from localhost ([::1]:57997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiJf-0004Ve-Bz for importer@patchew.org; Fri, 18 Aug 2017 10:32:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiEq-0000GJ-39 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEm-0007kQ-SV for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEm-0007hq-Ls for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9DE1C047B6A; Fri, 18 Aug 2017 14:26:59 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D43466D76; Fri, 18 Aug 2017 14:26:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9DE1C047B6A 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:06 +0200 Message-Id: <20170818142613.32394-4-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 18 Aug 2017 14:26:59 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 03/10] qemu.py: Use iteritems rather than keys() 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's avoid creating an in-memory list of keys and query for each value and use `iteritems` which is an iterator of key-value pairs. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Cleber Rosa --- scripts/qemu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 5d09de4..db21407 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -186,11 +186,11 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=3DTrue, **args): '''Invoke a QMP command and return the response dict''' qmp_args =3D dict() - for key in args.keys(): + for key, value in args.iteritems(): if conv_keys: - qmp_args[key.translate(self.underscore_to_dash)] =3D args[= key] + qmp_args[key.translate(self.underscore_to_dash)] =3D value else: - qmp_args[key] =3D args[key] + qmp_args[key] =3D value =20 return self._qmp.cmd(cmd, args=3Dqmp_args) =20 --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066870581341.0574775101961; Fri, 18 Aug 2017 07:34:30 -0700 (PDT) Received: from localhost ([::1]:58101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiM1-0006g3-3D for importer@patchew.org; Fri, 18 Aug 2017 10:34:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiEs-0000KH-SL for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEs-0007yc-3B for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEr-0007wF-T3 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DDA9E4E4C8; Fri, 18 Aug 2017 14:27:04 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03FFC66D76; Fri, 18 Aug 2017 14:26:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DDA9E4E4C8 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:07 +0200 Message-Id: <20170818142613.32394-5-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 18 Aug 2017 14:27:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 04/10] qemu.py: Simplify QMP key-conversion 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The QMP key conversion consist of '_'s to be replaced with '-'s, which can easily be done by a single `str.replace` method which is faster and does not require `string` module import. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- scripts/qemu.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index db21407..19cbd34 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -13,7 +13,6 @@ # =20 import errno -import string import os import sys import subprocess @@ -181,14 +180,12 @@ class QEMUMachine(object): self._load_io_log() self._post_shutdown() =20 - underscore_to_dash =3D string.maketrans('_', '-') - def qmp(self, cmd, conv_keys=3DTrue, **args): '''Invoke a QMP command and return the response dict''' qmp_args =3D dict() for key, value in args.iteritems(): if conv_keys: - qmp_args[key.translate(self.underscore_to_dash)] =3D value + qmp_args[key.replace('_', '-')] =3D value else: qmp_args[key] =3D value =20 --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066967230709.4905070058505; Fri, 18 Aug 2017 07:36:07 -0700 (PDT) Received: from localhost ([::1]:58114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiNa-00086l-0q for importer@patchew.org; Fri, 18 Aug 2017 10:36:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiEz-0000RX-V2 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEw-0008B6-P1 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48404) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEw-00088t-JL for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:10 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 95123356C9; Fri, 18 Aug 2017 14:27:09 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3173066D98; Fri, 18 Aug 2017 14:27:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 95123356C9 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:08 +0200 Message-Id: <20170818142613.32394-6-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Aug 2017 14:27:09 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 05/10] qemu.py: Use custom exceptions rather than Exception 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The naked Exception should not be widely used. It makes sense to be a bit more specific and use better-suited custom exceptions. As a benefit we can store the full reply in the exception in case someone needs it when catching the exception. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost --- scripts/qemu.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 19cbd34..97ecb63 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -19,6 +19,19 @@ import subprocess import qmp.qmp =20 =20 +class MonitorResponseError(qmp.qmp.QMPError): + ''' + Represents erroneous QMP monitor reply + ''' + def __init__(self, reply): + try: + desc =3D reply["error"]["desc"] + except KeyError: + desc =3D reply + super(MonitorResponseError, self).__init__(desc) + self.reply =3D reply + + class QEMUMachine(object): '''A QEMU VM''' =20 @@ -199,9 +212,9 @@ class QEMUMachine(object): ''' reply =3D self.qmp(cmd, conv_keys, **args) if reply is None: - raise Exception("Monitor is closed") + raise qmp.qmp.QMPError("Monitor is closed") if "error" in reply: - raise Exception(reply["error"]["desc"]) + raise MonitorResponseError(reply) return reply["return"] =20 def get_qmp_event(self, wait=3DFalse): --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066724014803.8933634291973; Fri, 18 Aug 2017 07:32:04 -0700 (PDT) Received: from localhost ([::1]:57996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiJe-0004Ub-Mt for importer@patchew.org; Fri, 18 Aug 2017 10:32:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiF0-0000Rz-EK for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiEz-0008Cv-8Q for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiEy-0008CC-Vf for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:13 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02DF05F7AE; Fri, 18 Aug 2017 14:27:12 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id E541166D81; Fri, 18 Aug 2017 14:27:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 02DF05F7AE 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:09 +0200 Message-Id: <20170818142613.32394-7-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 18 Aug 2017 14:27:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 06/10] qmp.py: Couple of pylint/style fixes 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No actual code changes, just initializing attributes earlier to avoid AttributeError on early introspection, a few pylint/style fixes and docstring clarifications. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qmp/qmp.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index 62d3651..782d1ac 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -13,19 +13,30 @@ import errno import socket import sys =20 + class QMPError(Exception): pass =20 + class QMPConnectError(QMPError): pass =20 + class QMPCapabilitiesError(QMPError): pass =20 + class QMPTimeoutError(QMPError): pass =20 + class QEMUMonitorProtocol: + + #: Socket's error class + error =3D socket.error + #: Socket's timeout + timeout =3D socket.timeout + def __init__(self, address, server=3DFalse, debug=3DFalse): """ Create a QEMUMonitorProtocol class. @@ -42,6 +53,7 @@ class QEMUMonitorProtocol: self.__address =3D address self._debug =3D debug self.__sock =3D self.__get_sock() + self.__sockfile =3D None if server: self.__sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,= 1) self.__sock.bind(self.__address) @@ -56,7 +68,7 @@ class QEMUMonitorProtocol: =20 def __negotiate_capabilities(self): greeting =3D self.__json_read() - if greeting is None or not greeting.has_key('QMP'): + if greeting is None or "QMP" not in greeting: raise QMPConnectError # Greeting seems ok, negotiate capabilities resp =3D self.cmd('qmp_capabilities') @@ -78,8 +90,6 @@ class QEMUMonitorProtocol: continue return resp =20 - error =3D socket.error - def __get_events(self, wait=3DFalse): """ Check for new events in the stream and cache them in __events. @@ -89,8 +99,8 @@ class QEMUMonitorProtocol: =20 @raise QMPTimeoutError: If a timeout float is provided and the tim= eout period elapses. - @raise QMPConnectError: If wait is True but no events could be ret= rieved - or if some other error occurred. + @raise QMPConnectError: If wait is True but no events could be + retrieved or if some other error occurred. """ =20 # Check for new events regardless and pull them into the cache: @@ -175,7 +185,7 @@ class QEMUMonitorProtocol: @param args: command arguments (dict) @param id: command id (dict, list, string or int) """ - qmp_cmd =3D { 'execute': name } + qmp_cmd =3D {'execute': name} if args: qmp_cmd['arguments'] =3D args if id: @@ -183,6 +193,9 @@ class QEMUMonitorProtocol: return self.cmd_obj(qmp_cmd) =20 def command(self, cmd, **kwds): + """ + Build and send a QMP command to the monitor, report errors if any + """ ret =3D self.cmd(cmd, kwds) if ret.has_key('error'): raise Exception(ret['error']['desc']) @@ -190,15 +203,15 @@ class QEMUMonitorProtocol: =20 def pull_event(self, wait=3DFalse): """ - Get and delete the first available QMP event. + Pulls a single event. =20 @param wait (bool): block until an event is available. @param wait (float): If wait is a float, treat it as a timeout val= ue. =20 @raise QMPTimeoutError: If a timeout float is provided and the tim= eout period elapses. - @raise QMPConnectError: If wait is True but no events could be ret= rieved - or if some other error occurred. + @raise QMPConnectError: If wait is True but no events could be + retrieved or if some other error occurred. =20 @return The first available QMP event, or None. """ @@ -217,8 +230,8 @@ class QEMUMonitorProtocol: =20 @raise QMPTimeoutError: If a timeout float is provided and the tim= eout period elapses. - @raise QMPConnectError: If wait is True but no events could be ret= rieved - or if some other error occurred. + @raise QMPConnectError: If wait is True but no events could be + retrieved or if some other error occurred. =20 @return The list of available QMP events. """ @@ -235,8 +248,6 @@ class QEMUMonitorProtocol: self.__sock.close() self.__sockfile.close() =20 - timeout =3D socket.timeout - def settimeout(self, timeout): self.__sock.settimeout(timeout) =20 --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503066908050792.0794169013815; Fri, 18 Aug 2017 07:35:08 -0700 (PDT) Received: from localhost ([::1]:58102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiMc-00079w-S7 for importer@patchew.org; Fri, 18 Aug 2017 10:35:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiF4-0000VW-Ds for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiF3-0008FG-EF for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiF3-0008Em-7V for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A79C883D2; Fri, 18 Aug 2017 14:27:16 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 506FE66D81; Fri, 18 Aug 2017 14:27:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A79C883D2 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:10 +0200 Message-Id: <20170818142613.32394-8-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Aug 2017 14:27:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 07/10] qmp.py: Use object-based class for QEMUMonitorProtocol 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There is no need to define QEMUMonitorProtocol as old-style class. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost --- scripts/qmp/qmp-shell | 4 ++-- scripts/qmp/qmp.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 860ffb2..be449de 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -106,7 +106,7 @@ class FuzzyJSON(ast.NodeTransformer): # _execute_cmd()). Let's design a better one. class QMPShell(qmp.QEMUMonitorProtocol): def __init__(self, address, pretty=3DFalse): - qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address)) + super(QMPShell, self).__init__(self.__get_address(address)) self._greeting =3D None self._completer =3D None self._pretty =3D pretty @@ -281,7 +281,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): return True =20 def connect(self, negotiate): - self._greeting =3D qmp.QEMUMonitorProtocol.connect(self, negotiate) + self._greeting =3D super(QMPShell, self).connect(negotiate) self.__completer_setup() =20 def show_banner(self, msg=3D'Welcome to the QMP low-level shell!'): diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index 782d1ac..95ff5cc 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -30,7 +30,7 @@ class QMPTimeoutError(QMPError): pass =20 =20 -class QEMUMonitorProtocol: +class QEMUMonitorProtocol(object): =20 #: Socket's error class error =3D socket.error --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503067058367646.0972560576704; Fri, 18 Aug 2017 07:37:38 -0700 (PDT) Received: from localhost ([::1]:58370 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiP3-0001Hd-4K for importer@patchew.org; Fri, 18 Aug 2017 10:37:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58337) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiF9-0000WE-0j for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiF5-0008Gc-M5 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5066) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiF5-0008G6-FG for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7A1037E423; Fri, 18 Aug 2017 14:27:18 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 866914FA04; Fri, 18 Aug 2017 14:27:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7A1037E423 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=fail smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:11 +0200 Message-Id: <20170818142613.32394-9-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 18 Aug 2017 14:27:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 08/10] qmp.py: Avoid "has_key" usage 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The "has_key" is deprecated in favor of "__in__" operator. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qmp/qmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index 95ff5cc..f2f5a9b 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -197,7 +197,7 @@ class QEMUMonitorProtocol(object): Build and send a QMP command to the monitor, report errors if any """ ret =3D self.cmd(cmd, kwds) - if ret.has_key('error'): + if "error" in ret: raise Exception(ret['error']['desc']) return ret['return'] =20 --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503067140036449.2112678181528; Fri, 18 Aug 2017 07:39:00 -0700 (PDT) Received: from localhost ([::1]:58408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiQM-0002MV-OD for importer@patchew.org; Fri, 18 Aug 2017 10:38:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiFA-0000Xx-RE for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiF9-0008Iv-UB for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiF9-0008IQ-NJ for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:23 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA181C0587C7; Fri, 18 Aug 2017 14:27:22 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id C83044FA04; Fri, 18 Aug 2017 14:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA181C0587C7 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:12 +0200 Message-Id: <20170818142613.32394-10-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 18 Aug 2017 14:27:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 09/10] qmp.py: Avoid overriding a builtin object 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The "id" is a builtin method to get object's identity and should not be overridden. This might bring some issues in case someone was directly calling "cmd(..., id=3Did)" but I haven't found such usage on brief search for "cmd\(.*id=3D". Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: Eduardo Habkost --- scripts/qmp/qmp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index f2f5a9b..ef12e8a 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -177,19 +177,19 @@ class QEMUMonitorProtocol(object): print >>sys.stderr, "QMP:<<< %s" % resp return resp =20 - def cmd(self, name, args=3DNone, id=3DNone): + def cmd(self, name, args=3DNone, cmd_id=3DNone): """ Build a QMP command and send it to the QMP Monitor. =20 @param name: command name (string) @param args: command arguments (dict) - @param id: command id (dict, list, string or int) + @param cmd_id: command id (dict, list, string or int) """ qmp_cmd =3D {'execute': name} if args: qmp_cmd['arguments'] =3D args - if id: - qmp_cmd['id'] =3D id + if cmd_id: + qmp_cmd['id'] =3D cmd_id return self.cmd_obj(qmp_cmd) =20 def command(self, cmd, **kwds): --=20 2.9.4 From nobody Mon Apr 29 22:21:15 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 1503067293962173.96831630702422; Fri, 18 Aug 2017 07:41:33 -0700 (PDT) Received: from localhost ([::1]:58584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiSq-0004kq-G9 for importer@patchew.org; Fri, 18 Aug 2017 10:41:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diiFH-0000f2-NF for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diiFE-0008LK-Fj for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diiFE-0008Ks-9c for qemu-devel@nongnu.org; Fri, 18 Aug 2017 10:27:28 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4794C3DE3D; Fri, 18 Aug 2017 14:27:27 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.205.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 140905D96E; Fri, 18 Aug 2017 14:27:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4794C3DE3D 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:26:13 +0200 Message-Id: <20170818142613.32394-11-ldoktor@redhat.com> In-Reply-To: <20170818142613.32394-1-ldoktor@redhat.com> References: <20170818142613.32394-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 14:27:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v6 10/10] qtest.py: Few pylint/style fixes 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: ldoktor@redhat.com, famz@redhat.com, ehabkost@redhat.com, apahim@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com, f4bug@amsat.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No actual code changes, just few pylint/style fixes. Signed-off-by: Luk=C3=A1=C5=A1 Doktor Reviewed-by: John Snow --- scripts/qtest.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/qtest.py b/scripts/qtest.py index ab183c0..df0daf2 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -11,14 +11,11 @@ # Based on qmp.py. # =20 -import errno import socket -import string import os -import subprocess -import qmp.qmp import qemu =20 + class QEMUQtestProtocol(object): def __init__(self, address, server=3DFalse): """ @@ -83,8 +80,10 @@ class QEMUQtestMachine(qemu.QEMUMachine): socket_scm_helper=3DNone): if name is None: name =3D "qemu-%d" % os.getpid() - super(QEMUQtestMachine, self).__init__(binary, args, name=3Dname, = test_dir=3Dtest_dir, - socket_scm_helper=3Dsocket_= scm_helper) + super(QEMUQtestMachine, + self).__init__(binary, args, name=3Dname, test_dir=3Dtest_di= r, + socket_scm_helper=3Dsocket_scm_helper) + self._qtest =3D None self._qtest_path =3D os.path.join(test_dir, name + "-qtest.sock") =20 def _base_args(self): --=20 2.9.4