From nobody Fri May 3 04:58:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577454187; cv=none; d=zohomail.com; s=zohoarc; b=PCZGzzkOuQliIhWHsrvwcDImTwv9XusFCFVo9hwjgzNcNMkx7ynaQfvzOFw2WDHyj6zhsY6z+yxRVqFtoVGIACLzV+pO0Jos0cWoUtS8qyS9fHOf4QPc+FiTob1mKx02Qc89D5XAqwaijt/gcm2rSIBkhoronB75/WqpPswWmPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577454187; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rsnPAQSkWvtcYpvI7N8qYJnicQPbC05o8HCtvE27HQw=; b=bLY6BuPEmhInTd8q5RcXCxavNUVHC0lKYS48xaK+/GdLJVMHqTTxcO58Gueiu05YbPHZgWdqIE1LgBZ199V83Oc6uF8fH8TLMu4YtFRAXgIjbWGLRJ/RjdD/3BWwPqKIensZaVctpJIBcC8GkirpBQuyn9umMGd6EE8sQO2y0zA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577454187404537.5186547324834; Fri, 27 Dec 2019 05:43:07 -0800 (PST) Received: from localhost ([::1]:35540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikptR-0007wG-3S for importer@patchew.org; Fri, 27 Dec 2019 08:43:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58828) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikprb-0006Hh-7n for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikprZ-0002yh-Fi for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:10 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:30916 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikprZ-0002yT-CO for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:09 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-252-71KYVSqFPGW6o9-_KXWFpQ-1; Fri, 27 Dec 2019 08:41:07 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A48E6801E7A for ; Fri, 27 Dec 2019 13:41:06 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4962781765; Fri, 27 Dec 2019 13:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577454068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rsnPAQSkWvtcYpvI7N8qYJnicQPbC05o8HCtvE27HQw=; b=BF6owoGXdc8YBo1HWkJ0LiOMMF5KHX8u68s+CE2cARbdnZd8PFzv9a46AQXP3QZRiNtDtw SEjeOd2WpYhz7oGDiFDMZpIkbu4g6AiK26VtDqcNynRZYpzsv72WkvBqPAIgFgki+a6hee gEmOVxTpKOd5Z/pS06cw5FJ1MIullGc= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 1/5] python/qemu: qmp: Replace socket.error with OSError Date: Fri, 27 Dec 2019 10:40:57 -0300 Message-Id: <20191227134101.244496-2-wainersm@redhat.com> In-Reply-To: <20191227134101.244496-1-wainersm@redhat.com> References: <20191227134101.244496-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 71KYVSqFPGW6o9-_KXWFpQ-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The socket.error is deprecated from Python 3.3, instead it is made a link to OSError. This change replaces the occurences of socket.error with OSError. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow --- python/qemu/qmp.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 5c8cf6a056..8c6c9847d0 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -47,7 +47,7 @@ class QEMUMonitorProtocol(object): or a tuple in the form ( address, port ) for a TCP connection @param server: server mode listens on the socket (bool) - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @note No connection is established, this is done by the connect() = or accept() methods """ @@ -107,8 +107,8 @@ class QEMUMonitorProtocol(object): self.__sock.setblocking(0) try: self.__json_read() - except socket.error as err: - if err[0] =3D=3D errno.EAGAIN: + except OSError as err: + if err.errno =3D=3D errno.EAGAIN: # No data available pass self.__sock.setblocking(1) @@ -133,7 +133,7 @@ class QEMUMonitorProtocol(object): Connect to the QMP Monitor and perform capabilities negotiation. =20 @return QMP greeting dict - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ @@ -147,7 +147,7 @@ class QEMUMonitorProtocol(object): Await connection from QMP Monitor and perform capabilities negotia= tion. =20 @return QMP greeting dict - @raise socket.error on socket connection errors + @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ @@ -167,10 +167,10 @@ class QEMUMonitorProtocol(object): self.logger.debug(">>> %s", qmp_cmd) try: self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) - except socket.error as err: - if err[0] =3D=3D errno.EPIPE: + except OSError as err: + if err.errno =3D=3D errno.EPIPE: return - raise socket.error(err) + raise err resp =3D self.__json_read() self.logger.debug("<<< %s", resp) return resp --=20 2.23.0 From nobody Fri May 3 04:58:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577454195; cv=none; d=zohomail.com; s=zohoarc; b=m6NalcQ0VsV2N5/EkYu3klTshyyT9cR8Gs4qTwrIO5k/g/0FAv96sgRfcpxbby9v38eOZf4uBwu2j0u9W4oKXkhArYJp+ZSWdZmLztTWspR/YJS8JDlgkKzeOJ4Xdph9n3ugVsSG7mCxs8s7SRAs61fM75X28Cx7u+Lfhh8/Zt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577454195; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oOjUyDHbviUeWxs2MNUwGFkBbxmqmMuSESvGijd12zQ=; b=AVpvOsUcpmZkGhmwI8TF86tkji2tW9tJv0BDx6tKUh7ykRsd9Qvm/n8S/LdJvKQa0ETvjpEjtCKjM+DdugYuy0nxC3GOe0pwA8s13gOs6+yrVZ4AR/526faurrE4BmWgvnILNUNd/33o9PbpbPcc5yr6CrI8RsWtVHlUGK8RcA8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577454195309685.5985445995224; Fri, 27 Dec 2019 05:43:15 -0800 (PST) Received: from localhost ([::1]:35546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikpta-00085l-0O for importer@patchew.org; Fri, 27 Dec 2019 08:43:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58848) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikprd-0006Ht-5u for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikprb-00030X-JU for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:13 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:37503 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikprb-000300-GA for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-135-vj7bqWw3M-2as7Coi2Z2tw-1; Fri, 27 Dec 2019 08:41:09 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 94E341804193 for ; Fri, 27 Dec 2019 13:41:08 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1921A81C10; Fri, 27 Dec 2019 13:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577454070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oOjUyDHbviUeWxs2MNUwGFkBbxmqmMuSESvGijd12zQ=; b=Ex4ATej+lcLDrZJDBmUnkIGoboFfSSofPaiEe/7nLTKrhrgHviZT/iPk8MolmeZuVYRFp3 04BsEIyfmj7O4HW+qvP05walGiFyfQBPhv8b4fTBHqZKxzkfV84k8dAfp5F9VsYtFA/SDn zbXVA+ri8Fcx1JhK64FkPUJmT5Qp4bk= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 2/5] python/qemu: Delint the qmp module Date: Fri, 27 Dec 2019 10:40:58 -0300 Message-Id: <20191227134101.244496-3-wainersm@redhat.com> In-Reply-To: <20191227134101.244496-1-wainersm@redhat.com> References: <20191227134101.244496-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: vj7bqWw3M-2as7Coi2Z2tw-1 X-Mimecast-Spam-Score: 0 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: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This clean up the pylint-3 report on qmp: ************* Module qemu.qmp python/qemu/qmp.py:1:0: C0111: Missing module docstring (missing-docstring) python/qemu/qmp.py:17:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:21:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:25:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:29:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:33:0: C0111: Missing class docstring (missing-docstring) python/qemu/qmp.py:33:0: R0205: Class 'QEMUMonitorProtocol' inherits from o= bject, can be safely removed from bases in python3 (useless-object-inherita= nce) python/qemu/qmp.py:80:4: R1710: Either all return statements in a function = should return an expression, or none of them should. (inconsistent-return-s= tatements) python/qemu/qmp.py:131:4: R1710: Either all return statements in a function= should return an expression, or none of them should. (inconsistent-return-= statements) python/qemu/qmp.py:159:4: R1710: Either all return statements in a function= should return an expression, or none of them should. (inconsistent-return-= statements) python/qemu/qmp.py:245:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:249:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:252:4: C0111: Missing method docstring (missing-docstrin= g) python/qemu/qmp.py:255:4: C0111: Missing method docstring (missing-docstrin= g) Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/qmp.py | 51 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 8c6c9847d0..f4e04a6683 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -1,5 +1,4 @@ -# QEMU Monitor Protocol Python class -# +""" QEMU Monitor Protocol Python class """ # Copyright (C) 2009, 2010 Red Hat Inc. # # Authors: @@ -15,22 +14,34 @@ import logging =20 =20 class QMPError(Exception): - pass + """ + QMP base exception + """ =20 =20 class QMPConnectError(QMPError): - pass + """ + QMP connection exception + """ =20 =20 class QMPCapabilitiesError(QMPError): - pass + """ + QMP negotiate capabilities exception + """ =20 =20 class QMPTimeoutError(QMPError): - pass + """ + QMP timeout exception + """ =20 =20 -class QEMUMonitorProtocol(object): +class QEMUMonitorProtocol: + """ + Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and = then + allow to handle commands and events. + """ =20 #: Logger object for debugging messages logger =3D logging.getLogger('QMP') @@ -81,7 +92,7 @@ class QEMUMonitorProtocol(object): while True: data =3D self.__sockfile.readline() if not data: - return + return None resp =3D json.loads(data) if 'event' in resp: self.logger.debug("<<< %s", resp) @@ -132,7 +143,7 @@ class QEMUMonitorProtocol(object): """ Connect to the QMP Monitor and perform capabilities negotiation. =20 - @return QMP greeting dict + @return QMP greeting dict, or None if negotiate is false @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities @@ -141,6 +152,7 @@ class QEMUMonitorProtocol(object): self.__sockfile =3D self.__sock.makefile() if negotiate: return self.__negotiate_capabilities() + return None =20 def accept(self): """ @@ -169,7 +181,7 @@ class QEMUMonitorProtocol(object): self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) except OSError as err: if err.errno =3D=3D errno.EPIPE: - return + return None raise err resp =3D self.__json_read() self.logger.debug("<<< %s", resp) @@ -243,14 +255,33 @@ class QEMUMonitorProtocol(object): self.__events =3D [] =20 def close(self): + """ + Close the socket and socket file. + """ self.__sock.close() self.__sockfile.close() =20 def settimeout(self, timeout): + """ + Set the socket timeout. + + @param timeout (float): timeout in seconds, or None. + @note This is a wrap around socket.settimeout + """ self.__sock.settimeout(timeout) =20 def get_sock_fd(self): + """ + Get the socket file descriptor. + + @return The file descriptor number. + """ return self.__sock.fileno() =20 def is_scm_available(self): + """ + Check if the socket allows for SCM_RIGHTS. + + @return True if SCM_RIGHTS is available, otherwise False. + """ return self.__sock.family =3D=3D socket.AF_UNIX --=20 2.23.0 From nobody Fri May 3 04:58:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577454188; cv=none; d=zohomail.com; s=zohoarc; b=Ye0EK9uNXKh/vd9dP5w6BaDrEMMgOSp9ROyUm8BPUOcgqjz34uLBAJX1gXKZyAYSmT1GXsLtGkFgljVRGF9XrzXSqdLfkqnaVtfKeQKw2OnZAugPOQmvpyOobV7tZu+wNuYkvpo27e9s3OnjSHJjZMjkyTDcPLsosmFUAIeGLac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577454188; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UDuh+n+0bICDUrGAWdnvNOHlqbxC8cUgCjIl35Pk3/I=; b=NnFwuYiLKwqBrxUO9nkD2g53MH/Ur3rk/zmRGGpkxPAzky3bGPBNm1ET4JrpBOdv+eBpH8HWwyejBz8hIqyG8jw8ZbAHd5rq+rOsPEkJ50QugxHtSGAnh8x3mrWSdGPxUdWRQuQRYbX925olyEraf3JrhkCuxvoyjjym/S0nxO8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577454188491583.7626427848688; Fri, 27 Dec 2019 05:43:08 -0800 (PST) Received: from localhost ([::1]:35542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikptT-0007yf-9k for importer@patchew.org; Fri, 27 Dec 2019 08:43:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58868) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikpre-0006J0-Ic for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikprd-00034p-HQ for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:14 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:49046 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikprd-00032D-Dd for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:13 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-142-Vaff-dqqNX6FxXurVtQLWQ-1; Fri, 27 Dec 2019 08:41:11 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id BA88D180418B for ; Fri, 27 Dec 2019 13:41:10 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30AFC81C11; Fri, 27 Dec 2019 13:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577454072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UDuh+n+0bICDUrGAWdnvNOHlqbxC8cUgCjIl35Pk3/I=; b=J9LlYsWB9IbBIuePmbosoRw6sjX+81YYiDGhl+X25x7+L+RjCsLEd11Nx2D+wpkJ6NBiHS 8AMolSQIup4fLy8Xr4AsLXyEsVuBLRVDwBz49KzEJzw8oj+JsuYTBoXVs+ZF1On4WBbH6C temYaMs3CPKMh7JaZUfddS1eXmGS22o= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 3/5] python/qemu: qmp: Make accept()'s timeout configurable Date: Fri, 27 Dec 2019 10:40:59 -0300 Message-Id: <20191227134101.244496-4-wainersm@redhat.com> In-Reply-To: <20191227134101.244496-1-wainersm@redhat.com> References: <20191227134101.244496-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: Vaff-dqqNX6FxXurVtQLWQ-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Currently the timeout of QEMUMonitorProtocol.accept() is hard-coded to 15 seconds. This added the parameter `timeout` so the value can be configured by the user. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/qmp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index f4e04a6683..914b8c6774 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -154,16 +154,17 @@ class QEMUMonitorProtocol: return self.__negotiate_capabilities() return None =20 - def accept(self): + def accept(self, timeout=3D15): """ Await connection from QMP Monitor and perform capabilities negotia= tion. =20 + @param timeout (float): timeout in seconds. Default is 15. @return QMP greeting dict @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received @raise QMPCapabilitiesError if fails to negotiate capabilities """ - self.__sock.settimeout(15) + self.__sock.settimeout(timeout) self.__sock, _ =3D self.__sock.accept() self.__sockfile =3D self.__sock.makefile() return self.__negotiate_capabilities() --=20 2.23.0 From nobody Fri May 3 04:58:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577454315; cv=none; d=zohomail.com; s=zohoarc; b=PPrL/xwvufYOahQgODEuz9tizpm6uOYlC7XAahBCXfhWTbb9M/UiKrTFdaDF+8EwIWPv4P7nOvbpI1nPnx1MrhzHAKQDxY2jRm5Bs66xIhdQdt6pEpN7BL25I57hyma9KMbyBd0c8Qm27HebFfblG4M27hDFllf6fBQ81zMnjMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577454315; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1l/tQ5+l+T1XzctYuN14RZwqLGUquGObj/tL5Pe29Ek=; b=oI+x4LeW3IIzLPNj+XOwE4AfSnvENs1Rg8eTwj9a077LkDtU01b6vT6C1Tx7285n9iPOG+l+RjCCYPmHmZlBhOayM+oIr7RC/nweC7DJpCX4Xkivw1GuJmnbDWMneGoU5Dceh08TN30e2DB8A2LGmRInZaWwre54ciGR3w5BCWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577454315483893.5441672286009; Fri, 27 Dec 2019 05:45:15 -0800 (PST) Received: from localhost ([::1]:35562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikpvW-0002Bc-KV for importer@patchew.org; Fri, 27 Dec 2019 08:45:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58898) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikprh-0006OB-AF for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikprg-00038d-79 for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:17 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:39633 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikprg-00037W-3o for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:16 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-BTa-AUmoOjWvixkFlInXAw-1; Fri, 27 Dec 2019 08:41:14 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id E0F2D801E7A for ; Fri, 27 Dec 2019 13:41:12 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 561CA81C11; Fri, 27 Dec 2019 13:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577454075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1l/tQ5+l+T1XzctYuN14RZwqLGUquGObj/tL5Pe29Ek=; b=Nly/MPxoma6KiJQ7nq2sVhPozUYK4QSVH1kimGlZeH4w0gS0g7RtLmnSF7AFtJRXXECl2+ B5rZjzmpPOOjY7uQR/XBnDFeXqU3yY8T/niW0LOTAgQ05tvLW5Sm1tXWudX0qg9ryLO1Yn JYiz+Sp8UvwSuPamC9rEB4s4L1qShC8= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 4/5] python/qemu: qmp: Make QEMUMonitorProtocol a context manager Date: Fri, 27 Dec 2019 10:41:00 -0300 Message-Id: <20191227134101.244496-5-wainersm@redhat.com> In-Reply-To: <20191227134101.244496-1-wainersm@redhat.com> References: <20191227134101.244496-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: BTa-AUmoOjWvixkFlInXAw-1 X-Mimecast-Spam-Score: 0 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: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This implement the __enter__ and __exit__ functions on QEMUMonitorProtocol class so that it can be used on 'with' statement and the resources will be free up on block end: with QEMUMonitorProtocol(socket_path) as qmp: qmp.connect() qmp.command('query-status') Signed-off-by: Wainer dos Santos Moschetta --- python/qemu/qmp.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 914b8c6774..6d55f53595 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -139,6 +139,15 @@ class QEMUMonitorProtocol: raise QMPConnectError("Error while reading from socket") self.__sock.settimeout(None) =20 + def __enter__(self): + # Implement context manager enter function. + return self + + def __exit__(self, exc_type, exc_value, exc_traceback): + # Implement context manager exit function. + self.close() + return False + def connect(self, negotiate=3DTrue): """ Connect to the QMP Monitor and perform capabilities negotiation. @@ -259,8 +268,10 @@ class QEMUMonitorProtocol: """ Close the socket and socket file. """ - self.__sock.close() - self.__sockfile.close() + if self.__sock: + self.__sock.close() + if self.__sockfile: + self.__sockfile.close() =20 def settimeout(self, timeout): """ --=20 2.23.0 From nobody Fri May 3 04:58:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1577454412; cv=none; d=zohomail.com; s=zohoarc; b=e4mbXW0cTvan+mKWqFG345XSmnRZ1NPnpdEl9WB20uWmejF/VSfBBovL4hkS/hDYCO+Dh0J0uCAvKEpNVZYKbdifjXx39JodKbOUCNQYYbiuELQXyXJz74KJiq/d8i+91mBUBMDxo8pZB7du0Dnq3hAQJmgC+3lMSN47eZ6F5dY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577454412; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=O/g0/t8tWVEaHSz/dulzIlsqxeIhd6paNZMvmjPyJhI=; b=C+dNotEFvWKFTVagStJJVY6qdo57fn0DVemBUaeocfxmCRUdvEh88hlcW/EtJtqyEiQfRxf3/eIMYNKcjfzwSivylWZ7MBoUEhRFNdjHsvMRxmH+HUtMa1guOVmYdAa8AAoP9kxfqbmv72cun9bLtt4SIYoHoAy8YCC42NmT4yY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1577454412827310.7893827463067; Fri, 27 Dec 2019 05:46:52 -0800 (PST) Received: from localhost ([::1]:35594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikpx5-0003D3-W8 for importer@patchew.org; Fri, 27 Dec 2019 08:46:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58918) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ikprl-0006Sd-7E for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ikprj-0003Cx-1D for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:21 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:60785 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ikpri-0003BI-UJ for qemu-devel@nongnu.org; Fri, 27 Dec 2019 08:41:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-77-YwYLRECYPSSJXv11M6rf_g-1; Fri, 27 Dec 2019 08:41:16 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EA68800D48 for ; Fri, 27 Dec 2019 13:41:15 +0000 (UTC) Received: from localhost.localdomain (ovpn-116-24.gru2.redhat.com [10.97.116.24]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A49B81C00; Fri, 27 Dec 2019 13:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577454077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O/g0/t8tWVEaHSz/dulzIlsqxeIhd6paNZMvmjPyJhI=; b=ItWXsap9m5cWh9rAHfRvJryvBOEQzxDZcuQB62XkCFYsFct3MYmHxTyUxWZu07rv0fD+5A HrVxyUVek+XNgpX0c+30THA54CWIoep9U+LssYQnsSGZ42ccDIDW3UfgB38x4vJdm7qjZg B2JZKYVVUan2mS3uE0V5cJ1q/7hVA7I= From: Wainer dos Santos Moschetta To: qemu-devel@nongnu.org Subject: [PATCH 5/5] python/qemu: qmp: Remove unnused attributes Date: Fri, 27 Dec 2019 10:41:01 -0300 Message-Id: <20191227134101.244496-6-wainersm@redhat.com> In-Reply-To: <20191227134101.244496-1-wainersm@redhat.com> References: <20191227134101.244496-1-wainersm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: YwYLRECYPSSJXv11M6rf_g-1 X-Mimecast-Spam-Score: 0 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: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, crosa@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The `error` and `timeout` attributes in QEMUMonitorProtocol are not used, so this delete them. Signed-off-by: Wainer dos Santos Moschetta Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/qmp.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 6d55f53595..cddb94bb3c 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -45,10 +45,6 @@ class QEMUMonitorProtocol: =20 #: Logger object for debugging messages logger =3D logging.getLogger('QMP') - #: Socket's error class - error =3D socket.error - #: Socket's timeout - timeout =3D socket.timeout =20 def __init__(self, address, server=3DFalse): """ --=20 2.23.0