From nobody Thu May 2 04:47:24 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 150099552537723.103780648739303; Tue, 25 Jul 2017 08:12:05 -0700 (PDT) Received: from localhost ([::1]:33129 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1V8-000164-Qh for importer@patchew.org; Tue, 25 Jul 2017 11:11:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1TQ-0008Q8-Ky for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1TP-0006hO-2B for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35212) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1TO-0006gb-PM for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF8AB7F7D0; Tue, 25 Jul 2017 15:10:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49D1560619; Tue, 25 Jul 2017 15:10:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF8AB7F7D0 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:42 +0200 Message-Id: <20170725150951.16038-2-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 25 Jul 2017 15:10:10 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 --- scripts/qemu.py | 76 ++++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 53 insertions(+), 23 deletions(-) diff --git a/scripts/qemu.py b/scripts/qemu.py index 880e3e8..191c916 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 os.path.exists(self._socket_scm_helper) is False: 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 report 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 Thu May 2 04:47:24 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 1500995673920448.35225926795556; Tue, 25 Jul 2017 08:14:33 -0700 (PDT) Received: from localhost ([::1]:33139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Xa-0003K8-7N for importer@patchew.org; Tue, 25 Jul 2017 11:14:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1TT-0008Sa-MX for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1TS-0006kz-PE for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42824) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1TS-0006kW-Iv for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC706C058EDD; Tue, 25 Jul 2017 15:10:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 292D56061D; Tue, 25 Jul 2017 15:10:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AC706C058EDD 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:43 +0200 Message-Id: <20170725150951.16038-3-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Jul 2017 15:10:13 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 191c916..66fd863 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 Thu May 2 04:47:24 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 1500995820247925.4035469470359; Tue, 25 Jul 2017 08:17:00 -0700 (PDT) Received: from localhost ([::1]:33152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Zv-0005Tm-Fm for importer@patchew.org; Tue, 25 Jul 2017 11:16:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45904) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tc-00008Z-RH for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1TX-0006o0-8X for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35538) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1TX-0006mg-2E for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2AC198046F; Tue, 25 Jul 2017 15:10:18 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06B0660604; Tue, 25 Jul 2017 15:10:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2AC198046F 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:44 +0200 Message-Id: <20170725150951.16038-4-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 25 Jul 2017 15:10: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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 66fd863..7e95c25 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 Thu May 2 04:47:24 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 1500995535004866.2619832331611; Tue, 25 Jul 2017 08:12:15 -0700 (PDT) Received: from localhost ([::1]:33130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1VI-0001GJ-KJ for importer@patchew.org; Tue, 25 Jul 2017 11:12:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tb-00007J-7V for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Ta-0006oe-C9 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43180) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Ta-0006oS-5k for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44632C0587E3; Tue, 25 Jul 2017 15:10:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7949660607; Tue, 25 Jul 2017 15:10:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 44632C0587E3 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:45 +0200 Message-Id: <20170725150951.16038-5-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 25 Jul 2017 15:10:21 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 7e95c25..5948e19 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 Thu May 2 04:47:24 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 1500995989719837.6440574458626; Tue, 25 Jul 2017 08:19:49 -0700 (PDT) Received: from localhost ([::1]:33162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1cg-0007k7-5E for importer@patchew.org; Tue, 25 Jul 2017 11:19:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tf-0000BI-Kp for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Te-0006qR-Oc for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Te-0006q3-Ij for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9796285D0; Tue, 25 Jul 2017 15:10:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 945DD60604; Tue, 25 Jul 2017 15:10:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9796285D0 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:46 +0200 Message-Id: <20170725150951.16038-6-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Jul 2017 15:10:25 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 5948e19..e6df54c 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__(repr(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 Thu May 2 04:47:24 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 1500996148697641.1716487188849; Tue, 25 Jul 2017 08:22:28 -0700 (PDT) Received: from localhost ([::1]:33181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1fF-0001TW-5Y for importer@patchew.org; Tue, 25 Jul 2017 11:22:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tk-0000Ex-TT for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Th-0006r2-N4 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Th-0006qr-DG for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32D3E8047E; Tue, 25 Jul 2017 15:10:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D4A60604; Tue, 25 Jul 2017 15:10:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 32D3E8047E 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:47 +0200 Message-Id: <20170725150951.16038-7-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 25 Jul 2017 15:10:28 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 Thu May 2 04:47:24 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 1500995823247278.5265824198798; Tue, 25 Jul 2017 08:17:03 -0700 (PDT) Received: from localhost ([::1]:33153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1a0-0005Xq-M6 for importer@patchew.org; Tue, 25 Jul 2017 11:17:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tk-0000Ey-Ti for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Tj-0006rt-EU for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60154) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Tj-0006ra-8i for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 547F967AD2; Tue, 25 Jul 2017 15:10:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6391260607; Tue, 25 Jul 2017 15:10:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 547F967AD2 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:48 +0200 Message-Id: <20170725150951.16038-8-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 25 Jul 2017 15:10:30 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 Thu May 2 04:47:24 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 1500995602536558.4665174004939; Tue, 25 Jul 2017 08:13:22 -0700 (PDT) Received: from localhost ([::1]:33134 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1WQ-0002Ff-Ni for importer@patchew.org; Tue, 25 Jul 2017 11:13:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tm-0000GY-R0 for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Tm-0006sj-0I for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Tl-0006sK-JR for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA0C1369C3; Tue, 25 Jul 2017 15:10:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id A231260618; Tue, 25 Jul 2017 15:10:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AA0C1369C3 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:49 +0200 Message-Id: <20170725150951.16038-9-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 25 Jul 2017 15:10:32 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 Thu May 2 04:47:24 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 1500996285804520.2375476885812; Tue, 25 Jul 2017 08:24:45 -0700 (PDT) Received: from localhost ([::1]:33194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1hR-0003Rh-0A for importer@patchew.org; Tue, 25 Jul 2017 11:24:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46017) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tt-0000OA-LW for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Tq-0006tm-FI for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45056) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Tq-0006tV-0q for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E7A9659AD; Tue, 25 Jul 2017 15:10:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06C1060604; Tue, 25 Jul 2017 15:10:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1E7A9659AD 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=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:50 +0200 Message-Id: <20170725150951.16038-10-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 25 Jul 2017 15:10:37 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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 Thu May 2 04:47:24 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 150099575040866.7390636902253; Tue, 25 Jul 2017 08:15:50 -0700 (PDT) Received: from localhost ([::1]:33149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Yo-0004VW-SI for importer@patchew.org; Tue, 25 Jul 2017 11:15:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46023) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1da1Tu-0000Om-AJ for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1da1Tt-0006uF-9S for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43246) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1da1Ts-0006u4-OV for qemu-devel@nongnu.org; Tue, 25 Jul 2017 11:10:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C204D7F413; Tue, 25 Jul 2017 15:10:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-88.brq.redhat.com [10.40.204.88]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B22F60604; Tue, 25 Jul 2017 15:10:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C204D7F413 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ldoktor@redhat.com From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: qemu-devel@nongnu.org Date: Tue, 25 Jul 2017 17:09:51 +0200 Message-Id: <20170725150951.16038-11-ldoktor@redhat.com> In-Reply-To: <20170725150951.16038-1-ldoktor@redhat.com> References: <20170725150951.16038-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 25 Jul 2017 15:10:39 +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 v2 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, armbru@redhat.com, apahim@redhat.com, f4bug@amsat.org, mreitz@redhat.com 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