From nobody Wed May 1 11:29:51 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 1500569582292566.5860407618287; Thu, 20 Jul 2017 09:53:02 -0700 (PDT) Received: from localhost ([::1]:39099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEYE-0001ie-4O for importer@patchew.org; Thu, 20 Jul 2017 12:43:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYETP-0005xM-C5 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYETM-0002it-5S for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46994) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYETL-0002ig-S8 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1CBAC0273B4 for ; Thu, 20 Jul 2017 16:29:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1107F82707; Thu, 20 Jul 2017 16:29:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E1CBAC0273B4 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=pass smtp.mailfrom=ldoktor@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E1CBAC0273B4 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:05 +0200 Message-Id: <20170720162815.19802-2-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 20 Jul 2017 16:29:14 +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 01/11] 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: , 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 Wed May 1 11:29:51 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 1500569596933688.4498604124901; Thu, 20 Jul 2017 09:53:16 -0700 (PDT) Received: from localhost ([::1]:39078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEUX-0006ou-5y for importer@patchew.org; Thu, 20 Jul 2017 12:39:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYESh-0004rz-IW for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESe-0002ar-D6 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESe-0002aQ-6u for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A1E536574B for ; Thu, 20 Jul 2017 16:29:16 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4112F82707; Thu, 20 Jul 2017 16:29:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A1E536574B 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A1E536574B From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:06 +0200 Message-Id: <20170720162815.19802-3-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Jul 2017 16:29:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/11] qemu.py: 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: , 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. 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, 5 insertions(+), 1 deletion(-) 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: --=20 2.9.4 From nobody Wed May 1 11:29:51 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 150056959882866.3388326678297; Thu, 20 Jul 2017 09:53:18 -0700 (PDT) Received: from localhost ([::1]:39079 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEUY-0006pX-9w for importer@patchew.org; Thu, 20 Jul 2017 12:39:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYESh-0004ry-IX for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESe-0002at-Cq for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37354) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESe-0002aP-6r for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26A1665871 for ; Thu, 20 Jul 2017 16:29:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F306782707; Thu, 20 Jul 2017 16:29:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 26A1665871 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 26A1665871 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:07 +0200 Message-Id: <20170720162815.19802-4-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Jul 2017 16:29:19 +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 03/11] 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: , 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 Wed May 1 11:29:51 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 1500569499231741.7296072881111; Thu, 20 Jul 2017 09:51:39 -0700 (PDT) Received: from localhost ([::1]:39065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYERa-0003YV-Vj for importer@patchew.org; Thu, 20 Jul 2017 12:36:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEQO-0002yC-BR for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:35:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYEQL-000140-5d for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:35:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52252) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYEQK-00011k-Qn for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:35:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63C6F655A for ; Thu, 20 Jul 2017 16:29:21 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71D4982707; Thu, 20 Jul 2017 16:29:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63C6F655A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=ldoktor@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 63C6F655A From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:08 +0200 Message-Id: <20170720162815.19802-5-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Jul 2017 16:29: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 04/11] 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: , 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 Wed May 1 11:29:51 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 1500569030182870.9315066503963; Thu, 20 Jul 2017 09:43:50 -0700 (PDT) Received: from localhost ([::1]:39089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEWG-0008RC-JI for importer@patchew.org; Thu, 20 Jul 2017 12:41:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYET0-0005Bl-7c for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESx-0002f8-2x for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESw-0002eu-SQ for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D902F7AE83 for ; Thu, 20 Jul 2017 16:29:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA26182729; Thu, 20 Jul 2017 16:29:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D902F7AE83 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D902F7AE83 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:09 +0200 Message-Id: <20170720162815.19802-6-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 16:29: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 05/11] 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: , 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..2bd522f 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 Wed May 1 11:29:51 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 1500569394377508.37557537886903; Thu, 20 Jul 2017 09:49:54 -0700 (PDT) Received: from localhost ([::1]:39125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEaj-00048i-4o for importer@patchew.org; Thu, 20 Jul 2017 12:46:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYETP-0005xL-Bq for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYETM-0002iy-5U for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47002) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYETL-0002ih-SH for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0044C0467DA for ; Thu, 20 Jul 2017 16:29:30 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F79C82707; Thu, 20 Jul 2017 16:29:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A0044C0467DA 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=pass smtp.mailfrom=ldoktor@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A0044C0467DA From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:10 +0200 Message-Id: <20170720162815.19802-7-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 20 Jul 2017 16:29: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 06/11] 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: , 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 a few pylint/style fixes and docstring clarifications. Signed-off-by: Luk=C3=A1=C5=A1 Doktor --- 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..bb4d614 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 when 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. + Get and pop the first available QMP 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 Wed May 1 11:29:51 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 1500569525460296.9488802207369; Thu, 20 Jul 2017 09:52:05 -0700 (PDT) Received: from localhost ([::1]:39103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEYp-0002JH-3A for importer@patchew.org; Thu, 20 Jul 2017 12:44:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYETQ-0005yA-5s for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYETP-0002ju-5x for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39404) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYETO-0002jb-VD for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9DFC6C057FAB for ; Thu, 20 Jul 2017 16:29:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F07FC8271F; Thu, 20 Jul 2017 16:29:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9DFC6C057FAB 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9DFC6C057FAB From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:11 +0200 Message-Id: <20170720162815.19802-8-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 20 Jul 2017 16:29: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 07/11] 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: , 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.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index bb4d614..68f3420 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 Wed May 1 11:29:51 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 1500569586845262.6578461032435; Thu, 20 Jul 2017 09:53:06 -0700 (PDT) Received: from localhost ([::1]:39087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEVg-0007zJ-RQ for importer@patchew.org; Thu, 20 Jul 2017 12:41:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYESm-0004wp-Ng for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESh-0002cH-7a for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESh-0002bs-1x for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:03 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD75C806BA for ; Thu, 20 Jul 2017 16:29:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF82082707; Thu, 20 Jul 2017 16:29:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AD75C806BA 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=pass smtp.mailfrom=ldoktor@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AD75C806BA From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:12 +0200 Message-Id: <20170720162815.19802-9-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 20 Jul 2017 16:29:34 +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 08/11] 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: , 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 68f3420..a14b001 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 when 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 Wed May 1 11:29:51 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 1500568946603212.81432048398972; Thu, 20 Jul 2017 09:42:26 -0700 (PDT) Received: from localhost ([::1]:39094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEWv-0000dk-5c for importer@patchew.org; Thu, 20 Jul 2017 12:42:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYET0-0005Bm-89 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESx-0002fB-32 for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESw-0002ev-TD for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 151858E3DA for ; Thu, 20 Jul 2017 16:29:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1EC6082707; Thu, 20 Jul 2017 16:29:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 151858E3DA 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 151858E3DA From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:13 +0200 Message-Id: <20170720162815.19802-10-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 16:29: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 09/11] 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: , 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 --- 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 a14b001..c3e0206 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['cmd_id'] =3D cmd_id return self.cmd_obj(qmp_cmd) =20 def command(self, cmd, **kwds): --=20 2.9.4 From nobody Wed May 1 11:29:51 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 1500569410194438.5941465177589; Thu, 20 Jul 2017 09:50:10 -0700 (PDT) Received: from localhost ([::1]:39102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYEYn-0002Hs-GH for importer@patchew.org; Thu, 20 Jul 2017 12:44:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYET0-0005Bn-8C for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYESx-0002f2-1v for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYESw-0002et-Rm for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:38:18 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 11107796FE for ; Thu, 20 Jul 2017 16:29:41 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F7C582720; Thu, 20 Jul 2017 16:29:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 11107796FE 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 11107796FE From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:14 +0200 Message-Id: <20170720162815.19802-11-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 20 Jul 2017 16:29:41 +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 10/11] 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: , 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 --- scripts/qtest.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qtest.py b/scripts/qtest.py index d5aecb5..e4b5788 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,11 @@ 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) + scm_helper =3D socket_scm_helper + super(QEMUQtestMachine, self).__init__(binary, args, name=3Dname, + test_dir=3Dtest_dir, + socket_scm_helper=3Dscm_hel= per) + 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 From nobody Wed May 1 11:29:51 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 1500569656156897.2701276398759; Thu, 20 Jul 2017 09:54:16 -0700 (PDT) Received: from localhost ([::1]:39073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYETh-0005pt-5c for importer@patchew.org; Thu, 20 Jul 2017 12:39:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYES8-0004S8-8S for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:37:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYES4-0002I1-Vk for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:37:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49974) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYERs-0002CW-0N for qemu-devel@nongnu.org; Thu, 20 Jul 2017 12:37:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A6B68553D for ; Thu, 20 Jul 2017 16:29:43 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-204-43.brq.redhat.com [10.40.204.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6417382707; Thu, 20 Jul 2017 16:29:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3A6B68553D 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 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3A6B68553D From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Doktor?= To: ldoktor@redhat.com, apahim@redhat.com, qemu-devel@nongnu.org, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, ehabkost@redhat.com Date: Thu, 20 Jul 2017 18:28:15 +0200 Message-Id: <20170720162815.19802-12-ldoktor@redhat.com> In-Reply-To: <20170720162815.19802-1-ldoktor@redhat.com> References: <20170720162815.19802-1-ldoktor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Jul 2017 16:29:43 +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 11/11] qtest.py: Avoid using mutable list as default argument 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: , 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 is a mutable object and is dangerous to use it. Recently the QEMUMachine was adjusted to allow None as default, let's use it here as well. Signed-off-by: Luk=C3=A1=C5=A1 Doktor --- scripts/qtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qtest.py b/scripts/qtest.py index e4b5788..ba3233c 100644 --- a/scripts/qtest.py +++ b/scripts/qtest.py @@ -76,7 +76,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