From nobody Tue Apr 30 23:25:56 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 1502788063920729.0344478180424; Tue, 15 Aug 2017 02:07:43 -0700 (PDT) Received: from localhost ([::1]:47351 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXp8-00045S-Jb for importer@patchew.org; Tue, 15 Aug 2017 05:07:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXkT-0007zi-G4 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:02:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXkS-0002aQ-8l for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:02:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXkR-0002a4-VX for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:02:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45B0EE183F; Tue, 15 Aug 2017 08:57:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEB155D6A8; Tue, 15 Aug 2017 08:57:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 45B0EE183F 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: Tue, 15 Aug 2017 10:57:23 +0200 Message-Id: <20170815085732.9794-2-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 15 Aug 2017 08:57:45 +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 v5 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 --- scripts/qemu.py | 76 ++++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8..466aaab 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): + ''' + Create a QEMUMachine object + + @param binary: path to the qemu binary (str) + @param args: initial list of extra arguments + @param wrapper: list of arguments used as prefix to qemu binary + @param name: name of this object (used for log/monitor/... file na= mes) + @param test_dir: base location to put log/monitor/... files in + @param monitor_address: custom address for QMP monitor + @param socket_scm_helper: path to scm_helper binary (to forward fd= s) + @param debug: enable debug mode (forwarded to QMP helper and such) + @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,8 +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, - debug=3Dself._debug) + self._qmp =3D qmp.qmp.QEMUMonitorProtocol(self._monitor_address, + server=3DTrue, debug=3Dsel= f._debug) =20 def _post_launch(self): self._qmp.accept() @@ -131,9 +146,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(): @@ -149,28 +166,34 @@ class QEMUMachine(object): try: self._qmp.cmd('quit') self._qmp.close() - except: + except: # kill VM on any failure pylint: disable=3DW0702 self._popen.kill() =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''' 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 and on success return result dict or on failu= re + raise exception with details. + ''' reply =3D self.qmp(cmd, conv_keys, **args) if reply is None: raise Exception("Monitor is closed") @@ -193,15 +216,18 @@ 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' - def event_match(event, match=3DNone): + '''Wait for event in QMP, optionally filter results by match.''' + # Test if 'match' is a recursive subset of 'event'; skips branch + # processing on match's value `None` + # {"foo": {"bar": 1} matches {"foo": None} + def _event_match(event, match=3DNone): if match is None: return True =20 for key in match: if key in event: if isinstance(event[key], dict): - if not event_match(event[key], match[key]): + if not _event_match(event[key], match[key]): return False elif event[key] !=3D match[key]: return False @@ -212,18 +238,22 @@ class QEMUMachine(object): =20 # Search cached events for event in self._events: - if (event['event'] =3D=3D name) and event_match(event, match): + if (event['event'] =3D=3D name) and _event_match(event, match): self._events.remove(event) return event =20 # Poll for new events while True: event =3D self._qmp.pull_event(wait=3Dtimeout) - if (event['event'] =3D=3D name) and event_match(event, match): + if (event['event'] =3D=3D name) and _event_match(event, match): return event self._events.append(event) =20 return None =20 def get_log(self): + ''' + After self.shutdown or failed qemu execution this returns the outp= ut + of the qemu process. + ''' return self._iolog --=20 2.9.4 From nobody Tue Apr 30 23:25:56 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 1502788076135453.7901656472493; Tue, 15 Aug 2017 02:07:56 -0700 (PDT) Received: from localhost ([::1]:47400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXpK-0004cz-Pj for importer@patchew.org; Tue, 15 Aug 2017 05:07:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXlg-0000hL-3G for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:04:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXlb-00036a-6l for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:04:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58430) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXlb-00036G-01 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:04:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CBE3D7ACC6; Tue, 15 Aug 2017 08:57:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9155B5D6A8; Tue, 15 Aug 2017 08:57:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CBE3D7ACC6 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: Tue, 15 Aug 2017 10:57:24 +0200 Message-Id: <20170815085732.9794-3-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 15 Aug 2017 08:57:48 +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 v5 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 --- 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 466aaab..888f5b3 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 (forwarded to QMP helper and such) @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 Tue Apr 30 23:25:56 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 1502788281051665.5041812534427; Tue, 15 Aug 2017 02:11:21 -0700 (PDT) Received: from localhost ([::1]:47598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXsd-00086M-OL for importer@patchew.org; Tue, 15 Aug 2017 05:11:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXoP-0003dV-Lh for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:06:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXoO-0005Ki-U0 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:06:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47746) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXoO-0005J3-Oo for qemu-devel@nongnu.org; Tue, 15 Aug 2017 05:06:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA6CEDF06; Tue, 15 Aug 2017 08:57:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20E565D6A8; Tue, 15 Aug 2017 08:57:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BA6CEDF06 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: Tue, 15 Aug 2017 10:57:25 +0200 Message-Id: <20170815085732.9794-4-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 15 Aug 2017 08:57:51 +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 v5 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 --- scripts/qemu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 888f5b3..571f852 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -185,11 +185,11 @@ class QEMUMachine(object): def qmp(self, cmd, conv_keys=3DTrue, **args): '''Invoke a QMP command and return the result 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 Tue Apr 30 23:25:56 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 1502787599472811.8207138379214; Tue, 15 Aug 2017 01:59:59 -0700 (PDT) Received: from localhost ([::1]:47077 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXhe-0004Mq-AZ for importer@patchew.org; Tue, 15 Aug 2017 04:59:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXft-0002rV-95 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXfo-0006eC-EL for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXfo-0006cL-8n for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 96531C29B608; Tue, 15 Aug 2017 08:58:00 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C79765D6A9; Tue, 15 Aug 2017 08:57:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 96531C29B608 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: Tue, 15 Aug 2017 10:57:26 +0200 Message-Id: <20170815085732.9794-5-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 15 Aug 2017 08:58:00 +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 v5 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 --- scripts/qemu.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 571f852..5ba17d0 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -13,7 +13,6 @@ # =20 import errno -import string import os import sys import subprocess @@ -180,14 +179,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 result 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 Tue Apr 30 23:25:56 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 150278759810014.622039835216128; Tue, 15 Aug 2017 01:59:58 -0700 (PDT) Received: from localhost ([::1]:47076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXhc-0004IC-Pe for importer@patchew.org; Tue, 15 Aug 2017 04:59:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56951) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXft-0002rW-97 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXfq-0006f3-R9 for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48208) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXfq-0006eh-LF for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91F3ECAA68; Tue, 15 Aug 2017 08:58:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF2225D6A8; Tue, 15 Aug 2017 08:58:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 91F3ECAA68 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: Tue, 15 Aug 2017 10:57:27 +0200 Message-Id: <20170815085732.9794-6-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 15 Aug 2017 08:58: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 v5 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 5ba17d0..0c00e91 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 @@ -197,9 +210,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 Tue Apr 30 23:25:56 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 1502787763657516.9467439010375; Tue, 15 Aug 2017 02:02:43 -0700 (PDT) Received: from localhost ([::1]:47101 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXkI-0007Pz-Fy for importer@patchew.org; Tue, 15 Aug 2017 05:02:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXfy-0002w9-BL for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXfx-0006gR-8l for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXfw-0006g8-Vb for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD00D6881A; Tue, 15 Aug 2017 08:58:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE0AF5D75B; Tue, 15 Aug 2017 08:58:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DD00D6881A 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=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 15 Aug 2017 10:57:28 +0200 Message-Id: <20170815085732.9794-7-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 15 Aug 2017 08:58: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 v5 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 Tue Apr 30 23:25:56 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 1502787619247838.0198873368366; Tue, 15 Aug 2017 02:00:19 -0700 (PDT) Received: from localhost ([::1]:47083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXhx-0004jG-4m for importer@patchew.org; Tue, 15 Aug 2017 05:00:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXgC-0003Bv-9G for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXg7-0006of-EX for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXg7-0006m9-8S for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 226D5A0C59; Tue, 15 Aug 2017 08:58:22 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 322165D6A8; Tue, 15 Aug 2017 08:58:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 226D5A0C59 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: Tue, 15 Aug 2017 10:57:29 +0200 Message-Id: <20170815085732.9794-8-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 15 Aug 2017 08:58: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 v5 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 Tue Apr 30 23:25:56 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 1502787781788338.34072321976373; Tue, 15 Aug 2017 02:03:01 -0700 (PDT) Received: from localhost ([::1]:47133 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXka-0007jk-NT for importer@patchew.org; Tue, 15 Aug 2017 05:03:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXgC-0003Bw-9T for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXg9-0006re-TF for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXg9-0006pp-NQ for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99E4A3D3F94; Tue, 15 Aug 2017 08:58:24 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E5F25D6A8; Tue, 15 Aug 2017 08:58:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 99E4A3D3F94 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: Tue, 15 Aug 2017 10:57:30 +0200 Message-Id: <20170815085732.9794-9-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 15 Aug 2017 08:58:24 +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 v5 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 Tue Apr 30 23:25:56 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 150278769364728.530776034341102; Tue, 15 Aug 2017 02:01:33 -0700 (PDT) Received: from localhost ([::1]:47097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXjA-00068b-EB for importer@patchew.org; Tue, 15 Aug 2017 05:01:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXgD-0003Cc-2p for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXgC-0006uX-CO for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXgC-0006u5-5u for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13498A0C59; Tue, 15 Aug 2017 08:58:27 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E757C5D6A8; Tue, 15 Aug 2017 08:58:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13498A0C59 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: Tue, 15 Aug 2017 10:57:31 +0200 Message-Id: <20170815085732.9794-10-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 15 Aug 2017 08:58: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 v5 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 Tue Apr 30 23:25:56 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 1502787763623276.2260127828772; Tue, 15 Aug 2017 02:02:43 -0700 (PDT) Received: from localhost ([::1]:47100 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXkI-0007Pw-IN for importer@patchew.org; Tue, 15 Aug 2017 05:02:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhXgF-0003Fp-MP for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhXgF-0006xz-0n for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44924) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhXgE-0006wy-RG for qemu-devel@nongnu.org; Tue, 15 Aug 2017 04:58:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADC06C0546F0; Tue, 15 Aug 2017 08:58:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-136.brq.redhat.com [10.40.204.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62BD65D6A8; Tue, 15 Aug 2017 08:58:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ADC06C0546F0 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: Tue, 15 Aug 2017 10:57:32 +0200 Message-Id: <20170815085732.9794-11-ldoktor@redhat.com> In-Reply-To: <20170815085732.9794-1-ldoktor@redhat.com> References: <20170815085732.9794-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 15 Aug 2017 08:58:29 +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 v5 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