From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602028858; cv=none; d=zohomail.com; s=zohoarc; b=h4M5zEAosuXJjBYySIREp97QCVOrv+c81doo0TP1QMO0ooHToadB9ldo/O3HJskoJCXQIGwXluf0aLdzSkN8KzkCyl/V6t3FODIubtcysghBJQHD/VCijzS5M8V6cs/j3B7iJ+fk7ObhsxuIYuIC6NS2nciLVT1wYG4u6jRsR0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602028858; 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=dm3LrLUdePuq3us66UcV7FCBRQCAmijB+fVoXut0lAo=; b=OFCGN+QPj+RG884lOlcjYMVETbvXK78u/dDF4A9/fT7pBSqyCrdzwGX/uNd8BH7oRQKbzkdT885zd2vBIzkI6wK4VkLUZeROIXAvHLEEoNOPhuq+yOSXkSwvI2qaMu5MG8X6wa9k9BLPajTV36W8F1jLOM3poLEp3D7nZf4K5OI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602028858459335.274276623942; Tue, 6 Oct 2020 17:00:58 -0700 (PDT) Received: from localhost ([::1]:57684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwt6-0001Fm-DC for importer@patchew.org; Tue, 06 Oct 2020 20:00:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqi-0007mQ-Iw for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqd-0002HY-VW for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:26 -0400 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-317-9dHhBEtPN9e0crfJEbfeeg-1; Tue, 06 Oct 2020 19:58:21 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CC9987950D; Tue, 6 Oct 2020 23:58:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3416265F5E; Tue, 6 Oct 2020 23:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028703; 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=dm3LrLUdePuq3us66UcV7FCBRQCAmijB+fVoXut0lAo=; b=FS0bTPfG+vPY3myWq+JnqyLeWJbegrqQ1Qk1cf40IdbGwnBVngO3qkyxheiE7by0+pWFlE Cs6nHam/EsNBqUUVBtg7Gxpuzf/HWtU+MU7Gp/bwd2qEvIb9pH1QYfYb/ZfoH4OsDz9Yds A1RpVf/aoZ59TDk+AHKA4GPl4Ft5SCU= X-MC-Unique: 9dHhBEtPN9e0crfJEbfeeg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 01/20] python/qemu: use isort to lay out imports Date: Tue, 6 Oct 2020 19:57:58 -0400 Message-Id: <20201006235817.3280413-2-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Borrowed from the QAPI cleanup series, use the same configuration to standardize the way we write and sort imports. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/.isort.cfg | 7 +++++++ python/qemu/accel.py | 1 + python/qemu/console_socket.py | 2 +- python/qemu/machine.py | 8 ++++---- python/qemu/qmp.py | 10 +++++----- python/qemu/qtest.py | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 python/qemu/.isort.cfg diff --git a/python/qemu/.isort.cfg b/python/qemu/.isort.cfg new file mode 100644 index 00000000000..6d0fd6cc0d3 --- /dev/null +++ b/python/qemu/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +force_grid_wrap=3D4 +force_sort_within_sections=3DTrue +include_trailing_comma=3DTrue +line_length=3D72 +lines_after_imports=3D2 +multi_line_output=3D3 \ No newline at end of file diff --git a/python/qemu/accel.py b/python/qemu/accel.py index 7fabe629208..3ec6bdcfdb5 100644 --- a/python/qemu/accel.py +++ b/python/qemu/accel.py @@ -18,6 +18,7 @@ import os import subprocess =20 + LOG =3D logging.getLogger(__name__) =20 # Mapping host architecture to any additional architectures it can diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index 70869fbbdc4..69f604c77fe 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -13,9 +13,9 @@ # the COPYING file in the top-level directory. # =20 +from collections import deque import socket import threading -from collections import deque import time =20 =20 diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 82f3731fc3f..bc83f399c1b 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -20,15 +20,15 @@ import errno import logging import os -import subprocess import shutil import signal +import subprocess import tempfile -from typing import Optional, Type from types import TracebackType -from . import console_socket +from typing import Optional, Type + +from . import console_socket, qmp =20 -from . import qmp =20 LOG =3D logging.getLogger(__name__) =20 diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 7935dababbf..ddf8347ac12 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -7,21 +7,21 @@ # This work is licensed under the terms of the GNU GPL, version 2. See # the COPYING file in the top-level directory. =20 -import json import errno -import socket +import json import logging +import socket +from types import TracebackType from typing import ( Any, - cast, Dict, Optional, TextIO, - Type, Tuple, + Type, Union, + cast, ) -from types import TracebackType =20 =20 # QMPMessage is a QMP Message of any kind. diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py index 888c8bd2f60..7700c0b09b6 100644 --- a/python/qemu/qtest.py +++ b/python/qemu/qtest.py @@ -17,8 +17,8 @@ # Based on qmp.py. # =20 -import socket import os +import socket from typing import Optional, TextIO =20 from .machine import QEMUMachine --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602028872; cv=none; d=zohomail.com; s=zohoarc; b=I4VFZkgB5NM7IIL7iESnJk8qZINsHBRU18sRH8kgT9Njzb9fGCRW5UgSZqlTV1uYr0bd5sK1E59s+De46YyRE66ViTwEjgCLmTDvEpRiHPH1QEOXr/Ss6wkIv0fRQgLCWFfkV+3WRQTBaFwsiZ63OsXdcLmPeyoJMXDc2XZ/+78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602028872; 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=kn888XOGJoWD2QFt78fuRBExMTFaJ1fF2Lgz5K7oy8E=; b=PsHYbPuc7b49X5ACJNtMJsMKYmwD3ENCAcVABBfNZ5LWUXMGVpBFO2ODxfRiU6JJAi8IV8SeHW0kQRA7blnf6cgN0sv3AjgBGp1LO6aESwXomTbI27gM3Cs1FbsHBSf+cOtq+7OzXDcybswqTMh0N9cxHMn7x5YfsmpwrfBBvoM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602028872520922.9502867667665; Tue, 6 Oct 2020 17:01:12 -0700 (PDT) Received: from localhost ([::1]:58192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwtL-0001Ti-5v for importer@patchew.org; Tue, 06 Oct 2020 20:01:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqm-0007nU-RU for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqf-0002Hy-Ba for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:31 -0400 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-505-fQcLtrLzMeiv_MgJxhk0ZA-1; Tue, 06 Oct 2020 19:58:22 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 225AF64097; Tue, 6 Oct 2020 23:58:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 63602610F3; Tue, 6 Oct 2020 23:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028704; 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=kn888XOGJoWD2QFt78fuRBExMTFaJ1fF2Lgz5K7oy8E=; b=ONIZVTmRewiUZG8d0m8dXF1nGkhQhrgFexYmkuhePEL+WdfgBFB230Ytd+gQPiqiKyuw5y gSl4nzhF8FmKE3SfPg48yPF2MkCeJV+tcPD+kLutEsJI0ecTVP+LsL6s970lvnesi7Fg5b SmqNyXt7Ify5EQqzKsTsISZMNzura38= X-MC-Unique: fQcLtrLzMeiv_MgJxhk0ZA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 02/20] python/machine.py: Fix monitor address typing Date: Tue, 6 Oct 2020 19:57:59 -0400 Message-Id: <20201006235817.3280413-3-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Prior to this, it's difficult for mypy to intuit what the concrete type of the monitor address is; it has difficulty inferring the type across two variables. Create _monitor_address as a property that always returns a valid address to simplify static type analysis. To preserve our ability to clean up, use a simple boolean to indicate whether or not we should try to clean up the sock file after execution. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/machine.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index bc83f399c1b..3017ec072df 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -28,6 +28,7 @@ from typing import Optional, Type =20 from . import console_socket, qmp +from .qmp import SocketAddrT =20 =20 LOG =3D logging.getLogger(__name__) @@ -68,7 +69,8 @@ class QEMUMachine: """ =20 def __init__(self, binary, args=3DNone, wrapper=3DNone, name=3DNone, - test_dir=3D"/var/tmp", monitor_address=3DNone, + test_dir=3D"/var/tmp", + monitor_address: Optional[SocketAddrT] =3D None, socket_scm_helper=3DNone, sock_dir=3DNone, drain_console=3DFalse, console_log=3DNone): ''' @@ -95,8 +97,14 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone, = name=3DNone, if sock_dir is None: sock_dir =3D test_dir self._name =3D name - self._monitor_address =3D monitor_address - self._vm_monitor =3D None + if monitor_address is not None: + self._monitor_address =3D monitor_address + self._remove_monitor_sockfile =3D False + else: + self._monitor_address =3D os.path.join( + sock_dir, f"{name}-monitor.sock" + ) + self._remove_monitor_sockfile =3D True self._qemu_log_path =3D None self._qemu_log_file =3D None self._popen =3D None @@ -241,15 +249,17 @@ def _load_io_log(self): =20 def _base_args(self): args =3D ['-display', 'none', '-vga', 'none'] + if self._qmp_set: if isinstance(self._monitor_address, tuple): - moncdev =3D "socket,id=3Dmon,host=3D%s,port=3D%s" % ( - self._monitor_address[0], - self._monitor_address[1]) + moncdev =3D "socket,id=3Dmon,host=3D{},port=3D{}".format( + *self._monitor_address + ) else: - moncdev =3D 'socket,id=3Dmon,path=3D%s' % self._vm_monitor + moncdev =3D f"socket,id=3Dmon,path=3D{self._monitor_addres= s}" args.extend(['-chardev', moncdev, '-mon', 'chardev=3Dmon,mode=3Dcontrol']) + if self._machine is not None: args.extend(['-machine', self._machine]) for _ in range(self._console_index): @@ -274,14 +284,14 @@ def _pre_launch(self): self._qemu_log_file =3D open(self._qemu_log_path, 'wb') =20 if self._qmp_set: - if self._monitor_address is not None: - self._vm_monitor =3D self._monitor_address - else: - self._vm_monitor =3D os.path.join(self._sock_dir, - self._name + "-monitor.soc= k") - self._remove_files.append(self._vm_monitor) - self._qmp =3D qmp.QEMUMonitorProtocol(self._vm_monitor, server= =3DTrue, - nickname=3Dself._name) + if self._remove_monitor_sockfile: + assert isinstance(self._monitor_address, str) + self._remove_files.append(self._monitor_address) + self._qmp =3D qmp.QEMUMonitorProtocol( + self._monitor_address, + server=3DTrue, + nickname=3Dself._name + ) =20 def _post_launch(self): if self._qmp: --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602028858; cv=none; d=zohomail.com; s=zohoarc; b=XTGmwjolo2cwSqh+2DnFsPRSZbslJTO6HOq+zc1hfmOlr0lqGPqGrROJI/YFcA9iVOQMz9rQ6rbunFZpm+ohpglP4fnJ5TZ5HIb6+ByEKJ7t0WA6tsW2c1L75/8lcf9zmeE73pG8d+4UkQ/rgTc88n1FW0JB8I1mwwPnSnFW978= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602028858; 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=13f7ZcwyL2HoUTVislrZE9zDCzpag0gsSKlPXvDs438=; b=bMh3oZPLbUCXmWfBNFcoUEldMvEJNPClazzDl1TQdnu0+lxBfQMHhX3YyMVMhl8CTGmzjEgJVid14MOUXVZl87S2AgxnPPQBAVf3FzxMXxBxPqkwQudYNglF2CMfOWC5W/+zmMHyu0+W1obL+K0280KyXLlGM8FM9IHsVSRi3g0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602028858346116.01869959313149; Tue, 6 Oct 2020 17:00:58 -0700 (PDT) Received: from localhost ([::1]:57612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwt5-0001Dr-U1 for importer@patchew.org; Tue, 06 Oct 2020 20:00:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqm-0007mj-5p for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53357) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqg-0002IB-CQ for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:30 -0400 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-27-sNm8QWVuMRasK3lIABCKYw-1; Tue, 06 Oct 2020 19:58:23 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A4C11084D64; Tue, 6 Oct 2020 23:58:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D80160BFA; Tue, 6 Oct 2020 23:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028705; 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=13f7ZcwyL2HoUTVislrZE9zDCzpag0gsSKlPXvDs438=; b=f9QO+1qPp1ig6ZdFGg2PdQ6YHZbyeC/6mTdR38Ju8EENkS+smLv8D4aajT8STEq8E2WULb KEDLzt8C9TZN31WNglQtDoQphHRyOnXg8KaJ/nLONcP8VtoC1A2m4Kov3mWg4wRJF/r9oc oeT0MUm6Z21+aCMdHHqDQNa7ya70huE= X-MC-Unique: sNm8QWVuMRasK3lIABCKYw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 03/20] python/machine.py: reorder __init__ Date: Tue, 6 Oct 2020 19:58:00 -0400 Message-Id: <20201006235817.3280413-4-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Put the init arg handling all at the top, and mostly in order (deviating when one is dependent on another), and put what is effectively runtime state declaration at the bottom. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/machine.py | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 3017ec072df..71fe58be050 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -84,42 +84,54 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, @param monitor_address: address for QMP monitor @param socket_scm_helper: helper program, required for send_fd_scm= () @param sock_dir: where to create socket (overrides test_dir for so= ck) - @param console_log: (optional) path to console log file @param drain_console: (optional) True to drain console socket to b= uffer + @param console_log: (optional) path to console log file @note: Qemu process is not started until launch() is used. ''' + # Direct user configuration + + self._binary =3D binary + if args is None: args =3D [] + # Copy mutable input: we will be modifying our copy + self._args =3D list(args) + if wrapper is None: wrapper =3D [] - if name is None: - name =3D "qemu-%d" % os.getpid() - if sock_dir is None: - sock_dir =3D test_dir - self._name =3D name + self._wrapper =3D wrapper + + self._name =3D name or "qemu-%d" % os.getpid() + self._test_dir =3D test_dir + self._sock_dir =3D sock_dir or self._test_dir + self._socket_scm_helper =3D socket_scm_helper + if monitor_address is not None: self._monitor_address =3D monitor_address self._remove_monitor_sockfile =3D False else: self._monitor_address =3D os.path.join( - sock_dir, f"{name}-monitor.sock" + self._sock_dir, f"{self._name}-monitor.sock" ) self._remove_monitor_sockfile =3D True + + self._console_log_path =3D console_log + if self._console_log_path: + # In order to log the console, buffering needs to be enabled. + self._drain_console =3D True + else: + self._drain_console =3D drain_console + + # Runstate self._qemu_log_path =3D None self._qemu_log_file =3D None self._popen =3D None - self._binary =3D binary - 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._qmp_set =3D True # Enable QMP monitor by default. self._qmp =3D None self._qemu_full_args =3D None - self._test_dir =3D test_dir self._temp_dir =3D None - self._sock_dir =3D sock_dir self._launched =3D False self._machine =3D None self._console_index =3D 0 @@ -129,12 +141,6 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone= , name=3DNone, self._console_socket =3D None self._remove_files =3D [] self._user_killed =3D False - self._console_log_path =3D console_log - if self._console_log_path: - # In order to log the console, buffering needs to be enabled. - self._drain_console =3D True - else: - self._drain_console =3D drain_console =20 def __enter__(self): return self --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029308; cv=none; d=zohomail.com; s=zohoarc; b=ARr30XGY9O7sT+hxjgDjyXRIHfYKAueObajIOWkakgSlTRNY8tPQNrwAwcsD8bNwdSjtJhYmNpAZoyqcnaRiivn2Tjt1DZQ4O2Q9nl1KKBff+g7FfGKTDEKkuM7MOgTWExiaaLa70S4NhDM/4g5TNSyjrd7wfcRdz/DmRNJQkZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029308; 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=aYDwOvBaZTLf7VnYdeUTS/wPHO3+/u8SxUA78Ch0tKM=; b=a7wkb6djJ6ihtw+Zi78iVQLTzUZtGnsOBpWcAF3sz5eNgjSZh753kTPVcKsC06DTKfqm8M7pPA1p5s940K907fbZZ5g5cB8Kns/sT8giRms4A6krYSlD17I7zwg1AdWREVqH4I7+ImylKGfTrEbwDEganRQ02DSPb45ZuIDwVrk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029308525599.9215942039506; Tue, 6 Oct 2020 17:08:28 -0700 (PDT) Received: from localhost ([::1]:46338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx0M-0008UB-5s for importer@patchew.org; Tue, 06 Oct 2020 20:08:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0007on-OG for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqn-0002JL-W3 for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:38 -0400 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-589-xAeD5HxpNSGJ_yAkEC5HDw-1; Tue, 06 Oct 2020 19:58:27 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3DFCC18BE165; Tue, 6 Oct 2020 23:58:26 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC0C760BFA; Tue, 6 Oct 2020 23:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028711; 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=aYDwOvBaZTLf7VnYdeUTS/wPHO3+/u8SxUA78Ch0tKM=; b=VsiEPHuZHRvCFnXWVM1XCnec6i7YdtsGmqgqnFliH/kN9V5J89VNOq/L114QI+cB7IroB+ y9u8Xddfhb9fjzI54GX41pkqlH6Lysy8+h0WIjU6aesgQZSSHyFVE20gSzSydGmGSn3kUY GASSVCH6yx6rC6epm4xMx/deq9hVbok= X-MC-Unique: xAeD5HxpNSGJ_yAkEC5HDw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 04/20] python/machine.py: Don't modify state in _base_args() Date: Tue, 6 Oct 2020 19:58:01 -0400 Message-Id: <20201006235817.3280413-5-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Don't append to the _remove_files list during _base_args; instead do so during _launch. Rework _base_args as a @property to help facilitate this impression. This has the additional benefit of making the type of _console_address easier to analyze statically. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/machine.py | 17 ++++++++++------- python/qemu/qtest.py | 7 ++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 71fe58be050..812ca7d3497 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -25,7 +25,7 @@ import subprocess import tempfile from types import TracebackType -from typing import Optional, Type +from typing import List, Optional, Type =20 from . import console_socket, qmp from .qmp import SocketAddrT @@ -137,7 +137,9 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, self._console_index =3D 0 self._console_set =3D False self._console_device_type =3D None - self._console_address =3D None + self._console_address =3D os.path.join( + self._sock_dir, f"{self._name}-console.sock" + ) self._console_socket =3D None self._remove_files =3D [] self._user_killed =3D False @@ -253,7 +255,8 @@ def _load_io_log(self): with open(self._qemu_log_path, "r") as iolog: self._iolog =3D iolog.read() =20 - def _base_args(self): + @property + def _base_args(self) -> List[str]: args =3D ['-display', 'none', '-vga', 'none'] =20 if self._qmp_set: @@ -271,9 +274,6 @@ def _base_args(self): for _ in range(self._console_index): args.extend(['-serial', 'null']) if self._console_set: - self._console_address =3D os.path.join(self._sock_dir, - self._name + "-console.so= ck") - self._remove_files.append(self._console_address) chardev =3D ('socket,id=3Dconsole,path=3D%s,server,nowait' % self._console_address) args.extend(['-chardev', chardev]) @@ -289,6 +289,9 @@ def _pre_launch(self): self._qemu_log_path =3D os.path.join(self._temp_dir, self._name + = ".log") self._qemu_log_file =3D open(self._qemu_log_path, 'wb') =20 + if self._console_set: + self._remove_files.append(self._console_address) + if self._qmp_set: if self._remove_monitor_sockfile: assert isinstance(self._monitor_address, str) @@ -374,7 +377,7 @@ def _launch(self): devnull =3D open(os.path.devnull, 'rb') self._pre_launch() self._qemu_full_args =3D (self._wrapper + [self._binary] + - self._base_args() + self._args) + self._base_args + self._args) LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args)) self._popen =3D subprocess.Popen(self._qemu_full_args, stdin=3Ddevnull, diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py index 7700c0b09b6..7fde2565a0a 100644 --- a/python/qemu/qtest.py +++ b/python/qemu/qtest.py @@ -19,7 +19,7 @@ =20 import os import socket -from typing import Optional, TextIO +from typing import List, Optional, TextIO =20 from .machine import QEMUMachine =20 @@ -111,8 +111,9 @@ def __init__(self, binary, args=3DNone, name=3DNone, te= st_dir=3D"/var/tmp", self._qtest =3D None self._qtest_path =3D os.path.join(sock_dir, name + "-qtest.sock") =20 - def _base_args(self): - args =3D super()._base_args() + @property + def _base_args(self) -> List[str]: + args =3D super()._base_args args.extend(['-qtest', 'unix:path=3D' + self._qtest_path, '-accel', 'qtest']) return args --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029085; cv=none; d=zohomail.com; s=zohoarc; b=YsHVQowA49UgUfJxxTJmIT0zj3ewIgf4mWr1hM9QM8peElhJX8CVD45expYUHJZ12+Odn2DzwZbE0ZEkkBYnajYn1q9ucPfCv90yWRCQywXK3RsPShFrSl/2cJNU0D+FBTAWBEB6P92jUMKQNqWacIxGSde1YVbojFO31vE3UOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029085; 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=/zSGVM2JkgSSLZO/grIC7BOqY6pXx4z7e2BAs6DDva0=; b=lj4yUjzxgr+X9skV89dxuZamAPjMUcpcE7/hjQiRa8yQOuyQxmu1nSpxgjVMwd+P+hLCA2BRX3cPeem+l7rx4XVEqVX6HQXGx1xINUWU2EoyD+eqePs/hMFl9LIFIQZKy70Zt3oCY7wgdNM+UKYmCJF/2CgkymUbJy3DXDAxVSA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029085247932.9112343075093; Tue, 6 Oct 2020 17:04:45 -0700 (PDT) Received: from localhost ([::1]:38592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwwl-0005AP-U1 for importer@patchew.org; Tue, 06 Oct 2020 20:04:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0007ob-CV for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqn-0002J2-Vp for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:38 -0400 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-273-qxyx64t7OtS381zpJY5Kuw-1; Tue, 06 Oct 2020 19:58:29 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3A721084D6F; Tue, 6 Oct 2020 23:58:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D1CE610F3; Tue, 6 Oct 2020 23:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028710; 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=/zSGVM2JkgSSLZO/grIC7BOqY6pXx4z7e2BAs6DDva0=; b=fzlDCJwkgSdOwCISNWAG1GTcPEK4qQfjfyXLh/C7DrJjf0EhkkDJRmNBizPJaB+OUtU0zY QxR2vCzHmYAgyIybBDXFjAwott6NW9ZufpROER+16fRyO7e1ariKZq4CnfwWJdEU0To6GC +RHCyHMwO4+7MFyBD+OF0G+C12RCQNA= X-MC-Unique: qxyx64t7OtS381zpJY5Kuw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 05/20] python/machine.py: Handle None events in events_wait Date: Tue, 6 Oct 2020 19:58:02 -0400 Message-Id: <20201006235817.3280413-6-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If the timeout is 0, we can get None back. Handle this explicitly. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/machine.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 812ca7d3497..aebfa09e9de 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -28,7 +28,7 @@ from typing import List, Optional, Type =20 from . import console_socket, qmp -from .qmp import SocketAddrT +from .qmp import QMPMessage, SocketAddrT =20 =20 LOG =3D logging.getLogger(__name__) @@ -604,13 +604,20 @@ def event_wait(self, name, timeout=3D60.0, match=3DNo= ne): =20 def events_wait(self, events, timeout=3D60.0): """ - events_wait waits for and returns a named event - from QMP with a timeout. + events_wait waits for and returns a single named event from QMP. + In the case of multiple qualifying events, this function returns t= he + first one. =20 - events: a sequence of (name, match_criteria) tuples. - The match criteria are optional and may be None. - See event_match for details. - timeout: QEMUMonitorProtocol.pull_event timeout parameter. + :param events: A sequence of (name, match_criteria) tuples. + The match criteria are optional and may be None. + See event_match for details. + :param timeout: Optional timeout, in seconds. + See QEMUMonitorProtocol.pull_event. + + :raise QMPTimeoutError: If timeout was non-zero and no matching ev= ents + were found. + :return: A QMP event matching the filter criteria. + If timeout was 0 and no event matched, None. """ def _match(event): for name, match in events: @@ -618,6 +625,8 @@ def _match(event): return True return False =20 + event: Optional[QMPMessage] + # Search cached events for event in self._events: if _match(event): @@ -627,6 +636,10 @@ def _match(event): # Poll for new events while True: event =3D self._qmp.pull_event(wait=3Dtimeout) + if event is None: + # NB: None is only returned when timeout is false-ish. + # Timeouts raise QMPTimeoutError instead! + break if _match(event): return event self._events.append(event) --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029090; cv=none; d=zohomail.com; s=zohoarc; b=D8xYaSA5lXjHvG4C+LX30PxCVvxSe2rwqDOujK49iY1VWReLrTj221T2uXVtOJgcrJWwLD1cxDtwVonor4Jk85W4dOggTx4g1gaQ3uorVS4pE4E9T/y4orgu3WxP8RCLj2e4uCMGvMp8nW8hujWa9OYfWwmYSue8U/TOZw2y3ng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029090; 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=2l4JO+5gQp+SBGBAr/pLt0X3eyA5bOSsj9z+ljUrjso=; b=LZRFUbHnmWY82Mh07G34KhDGYKa58pinFeAHYTJNbih4ULB6GXEjpsrgGOFINyJ88Ic1Zqqg2HjL1bSNiTJpZkcyqftj2sj8DZ0A0ZEwU1pr0O23KZJX/hbYMuRR/mLK2BohVEqDOhIMa0ZCFlHyMAwalNiR2zkt1ACNFTOwawU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029090601770.8459837947298; Tue, 6 Oct 2020 17:04:50 -0700 (PDT) Received: from localhost ([::1]:39066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwwr-0005Lz-6v for importer@patchew.org; Tue, 06 Oct 2020 20:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqw-0007tR-Cx for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20620) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0002Jo-3D for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:42 -0400 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-436-1ChF47WsNiq0w0MeKfdiKQ-1; Tue, 06 Oct 2020 19:58:32 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C9178070F7; Tue, 6 Oct 2020 23:58:31 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 435CD9F54; Tue, 6 Oct 2020 23:58:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028714; 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=2l4JO+5gQp+SBGBAr/pLt0X3eyA5bOSsj9z+ljUrjso=; b=EmwacviE3li15EDpfFyd0O2/2AR6TdJlqM/+vSYjNHpO09hQSxbdrVW83Dyxp1WjgW6YRK exrnC/AbXJijemfNAvuw/qLDJL+9mgLFrxp/73WeBqlBfUa9abMWUxNIg8s6ymWQVzf8SI G5lm2n2OeGUfvPOtKY6dmd7pQYLUy10= X-MC-Unique: 1ChF47WsNiq0w0MeKfdiKQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 06/20] python/machine.py: use qmp.command Date: Tue, 6 Oct 2020 19:58:03 -0400 Message-Id: <20201006235817.3280413-7-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" machine.py and qmp.py both do the same thing here; refactor machine.py to use qmp.py's functionality more directly. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/machine.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index aebfa09e9de..d788e8aba8c 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -25,7 +25,13 @@ import subprocess import tempfile from types import TracebackType -from typing import List, Optional, Type +from typing import ( + Any, + Dict, + List, + Optional, + Type, +) =20 from . import console_socket, qmp from .qmp import QMPMessage, SocketAddrT @@ -515,17 +521,23 @@ def set_qmp_monitor(self, enabled=3DTrue): self._qmp_set =3D False self._qmp =3D None =20 - def qmp(self, cmd, conv_keys=3DTrue, **args): - """ - Invoke a QMP command and return the response dict - """ + @classmethod + def _qmp_args(cls, _conv_keys: bool =3D True, **args: Any) -> Dict[str= , Any]: qmp_args =3D dict() for key, value in args.items(): - if conv_keys: + if _conv_keys: qmp_args[key.replace('_', '-')] =3D value else: qmp_args[key] =3D value + return qmp_args =20 + def qmp(self, cmd: str, + conv_keys: bool =3D True, + **args: Any) -> QMPMessage: + """ + Invoke a QMP command and return the response dict + """ + qmp_args =3D self._qmp_args(conv_keys, **args) return self._qmp.cmd(cmd, args=3Dqmp_args) =20 def command(self, cmd, conv_keys=3DTrue, **args): @@ -534,12 +546,8 @@ def command(self, cmd, conv_keys=3DTrue, **args): On success return the response dict. On failure raise an exception. """ - reply =3D self.qmp(cmd, conv_keys, **args) - if reply is None: - raise qmp.QMPError("Monitor is closed") - if "error" in reply: - raise qmp.QMPResponseError(reply) - return reply["return"] + qmp_args =3D self._qmp_args(conv_keys, **args) + return self._qmp.command(cmd, **qmp_args) =20 def get_qmp_event(self, wait=3DFalse): """ --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602028882; cv=none; d=zohomail.com; s=zohoarc; b=ee8rhntEVskXy9u7BSiGNnaD94mfsGEcoaNpT5Ozr2+jYCdL3JgsSf0wMclZxPgnjWqCH04kwTxFBi74tPbXaKQzfzVqGD5VBqj6in+wVgiMH+cuGIj5WNz1huqBdcSOoDABlo2YADevr7m/Hz9TMZ+jEdnoh6Nz0Qn+qRz82NA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602028882; 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=aXtAa28vJz2L/wQ3Jh/YpBLJMIWsXeQxkfChMSZykRs=; b=JHeqkFBF1QywEeSLUfrheklm4qZpxVOmdW/NjGDl7qd+BCF6zFEfhs1GzmiY8xXD2eItmc4qMfdVKJp3Xks97ce0HYmTF0EbYGMP4P3iniHZbNi2+BUJyJPURqUz5yk+AHU65szXG4AZGf83rqJUZyDxkS2PoKTupol/qMRa6XI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602028882839323.0381705231615; Tue, 6 Oct 2020 17:01:22 -0700 (PDT) Received: from localhost ([::1]:59042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwtV-0001uo-Eb for importer@patchew.org; Tue, 06 Oct 2020 20:01:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqw-0007tS-F0 for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0002Jr-3Y for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:42 -0400 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-377-EkqOACcdN7iQEezyTsYhgg-1; Tue, 06 Oct 2020 19:58:33 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60EBA802ED5; Tue, 6 Oct 2020 23:58:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DFE6BABA; Tue, 6 Oct 2020 23:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028715; 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=aXtAa28vJz2L/wQ3Jh/YpBLJMIWsXeQxkfChMSZykRs=; b=bR48DZNmc0U7oersonoSPfIEhR4t06S1IWJrfZ9nYNJYqyReU5P0wFxwI34eCqt/PF/ZOD GmOi9WY75G1vOgMzVkq8nNkAC0MlrhkGRsVfucpAjHZzFavSPgNWZoUPrxOq23TMIg0aPT CRRgGhOdYnPAiRK40Hq7LiphqdbnKxU= X-MC-Unique: EkqOACcdN7iQEezyTsYhgg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 07/20] python/machine.py: Add _qmp access shim Date: Tue, 6 Oct 2020 19:58:04 -0400 Message-Id: <20201006235817.3280413-8-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Like many other Optional[] types, it's not always a given that this object will be set. Wrap it in a type-shim that raises a meaningful error and will always return a concrete type. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/machine.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index d788e8aba8c..3e9cf09fd2d 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -135,7 +135,7 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, self._events =3D [] self._iolog =3D None self._qmp_set =3D True # Enable QMP monitor by default. - self._qmp =3D None + self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] =3D None self._qemu_full_args =3D None self._temp_dir =3D None self._launched =3D False @@ -302,14 +302,14 @@ def _pre_launch(self): if self._remove_monitor_sockfile: assert isinstance(self._monitor_address, str) self._remove_files.append(self._monitor_address) - self._qmp =3D qmp.QEMUMonitorProtocol( + self._qmp_connection =3D qmp.QEMUMonitorProtocol( self._monitor_address, server=3DTrue, nickname=3Dself._name ) =20 def _post_launch(self): - if self._qmp: + if self._qmp_connection: self._qmp.accept() =20 def _post_shutdown(self): @@ -320,9 +320,9 @@ def _post_shutdown(self): # Comprehensive reset for the failed launch case: self._early_cleanup() =20 - if self._qmp: + if self._qmp_connection: self._qmp.close() - self._qmp =3D None + self._qmp_connection =3D None =20 self._load_io_log() =20 @@ -434,7 +434,7 @@ def _soft_shutdown(self, timeout: Optional[int], """ self._early_cleanup() =20 - if self._qmp is not None: + if self._qmp_connection: if not has_quit: # Might raise ConnectionReset self._qmp.cmd('quit') @@ -515,11 +515,13 @@ def set_qmp_monitor(self, enabled=3DTrue): line. Default is True. @note: call this function before launch(). """ - if enabled: - self._qmp_set =3D True - else: - self._qmp_set =3D False - self._qmp =3D None + self._qmp_set =3D enabled + + @property + def _qmp(self) -> qmp.QEMUMonitorProtocol: + if self._qmp_connection is None: + raise QEMUMachineError("Attempt to access QMP with no connecti= on") + return self._qmp_connection =20 @classmethod def _qmp_args(cls, _conv_keys: bool =3D True, **args: Any) -> Dict[str= , Any]: --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029582; cv=none; d=zohomail.com; s=zohoarc; b=Cvi/aDwY/VeDETSb7dXJkKzHtBJxTF9vaqy0GtFq9qq0u7ClcZHfpIcUvX/I7WM35ZE3OZCSAt4w+4ccz7/COVvqRHvPDZcQnncxHtUTBm6Y2MVNtWWyLs1ybP06qyA1hhRDQgK6nNcd8zl0l8zaUHvDn71PokZwdLf9PY8X79M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029582; 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=m8hN6lCWw4mZZXn+2POwMA4lzqzGKKOBza3JkPyASJA=; b=A38ZcN/lIjd4zeTCwaIvH8aax3T5hTOOtDBk0LVdpmp3dNVKp4kVbYfqKaBJKh36l+zp6Oc81Y3+zGqmAYu1jl0pe/6XNe/7krZL1iq8Gra5v0rALA0Kp8QrZvwrixSm6drrlT4EUQenllXhOgUJpKzmrH4ej2Nmwutv9XWiXBA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029582581257.43087009053363; Tue, 6 Oct 2020 17:13:02 -0700 (PDT) Received: from localhost ([::1]:54508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx4n-0003h1-A5 for importer@patchew.org; Tue, 06 Oct 2020 20:13:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqv-0007sm-Pz for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0002K2-36 for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:41 -0400 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-529-rzmBAxG2Onm28GEjvgHZ7A-1; Tue, 06 Oct 2020 19:58:34 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C3FE802ED7; Tue, 6 Oct 2020 23:58:33 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83C1760BFA; Tue, 6 Oct 2020 23:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028716; 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=m8hN6lCWw4mZZXn+2POwMA4lzqzGKKOBza3JkPyASJA=; b=RqjW+1sfztc22c9Ap/8R+8QZelYfzD6jkDdBFD4ceaadm7gO1rHVn0kaKCF/XQMRLEXfMA HBwjc2H+i8A9JCLgVsomUWvynVWnuiv3EnRnh8w4+RApFbXeD79ogMzUY8SzX4LsHo/qcU 5+zoZ08ei8OKR3KQZanrg7tw9+AwzMM= X-MC-Unique: rzmBAxG2Onm28GEjvgHZ7A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 08/20] python/machine.py: fix _popen access Date: Tue, 6 Oct 2020 19:58:05 -0400 Message-Id: <20201006235817.3280413-9-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As always, Optional[T] causes problems with unchecked access. Add a helper that asserts the pipe is present before we attempt to talk with it. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/machine.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 3e9cf09fd2d..4e762fcd529 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -131,7 +131,7 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, # Runstate self._qemu_log_path =3D None self._qemu_log_file =3D None - self._popen =3D None + self._popen: Optional['subprocess.Popen[bytes]'] =3D None self._events =3D [] self._iolog =3D None self._qmp_set =3D True # Enable QMP monitor by default. @@ -244,6 +244,12 @@ def is_running(self): """Returns true if the VM is running.""" return self._popen is not None and self._popen.poll() is None =20 + @property + def _subp(self) -> 'subprocess.Popen[bytes]': + if self._popen is None: + raise QEMUMachineError('Subprocess pipe not present') + return self._popen + def exitcode(self): """Returns the exit code if possible, or None.""" if self._popen is None: @@ -254,7 +260,7 @@ def get_pid(self): """Returns the PID of the running process, or None.""" if not self.is_running(): return None - return self._popen.pid + return self._subp.pid =20 def _load_io_log(self): if self._qemu_log_path is not None: @@ -415,8 +421,8 @@ def _hard_shutdown(self) -> None: waiting for the QEMU process to terminate. """ self._early_cleanup() - self._popen.kill() - self._popen.wait(timeout=3D60) + self._subp.kill() + self._subp.wait(timeout=3D60) =20 def _soft_shutdown(self, timeout: Optional[int], has_quit: bool =3D False) -> None: @@ -440,7 +446,7 @@ def _soft_shutdown(self, timeout: Optional[int], self._qmp.cmd('quit') =20 # May raise subprocess.TimeoutExpired - self._popen.wait(timeout=3Dtimeout) + self._subp.wait(timeout=3Dtimeout) =20 def _do_shutdown(self, timeout: Optional[int], has_quit: bool =3D False) -> None: --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029109; cv=none; d=zohomail.com; s=zohoarc; b=Z+TbkWRSfFQz6sB/LKAQGv+3Sm8ENKEye/BJF8bRz4OYgRzgIAIlfYuY4siRgqaG1KUZpc0oHjrZIYObLr5yGO5ntJrxDmImFKg6j75s8l1R4AipQ6rYksMwLBfwNEVd0bmsZIyzE0onXvwr+O9+1jfslIqfKjoNFFWEAqStw7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029109; 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=FO0jEg0I+s+8GacxuFA2gFC2mh6kToiUL7H5gdtJav0=; b=LzIBd5QF01wlw4XrjLCIdwnTMq7MDsz2WlhfLfpqiI1B2QSoWYuwZC9aJMrgayFj8+KUl1OD0nrEMSJ228vVbP2HfEH4AUb768tvaJMLKnhHv4wQHSz63H8PIxJiQ+h8uefaKGwaaCOoijnRbDRv5m2XriuIIafCuQS5qOZ0rwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160202910908567.62583345559426; Tue, 6 Oct 2020 17:05:09 -0700 (PDT) Received: from localhost ([::1]:39970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPwx9-0005kr-Qa for importer@patchew.org; Tue, 06 Oct 2020 20:05:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwqx-0007v3-Iw for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26582) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqs-0002KL-ET for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:43 -0400 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-158-uy_O1xTlMFWeSDElAlTLxA-1; Tue, 06 Oct 2020 19:58:35 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B916F106F8E1; Tue, 6 Oct 2020 23:58:34 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8069160BFA; Tue, 6 Oct 2020 23:58:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028717; 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=FO0jEg0I+s+8GacxuFA2gFC2mh6kToiUL7H5gdtJav0=; b=YBLkFXuxL0HUexxv03RfZMBdvky4eUdzerYXhGZdK1qsE4WSqOToZdCzp3RsF6Leks2o+k Y+1QYNA/TG4kLbcW0WBSTTuIFrohOudLAjZgj6u7WDtsD4kaU7St5K6s6G6+dyXkyPLYnJ 1rZf9ay/fTb5TZazySh+6b10KpoPxwo= X-MC-Unique: uy_O1xTlMFWeSDElAlTLxA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 09/20] python/qemu: make 'args' style arguments immutable Date: Tue, 6 Oct 2020 19:58:06 -0400 Message-Id: <20201006235817.3280413-10-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These arguments don't need to be mutable and aren't really used as such. Clarify their types as immutable and adjust code to match where necessary. In general, It's probably best not to accept a user-defined mutable object and store it as internal object state unless there's a strong justification for doing so. Instead, try to use generic types as input with empty tuples as the default, and coerce to list where necessary. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/machine.py | 30 +++++++++++++++++------------- python/qemu/qtest.py | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 4e762fcd529..e599cb7439b 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -18,6 +18,7 @@ # =20 import errno +from itertools import chain import logging import os import shutil @@ -30,6 +31,8 @@ Dict, List, Optional, + Sequence, + Tuple, Type, ) =20 @@ -74,8 +77,12 @@ class QEMUMachine: # vm is guaranteed to be shut down here """ =20 - def __init__(self, binary, args=3DNone, wrapper=3DNone, name=3DNone, - test_dir=3D"/var/tmp", + def __init__(self, + binary: str, + args: Sequence[str] =3D (), + wrapper: Sequence[str] =3D (), + name: Optional[str] =3D None, + test_dir: str =3D "/var/tmp", monitor_address: Optional[SocketAddrT] =3D None, socket_scm_helper=3DNone, sock_dir=3DNone, drain_console=3DFalse, console_log=3DNone): @@ -97,14 +104,7 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, # Direct user configuration =20 self._binary =3D binary - - if args is None: - args =3D [] - # Copy mutable input: we will be modifying our copy self._args =3D list(args) - - if wrapper is None: - wrapper =3D [] self._wrapper =3D wrapper =20 self._name =3D name or "qemu-%d" % os.getpid() @@ -136,7 +136,7 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, self._iolog =3D None self._qmp_set =3D True # Enable QMP monitor by default. self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] =3D None - self._qemu_full_args =3D None + self._qemu_full_args: Tuple[str, ...] =3D () self._temp_dir =3D None self._launched =3D False self._machine =3D None @@ -368,7 +368,7 @@ def launch(self): raise QEMUMachineError('VM already launched') =20 self._iolog =3D None - self._qemu_full_args =3D None + self._qemu_full_args =3D () try: self._launch() self._launched =3D True @@ -388,8 +388,12 @@ def _launch(self): """ devnull =3D open(os.path.devnull, 'rb') self._pre_launch() - self._qemu_full_args =3D (self._wrapper + [self._binary] + - self._base_args + self._args) + self._qemu_full_args =3D tuple( + chain(self._wrapper, + [self._binary], + self._base_args, + self._args) + ) LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args)) self._popen =3D subprocess.Popen(self._qemu_full_args, stdin=3Ddevnull, diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py index 7fde2565a0a..675310d8dfe 100644 --- a/python/qemu/qtest.py +++ b/python/qemu/qtest.py @@ -19,7 +19,12 @@ =20 import os import socket -from typing import List, Optional, TextIO +from typing import ( + List, + Optional, + Sequence, + TextIO, +) =20 from .machine import QEMUMachine =20 @@ -99,8 +104,13 @@ class QEMUQtestMachine(QEMUMachine): A QEMU VM, with a qtest socket available. """ =20 - def __init__(self, binary, args=3DNone, name=3DNone, test_dir=3D"/var/= tmp", - socket_scm_helper=3DNone, sock_dir=3DNone): + def __init__(self, + binary: str, + args: Sequence[str] =3D (), + name: Optional[str] =3D None, + test_dir: str =3D "/var/tmp", + socket_scm_helper: Optional[str] =3D None, + sock_dir: Optional[str] =3D None): if name is None: name =3D "qemu-%d" % os.getpid() if sock_dir is None: @@ -114,8 +124,10 @@ def __init__(self, binary, args=3DNone, name=3DNone, t= est_dir=3D"/var/tmp", @property def _base_args(self) -> List[str]: args =3D super()._base_args - args.extend(['-qtest', 'unix:path=3D' + self._qtest_path, - '-accel', 'qtest']) + args.extend([ + '-qtest', f"unix:path=3D{self._qtest_path}", + '-accel', 'qtest' + ]) return args =20 def _pre_launch(self): --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029349; cv=none; d=zohomail.com; s=zohoarc; b=nMCRX3Zq/JoaAbkFJedqRKLJaFFx2G1I2mPBLDdVDx5tKLjoCrnz3K2Pq06wl++4BBp1qEcjveG5jpnibSkwo9A9fXvXMF7KdK7vDdXJ00s1NTMpqC1sVt56zS8zhal5c0H4dp3hA+CNpZZ0Cj75S2O+XP+Rrx0Xe31Hq4sAQZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029349; 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=1MPOJuScEm7RIk4aM+TWMDD8tDjjt3/sRWTZPDfHOjE=; b=BJr2BHc84Dwx7q97Gy3K3H/x9OUGmxc0O9Udc9K31cCTcQqo5iUu5oq3UF50+Y9OgvM0Xgm4jUrWckBtsvU+S7OXfFBu+H2yti+nB+h2ZZgIU9jc/ZMwgMPODQFmjdKn9r4nZZ6+vgUffzH1/gc9ObpMG+5IRRAcw/4r0eurxsQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160202934972584.08253263320762; Tue, 6 Oct 2020 17:09:09 -0700 (PDT) Received: from localhost ([::1]:47420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx12-0000Xa-Gu for importer@patchew.org; Tue, 06 Oct 2020 20:09:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwr2-00086g-M0 for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwqz-0002M0-2j for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:48 -0400 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-126-dMbMDpn-NEGXLtkSB1deTQ-1; Tue, 06 Oct 2020 19:58:42 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7FC66101FFA5; Tue, 6 Oct 2020 23:58:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 093316198B; Tue, 6 Oct 2020 23:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028724; 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=1MPOJuScEm7RIk4aM+TWMDD8tDjjt3/sRWTZPDfHOjE=; b=H8Rxpkk+xfoaHZIjz1WxX2F6BNKYvZMrAb/JlKYq1zzdwWHaINF60tYBlrWEtu6U9p/6oH 5EFMfNaKW39dTA5oBWggGT35MD2GWEN0xxn2sWQbCW+k2kMIrnMRZ4WNIyiW78wLN713Mp fZTineuaF5/+LGNOWKB8E4Lnmj44MuU= X-MC-Unique: dMbMDpn-NEGXLtkSB1deTQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 10/20] iotests.py: Adjust HMP kwargs typing Date: Tue, 6 Oct 2020 19:58:07 -0400 Message-Id: <20201006235817.3280413-11-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" mypy wants to ensure there's consistency between the kwargs arguments types and any unspecified keyword arguments. In this case, conv_keys is a bool, but the remaining keys are Any type. Mypy (correctly) infers the **kwargs type to be **Dict[str, str], which is not compatible with conv_keys: bool. Because QMP typing is a little fraught right now anyway, re-type kwargs to Dict[str, Any] which has the benefit of silencing this check right now. A future re-design might type these more aggressively, but this will give us a baseline to work from with minimal disruption. (Thanks Kevin Wolf for the debugging assist here) Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- tests/qemu-iotests/iotests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index f212cec446d..63d2ace93c0 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -605,7 +605,7 @@ def add_incoming(self, addr): =20 def hmp(self, command_line: str, use_log: bool =3D False) -> QMPMessag= e: cmd =3D 'human-monitor-command' - kwargs =3D {'command-line': command_line} + kwargs: Dict[str, Any] =3D {'command-line': command_line} if use_log: return self.qmp_log(cmd, **kwargs) else: --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029472; cv=none; d=zohomail.com; s=zohoarc; b=IHn3+z8RXQaAD3ws2ysxCXOrkg1RlI/KxAxDtDRgCBgpYVQ+IWZGmwszRzSuEG0T688hgsWmQnWo3NVZayEJFLtA3rKbq5tAOx/cA7uPvm815hfVLcdfODiiTsZ2Lx6AVY9B/WAOihCJjD8DXhGZKz/AyGpN+T+pNAyDVxYWOEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029472; 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=2Cwbwc7sP8pU6H/+Lj4YUGFbHooK8u9zFZX1zMrpByE=; b=iw3Y0aN2y+yluBrLSGgcDur3/ZDx3I0jxdrLnGI3sSzLfigq0e0UKL8HFzH1eWFuEggnsEGnmx3DQHbSp3MFaZjtC0KRKABmlzdu1ZSC/Qm8zoZFj5AAVtT2YzfIo0Fehkm7dsvlvNXG6fkEngEHdSrwvTBH/0LSiYFKhZCjFpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160202947222073.42690737876387; Tue, 6 Oct 2020 17:11:12 -0700 (PDT) Received: from localhost ([::1]:51608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx30-0002Mo-LN for importer@patchew.org; Tue, 06 Oct 2020 20:11:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwr4-0008Bu-KM for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwr0-0002MH-9X for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:58:50 -0400 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-303-l2rkfKGZPIa_JaHopregog-1; Tue, 06 Oct 2020 19:58:43 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 701B464144; Tue, 6 Oct 2020 23:58:42 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id A302460BFA; Tue, 6 Oct 2020 23:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028725; 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=2Cwbwc7sP8pU6H/+Lj4YUGFbHooK8u9zFZX1zMrpByE=; b=dH6sPgjxTEiqaCx5oEn2v78tx2pXvq4NiNfsDhJ0qOpSXc7U8caIeYrPOoQ4gshMRC++Vg bnuFj2VNA6HCVYekbj25c3oNqYzShZrXEfdTA04c8+Q5rYx8tAPFQ147MLwkvirBTj3xxZ huwhnIbifEKZauEUB7AYKzsf1F/iKn0= X-MC-Unique: l2rkfKGZPIa_JaHopregog-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 11/20] python/qemu: Add mypy type annotations Date: Tue, 6 Oct 2020 19:58:08 -0400 Message-Id: <20201006235817.3280413-12-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" These should all be purely annotations with no changes in behavior at all. You need to be in the python folder, but you should be able to confirm that these annotations are correct (or at least self-consistent) by running `mypy --strict qemu`. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/accel.py | 8 ++-- python/qemu/machine.py | 98 ++++++++++++++++++++++++------------------ python/qemu/qmp.py | 44 +++++++++++-------- python/qemu/qtest.py | 26 ++++++----- 4 files changed, 101 insertions(+), 75 deletions(-) diff --git a/python/qemu/accel.py b/python/qemu/accel.py index 3ec6bdcfdb5..297933df2a3 100644 --- a/python/qemu/accel.py +++ b/python/qemu/accel.py @@ -17,6 +17,7 @@ import logging import os import subprocess +from typing import List, Optional =20 =20 LOG =3D logging.getLogger(__name__) @@ -30,7 +31,7 @@ } =20 =20 -def list_accel(qemu_bin): +def list_accel(qemu_bin: str) -> List[str]: """ List accelerators enabled in the QEMU binary. =20 @@ -50,7 +51,8 @@ def list_accel(qemu_bin): return [acc.strip() for acc in out.splitlines()[1:]] =20 =20 -def kvm_available(target_arch=3DNone, qemu_bin=3DNone): +def kvm_available(target_arch: Optional[str] =3D None, + qemu_bin: Optional[str] =3D None) -> bool: """ Check if KVM is available using the following heuristic: - Kernel module is present in the host; @@ -73,7 +75,7 @@ def kvm_available(target_arch=3DNone, qemu_bin=3DNone): return True =20 =20 -def tcg_available(qemu_bin): +def tcg_available(qemu_bin: str) -> bool: """ Check if TCG is available. =20 diff --git a/python/qemu/machine.py b/python/qemu/machine.py index e599cb7439b..6420f01bed4 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -23,11 +23,13 @@ import os import shutil import signal +import socket import subprocess import tempfile from types import TracebackType from typing import ( Any, + BinaryIO, Dict, List, Optional, @@ -37,7 +39,7 @@ ) =20 from . import console_socket, qmp -from .qmp import QMPMessage, SocketAddrT +from .qmp import QMPMessage, QMPReturnValue, SocketAddrT =20 =20 LOG =3D logging.getLogger(__name__) @@ -67,7 +69,7 @@ class AbnormalShutdown(QEMUMachineError): =20 class QEMUMachine: """ - A QEMU VM + A QEMU VM. =20 Use this object as a context manager to ensure the QEMU process terminates:: @@ -84,8 +86,10 @@ def __init__(self, name: Optional[str] =3D None, test_dir: str =3D "/var/tmp", monitor_address: Optional[SocketAddrT] =3D None, - socket_scm_helper=3DNone, sock_dir=3DNone, - drain_console=3DFalse, console_log=3DNone): + socket_scm_helper: Optional[str] =3D None, + sock_dir: Optional[str] =3D None, + drain_console: bool =3D False, + console_log: Optional[str] =3D None): ''' Initialize a QEMUMachine =20 @@ -129,28 +133,28 @@ def __init__(self, self._drain_console =3D drain_console =20 # Runstate - self._qemu_log_path =3D None - self._qemu_log_file =3D None + self._qemu_log_path: Optional[str] =3D None + self._qemu_log_file: Optional[BinaryIO] =3D None self._popen: Optional['subprocess.Popen[bytes]'] =3D None - self._events =3D [] - self._iolog =3D None + self._events: List[QMPMessage] =3D [] + self._iolog: Optional[str] =3D None self._qmp_set =3D True # Enable QMP monitor by default. self._qmp_connection: Optional[qmp.QEMUMonitorProtocol] =3D None self._qemu_full_args: Tuple[str, ...] =3D () - self._temp_dir =3D None + self._temp_dir: Optional[str] =3D None self._launched =3D False - self._machine =3D None + self._machine: Optional[str] =3D None self._console_index =3D 0 self._console_set =3D False - self._console_device_type =3D None + self._console_device_type: Optional[str] =3D None self._console_address =3D os.path.join( self._sock_dir, f"{self._name}-console.sock" ) - self._console_socket =3D None - self._remove_files =3D [] + self._console_socket: Optional[socket.socket] =3D None + self._remove_files: List[str] =3D [] self._user_killed =3D False =20 - def __enter__(self): + def __enter__(self) -> 'QEMUMachine': return self =20 def __exit__(self, @@ -159,14 +163,15 @@ def __exit__(self, exc_tb: Optional[TracebackType]) -> None: self.shutdown() =20 - def add_monitor_null(self): + def add_monitor_null(self) -> None: """ This can be used to add an unused monitor instance. """ self._args.append('-monitor') self._args.append('null') =20 - def add_fd(self, fd, fdset, opaque, opts=3D''): + def add_fd(self, fd: int, fdset: int, + opaque: str, opts: str =3D '') -> 'QEMUMachine': """ Pass a file descriptor to the VM """ @@ -185,7 +190,8 @@ def add_fd(self, fd, fdset, opaque, opts=3D''): self._args.append(','.join(options)) return self =20 - def send_fd_scm(self, fd=3DNone, file_path=3DNone): + def send_fd_scm(self, fd: Optional[int] =3D None, + file_path: Optional[str] =3D None) -> int: """ Send an fd or file_path to socket_scm_helper. =20 @@ -229,7 +235,7 @@ def send_fd_scm(self, fd=3DNone, file_path=3DNone): return proc.returncode =20 @staticmethod - def _remove_if_exists(path): + def _remove_if_exists(path: str) -> None: """ Remove file object at path if it exists """ @@ -240,7 +246,7 @@ def _remove_if_exists(path): return raise =20 - def is_running(self): + def is_running(self) -> bool: """Returns true if the VM is running.""" return self._popen is not None and self._popen.poll() is None =20 @@ -250,19 +256,19 @@ def _subp(self) -> 'subprocess.Popen[bytes]': raise QEMUMachineError('Subprocess pipe not present') return self._popen =20 - def exitcode(self): + def exitcode(self) -> Optional[int]: """Returns the exit code if possible, or None.""" if self._popen is None: return None return self._popen.poll() =20 - def get_pid(self): + def get_pid(self) -> Optional[int]: """Returns the PID of the running process, or None.""" if not self.is_running(): return None return self._subp.pid =20 - def _load_io_log(self): + def _load_io_log(self) -> None: if self._qemu_log_path is not None: with open(self._qemu_log_path, "r") as iolog: self._iolog =3D iolog.read() @@ -296,7 +302,7 @@ def _base_args(self) -> List[str]: args.extend(['-device', device]) return args =20 - def _pre_launch(self): + def _pre_launch(self) -> None: self._temp_dir =3D tempfile.mkdtemp(dir=3Dself._test_dir) self._qemu_log_path =3D os.path.join(self._temp_dir, self._name + = ".log") self._qemu_log_file =3D open(self._qemu_log_path, 'wb') @@ -314,11 +320,11 @@ def _pre_launch(self): nickname=3Dself._name ) =20 - def _post_launch(self): + def _post_launch(self) -> None: if self._qmp_connection: self._qmp.accept() =20 - def _post_shutdown(self): + def _post_shutdown(self) -> None: """ Called to cleanup the VM instance after the process has exited. May also be called after a failed launch. @@ -358,7 +364,7 @@ def _post_shutdown(self): self._user_killed =3D False self._launched =3D False =20 - def launch(self): + def launch(self) -> None: """ Launch the VM and make sure we cleanup and expose the command line/output in case of exception @@ -382,7 +388,7 @@ def launch(self): LOG.debug('Output: %r', self._iolog) raise =20 - def _launch(self): + def _launch(self) -> None: """ Launch the VM and establish a QMP connection """ @@ -501,7 +507,7 @@ def shutdown(self, has_quit: bool =3D False, finally: self._post_shutdown() =20 - def kill(self): + def kill(self) -> None: """ Terminate the VM forcefully, wait for it to exit, and perform clea= nup. """ @@ -516,7 +522,7 @@ def wait(self, timeout: Optional[int] =3D 30) -> None: """ self.shutdown(has_quit=3DTrue, timeout=3Dtimeout) =20 - def set_qmp_monitor(self, enabled=3DTrue): + def set_qmp_monitor(self, enabled: bool =3D True) -> None: """ Set the QMP monitor. =20 @@ -552,7 +558,9 @@ def qmp(self, cmd: str, qmp_args =3D self._qmp_args(conv_keys, **args) return self._qmp.cmd(cmd, args=3Dqmp_args) =20 - def command(self, cmd, conv_keys=3DTrue, **args): + def command(self, cmd: str, + conv_keys: bool =3D True, + **args: Any) -> QMPReturnValue: """ Invoke a QMP command. On success return the response dict. @@ -561,7 +569,7 @@ def command(self, cmd, conv_keys=3DTrue, **args): qmp_args =3D self._qmp_args(conv_keys, **args) return self._qmp.command(cmd, **qmp_args) =20 - def get_qmp_event(self, wait=3DFalse): + def get_qmp_event(self, wait: bool =3D False) -> Optional[QMPMessage]: """ Poll for one queued QMP events and return it """ @@ -569,7 +577,7 @@ def get_qmp_event(self, wait=3DFalse): return self._events.pop(0) return self._qmp.pull_event(wait=3Dwait) =20 - def get_qmp_events(self, wait=3DFalse): + def get_qmp_events(self, wait: bool =3D False) -> List[QMPMessage]: """ Poll for queued QMP events and return a list of dicts """ @@ -580,7 +588,7 @@ def get_qmp_events(self, wait=3DFalse): return events =20 @staticmethod - def event_match(event, match=3DNone): + def event_match(event: Any, match: Optional[Any]) -> bool: """ Check if an event matches optional match criteria. =20 @@ -610,9 +618,11 @@ def event_match(event, match=3DNone): return True except TypeError: # either match or event wasn't iterable (not a dict) - return match =3D=3D event + return bool(match =3D=3D event) =20 - def event_wait(self, name, timeout=3D60.0, match=3DNone): + def event_wait(self, name: str, + timeout: float =3D 60.0, + match: Optional[QMPMessage] =3D None) -> Optional[QMPMe= ssage]: """ event_wait waits for and returns a named event from QMP with a tim= eout. =20 @@ -622,7 +632,9 @@ def event_wait(self, name, timeout=3D60.0, match=3DNone= ): """ return self.events_wait([(name, match)], timeout) =20 - def events_wait(self, events, timeout=3D60.0): + def events_wait(self, + events: Sequence[Tuple[str, Any]], + timeout: float =3D 60.0) -> Optional[QMPMessage]: """ events_wait waits for and returns a single named event from QMP. In the case of multiple qualifying events, this function returns t= he @@ -639,7 +651,7 @@ def events_wait(self, events, timeout=3D60.0): :return: A QMP event matching the filter criteria. If timeout was 0 and no event matched, None. """ - def _match(event): + def _match(event: QMPMessage) -> bool: for name, match in events: if event['event'] =3D=3D name and self.event_match(event, = match): return True @@ -666,20 +678,20 @@ def _match(event): =20 return None =20 - def get_log(self): + def get_log(self) -> Optional[str]: """ After self.shutdown or failed qemu execution, this returns the out= put of the qemu process. """ return self._iolog =20 - def add_args(self, *args): + def add_args(self, *args: str) -> None: """ Adds to the list of extra arguments to be given to the QEMU binary """ self._args.extend(args) =20 - def set_machine(self, machine_type): + def set_machine(self, machine_type: str) -> None: """ Sets the machine type =20 @@ -688,7 +700,9 @@ def set_machine(self, machine_type): """ self._machine =3D machine_type =20 - def set_console(self, device_type=3DNone, console_index=3D0): + def set_console(self, + device_type: Optional[str] =3D None, + console_index: int =3D 0) -> None: """ Sets the device type for a console device =20 @@ -719,7 +733,7 @@ def set_console(self, device_type=3DNone, console_index= =3D0): self._console_index =3D console_index =20 @property - def console_socket(self): + def console_socket(self) -> socket.socket: """ Returns a socket connected to the console """ diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index ddf8347ac12..9223307ed81 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -15,6 +15,7 @@ from typing import ( Any, Dict, + List, Optional, TextIO, Tuple, @@ -90,7 +91,9 @@ class QEMUMonitorProtocol: #: Logger object for debugging messages logger =3D logging.getLogger('QMP') =20 - def __init__(self, address, server=3DFalse, nickname=3DNone): + def __init__(self, address: SocketAddrT, + server: bool =3D False, + nickname: Optional[str] =3D None): """ Create a QEMUMonitorProtocol class. =20 @@ -102,7 +105,7 @@ def __init__(self, address, server=3DFalse, nickname=3D= None): @note No connection is established, this is done by the connect() = or accept() methods """ - self.__events =3D [] + self.__events: List[QMPMessage] =3D [] self.__address =3D address self.__sock =3D self.__get_sock() self.__sockfile: Optional[TextIO] =3D None @@ -114,14 +117,14 @@ def __init__(self, address, server=3DFalse, nickname= =3DNone): self.__sock.bind(self.__address) self.__sock.listen(1) =20 - def __get_sock(self): + def __get_sock(self) -> socket.socket: if isinstance(self.__address, tuple): family =3D socket.AF_INET else: family =3D socket.AF_UNIX return socket.socket(family, socket.SOCK_STREAM) =20 - def __negotiate_capabilities(self): + def __negotiate_capabilities(self) -> QMPMessage: greeting =3D self.__json_read() if greeting is None or "QMP" not in greeting: raise QMPConnectError @@ -131,7 +134,7 @@ def __negotiate_capabilities(self): return greeting raise QMPCapabilitiesError =20 - def __json_read(self, only_event=3DFalse): + def __json_read(self, only_event: bool =3D False) -> Optional[QMPMessa= ge]: assert self.__sockfile is not None while True: data =3D self.__sockfile.readline() @@ -148,7 +151,7 @@ def __json_read(self, only_event=3DFalse): continue return resp =20 - def __get_events(self, wait=3DFalse): + def __get_events(self, wait: Union[bool, float] =3D False) -> None: """ Check for new events in the stream and cache them in __events. =20 @@ -186,7 +189,7 @@ def __get_events(self, wait=3DFalse): raise QMPConnectError("Error while reading from socket") self.__sock.settimeout(None) =20 - def __enter__(self): + def __enter__(self) -> 'QEMUMonitorProtocol': # Implement context manager enter function. return self =20 @@ -199,7 +202,7 @@ def __exit__(self, # Implement context manager exit function. self.close() =20 - def connect(self, negotiate=3DTrue): + def connect(self, negotiate: bool =3D True) -> Optional[QMPMessage]: """ Connect to the QMP Monitor and perform capabilities negotiation. =20 @@ -214,7 +217,7 @@ def connect(self, negotiate=3DTrue): return self.__negotiate_capabilities() return None =20 - def accept(self, timeout=3D15.0): + def accept(self, timeout: float =3D 15.0) -> QMPMessage: """ Await connection from QMP Monitor and perform capabilities negotia= tion. =20 @@ -250,7 +253,9 @@ def cmd_obj(self, qmp_cmd: QMPMessage) -> QMPMessage: self.logger.debug("<<< %s", resp) return resp =20 - def cmd(self, name, args=3DNone, cmd_id=3DNone): + def cmd(self, name: str, + args: Optional[Dict[str, Any]] =3D None, + cmd_id: Optional[Any] =3D None) -> QMPMessage: """ Build a QMP command and send it to the QMP Monitor. =20 @@ -258,14 +263,14 @@ def cmd(self, name, args=3DNone, cmd_id=3DNone): @param args: command arguments (dict) @param cmd_id: command id (dict, list, string or int) """ - qmp_cmd =3D {'execute': name} + qmp_cmd: QMPMessage =3D {'execute': name} if args: qmp_cmd['arguments'] =3D args if cmd_id: qmp_cmd['id'] =3D cmd_id return self.cmd_obj(qmp_cmd) =20 - def command(self, cmd, **kwds): + def command(self, cmd: str, **kwds: Any) -> QMPReturnValue: """ Build and send a QMP command to the monitor, report errors if any """ @@ -278,7 +283,8 @@ def command(self, cmd, **kwds): ) return cast(QMPReturnValue, ret['return']) =20 - def pull_event(self, wait=3DFalse): + def pull_event(self, + wait: Union[bool, float] =3D False) -> Optional[QMPMess= age]: """ Pulls a single event. =20 @@ -298,7 +304,7 @@ def pull_event(self, wait=3DFalse): return self.__events.pop(0) return None =20 - def get_events(self, wait=3DFalse): + def get_events(self, wait: bool =3D False) -> List[QMPMessage]: """ Get a list of available QMP events. =20 @@ -315,13 +321,13 @@ def get_events(self, wait=3DFalse): self.__get_events(wait) return self.__events =20 - def clear_events(self): + def clear_events(self) -> None: """ Clear current list of pending events. """ self.__events =3D [] =20 - def close(self): + def close(self) -> None: """ Close the socket and socket file. """ @@ -330,7 +336,7 @@ def close(self): if self.__sockfile: self.__sockfile.close() =20 - def settimeout(self, timeout): + def settimeout(self, timeout: float) -> None: """ Set the socket timeout. =20 @@ -339,7 +345,7 @@ def settimeout(self, timeout): """ self.__sock.settimeout(timeout) =20 - def get_sock_fd(self): + def get_sock_fd(self) -> int: """ Get the socket file descriptor. =20 @@ -347,7 +353,7 @@ def get_sock_fd(self): """ return self.__sock.fileno() =20 - def is_scm_available(self): + def is_scm_available(self) -> bool: """ Check if the socket allows for SCM_RIGHTS. =20 diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py index 675310d8dfe..39a0cf62fe9 100644 --- a/python/qemu/qtest.py +++ b/python/qemu/qtest.py @@ -27,6 +27,7 @@ ) =20 from .machine import QEMUMachine +from .qmp import SocketAddrT =20 =20 class QEMUQtestProtocol: @@ -43,7 +44,8 @@ class QEMUQtestProtocol: No conection is estabalished by __init__(), this is done by the connect() or accept() methods. """ - def __init__(self, address, server=3DFalse): + def __init__(self, address: SocketAddrT, + server: bool =3D False): self._address =3D address self._sock =3D self._get_sock() self._sockfile: Optional[TextIO] =3D None @@ -51,14 +53,14 @@ def __init__(self, address, server=3DFalse): self._sock.bind(self._address) self._sock.listen(1) =20 - def _get_sock(self): + def _get_sock(self) -> socket.socket: if isinstance(self._address, tuple): family =3D socket.AF_INET else: family =3D socket.AF_UNIX return socket.socket(family, socket.SOCK_STREAM) =20 - def connect(self): + def connect(self) -> None: """ Connect to the qtest socket. =20 @@ -67,7 +69,7 @@ def connect(self): self._sock.connect(self._address) self._sockfile =3D self._sock.makefile(mode=3D'r') =20 - def accept(self): + def accept(self) -> None: """ Await connection from QEMU. =20 @@ -76,7 +78,7 @@ def accept(self): self._sock, _ =3D self._sock.accept() self._sockfile =3D self._sock.makefile(mode=3D'r') =20 - def cmd(self, qtest_cmd): + def cmd(self, qtest_cmd: str) -> str: """ Send a qtest command on the wire. =20 @@ -87,14 +89,16 @@ def cmd(self, qtest_cmd): resp =3D self._sockfile.readline() return resp =20 - def close(self): - """Close this socket.""" + def close(self) -> None: + """ + Close this socket. + """ self._sock.close() if self._sockfile: self._sockfile.close() self._sockfile =3D None =20 - def settimeout(self, timeout): + def settimeout(self, timeout: Optional[float]) -> None: """Set a timeout, in seconds.""" self._sock.settimeout(timeout) =20 @@ -118,7 +122,7 @@ def __init__(self, super().__init__(binary, args, name=3Dname, test_dir=3Dtest_dir, socket_scm_helper=3Dsocket_scm_helper, sock_dir=3Dsock_dir) - self._qtest =3D None + self._qtest: Optional[QEMUQtestProtocol] =3D None self._qtest_path =3D os.path.join(sock_dir, name + "-qtest.sock") =20 @property @@ -130,7 +134,7 @@ def _base_args(self) -> List[str]: ]) return args =20 - def _pre_launch(self): + def _pre_launch(self) -> None: super()._pre_launch() self._qtest =3D QEMUQtestProtocol(self._qtest_path, server=3DTrue) =20 @@ -139,7 +143,7 @@ def _post_launch(self) -> None: super()._post_launch() self._qtest.accept() =20 - def _post_shutdown(self): + def _post_shutdown(self) -> None: super()._post_shutdown() self._remove_if_exists(self._qtest_path) =20 --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029699; cv=none; d=zohomail.com; s=zohoarc; b=V4/0rnPEAsG2eM+iStItTP2g7Gd+kugyGs6ZZOqGlrGlEtiRwMen6jR/SbfFEOPr1BzYuNujqofhPxXLgCfYgaZbUcWlWnikoyS4pjUWNZmkkCp4nlfo/GC/FUOODSAC8IMIiCcQeWxOzONjqTQSnZvZKnZxM0JIE2snbSDbIZI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029699; 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=r0wJ+GPmqvcUVkaYcV6Fcgm91lvZ/ywO2xaD2Z21vyA=; b=mun9zEYHgrFROgH3N6tFpZSq3BcWF24FREeUECuYS2tXqdkaEy7iwiFJh9sMDKzozD6djiuCyy5g806hsFnD39VQQ42XmLPufGAtsq2IUKIx9ewRlUY4jGQd3yTsbrZOtrA28oZ7CrJpWPNe2kO3AdBPGOujun8yXKwz+mrvrUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 160202969992784.22395817452673; Tue, 6 Oct 2020 17:14:59 -0700 (PDT) Received: from localhost ([::1]:60060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx6g-000635-Nw for importer@patchew.org; Tue, 06 Oct 2020 20:14:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrK-00006K-1e for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrH-0002Ni-QH for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:05 -0400 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-432-o1rsv0-ROFyLSBu7S_G8rg-1; Tue, 06 Oct 2020 19:59:01 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB0B264144; Tue, 6 Oct 2020 23:58:59 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91E0A60BFA; Tue, 6 Oct 2020 23:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028742; 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=r0wJ+GPmqvcUVkaYcV6Fcgm91lvZ/ywO2xaD2Z21vyA=; b=i9fqW2lhOuLB11VfROjfVsnUb1nHFZLKDkxfoVwqkRB/FOBqe19u4TdA4hOknD4ZiEHfLo +YzmofwEsNNAfxM6+9UCfhoyQCLxETqaoHsoXQGjnFKJRmzJr14KbGfod0IvUz4qfrtvZr So1ybp+/8t9YuahQ8C7PHg/CP+XpurI= X-MC-Unique: o1rsv0-ROFyLSBu7S_G8rg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 12/20] python/qemu/console_socket.py: Correct type of recv() Date: Tue, 6 Oct 2020 19:58:09 -0400 Message-Id: <20201006235817.3280413-13-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The type and parameter names of recv() should match socket.socket(). OK, easy enough, but in the cases we don't pass straight through to the real socket implementation, we probably can't accept such flags. OK, for now, assert that we don't receive flags in such cases. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/console_socket.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index 69f604c77fe..cb3400a0385 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -92,13 +92,14 @@ def _drain_socket(self): for c in string: self._buffer.extend(c) =20 - def recv(self, bufsize=3D1): + def recv(self, bufsize: int =3D 1, flags: int =3D 0) -> bytes: """Return chars from in memory buffer. Maintains the same API as socket.socket.recv. """ if self._drain_thread is None: # Not buffering the socket, pass thru to socket. - return socket.socket.recv(self, bufsize) + return socket.socket.recv(self, bufsize, flags) + assert not flags, "Cannot pass flags to recv() in drained mode" start_time =3D time.time() while len(self._buffer) < bufsize: time.sleep(self._sleep_time) --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029891; cv=none; d=zohomail.com; s=zohoarc; b=QGbPqfXKs/4G3iIzR+Qa9JfArU3/fRkXdBTYImRsWogWUOVCouu2K/7BO+P6LUQf21GNUTUkmJj1Ytux2kMm5BqtVaxbqdN73UfRrWyaCcuP+zrSAbAtrPTNX9DZUUyrpxCj1lMhbHEHy3c/S9KDLvmbJb1cpRsZhK7VqvlB17I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029891; 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=BZ43iMFAKxgPY+wuGSTsbc0IkhP4uN7aBNnMX+enmSg=; b=iXsVIFUTFckzVVRAnWEl3F7jnBew8cVTvyt1N56iIcqiSPZECWiVHnxxN5erBPea+Nlk5T6A0eXcjSc/6DpOHjgPQOG5ULCg+l78deASPcN+OG3Wf6blX77KXSJUikjyXsMOpQb36k0cUkIZDbQOnbGoQL9XLnGnnNqoA01IacU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029891035360.31824681981993; Tue, 6 Oct 2020 17:18:11 -0700 (PDT) Received: from localhost ([::1]:37282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx9l-0008Mx-JJ for importer@patchew.org; Tue, 06 Oct 2020 20:18:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrN-00006t-08 for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56005) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrK-0002O1-7M for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:08 -0400 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-527-d5Rout71MdG4qMJzPHrjZQ-1; Tue, 06 Oct 2020 19:59:02 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAAA618C5206; Tue, 6 Oct 2020 23:59:00 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 399586115F; Tue, 6 Oct 2020 23:59:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028745; 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=BZ43iMFAKxgPY+wuGSTsbc0IkhP4uN7aBNnMX+enmSg=; b=Pn4xjoyJAx7Cc338hHVE564+DHUGOUJ9CmZjCVsNxB3Z/FEAGQEyFd3S4fihHZhU5F4wWK BzmQqkmDP1vEpmf++E2yrYokA+DYugn0vIWu4qVoSGyvmPoKdywCyb64BPNh6w7DpO1am7 3djCFFkwDaV6l7rqcvPv83kZrT/e+rk= X-MC-Unique: d5Rout71MdG4qMJzPHrjZQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 13/20] python/qemu/console_socket.py: fix typing of settimeout Date: Tue, 6 Oct 2020 19:58:10 -0400 Message-Id: <20201006235817.3280413-14-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The types and names of the parameters must match the socket.socket interfac= e. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/console_socket.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index cb3400a0385..39456825064 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -17,6 +17,7 @@ import socket import threading import time +from typing import Optional =20 =20 class ConsoleSocket(socket.socket): @@ -31,6 +32,7 @@ class ConsoleSocket(socket.socket): """ def __init__(self, address, file=3DNone, drain=3DFalse): self._recv_timeout_sec =3D 300 + self._recv_timeout_sec =3D 300.0 self._sleep_time =3D 0.5 self._buffer =3D deque() socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM) @@ -120,11 +122,11 @@ def setblocking(self, value): if self._drain_thread is None: socket.socket.setblocking(self, value) =20 - def settimeout(self, seconds): + def settimeout(self, value: Optional[float]) -> None: """When not draining we pass thru to the socket, since when draining we control the timeout. """ - if seconds is not None: - self._recv_timeout_sec =3D seconds + if value is not None: + self._recv_timeout_sec =3D value if self._drain_thread is None: - socket.socket.settimeout(self, seconds) + socket.socket.settimeout(self, value) --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029399; cv=none; d=zohomail.com; s=zohoarc; b=AIQeB0W6Olzy4eh/wAbPkpF3OE2KTl7br0nNZh8y96P1j3GHPqpKYL8hC929WxYrJwHQtjF7Gr8CuFPg0piAqQsED4JVLIV2hKBcpYArtWamOUqTYZWK++LUWVsuD4GWZBqHZtX+gtQWjrTc+bc1TEgmCPbtuQDpRCijyOMf+WM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029399; 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=I/SVgIYDVZxyfxzMfHshHtaT2i9zL5q4OFi2bVre86c=; b=J/kmZIzQC5T+l+XCWU9RAHI8yeAGtV1ECEXyCGbBok9j4H3qDOo4RBdU7mgrm0+CF+v/wz5uYfGQmdhqSTa7HVF+hmcz0eUeDdtozkzhdrohDA+V57QzoEvkrSKB9HtcOCQAJrHg1nAUpSfNHi7/67znXG6dTGxTDXE36b75uBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 16020293997862.51448377336078; Tue, 6 Oct 2020 17:09:59 -0700 (PDT) Received: from localhost ([::1]:48950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx1q-0001Et-HK for importer@patchew.org; Tue, 06 Oct 2020 20:09:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrP-00007S-Iv for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrM-0002OG-EE for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:11 -0400 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-209-4kMwYobwN8Crt8rGGH7poA-1; Tue, 06 Oct 2020 19:59:06 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03B6F64156; Tue, 6 Oct 2020 23:59:05 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C26C6115F; Tue, 6 Oct 2020 23:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028747; 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=I/SVgIYDVZxyfxzMfHshHtaT2i9zL5q4OFi2bVre86c=; b=iL7J14rFzQ0NgzquCrU30YWqTe/O+uw8hSIhhRak5afGN8YfDsY72cmiBZ0SKZIAfFJKtC 2Xg50o0DuOxAwtJPX0w/rAX/7sk2nBNP+a3UQRBwcsesX78/M0DUFOE/gDk1/nuGnk72Uh M0okb8MyeQCyD/4d2QUY5vY6NS6MQKU= X-MC-Unique: 4kMwYobwN8Crt8rGGH7poA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 14/20] python/qemu/console_socket.py: Clarify type of drain_thread Date: Tue, 6 Oct 2020 19:58:11 -0400 Message-Id: <20201006235817.3280413-15-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Mypy needs just a little help to guess the type here. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/console_socket.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index 39456825064..d4669c441d0 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -41,10 +41,9 @@ def __init__(self, address, file=3DNone, drain=3DFalse): if file: self._logfile =3D open(file, "w") self._open =3D True + self._drain_thread =3D None if drain: self._drain_thread =3D self._thread_start() - else: - self._drain_thread =3D None =20 def _drain_fn(self): """Drains the socket and runs while the socket is open.""" --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602030099; cv=none; d=zohomail.com; s=zohoarc; b=dNNT1peRmVM1aP6fz/5In2PMdTNNVURRUj09jJsDLN7dn/+fyIZ16NR+rtPv162lWTIyjbjxP/E1mt8VctfIpNt6Q2+MDr0C+am8J0J5DxdmBrBJYZbO1CFKzfSz+tPqYC4hYfSfIqn3PvCKPti212YXZhOcIIIJs90HDzfo+J0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602030099; 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=cdt/gQSbEXPPZSDuvxQh3WndeeNgVlHo7TYDs2B3umE=; b=DEPwrn9I21HD/Ex6Mu4Z+LXp/v7EHvXhM6q5pFv8H1GC8SFwXxtAFbORHjABUl0RQO6jyS5VilU7u1iWRAj7zLI+XjAPEFjcmjwezmyr0VWia5FV/MmIY5lBTLIrveG9yHalgCNvM0EBHudDGxXdWooY2k2enQJzZdVfZ8P+Jxc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602030099272742.763287819068; Tue, 6 Oct 2020 17:21:39 -0700 (PDT) Received: from localhost ([::1]:45292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPxD7-0003Ij-Nf for importer@patchew.org; Tue, 06 Oct 2020 20:21:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrS-00008z-EK for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrP-0002Om-MO for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:14 -0400 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-101-BTT9eBsDOGuaHIRs81hOpA-1; Tue, 06 Oct 2020 19:59:07 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7662064145; Tue, 6 Oct 2020 23:59:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25DE360BFA; Tue, 6 Oct 2020 23:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028751; 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=cdt/gQSbEXPPZSDuvxQh3WndeeNgVlHo7TYDs2B3umE=; b=gnJn+LVEOjqdNa6Oq03JEswwdsrmeYsugLDkb+U5dM3AVk3GCxmgO+JaJ/5OcEjUovsiGJ Pwf+y0NrTlNAyouNT58yA4ij2FakX23k9JSHcL59ZSdN2e94DSzYXd81OF1T0EhEdbqBtY Vq9WVGFvSUbompIazMk0GdUMxFCVRqY= X-MC-Unique: BTT9eBsDOGuaHIRs81hOpA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 15/20] python/qemu/console_socket.py: Add type hint annotations Date: Tue, 6 Oct 2020 19:58:12 -0400 Message-Id: <20201006235817.3280413-16-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Finish the typing of console_socket.py with annotations and no code changes. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/console_socket.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index d4669c441d0..57e6eee0176 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -17,7 +17,7 @@ import socket import threading import time -from typing import Optional +from typing import Deque, Optional =20 =20 class ConsoleSocket(socket.socket): @@ -30,11 +30,11 @@ class ConsoleSocket(socket.socket): Optionally a file path can be passed in and we will also dump the characters to this file for debugging purposes. """ - def __init__(self, address, file=3DNone, drain=3DFalse): - self._recv_timeout_sec =3D 300 + def __init__(self, address: str, file: Optional[str] =3D None, + drain: bool =3D False): self._recv_timeout_sec =3D 300.0 self._sleep_time =3D 0.5 - self._buffer =3D deque() + self._buffer: Deque[str] =3D deque() socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM) self.connect(address) self._logfile =3D None @@ -45,7 +45,7 @@ def __init__(self, address, file=3DNone, drain=3DFalse): if drain: self._drain_thread =3D self._thread_start() =20 - def _drain_fn(self): + def _drain_fn(self) -> None: """Drains the socket and runs while the socket is open.""" while self._open: try: @@ -56,7 +56,7 @@ def _drain_fn(self): # self._open is set to False. time.sleep(self._sleep_time) =20 - def _thread_start(self): + def _thread_start(self) -> threading.Thread: """Kick off a thread to drain the socket.""" # Configure socket to not block and timeout. # This allows our drain thread to not block @@ -68,7 +68,7 @@ def _thread_start(self): drain_thread.start() return drain_thread =20 - def close(self): + def close(self) -> None: """Close the base object and wait for the thread to terminate""" if self._open: self._open =3D False @@ -80,7 +80,7 @@ def close(self): self._logfile.close() self._logfile =3D None =20 - def _drain_socket(self): + def _drain_socket(self) -> None: """process arriving characters into in memory _buffer""" data =3D socket.socket.recv(self, 1) # latin1 is needed since there are some chars @@ -114,7 +114,7 @@ def recv(self, bufsize: int =3D 1, flags: int =3D 0) ->= bytes: # socket w/o our intervention. return chars.encode("latin1") =20 - def setblocking(self, value): + def setblocking(self, value: bool) -> None: """When not draining we pass thru to the socket, since when draining we control socket blocking. """ --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029628; cv=none; d=zohomail.com; s=zohoarc; b=K3ZQv8Q6ofO4XMudwvmWKMiGJbqVxsTv2c9yjCONA6CV89staa9xctPAD3TruVaa7pNVDiiyWuvdrZBHa9Bzr05xClXcg057wBKzn1qMbmwqAwGTY4/QAhnOVTtCLdhl+aZ5Rovlmy19b6iJrK9f4HdByj94prafa4/00ZNlWeU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029628; 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=bi8KTrLebYMpML/77oR/Ex/2wVBs+0QzkhpIjMNk71Y=; b=F4zF0qsItH83B4qkCXIbOjg5OA1bcc9XL4RCLcRzK8jEAjX9TJ5zTljpFU4e1CPPb4Zhp3lqEJBfpmrlwwmRbShI/VP3mpB66pb5hDdOE/Td0zyxGxj+MO18JJEDic7dQ4x5xO9yu8jqH8uUMOzfGqwCEGtwZoiLA11Y3Jupg9M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029628256447.3749881561421; Tue, 6 Oct 2020 17:13:48 -0700 (PDT) Received: from localhost ([::1]:56772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx5X-0004fU-0o for importer@patchew.org; Tue, 06 Oct 2020 20:13:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrT-0000AZ-1U for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26688) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrP-0002Oa-0T for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:14 -0400 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-435-AYpSl5aLNwmVyVnM7StgUg-1; Tue, 06 Oct 2020 19:59:08 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1CFE8064BD; Tue, 6 Oct 2020 23:59:07 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6EF460BFA; Tue, 6 Oct 2020 23:59:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028750; 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=bi8KTrLebYMpML/77oR/Ex/2wVBs+0QzkhpIjMNk71Y=; b=QAmWXHprdqs72GAvdwWL4JdzT7V/9LFPv+PpCClk2D6VfPcUWzsyalqFydBcqMZOFNbAu7 AC9bdeQYecZQgYLzCMH5g6Df/mGiIR8r8tbcOvo5yPAw/L+IdL26rKBRB2Syttlm3Vfcuw Ne4XymvFWC9dWDEEfeoY34Xv8pZU/lg= X-MC-Unique: AYpSl5aLNwmVyVnM7StgUg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 16/20] python/console_socket: avoid encoding to/from string Date: Tue, 6 Oct 2020 19:58:13 -0400 Message-Id: <20201006235817.3280413-17-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We can work directly in bytes instead of translating back and forth to string, which removes the question of which encodings to use. Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/console_socket.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/python/qemu/console_socket.py b/python/qemu/console_socket.py index 57e6eee0176..f060d79e06d 100644 --- a/python/qemu/console_socket.py +++ b/python/qemu/console_socket.py @@ -34,12 +34,12 @@ def __init__(self, address: str, file: Optional[str] = =3D None, drain: bool =3D False): self._recv_timeout_sec =3D 300.0 self._sleep_time =3D 0.5 - self._buffer: Deque[str] =3D deque() + self._buffer: Deque[int] =3D deque() socket.socket.__init__(self, socket.AF_UNIX, socket.SOCK_STREAM) self.connect(address) self._logfile =3D None if file: - self._logfile =3D open(file, "w") + self._logfile =3D open(file, "bw") self._open =3D True self._drain_thread =3D None if drain: @@ -83,15 +83,10 @@ def close(self) -> None: def _drain_socket(self) -> None: """process arriving characters into in memory _buffer""" data =3D socket.socket.recv(self, 1) - # latin1 is needed since there are some chars - # we are receiving that cannot be encoded to utf-8 - # such as 0xe2, 0x80, 0xA6. - string =3D data.decode("latin1") if self._logfile: - self._logfile.write("{}".format(string)) + self._logfile.write(data) self._logfile.flush() - for c in string: - self._buffer.extend(c) + self._buffer.extend(data) =20 def recv(self, bufsize: int =3D 1, flags: int =3D 0) -> bytes: """Return chars from in memory buffer. @@ -107,12 +102,7 @@ def recv(self, bufsize: int =3D 1, flags: int =3D 0) -= > bytes: elapsed_sec =3D time.time() - start_time if elapsed_sec > self._recv_timeout_sec: raise socket.timeout - chars =3D ''.join([self._buffer.popleft() for i in range(bufsize)]) - # We choose to use latin1 to remain consistent with - # handle_read() and give back the same data as the user would - # receive if they were reading directly from the - # socket w/o our intervention. - return chars.encode("latin1") + return bytes((self._buffer.popleft() for i in range(bufsize))) =20 def setblocking(self, value: bool) -> None: """When not draining we pass thru to the socket, --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029979; cv=none; d=zohomail.com; s=zohoarc; b=LksSfV2uXyWgLbEs7ubX9S8bFieELh+lOPer40OhnAo48EguEbgqJewCCx6v0tm8VAZ9+UTkyJPZOpnbmFDsGtWtfUNOzy1b/8l8Z6kSP/04JUuJpDwLNG+c/mttybOQA53ZldEAU065ww7DNt9j1xml3kO+k26tPliW7QMgnWE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029979; 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=5wXzabkXZlXAv4NbEkdTh8mJjGPhjdHauSjMHiWu9HY=; b=fQz89eb06pgFxCXpK1MY4QyGqV7QV4/Fg4OAu+dR76P0j2CfW9iYFt6XjjmYxdjBEVdeGe4nAXXsc1N/CdBVit6m6AlSNFpC1ieCgOTENa9kk2oRiZJ3BBWuDe2Kzidu4gz8mWxq4P9AzzOVuQ7RkW71xoF15ihivxM3SALCJkA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029979380370.0078182993424; Tue, 6 Oct 2020 17:19:39 -0700 (PDT) Received: from localhost ([::1]:40208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPxBC-00018K-0c for importer@patchew.org; Tue, 06 Oct 2020 20:19:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrU-0000DP-Ce for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57265) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrP-0002Oq-RN for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:15 -0400 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-414-M0qQsXwHPnqNNBisroUocg-1; Tue, 06 Oct 2020 19:59:09 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A46810866AD; Tue, 6 Oct 2020 23:59:08 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id C50C460BFA; Tue, 6 Oct 2020 23:59:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028751; 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=5wXzabkXZlXAv4NbEkdTh8mJjGPhjdHauSjMHiWu9HY=; b=B5lFqhRR2UkQY14vkdMGU2l3zT4IQXqQXysX0QomaSJ9lMXU8ywcncB+OGFBIVqADOp9ZL DOWt1k77kMAzL2GnlMV6RCwmjdsGY0CjUbqw3kpbLMkle/Gptt5jaCM344nbsM4u5heKEj yxLtQvQ4nJY1oQXpY6RGk3T0QtDBXJE= X-MC-Unique: M0qQsXwHPnqNNBisroUocg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 17/20] python/qemu/qmp.py: Preserve error context on re-raise Date: Tue, 6 Oct 2020 19:58:14 -0400 Message-Id: <20201006235817.3280413-18-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use the "from ..." phrasing when re-raising errors to preserve their initial context, to help aid debugging when things go wrong. This also silences a pylint 2.6.0+ error. Signed-off-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/qmp.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index 9223307ed81..d911999da1f 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -181,10 +181,11 @@ def __get_events(self, wait: Union[bool, float] =3D F= alse) -> None: self.__sock.settimeout(wait) try: ret =3D self.__json_read(only_event=3DTrue) - except socket.timeout: - raise QMPTimeoutError("Timeout waiting for event") - except: - raise QMPConnectError("Error while reading from socket") + except socket.timeout as err: + raise QMPTimeoutError("Timeout waiting for event") from err + except Exception as err: + msg =3D "Error while reading from socket" + raise QMPConnectError(msg) from err if ret is None: raise QMPConnectError("Error while reading from socket") self.__sock.settimeout(None) --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602030168; cv=none; d=zohomail.com; s=zohoarc; b=JgTDMQ+bKC+jJf24I88O8yYVi9tSEGfSquGvyTZHxYZtGVlBOJAscgXIzjroxTyW/S/0lPIuZOT2YXzsre9ZqkbszWx3+i2YgC1u6hXh1pMqdq3+4vVZmTtwk3xem0t6hKJV4qTjeHqDW098vYMImTim4LWCt9ZV6SG1a1qUc2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602030168; 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=kFgYvql5sJB1bYpkJkbqDkyXzJ0+XhJ85dMfvV7KaaE=; b=fNnx+mFPKfd4HA00ZYOBVT6Q1s7/gI7cAHh5m7/Zr2wStbP6dALSPpQPahidxxuu2Gt5LjOZrsQAmJZYnGvm2YeyfKtlVs2vZ2OJ0uuzlnOomOyJy3mI+LNe6H52KpevIAt+DxdTGyIAWIK1qbglb3qWxaxGq4ugfKnO3v6Stbw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602030168148513.1907282867949; Tue, 6 Oct 2020 17:22:48 -0700 (PDT) Received: from localhost ([::1]:49058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPxEE-0004rn-SW for importer@patchew.org; Tue, 06 Oct 2020 20:22:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrV-0000Fe-8u for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59980) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrR-0002PC-Tp for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:16 -0400 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-494-IuNynBxrNSGaY8LpEgmCuA-1; Tue, 06 Oct 2020 19:59:10 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7311F64144; Tue, 6 Oct 2020 23:59:09 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD1E160BFA; Tue, 6 Oct 2020 23:59:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028753; 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=kFgYvql5sJB1bYpkJkbqDkyXzJ0+XhJ85dMfvV7KaaE=; b=LqCB5LjA6NQOkv8YGCNSc/KbU1p2BTKOfjupFqVNAWPPzppkiuZYRXW7tjVSHoSpHFE7kT ZSirjfdWkK9S9QzhxzD/nMIyAcYoJo/zZrAF3YyP4AoduisKilUnOW+vP+SFONI/Ertk7l cRa/opzSO09UGy/sN4B3KYOHmHPnKQU= X-MC-Unique: IuNynBxrNSGaY8LpEgmCuA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 18/20] python/qemu/qmp.py: re-raise OSError when encountered Date: Tue, 6 Oct 2020 19:58:15 -0400 Message-Id: <20201006235817.3280413-19-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Nested if conditions don't change when the exception block fires; we need to explicitly re-raise the error if we didn't intend to capture and suppress it. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/qmp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index d911999da1f..bdbd1e9bdbb 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -169,9 +169,9 @@ def __get_events(self, wait: Union[bool, float] =3D Fal= se) -> None: try: self.__json_read() except OSError as err: - if err.errno =3D=3D errno.EAGAIN: - # No data available - pass + # EAGAIN: No data available; not critical + if err.errno !=3D errno.EAGAIN: + raise self.__sock.setblocking(True) =20 # Wait for new events, if needed. --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029650; cv=none; d=zohomail.com; s=zohoarc; b=evuM7g/3AnCwaXx/qsdbfcuEC9plIn4OI1D3z3w/SSiVDOENVGnPgEPSNutEwSUoVx4QUFAIRAaEjob/CwXWwhq2YDsjsiW7377FKMYBNRiW96fUi2F+vUuNmpP3QWwdycq+CsZKjGfnMvrzrUXANbgdzDOcJ+PYMA62G5b4+iM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029650; 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=F4ZYfw0wyKC8llwQk6ARzElo7AwPPnxB7wz0BCPwLXc=; b=Piu3rLKKm3tPzqefVkjHUSdtwIw++cjmCuEklMo7V4zWi1hIOuA2fo+nabUhtroV4XPYx7WPG1YERWrt1mwHD8whZMLEpgJ7DchnoBt1CJgBCES31huv143vurrGGGXDiH8ePR3YWimQ99tOiPsZCv11cLMuFbj644Cwv+gnW5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029650152386.74320981630945; Tue, 6 Oct 2020 17:14:10 -0700 (PDT) Received: from localhost ([::1]:57122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx5s-0004oB-Ox for importer@patchew.org; Tue, 06 Oct 2020 20:14:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrW-0000IF-2u for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrT-0002PV-Hk for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:17 -0400 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-343-M_FEkTBzO_SqNJ3nrawBlw-1; Tue, 06 Oct 2020 19:59:12 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B3C210866A8; Tue, 6 Oct 2020 23:59:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9189E60BFA; Tue, 6 Oct 2020 23:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028754; 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=F4ZYfw0wyKC8llwQk6ARzElo7AwPPnxB7wz0BCPwLXc=; b=Q08b7KQ3E4TeGsz5o3WHRR+KZpjM6GMLNYULAGq7+6sOEP/xyyxO9lZ8BwAujUFeMeh330 sTLWlKGWhzsqEQAUVhQpWmuja/2g0Me8/Msz6bkd2xYf4V+JcjzMdvlrV39zNHciEbp07E vVfEXdVB4zhtLhj9loQcZATsayNNzec= X-MC-Unique: M_FEkTBzO_SqNJ3nrawBlw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 19/20] python/qemu/qmp.py: Straighten out exception hierarchy Date: Tue, 6 Oct 2020 19:58:16 -0400 Message-Id: <20201006235817.3280413-20-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 00:55:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Be a little more rigorous about which exception we use, and when. Primarily, this makes QMPCapabilitiesError an extension of QMPprotocolError. The family of errors: QMPError (generic base) QMPConnectError (For connection issues) QMPTimeoutError (when waiting for an event expires) QMPProtocolError (unexpected/garbled responses) QMPCapabilitiesError (handshake problems) QMPResponseError (For in-band QMP error returns) Signed-off-by: John Snow Reviewed-by: Kevin Wolf --- python/qemu/qmp.py | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/python/qemu/qmp.py b/python/qemu/qmp.py index bdbd1e9bdbb..1349632c101 100644 --- a/python/qemu/qmp.py +++ b/python/qemu/qmp.py @@ -41,7 +41,7 @@ =20 class QMPError(Exception): """ - QMP base exception + QMP base exception; all QMP errors derive from this. """ =20 =20 @@ -51,7 +51,13 @@ class QMPConnectError(QMPError): """ =20 =20 -class QMPCapabilitiesError(QMPError): +class QMPProtocolError(QMPError): + """ + QMP protocol error; unexpected response + """ + + +class QMPCapabilitiesError(QMPProtocolError): """ QMP negotiate capabilities exception """ @@ -63,15 +69,9 @@ class QMPTimeoutError(QMPError): """ =20 =20 -class QMPProtocolError(QMPError): - """ - QMP protocol error; unexpected response - """ - - class QMPResponseError(QMPError): """ - Represents erroneous QMP monitor reply + Represents in-band QMP replies indicating command failure """ def __init__(self, reply: QMPMessage): try: @@ -125,14 +125,23 @@ def __get_sock(self) -> socket.socket: return socket.socket(family, socket.SOCK_STREAM) =20 def __negotiate_capabilities(self) -> QMPMessage: + """ + @raise QMPConnectError on failure to receive the greeting. + @raise QMPCapabilitiesError on malformed greeting, or malformed + capabilities handshake response. + """ greeting =3D self.__json_read() - if greeting is None or "QMP" not in greeting: - raise QMPConnectError + if greeting is None: + raise QMPConnectError("Did not receive QMP greeting") + if 'QMP' not in greeting: + msg =3D f"Did not understand greeting: '{str(greeting)}'" + raise QMPCapabilitiesError(msg) # Greeting seems ok, negotiate capabilities resp =3D self.cmd('qmp_capabilities') if resp and "return" in resp: return greeting - raise QMPCapabilitiesError + msg =3D "Did not understand capabilities reply" + raise QMPCapabilitiesError(f"{msg}: {str(resp)}") =20 def __json_read(self, only_event: bool =3D False) -> Optional[QMPMessa= ge]: assert self.__sockfile is not None @@ -158,10 +167,12 @@ def __get_events(self, wait: Union[bool, float] =3D F= alse) -> None: @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 OSError: For backing socket connection errors @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 retrieved or if some other error occurred. + @raise QMPProtocolError: If a garbled message is received. """ =20 # Check for new events regardless and pull them into the cache: @@ -187,7 +198,7 @@ def __get_events(self, wait: Union[bool, float] =3D Fal= se) -> None: msg =3D "Error while reading from socket" raise QMPConnectError(msg) from err if ret is None: - raise QMPConnectError("Error while reading from socket") + raise QMPProtocolError("Unexpected empty message from serv= er") self.__sock.settimeout(None) =20 def __enter__(self) -> 'QEMUMonitorProtocol': @@ -245,12 +256,13 @@ def cmd_obj(self, qmp_cmd: QMPMessage) -> QMPMessage: =20 @param qmp_cmd: QMP command to be sent as a Python dict @return QMP response as a Python dict + @raise QMPProtocolError on unexpected empty messages. """ self.logger.debug(">>> %s", qmp_cmd) self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) resp =3D self.__json_read() if resp is None: - raise QMPConnectError("Unexpected empty reply from server") + raise QMPProtocolError("Unexpected empty reply from server") self.logger.debug("<<< %s", resp) return resp =20 @@ -274,13 +286,16 @@ def cmd(self, name: str, def command(self, cmd: str, **kwds: Any) -> QMPReturnValue: """ Build and send a QMP command to the monitor, report errors if any + + @raise QMPResponseError if the server returns an in-band error rep= ly. + @raise QMPProtocolError if the server reply is not understood. """ ret =3D self.cmd(cmd, kwds) if 'error' in ret: raise QMPResponseError(ret) if 'return' not in ret: raise QMPProtocolError( - "'return' key not found in QMP response '{}'".format(str(r= et)) + f"'return' key not found in QMP response '{str(ret)}'" ) return cast(QMPReturnValue, ret['return']) =20 --=20 2.26.2 From nobody Sat May 18 05:34:48 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602029893; cv=none; d=zohomail.com; s=zohoarc; b=JooC1Cb4HH9Q+XTc3lVl7mJLA/U0GzFU2S/gSespa2uryQ2ms9Dll8Xh102j8InMF5A9cxAtBwBacPYs+6r+90OdETVS0ReWSosjvU/kJnnxzhSCCkoIRRN3dapJenNCHfWlNuxDhk0R79LWbA2tINR6/93UP8FMdfU69ka1WSg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602029893; 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=tqTl4RtkP8A4aUSPCN1QLijelH/mJNfhb8wyLHrBLX4=; b=COkXK+fxyEz0HBAmLxkyMnFtzL2MHfHaDSyFAXJJfjvacTbSyjvC+8XJUJ/LEPoJ74+9oLy+6/1Ih7RJ0lNbC3OSkMzx3NnF/+tvyKJrQe/F08HmoVwdEQD9vlJ+ZOmguJRsjukxZWj2uV7IWcDJ7ZSyRbY0xhUsNjsWQZnCTec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail 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 1602029893917150.21964672977083; Tue, 6 Oct 2020 17:18:13 -0700 (PDT) Received: from localhost ([::1]:37608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPx9o-0008VA-GI for importer@patchew.org; Tue, 06 Oct 2020 20:18:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPwrd-0000YT-BY for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kPwrb-0002Rk-Pu for qemu-devel@nongnu.org; Tue, 06 Oct 2020 19:59:25 -0400 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-104-OylufoIMMo6n5Q6HaQFkGg-1; Tue, 06 Oct 2020 19:59:21 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51667101FFA7; Tue, 6 Oct 2020 23:59:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-120-38.rdu2.redhat.com [10.10.120.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFE0E60BFA; Tue, 6 Oct 2020 23:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602028763; 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=tqTl4RtkP8A4aUSPCN1QLijelH/mJNfhb8wyLHrBLX4=; b=DrwHH8Li7kQPbcYUhT9LGkH91GJolRpTtk6FE0qXKhG0Ga2pBTbI1nj2HVchFe32jWRNVr +k66tN5B9mAY3yG0YbqDDFa5nj5ZfNEPkw8quDCrYb4lxN3Iq1lt/govAATich1G5YN+2Q vFgn8Rm9Bmmrc+DaSlDWHosdBETCspE= X-MC-Unique: OylufoIMMo6n5Q6HaQFkGg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH 20/20] python: add mypy config Date: Tue, 6 Oct 2020 19:58:17 -0400 Message-Id: <20201006235817.3280413-21-jsnow@redhat.com> In-Reply-To: <20201006235817.3280413-1-jsnow@redhat.com> References: <20201006235817.3280413-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/06 01:55:55 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.733, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Eduardo Habkost , qemu-block@nongnu.org, Max Reitz , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Formalize the options used for checking the python library. You can run mypy from the directory that mypy.ini is in by typing `mypy qemu/`. Signed-off-by: John Snow --- python/mypy.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 python/mypy.ini diff --git a/python/mypy.ini b/python/mypy.ini new file mode 100644 index 00000000000..7a70eca47c6 --- /dev/null +++ b/python/mypy.ini @@ -0,0 +1,4 @@ +[mypy] +strict =3D True +python_version =3D 3.6 +warn_unused_configs =3D True \ No newline at end of file --=20 2.26.2