From nobody Fri Nov 14 16:37:27 2025 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=1589435725; cv=none; d=zohomail.com; s=zohoarc; b=XaNvxBreZ6Kw2hWpkDOU1HQwofew6hTjVifa2DRFytb0gqdamW/vmGzp8yK4uuFe0CMLiP5hKs+mLv1KvEfQlnaqTqX80RwYdN8b6YDju9vnPJIAC9iD5Sfosg7CsIHu9HZ81yhCgJTYIabW6pxU03QZBPHs5cgeNdiz4IOQjSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435725; 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=42GgRBxZblLaf2qM0qkYFg+G0IvXQZU790nzwM9ThSg=; b=mIOwpIhC3ciRA52YQG00jwdSDQOyRJILVal3BLVFr7KNe3jU6dISB/sEYL4aqrH38RyBk8bfWzg706oR+KHPOhn66lQ71xNzcBsWGxk2vQxeCxkU9Gt2lzhPF3AXIgwCovZW//tMN62xp3cXYG4W4E4qUgtJ/JxYxuVyMIKUFAU= 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 1589435725261307.75870340254653; Wed, 13 May 2020 22:55:25 -0700 (PDT) Received: from localhost ([::1]:54668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6q3-000622-PL for importer@patchew.org; Thu, 14 May 2020 01:55:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ou-0004FY-FP for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:44480 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ot-0001ZH-4U for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:12 -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-152-0JRiK0G9Mx2XCGUmaPB6pg-1; Thu, 14 May 2020 01:54:08 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 723B5107ACCA; Thu, 14 May 2020 05:54:07 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 028817D952; Thu, 14 May 2020 05:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435650; 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=42GgRBxZblLaf2qM0qkYFg+G0IvXQZU790nzwM9ThSg=; b=IUVisbNf+fKN7mcXdtmLp8E+LZKljI/qgi4bEcDPWwcDjDt2fczVBlp0AZee0Ln4HJzAWA dpuweiwzKXXhq/cY76xBx0BkkSbe/eFsKzAU+3Ls0/Q/Ivza7p2SQGajKkyRrTeBKJx0ip K0q+z698rJsC5eWHIPTt6rEk7BDg5fk= X-MC-Unique: 0JRiK0G9Mx2XCGUmaPB6pg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 01/32] python/qemu: create qemu.lib module Date: Thu, 14 May 2020 01:53:32 -0400 Message-Id: <20200514055403.18902-2-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" move python/qemu/*.py to python/qemu/lib/*.py. To create a namespace package, the 'qemu' directory itself shouldn't have module files in it. Thus, these files will go under a 'lib' package directory instead. Bolster the lib/__init__.py file a little bit, Make the top-level classes and functions available directly inside the `qemu.lib` namespace, to facilitate a convenient shorthand: > from qemu.lib import QEMUQtestMachine, QEMUMonitorProtocol Lastly, update all of the existing import directives. (Note: these scripts were not necessarily tested to see if they still work. Some of these scripts are in obvious states of disrepair and it is beyond the scope of this patch to attempt to fix them.) Signed-off-by: John Snow --- python/qemu/__init__.py | 11 ----- python/qemu/lib/__init__.py | 57 +++++++++++++++++++++++ python/qemu/{ =3D> lib}/accel.py | 0 python/qemu/{ =3D> lib}/machine.py | 0 python/qemu/{ =3D> lib}/qmp.py | 0 python/qemu/{ =3D> lib}/qtest.py | 0 scripts/device-crash-test | 2 +- scripts/qmp/qemu-ga-client | 2 +- scripts/qmp/qmp-shell | 2 +- scripts/render_block_graph.py | 3 +- scripts/simplebench/bench_block_job.py | 4 +- tests/acceptance/avocado_qemu/__init__.py | 2 +- tests/acceptance/boot_linux.py | 3 +- tests/acceptance/virtio_check_params.py | 2 +- tests/acceptance/virtio_version.py | 2 +- tests/migration/guestperf/engine.py | 2 +- tests/qemu-iotests/235 | 2 +- tests/qemu-iotests/iotests.py | 2 +- tests/vm/basevm.py | 6 +-- 19 files changed, 74 insertions(+), 28 deletions(-) delete mode 100644 python/qemu/__init__.py create mode 100644 python/qemu/lib/__init__.py rename python/qemu/{ =3D> lib}/accel.py (100%) rename python/qemu/{ =3D> lib}/machine.py (100%) rename python/qemu/{ =3D> lib}/qmp.py (100%) rename python/qemu/{ =3D> lib}/qtest.py (100%) diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py deleted file mode 100644 index 4ca06c34a4..0000000000 --- a/python/qemu/__init__.py +++ /dev/null @@ -1,11 +0,0 @@ -# QEMU library -# -# Copyright (C) 2015-2016 Red Hat Inc. -# Copyright (C) 2012 IBM Corp. -# -# Authors: -# Fam Zheng -# -# This work is licensed under the terms of the GNU GPL, version 2. See -# the COPYING file in the top-level directory. -# diff --git a/python/qemu/lib/__init__.py b/python/qemu/lib/__init__.py new file mode 100644 index 0000000000..afc587bfdc --- /dev/null +++ b/python/qemu/lib/__init__.py @@ -0,0 +1,57 @@ +""" +QEMU development and testing library. + +This library provides a few high-level classes for driving QEMU from a +test suite, not intended for production use. + +- QEMUMachine: Configure and Boot a QEMU VM + - QEMUQtestMachine: VM class, with a qtest socket. + +- QEMUMonitorProtocol: Connect to, send/receive QMP messages. +- QEMUQtestProtocol: Connect to, send/receive qtest message. + +- list_accel: List available accelerators +- kvm_available: Probe for KVM support +- tcg_available: Probe for TCG support +""" + +# Copyright (C) 2020 John Snow for Red Hat Inc. +# Copyright (C) 2015-2016 Red Hat Inc. +# Copyright (C) 2012 IBM Corp. +# +# Authors: +# John Snow +# Fam Zheng +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +from .accel import ( + list_accel, + kvm_available, + tcg_available, +) + +from .qmp import ( + QEMUMonitorProtocol, +) + +from .machine import ( + QEMUMachine, +) + +from .qtest import ( + QEMUQtestProtocol, + QEMUQtestMachine, +) + +__all__ =3D ( + 'list_accel', + 'kvm_available', + 'tcg_available', + 'QEMUMonitorProtocol', + 'QEMUMachine', + 'QEMUQtestProtocol', + 'QEMUQtestMachine', +) diff --git a/python/qemu/accel.py b/python/qemu/lib/accel.py similarity index 100% rename from python/qemu/accel.py rename to python/qemu/lib/accel.py diff --git a/python/qemu/machine.py b/python/qemu/lib/machine.py similarity index 100% rename from python/qemu/machine.py rename to python/qemu/lib/machine.py diff --git a/python/qemu/qmp.py b/python/qemu/lib/qmp.py similarity index 100% rename from python/qemu/qmp.py rename to python/qemu/lib/qmp.py diff --git a/python/qemu/qtest.py b/python/qemu/lib/qtest.py similarity index 100% rename from python/qemu/qtest.py rename to python/qemu/lib/qtest.py diff --git a/scripts/device-crash-test b/scripts/device-crash-test index 305d0427af..49efd4abd7 100755 --- a/scripts/device-crash-test +++ b/scripts/device-crash-test @@ -35,7 +35,7 @@ import argparse from itertools import chain =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python')) -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine =20 logger =3D logging.getLogger('device-crash-test') dbg =3D logger.debug diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index ce122984a9..db27cfcd55 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -42,7 +42,7 @@ import base64 import random =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu import qmp +from qemu.lib import qmp =20 =20 class QemuGuestAgent(qmp.QEMUMonitorProtocol): diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index a01d31de1e..2441f4ae01 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -75,7 +75,7 @@ import atexit import re =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu import qmp +from qemu.lib import qmp =20 if sys.version_info[0] =3D=3D 2: input =3D raw_input diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py index 409b4321f2..8048d9fbbe 100755 --- a/scripts/render_block_graph.py +++ b/scripts/render_block_graph.py @@ -25,7 +25,8 @@ from graphviz import Digraph =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python')) -from qemu.machine import MonitorResponseError +from qemu.lib import QEMUMonitorProtocol +from qemu.lib.machine import MonitorResponseError =20 =20 def perm(arr): diff --git a/scripts/simplebench/bench_block_job.py b/scripts/simplebench/b= ench_block_job.py index 9808d696cf..dbac12ddec 100755 --- a/scripts/simplebench/bench_block_job.py +++ b/scripts/simplebench/bench_block_job.py @@ -25,8 +25,8 @@ import json =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu.machine import QEMUMachine -from qemu.qmp import QMPConnectError +from qemu.lib import QEMUMachine +from qemu.lib.qmp import QMPConnectError =20 =20 def bench_block_job(cmd, cmd_args, qemu_args): diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index 59e7b4f763..bc433d4f40 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -32,7 +32,7 @@ =20 sys.path.append(os.path.join(SOURCE_DIR, 'python')) =20 -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine =20 def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK) diff --git a/tests/acceptance/boot_linux.py b/tests/acceptance/boot_linux.py index 075a386300..4a51e1324b 100644 --- a/tests/acceptance/boot_linux.py +++ b/tests/acceptance/boot_linux.py @@ -12,8 +12,7 @@ =20 from avocado_qemu import Test, BUILD_DIR =20 -from qemu.accel import kvm_available -from qemu.accel import tcg_available +from qemu.lib import kvm_available, tcg_available =20 from avocado.utils import cloudinit from avocado.utils import network diff --git a/tests/acceptance/virtio_check_params.py b/tests/acceptance/vir= tio_check_params.py index 87e6c839d1..be8069778a 100644 --- a/tests/acceptance/virtio_check_params.py +++ b/tests/acceptance/virtio_check_params.py @@ -23,7 +23,7 @@ import logging =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine from avocado_qemu import Test from avocado import skip =20 diff --git a/tests/acceptance/virtio_version.py b/tests/acceptance/virtio_v= ersion.py index 33593c29dd..726f50c603 100644 --- a/tests/acceptance/virtio_version.py +++ b/tests/acceptance/virtio_version.py @@ -12,7 +12,7 @@ import os =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine from avocado_qemu import Test =20 # Virtio Device IDs: diff --git a/tests/migration/guestperf/engine.py b/tests/migration/guestper= f/engine.py index fd63c66601..22dab849f9 100644 --- a/tests/migration/guestperf/engine.py +++ b/tests/migration/guestperf/engine.py @@ -29,7 +29,7 @@ =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'python')) -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine =20 =20 class Engine(object): diff --git a/tests/qemu-iotests/235 b/tests/qemu-iotests/235 index d1b10ac36b..13a565934c 100755 --- a/tests/qemu-iotests/235 +++ b/tests/qemu-iotests/235 @@ -25,7 +25,7 @@ from iotests import qemu_img_create, qemu_io, file_path, = log =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) =20 -from qemu.machine import QEMUMachine +from qemu.lib import QEMUMachine =20 iotests.script_initialize(supported_fmts=3D['qcow2']) =20 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 6c0e781af7..c69ac07e69 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -34,7 +34,7 @@ =20 # pylint: disable=3Dimport-error, wrong-import-position sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu import qtest +from qemu.lib import qtest =20 assert sys.version_info >=3D (3, 6) =20 diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py index 756ccf7aca..4c89c62fb8 100644 --- a/tests/vm/basevm.py +++ b/tests/vm/basevm.py @@ -18,9 +18,6 @@ import logging import time import datetime -sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) -from qemu.accel import kvm_available -from qemu.machine import QEMUMachine import subprocess import hashlib import optparse @@ -30,6 +27,9 @@ import multiprocessing import traceback =20 +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import kvm_available, QEMUMachine + SSH_KEY =3D open(os.path.join(os.path.dirname(__file__), "..", "keys", "id_rsa")).read() SSH_PUB_KEY =3D open(os.path.join(os.path.dirname(__file__), --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435737; cv=none; d=zohomail.com; s=zohoarc; b=FJmr82gYo+/e7wB6keqc5nnFj7SqHhu95edfOtHIABCPrCfGA7dwePWrgbv3kxJ4Gq1MocjVYHSCbmPCSRgk0ZF4pj0tfWBAWSQSBunu1chClWtUU2F/b1y8cWjL6k+dD0Q5MHrF0imH6eKW/rpyN/5qNnPJe3O1C4bGNwoVvLQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435737; 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=Kphp4db494N4NbfTFGW9gNNJWamBvMYYm3dwz875wYQ=; b=ZjYjzaGfO4sdtxPyLEGk/FpyvcfKTn6QzXB9OKFeY1PURGH0pn1+EGRmKyC0xc53HiVjtPCIm0mOYMDtEgq9iuHnQvpRbm507oDa9Hvg4AA8i6OOLXf5NU2V9aaQPvqqSOcq8wmt5SO7gYSSA5RoYuYi1HlYBEl5tsahF9FRuIM= 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 1589435737161982.2760800933231; Wed, 13 May 2020 22:55:37 -0700 (PDT) Received: from localhost ([::1]:55040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6qF-0006Cz-R5 for importer@patchew.org; Thu, 14 May 2020 01:55:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ow-0004H5-9a for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:37615 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ov-0001Zf-Ca for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54: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-182-gejrlwCwNciN_-ZxXV6aSQ-1; Thu, 14 May 2020 01:54:10 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 170668014D7; Thu, 14 May 2020 05:54:09 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FC877D959; Thu, 14 May 2020 05:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435652; 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=Kphp4db494N4NbfTFGW9gNNJWamBvMYYm3dwz875wYQ=; b=ZALWtkz5FdSHi8hHnIavHcRqlOEZqliw29Mst+cam5/dGTdAXX4YEFwQhNp5UE227vze18 H4sBnGaS6c0Hob7zN5lj/xNhMWMPA3StpWsjRY1yxNei4miNxzQMZvSI5nUPcWgbQedkNU +g7t8GcYspB7u7/myCWORbv5nMN5XJk= X-MC-Unique: gejrlwCwNciN_-ZxXV6aSQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 02/32] scripts/qmp: Fix shebang and imports Date: Thu, 14 May 2020 01:53:33 -0400 Message-Id: <20200514055403.18902-3-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" There's more wrong with these scripts; They are in various stages of disrepair. That's beyond the scope of this current patchset. This just mechanically corrects the imports and the shebangs, as part of ensuring that the python/qemu/lib refactoring didn't break anything needlessly. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qmp/qmp | 4 +++- scripts/qmp/qom-fuse | 4 +++- scripts/qmp/qom-get | 6 ++++-- scripts/qmp/qom-list | 4 +++- scripts/qmp/qom-set | 6 ++++-- scripts/qmp/qom-tree | 6 ++++-- 6 files changed, 21 insertions(+), 9 deletions(-) diff --git a/scripts/qmp/qmp b/scripts/qmp/qmp index 0625fc2aba..5981f7c414 100755 --- a/scripts/qmp/qmp +++ b/scripts/qmp/qmp @@ -11,7 +11,9 @@ # See the COPYING file in the top-level directory. =20 import sys, os -from qmp import QEMUMonitorProtocol + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import QEMUMonitorProtocol =20 def print_response(rsp, prefix=3D[]): if type(rsp) =3D=3D list: diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index 6bada2c33d..6006f1d562 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -15,7 +15,9 @@ import fuse, stat from fuse import Fuse import os, posix from errno import * -from qmp import QEMUMonitorProtocol + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import QEMUMonitorProtocol =20 fuse.fuse_python_api =3D (0, 2) =20 diff --git a/scripts/qmp/qom-get b/scripts/qmp/qom-get index 007b4cd442..1d04d1b119 100755 --- a/scripts/qmp/qom-get +++ b/scripts/qmp/qom-get @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools # @@ -13,7 +13,9 @@ =20 import sys import os -from qmp import QEMUMonitorProtocol + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import QEMUMonitorProtocol =20 cmd, args =3D sys.argv[0], sys.argv[1:] socket_path =3D None diff --git a/scripts/qmp/qom-list b/scripts/qmp/qom-list index 03bda3446b..94e3bc21ba 100755 --- a/scripts/qmp/qom-list +++ b/scripts/qmp/qom-list @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools # @@ -13,6 +13,8 @@ =20 import sys import os + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) from qmp import QEMUMonitorProtocol =20 cmd, args =3D sys.argv[0], sys.argv[1:] diff --git a/scripts/qmp/qom-set b/scripts/qmp/qom-set index c37fe78b00..a78080a4fc 100755 --- a/scripts/qmp/qom-set +++ b/scripts/qmp/qom-set @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools # @@ -13,7 +13,9 @@ =20 import sys import os -from qmp import QEMUMonitorProtocol + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import QEMUMonitorProtocol =20 cmd, args =3D sys.argv[0], sys.argv[1:] socket_path =3D None diff --git a/scripts/qmp/qom-tree b/scripts/qmp/qom-tree index 1c8acf61e7..4866c15581 100755 --- a/scripts/qmp/qom-tree +++ b/scripts/qmp/qom-tree @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 ## # QEMU Object Model test tools # @@ -15,7 +15,9 @@ =20 import sys import os -from qmp import QEMUMonitorProtocol + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'pytho= n')) +from qemu.lib import QEMUMonitorProtocol =20 cmd, args =3D sys.argv[0], sys.argv[1:] socket_path =3D None --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435827; cv=none; d=zohomail.com; s=zohoarc; b=hJqBgGJxsFA9VjQxAxOafwai4u+4Np/2zijKy5ylYWTMxZ40gbEO7GIJI4KlgPrkWnzIXwiqoM03vcKMrog6fv8P/kBHPfGTl/VsmqtoQhFo+626/FbBi+0sMWfD5AzMsL+3FeTTHdhsDbH2koAG5LOKvsRdb5xowoCRUGN0P8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435827; 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=tufz5NcW8hH/9Kxk+oqLSNwizTGlEXnvJ0RCo1dFD+o=; b=JWu6Bz5zI28tTYVH1rgXPkSvw18u/UtFYJSkglofvoIfEUDuAY4EdG9L2IyyYcVPBmc3k9L6s9rE6jwUrL4nmRtDxi09KGBybEcnFNZ2XL6RY9rEpYoAiI1rFlYb+8WRgPbo3uDjy/Lg6tn77OMHQm+eEVm9DcRIQurY8T4eE2A= 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 1589435827525647.589158887736; Wed, 13 May 2020 22:57:07 -0700 (PDT) Received: from localhost ([::1]:35458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6ri-0002YP-7T for importer@patchew.org; Thu, 14 May 2020 01:57:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6oz-0004Oj-F1 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:17 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:29468 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6oy-0001a9-2n for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54: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-407-weucs0WqNSK_c1E-BPMwfQ-1; Thu, 14 May 2020 01:54:11 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2ECE108BD0A; Thu, 14 May 2020 05:54:10 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 434267D952; Thu, 14 May 2020 05:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435655; 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=tufz5NcW8hH/9Kxk+oqLSNwizTGlEXnvJ0RCo1dFD+o=; b=T+TCzfxCY2PHo6MEC12CJ0zWCrBASYzCXhHbsxyPG4WwMkf17w4tp6aUufd0TLRKUmcEaj AFqlZzoLs4st0ku2mirVuToqknZrOUM2ubuwUs3LZKKdTOml/fasW2tJJC//LH8JC5i1tX Ds2T+87xgvKiUeNjxHQ/5/LVGZWkJOQ= X-MC-Unique: weucs0WqNSK_c1E-BPMwfQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 03/32] python//machine.py: remove bare except Date: Thu, 14 May 2020 01:53:34 -0400 Message-Id: <20200514055403.18902-4-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Catch only the timeout error; if there are other problems, allow the stack trace to be visible. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index b9a98e2c86..e3ea523571 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -342,7 +342,26 @@ def wait(self): self._load_io_log() self._post_shutdown() =20 - def shutdown(self, has_quit=3DFalse): + def _issue_shutdown(self, has_quit: bool =3D False) -> None: + """ + Shutdown the VM. + """ + if not self.is_running(): + return + + if self._qmp is not None: + if not has_quit: + self._qmp.cmd('quit') + self._qmp.close() + + try: + self._popen.wait(timeout=3D3) + except subprocess.TimeoutExpired: + self._popen.kill() + + self._popen.wait() + + def shutdown(self, has_quit: bool =3D False) -> None: """ Terminate the VM and clean up """ @@ -353,17 +372,7 @@ def shutdown(self, has_quit=3DFalse): self._console_socket.close() self._console_socket =3D None =20 - if self.is_running(): - if self._qmp: - try: - if not has_quit: - self._qmp.cmd('quit') - self._qmp.close() - self._popen.wait(timeout=3D3) - except: - self._popen.kill() - self._popen.wait() - + self._issue_shutdown(has_quit) self._load_io_log() self._post_shutdown() =20 --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435741; cv=none; d=zohomail.com; s=zohoarc; b=eYb+MOMC9DF5J/csdcG1RLfaEqGzHmm7KPtHuZsmIMiyTOAQWQB8yFQr9jyBvVFqaQ8tmWmTJI5Mw2DWLriQd026DHMylg57Rph/V+aJBD7aFq3oEEjc49gnQ8R9uZBFMxXdJetCU2/C7ZOuRO1UDaF0Oc78h/2gQqGEUGgxnF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435741; 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=A6LXeGnA7xEQmC4DWM+/mMqjngkV8ZV220khpw1JxO8=; b=K88CjIxv+kjrtRpMAyijx/T7koXokbXHO1zP+DeMcXjQxw/+TCiR5ge1Ru2xabZka5e27KDMVC1/N0+vvFj6Uj83Vn4qSlM9gAMLU5TZChcONLGCfXILAdSWqet2O+DBZn502We5whakgOBIzxtM4rI67ctPRGIbCh/FVH9SXp8= 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 158943574164594.01940185207513; Wed, 13 May 2020 22:55:41 -0700 (PDT) Received: from localhost ([::1]:55492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6qK-0006Rs-5k for importer@patchew.org; Thu, 14 May 2020 01:55:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6oy-0004N4-Td for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:16 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30604 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ox-0001aB-Qg for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54: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-500-oo8X7B_ZNEuqm5xZV0bOlA-1; Thu, 14 May 2020 01:54:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5A98D8014D7; Thu, 14 May 2020 05:54:12 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCAD57D952; Thu, 14 May 2020 05:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435655; 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=A6LXeGnA7xEQmC4DWM+/mMqjngkV8ZV220khpw1JxO8=; b=JYir+Y03bdsAGV7TacPfBTZBh1g+gG8/KxBAO6vYPMqwq+sZXw1/GhoYngqpUL3X02lzGp FAEgAnjeQkF36XOi8PWcaH661N626be4zeXBjRHJkDMmRpXd7uyX8dezDmmhb4bFCLvwwA CBsOx/8m6bZhQcz4JlnLbYeRGdngaEg= X-MC-Unique: oo8X7B_ZNEuqm5xZV0bOlA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 04/32] python/qemu/lib: delint, add pylintrc Date: Thu, 14 May 2020 01:53:35 -0400 Message-Id: <20200514055403.18902-5-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Bring our these files up to speed with pylint 2.5.0. Add a pylintrc file to formalize which pylint subset we are targeting. The similarity ignore is there to suppress similarity reports across imports, which for typing constants, are going to trigger this report erroneously. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 6 ++-- python/qemu/lib/pylintrc | 58 ++++++++++++++++++++++++++++++++++++++ python/qemu/lib/qtest.py | 42 +++++++++++++++++---------- 3 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 python/qemu/lib/pylintrc diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index e3ea523571..c79fc8fb89 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -58,7 +58,7 @@ def __init__(self, reply): self.reply =3D reply =20 =20 -class QEMUMachine(object): +class QEMUMachine: """ A QEMU VM =20 @@ -242,7 +242,7 @@ def _base_args(self): 'chardev=3Dmon,mode=3Dcontrol']) if self._machine is not None: args.extend(['-machine', self._machine]) - for i in range(self._console_index): + for _ in range(self._console_index): args.extend(['-serial', 'null']) if self._console_set: self._console_address =3D os.path.join(self._sock_dir, @@ -383,7 +383,7 @@ def shutdown(self, has_quit: bool =3D False) -> None: command =3D ' '.join(self._qemu_full_args) else: command =3D '' - LOG.warning(msg, -exitcode, command) + LOG.warning(msg, -int(exitcode), command) =20 self._launched =3D False =20 diff --git a/python/qemu/lib/pylintrc b/python/qemu/lib/pylintrc new file mode 100644 index 0000000000..5d6ae7367d --- /dev/null +++ b/python/qemu/lib/pylintrc @@ -0,0 +1,58 @@ +[MASTER] + +[MESSAGES CONTROL] + +# Disable the message, report, category or checker with the given id(s). Y= ou +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=3Dal= l" to +# disable everything first and then reenable specific checks. For example,= if +# you want to run only the similarities checker, you can use "--disable=3D= all +# --enable=3Dsimilarities". If you want to run only the classes checker, b= ut have +# no Warning level messages displayed, use "--disable=3Dall --enable=3Dcla= sses +# --disable=3DW". +disable=3Dtoo-many-arguments, + too-many-instance-attributes, + too-many-public-methods, + +[REPORTS] + +[REFACTORING] + +[MISCELLANEOUS] + +[LOGGING] + +[BASIC] + +# Good variable names which should always be accepted, separated by a comm= a. +good-names=3Di, + j, + k, + ex, + Run, + _, + fd, + +[VARIABLES] + +[STRING] + +[SPELLING] + +[FORMAT] + +[SIMILARITIES] + +# Ignore imports when computing similarities. +ignore-imports=3Dyes + +[TYPECHECK] + +[CLASSES] + +[IMPORTS] + +[DESIGN] + +[EXCEPTIONS] diff --git a/python/qemu/lib/qtest.py b/python/qemu/lib/qtest.py index d24ad04256..53d814c064 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -1,5 +1,11 @@ -# QEMU qtest library -# +""" +QEMU qtest library + +qtest offers the QEMUQtestProtocol and QEMUQTestMachine classes, which +offer a connection to QEMU's qtest protocol socket, and a qtest-enabled +subclass of QEMUMachine, respectively. +""" + # Copyright (C) 2015 Red Hat Inc. # # Authors: @@ -17,19 +23,21 @@ from .machine import QEMUMachine =20 =20 -class QEMUQtestProtocol(object): +class QEMUQtestProtocol: + """ + QEMUQtestProtocol implements a connection to a qtest socket. + + :param address: QEMU address, can be either a unix socket path (string) + or a tuple in the form ( address, port ) for a TCP + connection + :param server: server mode, listens on the socket (bool) + :raise socket.error: on socket connection errors + + .. note:: + No conection is estabalished by __init__(), this is done + by the connect() or accept() methods. + """ def __init__(self, address, server=3DFalse): - """ - Create a QEMUQtestProtocol object. - - @param address: QEMU address, can be either a unix socket path (st= ring) - or a tuple in the form ( address, port ) for a TCP - connection - @param server: server mode, listens on the socket (bool) - @raise socket.error on socket connection errors - @note No connection is established, this is done by the connect() = or - accept() methods - """ self._address =3D address self._sock =3D self._get_sock() self._sockfile =3D None @@ -73,15 +81,19 @@ def cmd(self, qtest_cmd): return resp =20 def close(self): + """Close this socket.""" self._sock.close() self._sockfile.close() =20 def settimeout(self, timeout): + """Set a timeout, in seconds.""" self._sock.settimeout(timeout) =20 =20 class QEMUQtestMachine(QEMUMachine): - '''A QEMU VM''' + """ + 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): --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435921; cv=none; d=zohomail.com; s=zohoarc; b=Y4boT5RnCBlmebnhqV+WBizfvr/60banOa3JdXLmiXF1LkZVlBKIA1kNugwrEmeF9SWnAmJhyMi6QqqWISGxjolID3emtDs+IUOum89ZhFbQlTqk6s8oAbuzt+sf8EvOqKQqWl/PZS93n3ZPHNT3j/aFxsggSQPOb248xEosMXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435921; 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=eIVREeXd6nvTZkOSZ5iRHZDJSFp7tIw6PyIaTwCOjGQ=; b=Q8Y3Ff1YLzkn5d8ywo80UItRqGXe4pL4XmZMNmi+myc0UrE3ie0qc7W89hOvpQN3Gu/MyKxmN0jfP1AR1MaqZLZLtg23YJZ0AviDoG463Hsw4z4wAlMXH5GPIcGuVePMaOJfU8giNi55/NbDgYSPCRLItr0n3U8HqYyPWozCjGk= 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 1589435921107891.01281536569; Wed, 13 May 2020 22:58:41 -0700 (PDT) Received: from localhost ([::1]:44096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6tD-0006XT-TL for importer@patchew.org; Thu, 14 May 2020 01:58:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p2-0004Z9-QQ for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:20 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:48472 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p2-0001b3-0Y for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:20 -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-503-aBVQFwdkNA2zDIkkVPt0qA-1; Thu, 14 May 2020 01:54:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEC341054F8F; Thu, 14 May 2020 05:54:13 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85D067D952; Thu, 14 May 2020 05:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435658; 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=eIVREeXd6nvTZkOSZ5iRHZDJSFp7tIw6PyIaTwCOjGQ=; b=P+uVGgvcgQRG7udCDuGzc3gJUhF24JVM5tzTnJ6Pscfs43mtzo3eJDT2y/vICbl2Z8uV1l r6s8gWTjxd80CdZ5WmJ8nlS8PXHJg2/VvMh0qPKxb557i3yIm0dgvuS1/nAdMMdID0KiNb xI05HwwknNItJs/TuTcmvetnBUESZy0= X-MC-Unique: aBVQFwdkNA2zDIkkVPt0qA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 05/32] python/qemu/lib: delint; add flake8 config Date: Thu, 14 May 2020 01:53:36 -0400 Message-Id: <20200514055403.18902-6-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Mostly, ignore the "no bare except" rule, because flake8 is not contextual and cannot determine if we re-raise. Pylint can, though, so always prefer pylint for that. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/.flake8 | 2 ++ python/qemu/lib/accel.py | 9 ++++++--- python/qemu/lib/machine.py | 13 +++++++++---- python/qemu/lib/qmp.py | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 python/qemu/lib/.flake8 diff --git a/python/qemu/lib/.flake8 b/python/qemu/lib/.flake8 new file mode 100644 index 0000000000..45d8146f3f --- /dev/null +++ b/python/qemu/lib/.flake8 @@ -0,0 +1,2 @@ +[flake8] +extend-ignore =3D E722 # Pylint handles this, but smarter. \ No newline at end of file diff --git a/python/qemu/lib/accel.py b/python/qemu/lib/accel.py index 36ae85791e..7fabe62920 100644 --- a/python/qemu/lib/accel.py +++ b/python/qemu/lib/accel.py @@ -23,11 +23,12 @@ # Mapping host architecture to any additional architectures it can # support which often includes its 32 bit cousin. ADDITIONAL_ARCHES =3D { - "x86_64" : "i386", - "aarch64" : "armhf", - "ppc64le" : "ppc64", + "x86_64": "i386", + "aarch64": "armhf", + "ppc64le": "ppc64", } =20 + def list_accel(qemu_bin): """ List accelerators enabled in the QEMU binary. @@ -47,6 +48,7 @@ def list_accel(qemu_bin): # Skip the first line which is the header. return [acc.strip() for acc in out.splitlines()[1:]] =20 + def kvm_available(target_arch=3DNone, qemu_bin=3DNone): """ Check if KVM is available using the following heuristic: @@ -69,6 +71,7 @@ def kvm_available(target_arch=3DNone, qemu_bin=3DNone): return False return True =20 + def tcg_available(qemu_bin): """ Check if TCG is available. diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index c79fc8fb89..4b260fa2cb 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -29,6 +29,7 @@ =20 LOG =3D logging.getLogger(__name__) =20 + class QEMUMachineError(Exception): """ Exception called when an error in QEMUMachine happens. @@ -62,7 +63,8 @@ class QEMUMachine: """ A QEMU VM =20 - Use this object as a context manager to ensure the QEMU process termin= ates:: + Use this object as a context manager to ensure + the QEMU process terminates:: =20 with VM(binary) as vm: ... @@ -188,8 +190,10 @@ def send_fd_scm(self, fd=3DNone, file_path=3DNone): fd_param.append(str(fd)) =20 devnull =3D open(os.path.devnull, 'rb') - proc =3D subprocess.Popen(fd_param, stdin=3Ddevnull, stdout=3Dsubp= rocess.PIPE, - stderr=3Dsubprocess.STDOUT, close_fds=3DFa= lse) + proc =3D subprocess.Popen( + fd_param, stdin=3Ddevnull, stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.STDOUT, close_fds=3DFalse + ) output =3D proc.communicate()[0] if output: LOG.debug(output) @@ -491,7 +495,8 @@ def event_wait(self, name, timeout=3D60.0, match=3DNone= ): =20 def events_wait(self, events, timeout=3D60.0): """ - events_wait waits for and returns a named event from QMP with a ti= meout. + events_wait waits for and returns a named event + from QMP with a timeout. =20 events: a sequence of (name, match_criteria) tuples. The match criteria are optional and may be None. diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index d6c9b2f4b1..6ae7693965 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -168,8 +168,8 @@ def accept(self, timeout=3D15.0): =20 @param timeout: timeout in seconds (nonnegative float number, or None). The value passed will set the behavior of t= he - underneath QMP socket as described in [1]. Default= value - is set to 15.0. + underneath QMP socket as described in [1]. + Default value is set to 15.0. @return QMP greeting dict @raise OSError on socket connection errors @raise QMPConnectError if the greeting is not received --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435743; cv=none; d=zohomail.com; s=zohoarc; b=fBSocvzMvmnTW/v0N0XjNpONO12PUhSFIQ+xjBYq3zmIxl/DJrpij9w7YxmUETPcViKLWY2HFlJh3yIh/HQvtIseCiWazhWIlEb3xBDadsm1QX7sg7JvA8FtMwfEYWwwvyB6XL6Rkm26BzSRlqehho56gwEl4JnauNfYU4lX4V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435743; 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=y1L7/1jsi/rhDBlb9C3wBKXfsbtA5yKILSP/UiA+PmE=; b=CgVbHNEgbj5N5n46g7f6OQdydqURuLpc6Wwvxk0cCOySnTeUNT2UdpqQ8S76TTahSsE+ljMUVduottKQkQMfNPsAezBQ3rEZ+DHkYBRoLB7lqz4f7JxngljXf6m0pXZ4lY+4KNx2lYHdrvZE0zzRl4wC2o/RlTDAsCntTO6Zxjw= 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 1589435743691574.6525981316718; Wed, 13 May 2020 22:55:43 -0700 (PDT) Received: from localhost ([::1]:55740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6qM-0006Zr-Dk for importer@patchew.org; Thu, 14 May 2020 01:55:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p3-0004br-S5 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:21 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55022 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p2-0001bD-Tw for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:21 -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-88-MWPk_DUnNt279V8j_uDrGQ-1; Thu, 14 May 2020 01:54:16 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8154D1899528; Thu, 14 May 2020 05:54:15 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26CB56A977; Thu, 14 May 2020 05:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435660; 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=y1L7/1jsi/rhDBlb9C3wBKXfsbtA5yKILSP/UiA+PmE=; b=BrfvKtZtyDqRYs1Pfr748bWErYbaC1OvwMQGQ/7pdmlPH9M58SkKuVKpwIqaQvpv35Kjvv a109HIg/xaOEs52CRuFgN281i33mJSytNVoT+PkTRIziL8XBOjSJBnr0quhREOgUjgsga+ XotkvAQelY8BA2Ygwd6OV58sQoQ31og= X-MC-Unique: MWPk_DUnNt279V8j_uDrGQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 06/32] python/qemu: formalize as package Date: Thu, 14 May 2020 01:53:37 -0400 Message-Id: <20200514055403.18902-7-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" NB: I am choosing Python 3.6 here. Although our minimum requirement is 3.5, this code is used only by iotests (so far) under which we have been using a minimum version of 3.6. 3.6 is being preferred here for variable type hint capability, which enables us to use mypy for this package. Signed-off-by: John Snow Acked-by: Philippe Mathieu-Daud=C3=A9 --- python/README.rst | 6 ++++++ python/setup.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 python/README.rst create mode 100755 python/setup.py diff --git a/python/README.rst b/python/README.rst new file mode 100644 index 0000000000..25f6d93fd5 --- /dev/null +++ b/python/README.rst @@ -0,0 +1,6 @@ +QEMU Python Tooling +------------------- + +This package provides QEMU tooling used by the QEMU project to build, +configure, and test QEMU. It is not a fully-fledged SDK and it is subject +to change at any time. diff --git a/python/setup.py b/python/setup.py new file mode 100755 index 0000000000..f897ceac97 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,50 @@ +#!/usr/bin/env3 python +""" +QEMU tooling installer script +Copyright (c) 2020 John Snow for Red Hat, Inc. +""" + +import setuptools + +def main(): + """ + QEMU tooling installer + """ + + kwargs =3D { + 'name': 'qemu', + 'use_scm_version': { + 'root': '..', + 'relative_to': __file__, + }, + 'maintainer': 'QEMU Developer Team', + 'maintainer_email': 'qemu-devel@nongnu.org', + 'url': 'https://www.qemu.org/', + 'download_url': 'https://www.qemu.org/download/', + 'packages': setuptools.find_namespace_packages(), + 'description': 'QEMU Python Build, Debug and SDK tooling.', + 'classifiers': [ + 'Development Status :: 5 - Production/Stable', + 'License :: OSI Approved :: GNU General Public License v2 (GPL= v2)', + 'Natural Language :: English', + 'Operating System :: OS Independent', + ], + 'platforms': [], + 'keywords': [], + 'setup_requires': [ + 'setuptools', + 'setuptools_scm', + ], + 'install_requires': [ + ], + 'python_requires': '>=3D3.6', + 'long_description_content_type': 'text/x-rst', + } + + with open("README.rst", "r") as fh: + kwargs['long_description'] =3D fh.read() + + setuptools.setup(**kwargs) + +if __name__ =3D=3D '__main__': + main() --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435836; cv=none; d=zohomail.com; s=zohoarc; b=DaqTL1Hl3fSUWYPEz7T4mwJL8bRxE2IH1RoNc0WBaw2J0xAN0CTiAMszL1HmhcCFF9ow8ftso8drCBvCahaiS4L3SEfoc8knaiB8TN9uF3wZZ8itWHYnqoRc9yQMsau3axZWNGBMZJ+ELfTHwAGP9m6C05ZgiKaTBqKfLDdADhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435836; 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=+JzfWCzjE2lMuCAEEmqDnbHD/UCKP/jRenYPsxCsazw=; b=mEHkCHKCJ7RU9eswNp9nFq27MFc5in4XbQNiRTSsiRtbucrf/5iQAi7Wdg6dNY91BR20OEqKf1L5tZIaH/mANQkVil43XCYvecCuK8wyt8NwRofR00ye1H1+1EaJ2U1wJD88bjvUY6XqpjovlzP+CjAcz2rxvRTT2HX9nbVd5Mc= 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 1589435836339301.32092584107545; Wed, 13 May 2020 22:57:16 -0700 (PDT) Received: from localhost ([::1]:36512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6rr-00031c-3I for importer@patchew.org; Thu, 14 May 2020 01:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p5-0004fo-Cy for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:23 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:38122 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6p4-0001bS-LH for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:23 -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-63-SU6d7FOnOZOP45urRPYlMA-1; Thu, 14 May 2020 01:54:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18ADD474; Thu, 14 May 2020 05:54:17 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC2C47D951; Thu, 14 May 2020 05:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435662; 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=+JzfWCzjE2lMuCAEEmqDnbHD/UCKP/jRenYPsxCsazw=; b=RJo3hfaoPgNs6DbTebB0ROBKBZk5uNiOcBicJm4qVbuXPjd6NG9nyJDu2iJabUE4LC7DPo qch2xonz4NhfY8liu55DU67JQYs7ZScUsvXGba8kDe8Rqp4DqrQXCuAzL7KeMvvb9IaYR/ ud5PKH0WYDzNMRTuVevEdXoJRFh3Hxc= X-MC-Unique: SU6d7FOnOZOP45urRPYlMA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 07/32] python/qemu: add README.rst Date: Thu, 14 May 2020 01:53:38 -0400 Message-Id: <20200514055403.18902-8-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Add a short readme that explains the package hierarchy, which will be visible while browsing the source on e.g. gitlab/github. Signed-off-by: John Snow --- python/qemu/README.rst | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 python/qemu/README.rst diff --git a/python/qemu/README.rst b/python/qemu/README.rst new file mode 100644 index 0000000000..96447b9061 --- /dev/null +++ b/python/qemu/README.rst @@ -0,0 +1,8 @@ +python/qemu/ +------------ + +This directory serves as the root of a `Python PEP 420 implicit +namespace package <`_. + +Each directory below is assumed to be an installable Python module that +will be available under the ``qemu.`` namespace. --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435866; cv=none; d=zohomail.com; s=zohoarc; b=fjqckm9ZO/Qr61Zv1MA54Obv/gOcwyVDGm1p7xqMRUx9pMmefEdZ0l5pVEpGHfzhWOVob0AAkzVwTJs34oR45XFnM2Whjt6QCYBPVubvyMsFxn1zV1h6dhn5FhjbYtnn5p/5M4+apBs/Wa+qpiXQ+LUyrrehVknGoCNZc/OekSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435866; 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=KuQUGKwxcqc75FlHH9kAyjtsHHn9B4JJ4wVIWtmj1ag=; b=AKetLSiuNcqQqo0giMzl3fKidraa6u7+hrP0BLO3v23X9V3BgmiMzq2V5l3H4tUv16bCEhhHOkB6rESeZmTCZG/seqI+1dswSLZe2WmFRD9nuhxe/AY0yn4gP3mlo7xHb5tYqQhLU96mg0NE9LP1dzTV1nbl2bYLv8QPe/a4glg= 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 1589435866880877.4077954366848; Wed, 13 May 2020 22:57:46 -0700 (PDT) Received: from localhost ([::1]:39876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6sL-0004hs-3E for importer@patchew.org; Thu, 14 May 2020 01:57:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pH-0005AV-DB for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57137 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pF-0001cr-Sd for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:35 -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-191-Y3D5FHGyPDqFHpH8Hll-OQ-1; Thu, 14 May 2020 01:54:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3E0AE461; Thu, 14 May 2020 05:54:21 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 450746A977; Thu, 14 May 2020 05:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435673; 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=KuQUGKwxcqc75FlHH9kAyjtsHHn9B4JJ4wVIWtmj1ag=; b=DnZgsI5EqZee7QpKrsdJQDOvTwd9XmxnQVwWPiiHkJ8kboJaQpkNQ/uSu2E+zk9e9+DtfO HHeMdJotJlVutUMJxAmVNpR1NR6PKJYiQzKbqPxz+vHJ70WvodgLOB1t3hmFfn+N4zgEHx UxjYImMr0pZdKttvBE+ZTMao+/Org9g= X-MC-Unique: Y3D5FHGyPDqFHpH8Hll-OQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 08/32] python/qemu: Add Pipfile Date: Thu, 14 May 2020 01:53:39 -0400 Message-Id: <20200514055403.18902-9-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" pipenv is a tool used for managing virtual environments with precisely specified dependencies. It is separate from the dependencies listed in setup.py, which are not pinned to precise versions. Note that pipenv is not required to install or use this module; this is just a convenience for in-tree developing. Here, a "blank" pipfile is added with no dependencies, but specifies Python 3.6 for the virtual environment. Signed-off-by: John Snow --- python/Pipfile | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 python/Pipfile diff --git a/python/Pipfile b/python/Pipfile new file mode 100644 index 0000000000..9534830b5e --- /dev/null +++ b/python/Pipfile @@ -0,0 +1,11 @@ +[[source]] +name =3D "pypi" +url =3D "https://pypi.org/simple" +verify_ssl =3D true + +[dev-packages] + +[packages] + +[requires] +python_version =3D "3.6" --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436165; cv=none; d=zohomail.com; s=zohoarc; b=LReoWylkp5QA+LbfmRfPeSbAeSkbOLEcqG0bfPYe+iNOLL9upnMl3XX+eMt0Aa4+2sNdW46g2zDix0Exxy2uEJdGCNsLwLpGa92Et3rhlkaSUjabUSVlU70sMez477dBlZkzVV32fHZ8gc32UQftuVNrZV8LsCGRS+MxVz1GGOg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436165; 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=sTntwih9GmipO+si162ywTzSXmoovsyQaYqvMXpd3UE=; b=EAXMNAEAbjzF3MNL8MeMLLvPsoMjuDL/JZ0EFjggxVtHOEugeOEurxyJ3qfv2XO1EwEktRQZg5FHfrhhfyQuYdEzZzpcAbkMlJ2xyLG4Q2doVrJLMvtxIWi2EZhYyyxMc2gylP4sitOBIEH7viLqosIy56av2NeWrFo8VAo6JSY= 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 1589436165162833.2312248271087; Wed, 13 May 2020 23:02:45 -0700 (PDT) Received: from localhost ([::1]:33186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6x9-0005yF-Ox for importer@patchew.org; Thu, 14 May 2020 02:02:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pF-00056U-Vz for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55006 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pE-0001cA-CW for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:33 -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-352-kzByuLuaMt2leZftNbQlrA-1; Thu, 14 May 2020 01:54:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA1848014D7; Thu, 14 May 2020 05:54:22 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69B6A6A977; Thu, 14 May 2020 05:54:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435671; 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=sTntwih9GmipO+si162ywTzSXmoovsyQaYqvMXpd3UE=; b=JfEgKufeekvZen1Lhwd0nRbyKP87g1wsNPOk74E/KWWOzYkrn894TEQ+MY1iIHZDj7IuCc lEgv9DG58kWyN1o/tMm5f4n8hC8STPPm2cHuntrYETD3P3rY2xOKiKONwp/b35XGGTG8mZ XP4hsQ7gEgGLMugShvsdo+zpcGN8+Io= X-MC-Unique: kzByuLuaMt2leZftNbQlrA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 09/32] python/qemu: add pylint to Pipfile Date: Thu, 14 May 2020 01:53:40 -0400 Message-Id: <20200514055403.18902-10-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" A bug in pylint 2.5.1 and 2.5.2 causes false positives for relative imports. This version is pinned at 2.5.0 until a fix is available. Signed-off-by: John Snow --- python/Pipfile | 1 + python/Pipfile.lock | 123 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 python/Pipfile.lock diff --git a/python/Pipfile b/python/Pipfile index 9534830b5e..ddb2b5a518 100644 --- a/python/Pipfile +++ b/python/Pipfile @@ -4,6 +4,7 @@ url =3D "https://pypi.org/simple" verify_ssl =3D true =20 [dev-packages] +pylint =3D "=3D=3D2.5.0" =20 [packages] =20 diff --git a/python/Pipfile.lock b/python/Pipfile.lock new file mode 100644 index 0000000000..e6faa832e4 --- /dev/null +++ b/python/Pipfile.lock @@ -0,0 +1,123 @@ +{ + "_meta": { + "hash": { + "sha256": "7815dedfd7481b645389153dd45e9adb82c72956d0efc74d8f0= 87497624b75e4" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": { + "astroid": { + "hashes": [ + "sha256:4c17cea3e592c21b6e222f673868961bad77e1f985cb1694ed= 077475a89229c1", + "sha256:d8506842a3faf734b81599c8b98dcc423de863adcc19992484= 80b18bd31a0f38" + ], + "version": "=3D=3D2.4.1" + }, + "isort": { + "hashes": [ + "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c3= 5a78b719dccab1", + "sha256:6e811fcb295968434526407adb8796944f1988c5b65e813905= 8f2014cbe100fd" + ], + "version": "=3D=3D4.3.21" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d0= 8c62d37e1a504d", + "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69= a4d66c3fda3449", + "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c9= 2d7d697e684c08", + "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213= 697e48d3902f5a", + "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182= 447281ebf3ac50", + "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06d= ba3e180f203dfd", + "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3= db7bdaabaf6239", + "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4= dc56701c8f2ffb", + "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a556= 9eee1cc6c1b9ea", + "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f= 6d0de31a80ec3e", + "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c835= 2789e103cf3156", + "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a= 1d2799f3edd142", + "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75= e1a7bcc250d442", + "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536= a60af2b7797c62", + "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0= 964a0a4149e3db", + "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551= db1edae4ad1531", + "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799= 347cfc95952383", + "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfab= b2568bd58afc5a", + "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24= b921398affc357", + "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a= 473e1d38f7d3e4", + "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa= 911141bc522af0" + ], + "version": "=3D=3D1.4.3" + }, + "mccabe": { + "hashes": [ + "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d= 64e79735b80d42", + "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb= 0f125271b8831f" + ], + "version": "=3D=3D0.6.1" + }, + "pylint": { + "hashes": [ + "sha256:588e114e3f9a1630428c35b7dd1c82c1c93e1b0e78ee312ae4= 724c5e1a1e0245", + "sha256:bd556ba95a4cf55a1fc0004c00cf4560b1e70598a54a74c690= 4d933c8f3bd5a8" + ], + "index": "pypi", + "version": "=3D=3D2.5.0" + }, + "six": { + "hashes": [ + "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87= a7ec7ce1319c0a", + "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da0= 13c76ea2724b6c" + ], + "version": "=3D=3D1.14.0" + }, + "toml": { + "hashes": [ + "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df= 18ce5f05e73d5c", + "sha256:235682dd292d5899d361a811df37e04a8828a5b1da3115886b= 73cf81ebc9100e" + ], + "version": "=3D=3D0.10.0" + }, + "typed-ast": { + "hashes": [ + "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351de= f9ea6fa28f6355", + "sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424= e462169c0a7919", + "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc1738= 4b209f091276aa", + "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b= 4a7cf491612652", + "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779= f908621e7d8b75", + "sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9c= f21a42780f6e01", + "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c= 013fbc683a8d2d", + "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8a= ea42fdfdfd51c1", + "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c= 31defeb059a907", + "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895= af64a77a8c852c", + "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578= 394694202a58c3", + "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1b= a129eb293ec30b", + "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869= b7580cdbb83614", + "sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19= be4e547ea01ebb", + "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4cc= ad28a8973f301b", + "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de= 33ff773fbd4b41", + "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec= 004b6a44f911f6", + "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf6= 4ad54933ad4d34", + "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d5= 91c533ad8562fe", + "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db0= 62fa98cf71fca4", + "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888= e7a17dc2b757e7" + ], + "markers": "implementation_name =3D=3D 'cpython' and python_ve= rsion < '3.8'", + "version": "=3D=3D1.4.1" + }, + "wrapt": { + "hashes": [ + "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec= 1eb88e6d9b97d7" + ], + "version": "=3D=3D1.12.1" + } + } +} --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436030; cv=none; d=zohomail.com; s=zohoarc; b=FJah9Y5IDFi5QZK4mlLaKVJ25r+nSEO28aR8DKQlbOQ9qpkmqIXfc3LkQN6t8tBeEnorDm7yQIXoJBLuXNYhqogxBJL9N/aET64tfMhkxPtlTYsm0QYoDuxTfMB9FPwELcMfyA6SGyxWQ3grSMVy2T+UalwcgKWElfs8I6pRSI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436030; 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=uyA/Tt4ZyIMFTx1MNg4wxDf19QwSyBh8NoJX+MNs9n0=; b=OzpCAd35bQXVRtQsWvArHFfzaU+qzrfOHNDRhA5sEGlpp9S2sn7CCA6APS7LGBB8ShyQ0zN/nNoOqdLI72aarvCHEoKtlucdSZz2AgLXLXZ0LaoLdLGqvNuxQov4OJFEdwqn6Po3iEpgJ1vJDdI73peErpVgkt1Qt2TrgF7IY/Q= 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 1589436030291977.3609801150837; Wed, 13 May 2020 23:00:30 -0700 (PDT) Received: from localhost ([::1]:52644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6uy-0001VA-Lg for importer@patchew.org; Thu, 14 May 2020 02:00:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pE-00052k-0a for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54750 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pD-0001bs-4T for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54: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-315-x93rqQLHPMiz7vgfg5a9dQ-1; Thu, 14 May 2020 01:54:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F22CE80183C; Thu, 14 May 2020 05:54:26 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 048876A977; Thu, 14 May 2020 05:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435670; 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=uyA/Tt4ZyIMFTx1MNg4wxDf19QwSyBh8NoJX+MNs9n0=; b=YdNdVwaN4JzSWu29fzYIDuViW2qhDOjTFUAmL/ACOuvw2vlHftZPcvC+e5aLh00kpC2Dwf fYpBHDnsq15rNjVzHYF+YtsGrVgWkg6Bz2PNyE4cFtjTWMyxFOAgwa0eOi8c+tndIRCzrY MgC8bFjRWOQ4BCwkolODOHW5lDiUEtc= X-MC-Unique: x93rqQLHPMiz7vgfg5a9dQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 10/32] python/qemu: Add flake8 to Pipfile Date: Thu, 14 May 2020 01:53:41 -0400 Message-Id: <20200514055403.18902-11-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Signed-off-by: John Snow --- python/Pipfile | 1 + python/Pipfile.lock | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/python/Pipfile b/python/Pipfile index ddb2b5a518..e396e56e06 100644 --- a/python/Pipfile +++ b/python/Pipfile @@ -5,6 +5,7 @@ verify_ssl =3D true =20 [dev-packages] pylint =3D "=3D=3D2.5.0" +flake8 =3D "*" =20 [packages] =20 diff --git a/python/Pipfile.lock b/python/Pipfile.lock index e6faa832e4..15cd8a918f 100644 --- a/python/Pipfile.lock +++ b/python/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "7815dedfd7481b645389153dd45e9adb82c72956d0efc74d8f0= 87497624b75e4" + "sha256": "58115144ace0f646b5c62da260fb4867ac0a0e485de3f5b0a56= c7854afa21f5b" }, "pipfile-spec": 6, "requires": { @@ -24,6 +24,21 @@ ], "version": "=3D=3D2.4.1" }, + "entrypoints": { + "hashes": [ + "sha256:589f874b313739ad35be6e0cd7efde2a4e9b6fea91edcc34e5= 8ecbb8dbe56d19", + "sha256:c70dd71abe5a8c85e55e12c19bd91ccfeec11a6e9904420451= 1f9ed547d48451" + ], + "version": "=3D=3D0.3" + }, + "flake8": { + "hashes": [ + "sha256:45681a117ecc81e870cbf1262835ae4af5e7a8b08e40b944a8= a6e6b895914cfb", + "sha256:49356e766643ad15072a789a20915d3c91dc89fd313ccd7180= 2303fd67e4deca" + ], + "index": "pypi", + "version": "=3D=3D3.7.9" + }, "isort": { "hashes": [ "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c3= 5a78b719dccab1", @@ -64,6 +79,20 @@ ], "version": "=3D=3D0.6.1" }, + "pycodestyle": { + "hashes": [ + "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe= 3f6fac3491ae56", + "sha256:e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa= 2b085bc0ca976c" + ], + "version": "=3D=3D2.5.0" + }, + "pyflakes": { + "hashes": [ + "sha256:17dbeb2e3f4d772725c777fabc446d5634d1038f234e773431= 08ce445ea69ce0", + "sha256:d976835886f8c5b31d47970ed689944a0262b5f3afa00a5a7b= 4dc81e5449f8a2" + ], + "version": "=3D=3D2.1.1" + }, "pylint": { "hashes": [ "sha256:588e114e3f9a1630428c35b7dd1c82c1c93e1b0e78ee312ae4= 724c5e1a1e0245", --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435968; cv=none; d=zohomail.com; s=zohoarc; b=jXXFz70nlTu3Ydft472JuoP+Z5bocQD2+hc7e5Gi2WECQnfFl4sEOAwADcFZH1gAmTIUL5euUha+CNyyaPoRI6ohEImXOe1pOKoWG/WeIx+DgD+jOVs4hQMiQMl3zRgYXGgdjMtYSqJuUVXHaAKiPnlhC2j2tRS5NyqiN5gkR4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435968; 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=dcSV8AcRgboD0791Na12TrghYbWW2S4QzDgd970wraM=; b=LKWkp89K/zQYLUzquRwKUIBi4iSP61eAe/sBiYiV5LyXjam1Bp2MloRUoMwbIdBh2SKHrPxyI/SAA7y5/H8AnuGI/sM07sNplmLFrguBy+fKj3E+HE8MYv941HwbjrbREHmVL9shRbMviLsUKq1fT1doOybs8Ik+OcMLaf1YRk0= 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 1589435968439834.9009497992313; Wed, 13 May 2020 22:59:28 -0700 (PDT) Received: from localhost ([::1]:47298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6ty-0007nQ-4A for importer@patchew.org; Thu, 14 May 2020 01:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pF-00055v-Lo for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:33 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:43705 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pE-0001c3-A6 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:33 -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-474-3iFNAzb_O8GPtS9Ssli7uA-1; Thu, 14 May 2020 01:54:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89DF2BFC0; Thu, 14 May 2020 05:54:28 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29B326A977; Thu, 14 May 2020 05:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435671; 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=dcSV8AcRgboD0791Na12TrghYbWW2S4QzDgd970wraM=; b=EXYki1MYAuEX7vro3IDYfq0E6EIsOqnNAvjeVBjGG2gQ92H1QEKpeLe3F7kXIV78ZpSfSW xbWo88yHIFMClVdIPMqC0jmF/CFpWagGopfv/MM9H5soj7eBpH+OUhqvx9n8swegu/WynY qKfNbQr8W+PIc78NouLhuDFwNSR9MEA= X-MC-Unique: 3iFNAzb_O8GPtS9Ssli7uA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 11/32] python/qemu/lib: remove Python2 style super() calls Date: Thu, 14 May 2020 01:53:42 -0400 Message-Id: <20200514055403.18902-12-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 Python3 style instead. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 2 +- python/qemu/lib/qtest.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 4b260fa2cb..b2f0412197 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -55,7 +55,7 @@ def __init__(self, reply): desc =3D reply["error"]["desc"] except KeyError: desc =3D reply - super(MonitorResponseError, self).__init__(desc) + super().__init__(desc) self.reply =3D reply =20 =20 diff --git a/python/qemu/lib/qtest.py b/python/qemu/lib/qtest.py index 53d814c064..7943487c2b 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -101,29 +101,28 @@ def __init__(self, binary, args=3DNone, name=3DNone, = test_dir=3D"/var/tmp", name =3D "qemu-%d" % os.getpid() if sock_dir is None: sock_dir =3D test_dir - super(QEMUQtestMachine, - self).__init__(binary, args, name=3Dname, test_dir=3Dtest_di= r, - socket_scm_helper=3Dsocket_scm_helper, - sock_dir=3Dsock_dir) + 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_path =3D os.path.join(sock_dir, name + "-qtest.sock") =20 def _base_args(self): - args =3D super(QEMUQtestMachine, self)._base_args() + args =3D super()._base_args() args.extend(['-qtest', 'unix:path=3D' + self._qtest_path, '-accel', 'qtest']) return args =20 def _pre_launch(self): - super(QEMUQtestMachine, self)._pre_launch() + super()._pre_launch() self._qtest =3D QEMUQtestProtocol(self._qtest_path, server=3DTrue) =20 def _post_launch(self): - super(QEMUQtestMachine, self)._post_launch() + super()._post_launch() self._qtest.accept() =20 def _post_shutdown(self): - super(QEMUQtestMachine, self)._post_shutdown() + super()._post_shutdown() self._remove_if_exists(self._qtest_path) =20 def qtest(self, cmd): --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436392; cv=none; d=zohomail.com; s=zohoarc; b=bnzRKbTXuUTqykC6i/bW19G/73St2K4+5wZ6hA+Lw5YpFzBT0//7qV4DxQf3iH1VgqnksSpUT6uWdPVJB64K8tAXAVoJG4p7BY7gyO5uHp3HsCqwZockiqFHBE+tIE9Q00Qt8us1gnc+pTKPbdmB4U5esUd49SWW0rbDTKCwpSE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436392; 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=qRLuNsUV4q6lrwdDP4dnHXeBvVF8C22HGPdVkR9yFzg=; b=He2Ob4FTW+YajzVkr3PfudUATjZq7mojxo86jS++efVuqh40Rayurvw0m16pOXpVQwLIk/6JvxnMQGSoZFeaYd2Dlp9lqJcn/cGmy4VvVgos1cuQBDrAGsD8hKOEBE9E6i82eFJsJJxa+3XbD+aBVLeyqyT3yW15tgh9BS/gWP4= 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 158943639212062.72325752038671; Wed, 13 May 2020 23:06:32 -0700 (PDT) Received: from localhost ([::1]:50822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ70o-0005aN-Re for importer@patchew.org; Thu, 14 May 2020 02:06:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pc-0005ja-Uc for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:46404 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pb-0001hY-5O for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:56 -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-47-MyrWZbVGOUWYjjTJXVQDiw-1; Thu, 14 May 2020 01:54:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DCE7F107ACCD; Thu, 14 May 2020 05:54:32 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5C6F6A977; Thu, 14 May 2020 05:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435694; 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=qRLuNsUV4q6lrwdDP4dnHXeBvVF8C22HGPdVkR9yFzg=; b=M0N5MQM+saDU7MCNPYUb5Jht6rDK55Qq2hpgRO7tR2K6PD8Pv8C89acNCiwUStWjMNSDhA /xtbBIF2ZJO9glvgksfaiEoPa6EpkKiJEf4YBWHl3iE8Ub+yHC+0xQMSW3+xsxtZYBMYJV p1bvUB4yMBpGIEzf+QnN3czbv1FIRMI= X-MC-Unique: MyrWZbVGOUWYjjTJXVQDiw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 12/32] python/qemu/lib: fix socket.makefile() typing Date: Thu, 14 May 2020 01:53:43 -0400 Message-Id: <20200514055403.18902-13-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Note: A bug in typeshed (https://github.com/python/typeshed/issues/3977) misinterprets the type of makefile(). Work around this by explicitly stating that we are opening a text-mode file. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qmp.py | 10 +++++++--- python/qemu/lib/qtest.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 6ae7693965..73d49050ed 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -11,6 +11,10 @@ import errno import socket import logging +from typing import ( + Optional, + TextIO, +) =20 =20 class QMPError(Exception): @@ -61,7 +65,7 @@ def __init__(self, address, server=3DFalse, nickname=3DNo= ne): self.__events =3D [] self.__address =3D address self.__sock =3D self.__get_sock() - self.__sockfile =3D None + self.__sockfile: Optional[TextIO] =3D None self._nickname =3D nickname if self._nickname: self.logger =3D logging.getLogger('QMP').getChild(self._nickna= me) @@ -157,7 +161,7 @@ def connect(self, negotiate=3DTrue): @raise QMPCapabilitiesError if fails to negotiate capabilities """ self.__sock.connect(self.__address) - self.__sockfile =3D self.__sock.makefile() + self.__sockfile =3D self.__sock.makefile(mode=3D'r') if negotiate: return self.__negotiate_capabilities() return None @@ -180,7 +184,7 @@ def accept(self, timeout=3D15.0): """ self.__sock.settimeout(timeout) self.__sock, _ =3D self.__sock.accept() - self.__sockfile =3D self.__sock.makefile() + self.__sockfile =3D self.__sock.makefile(mode=3D'r') return self.__negotiate_capabilities() =20 def cmd_obj(self, qmp_cmd): diff --git a/python/qemu/lib/qtest.py b/python/qemu/lib/qtest.py index 7943487c2b..4c88590eb0 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -19,6 +19,7 @@ =20 import socket import os +from typing import Optional, TextIO =20 from .machine import QEMUMachine =20 @@ -40,7 +41,7 @@ class QEMUQtestProtocol: def __init__(self, address, server=3DFalse): self._address =3D address self._sock =3D self._get_sock() - self._sockfile =3D None + self._sockfile: Optional[TextIO] =3D None if server: self._sock.bind(self._address) self._sock.listen(1) @@ -59,7 +60,7 @@ def connect(self): @raise socket.error on socket connection errors """ self._sock.connect(self._address) - self._sockfile =3D self._sock.makefile() + self._sockfile =3D self._sock.makefile(mode=3D'r') =20 def accept(self): """ @@ -68,7 +69,7 @@ def accept(self): @raise socket.error on socket connection errors """ self._sock, _ =3D self._sock.accept() - self._sockfile =3D self._sock.makefile() + self._sockfile =3D self._sock.makefile(mode=3D'r') =20 def cmd(self, qtest_cmd): """ @@ -76,6 +77,7 @@ def cmd(self, qtest_cmd): =20 @param qtest_cmd: qtest command text to be sent """ + assert self._sockfile is not None self._sock.sendall((qtest_cmd + "\n").encode('utf-8')) resp =3D self._sockfile.readline() return resp @@ -83,7 +85,9 @@ def cmd(self, qtest_cmd): def close(self): """Close this socket.""" self._sock.close() - self._sockfile.close() + if self._sockfile: + self._sockfile.close() + self._sockfile =3D None =20 def settimeout(self, timeout): """Set a timeout, in seconds.""" --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589435943; cv=none; d=zohomail.com; s=zohoarc; b=OgUOijD+siBxdLTMaMzWmhZ+VSk5jR0Ks31OKHnkbgmvoiWABlHFLvdbCSNQbptq3jR2GUD3wEGhXuetkBmUxjQniCYtEMiBpDNrTBuQGzI4vYRjt2ekzPStFWb7+fOD76jLVV7iC/g1uEKgrujUfaQrjq4IhtGmgPPXYJ2hbr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589435943; 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=v+ohm4XYXFRwTcdD2vs9B3hxYnBxrDcx8T9ob43s9gU=; b=Z5M3Zsvtuc9KMqZ8fHONFcm2SNbhNifLXihz+woMP6cTDNfcTYiMr56Z5tIaBsJv0M+0z6i6+GTcHmd2aZC27oW1hKDZvt08rLsvt/LT7+aOdoAy30QeyBFZ6XfuL7nWy26Ws4wemGFCQ26iujej7T6fyoo0mMUbrN0gJuBy3Io= 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 1589435943926175.1220903709168; Wed, 13 May 2020 22:59:03 -0700 (PDT) Received: from localhost ([::1]:46540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6ta-0007V3-K0 for importer@patchew.org; Thu, 14 May 2020 01:59:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pQ-0005QZ-Mf for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:44 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:24155 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pM-0001f4-3C for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:44 -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-253-tOe9s-0ZNleE0_prcAC5XA-1; Thu, 14 May 2020 01:54:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7293C1054F8B; Thu, 14 May 2020 05:54:34 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 140986A977; Thu, 14 May 2020 05:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435679; 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=v+ohm4XYXFRwTcdD2vs9B3hxYnBxrDcx8T9ob43s9gU=; b=DS+YmwwhjGXY3+j5dRdtObQxYY9uifSYf1240jdZBPnnSUabwga9sTdSfGZdx7jjr4aHhy e4HpE/V0KO7ggFhMnRV1vKH62e+0+TsXqEESGgVfMtnyiEjMBXW//hehQmZjE4LTLVzDHh tjKresxVECwceKvwmSOp8Z8WzAJDSMs= X-MC-Unique: tOe9s-0ZNleE0_prcAC5XA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 13/32] python/qemu/lib: Adjust traceback typing Date: Thu, 14 May 2020 01:53:44 -0400 Message-Id: <20200514055403.18902-14-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 considers it incorrect to use `bool` to statically return false, because it will assume that it could conceivably return True, and gives different analysis in that case. Use a None return to achieve the same effect, but make mypy happy. Note: Pylint considers function signatures as code that might trip the duplicate-code checker. I'd rather not disable this as it does not trigger often in practice, so I'm disabling it as a one-off and filed a change request; see https://github.com/PyCQA/pylint/issues/3619 Signed-off-by: John Snow Acked-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 8 ++++++-- python/qemu/lib/qmp.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index b2f0412197..2f94c851ed 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -24,6 +24,8 @@ import shutil import socket import tempfile +from typing import Optional, Type +from types import TracebackType =20 from . import qmp =20 @@ -127,9 +129,11 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone= , name=3DNone, def __enter__(self): return self =20 - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, + exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> None: self.shutdown() - return False =20 def add_monitor_null(self): """ diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 73d49050ed..b91c9d5c1c 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -14,7 +14,9 @@ from typing import ( Optional, TextIO, + Type, ) +from types import TracebackType =20 =20 class QMPError(Exception): @@ -146,10 +148,14 @@ def __enter__(self): # Implement context manager enter function. return self =20 - def __exit__(self, exc_type, exc_value, exc_traceback): + def __exit__(self, + # pylint: disable=3Dduplicate-code + # see https://github.com/PyCQA/pylint/issues/3619 + exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> None: # Implement context manager exit function. self.close() - return False =20 def connect(self, negotiate=3DTrue): """ --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436067; cv=none; d=zohomail.com; s=zohoarc; b=IH/lmJ721Sv0Hs8eZerp0wDcOa2tq38860dTwHeD214CmfIMTciBmYGK3HGmC0JuTUg2nVivOrwMpmNS9DYQ8Ma73yqQ0swoGsgeBHV0WuODegtedjz7Ufq24P6K3nZddFB7poG5ohyXQOtWcsN/jNt+dsYFNiGvOWhpLdiOO9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436067; 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=oHifl02psf9McvbqYFW46f21SYq2sg8MrnQzHRqXobQ=; b=Tkon564VP2qYwdIYg86sTTg5r8cyCWje61URBZwh7Ia6S+UZIq3OHZSAnfocvm83MBPSYofSC36Px2DrN/KZ9caTG7UBZiSRjBG4m9UfFhUNj4yeVCc44IrYG1VFcXOFgQf2Ulu/Uh+WCUX7NK5TAF/2nD5tKHhS171khn0jHeM= 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 1589436067098295.95039274477176; Wed, 13 May 2020 23:01:07 -0700 (PDT) Received: from localhost ([::1]:54828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6vZ-0002Yw-Mi for importer@patchew.org; Thu, 14 May 2020 02:01:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pQ-0005Qp-Pa for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:44 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30908 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pO-0001fI-8S for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:44 -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-108-qHhcrF_yMCSzSmFjCfEaSg-1; Thu, 14 May 2020 01:54:37 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 405F6800053; Thu, 14 May 2020 05:54:36 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E2CD6A977; Thu, 14 May 2020 05:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435681; 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=oHifl02psf9McvbqYFW46f21SYq2sg8MrnQzHRqXobQ=; b=GGGF8hNoyf47hCd2lbsCkeWmHtS10XfG1OzVGu18ZN8S6YJOlETBCKrAvfZfJ/i6+CB7H5 2EMDGMaXIOd2tGFjN89EoODm4s3OC8bZH+yIx+iF4dViZ7ynVxB2diPFOSlIYDV11xctDH 1DyebCZ0rtECuTNNjtmF+RyhAYbYSIg= X-MC-Unique: qHhcrF_yMCSzSmFjCfEaSg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 14/32] python//qmp.py: use True/False for non/blocking modes Date: Thu, 14 May 2020 01:53:45 -0400 Message-Id: <20200514055403.18902-15-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 system doesn't want integers. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qmp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index b91c9d5c1c..a634c4e26c 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -120,14 +120,14 @@ def __get_events(self, wait=3DFalse): """ =20 # Check for new events regardless and pull them into the cache: - self.__sock.setblocking(0) + self.__sock.setblocking(False) try: self.__json_read() except OSError as err: if err.errno =3D=3D errno.EAGAIN: # No data available pass - self.__sock.setblocking(1) + self.__sock.setblocking(True) =20 # Wait for new events, if needed. # if wait is 0.0, this means "no wait" and is also implicitly fals= e. --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436095; cv=none; d=zohomail.com; s=zohoarc; b=dhmcU4gCjzUKXyf1O4pu6sehU8bbSMuH/frQapEilmugA427m21Sk5vCR3Fb+fc3aGK40vjjDZpJUArz94ep74Z9hngGF/7S9/KJ197lBNWTMA7ITc8E9RbpVTj5pgCPF69ZRD3UHfICSgZQd3y/DRii+NzDF0jESlyGwo2/3eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436095; 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=GLopj5+tE2Im0zOun4FriY1g+NiPrVStSQhtAYK0hb4=; b=KNm2wldK8xK6OzfNn3gHXY6L2DIzj803/qNkJjrD+oNqdSTD7StragjvUUhfCpxM2DZ2S4wAzSTuOhbFcmi36DNWKHLdjO6VwT34Rsh9tN9zPs5HYqQwb30jvs1eWJ9irO5aUEJ42f55dQimzZGbt0KvnU3eutALm8vg3YNjJfI= 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 1589436095474447.85083048464514; Wed, 13 May 2020 23:01:35 -0700 (PDT) Received: from localhost ([::1]:56748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6w2-0003d8-2Q for importer@patchew.org; Thu, 14 May 2020 02:01:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pO-0005Ml-J1 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:42 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:34865 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pN-0001fD-7w for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54: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-109-ttWxpgxoM3GekPSRDjqL8g-1; Thu, 14 May 2020 01:54:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7BDA1054F90; Thu, 14 May 2020 05:54:37 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B0F16A977; Thu, 14 May 2020 05:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435680; 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=GLopj5+tE2Im0zOun4FriY1g+NiPrVStSQhtAYK0hb4=; b=VvSpgwjaUY7wK9wdWdUvXVJBEEZBLfQsTtbJGtqj3c41Or/MeCdrQGlIwYLUfaHDEs7fII Jyo2mwtzRZ33pY5CjkGcERTQmc/eFQQjYNJqQdmX1cqpqfIclfpZ2VpLevw4den9OWkUHZ Mi/MQhzCCIxzIJ38kUeNAnLdKCFRCoE= X-MC-Unique: ttWxpgxoM3GekPSRDjqL8g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 15/32] python//qmp.py: Define common types Date: Thu, 14 May 2020 01:53:46 -0400 Message-Id: <20200514055403.18902-16-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Define some common types that we'll need to annotate a lot of other functions going forward. Signed-off-by: John Snow --- python/qemu/lib/qmp.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index a634c4e26c..911da59888 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -12,13 +12,31 @@ import socket import logging from typing import ( + Any, + Dict, Optional, TextIO, Type, + Tuple, + Union, ) from types import TracebackType =20 =20 +# QMPMessage is a QMP Message of any kind. +# e.g. {'yee': 'haw'} +# +# QMPReturnValue is the inner value of return values only. +# {'return': {}} is the QMPMessage, +# {} is the QMPReturnValue. +QMPMessage =3D Dict[str, Any] +QMPReturnValue =3D Dict[str, Any] + +InternetAddrT =3D Tuple[str, str] +UnixAddrT =3D str +SocketAddrT =3D Union[InternetAddrT, UnixAddrT] + + class QMPError(Exception): """ QMP base exception --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436262; cv=none; d=zohomail.com; s=zohoarc; b=BlVNYx5g4RYCHcNqPkKVgbRgyPsnSzfRoqLvBadg7/QGOjgCP8clvRu8M8JYgbvbvRDHNrnnGyQuK/xshnTY3ra4HPtqMkLp9VeC15z7Qnmskzk47tz8T74Isu/LbsUAVOk3jYXs9UGK2ZOUFLI6kKoBn5MKS1lWk1mo68UzLzY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436262; 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=elYehREd0a/oOvrSyCX6VUdw8yTEwHtHM2XKJOrHQzQ=; b=lISoD+eaAPlpDpXiHWDhYaD4YyWHDWqoSvvIupBmwtghGD1eTmoEiKLTWB1l50AMU1r3rITGJMosfBMUaG6FnaZQtRc3N3mN9IkrfhpEULi5E5/eivYu/qHcghRtcOGuLr5W/PaH5Vt2//PVT1KO52PpGt8YSwcxqeL8qUT3r2M= 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 1589436262325674.76415051371; Wed, 13 May 2020 23:04:22 -0700 (PDT) Received: from localhost ([::1]:41124 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6yi-0000i3-W5 for importer@patchew.org; Thu, 14 May 2020 02:04:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pR-0005S1-Em for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47339 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pQ-0001ff-E1 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:45 -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-358-5oNYb_-TPKCA1EUKeFWrmA-1; Thu, 14 May 2020 01:54:40 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E46B184194F; Thu, 14 May 2020 05:54:39 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0106D6A977; Thu, 14 May 2020 05:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435683; 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=elYehREd0a/oOvrSyCX6VUdw8yTEwHtHM2XKJOrHQzQ=; b=WZBUF+h9UyaYcnRW4tPs4zSyQ8XeXGVGopBr8PxUj0JDz2nsIF+jOUTJse4H4QHTLLL5Gj ug1fwZ9NJgJy47Z4SNZQR1bWB/aLozGZIHMAJfy+qm5TIvdlOGYuOL5d8MZ04meTtRDwjc c7f8PtJ0uoGFyX0fk1kySzagmmOZhdY= X-MC-Unique: 5oNYb_-TPKCA1EUKeFWrmA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 16/32] python//qmp.py: re-absorb MonitorResponseError Date: Thu, 14 May 2020 01:53:47 -0400 Message-Id: <20200514055403.18902-17-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" When I initially split this out, I considered this more of a machine error than a QMP protocol error, but I think that's misguided. Move this back to qmp.py and name it QMPResponseError. Convert qmp.command() to use this exception type. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 15 +-------------- python/qemu/lib/qmp.py | 17 +++++++++++++++-- scripts/render_block_graph.py | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 2f94c851ed..c31bf7cabb 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -48,19 +48,6 @@ class QEMUMachineAddDeviceError(QEMUMachineError): """ =20 =20 -class MonitorResponseError(qmp.QMPError): - """ - Represents erroneous QMP monitor reply - """ - def __init__(self, reply): - try: - desc =3D reply["error"]["desc"] - except KeyError: - desc =3D reply - super().__init__(desc) - self.reply =3D reply - - class QEMUMachine: """ A QEMU VM @@ -433,7 +420,7 @@ def command(self, cmd, conv_keys=3DTrue, **args): if reply is None: raise qmp.QMPError("Monitor is closed") if "error" in reply: - raise MonitorResponseError(reply) + raise qmp.QMPResponseError(reply) return reply["return"] =20 def get_qmp_event(self, wait=3DFalse): diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 911da59888..82f86b4e45 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -61,6 +61,19 @@ class QMPTimeoutError(QMPError): """ =20 =20 +class QMPResponseError(QMPError): + """ + Represents erroneous QMP monitor reply + """ + def __init__(self, reply: QMPMessage): + try: + desc =3D reply['error']['desc'] + except KeyError: + desc =3D reply + super().__init__(desc) + self.reply =3D reply + + class QEMUMonitorProtocol: """ Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and = then @@ -250,8 +263,8 @@ def command(self, cmd, **kwds): Build and send a QMP command to the monitor, report errors if any """ ret =3D self.cmd(cmd, kwds) - if "error" in ret: - raise Exception(ret['error']['desc']) + if 'error' in ret: + raise QMPResponseError(ret) return ret['return'] =20 def pull_event(self, wait=3DFalse): diff --git a/scripts/render_block_graph.py b/scripts/render_block_graph.py index 8048d9fbbe..332ab49a91 100755 --- a/scripts/render_block_graph.py +++ b/scripts/render_block_graph.py @@ -26,7 +26,7 @@ =20 sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python')) from qemu.lib import QEMUMonitorProtocol -from qemu.lib.machine import MonitorResponseError +from qemu.lib.qmp import QMPResponseError =20 =20 def perm(arr): @@ -103,7 +103,7 @@ def command(self, cmd): reply =3D json.loads(subprocess.check_output(ar)) =20 if 'error' in reply: - raise MonitorResponseError(reply) + raise QEMUResponseError(reply) =20 return reply['return'] =20 --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436348; cv=none; d=zohomail.com; s=zohoarc; b=fRkVNb9TZRVkfNf6a41f4QrAUd0ue2toh/DzyJ248G2SigranNqMMFGFSMXANxDcc566W9Gfg/8wHRx+7xaKvNV322IUzt5LL2RzMytLcq56no0B2nRXNUvpCNVabWHFwFCJqvdAoSZcv6FAJhQT9xe0WWiVNfjBjVwXOGLkH4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436348; 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=1eUmzzQu8a5o0hG7jybwr3x5Au0DzMhehJQhftFqcec=; b=LX8BRGHtMfJ8su7uesaLa5+lLg5VqV1O3kSMaQKpr165X3EXaHwpaUoMjP7/oG0ciKycyjxQ+N+4dp7fSY+Q6LysLnSgDbXKFtBxU4uEidvez+Oern8Oh/n//QrifA/npBazWu6tI0b8qmiDHqcKWdKGnEIMWBuGQ5x7n5ajVUk= 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 158943634863630.78785979099257; Wed, 13 May 2020 23:05:48 -0700 (PDT) Received: from localhost ([::1]:47608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ707-0004Dk-DE for importer@patchew.org; Thu, 14 May 2020 02:05:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pS-0005Tz-7v for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:46 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:57396 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pR-0001fu-An for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:45 -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-431-PJwNSWEuM1utyleX3BIXag-1; Thu, 14 May 2020 01:54:42 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8567461; Thu, 14 May 2020 05:54:40 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B2A47D951; Thu, 14 May 2020 05:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435684; 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=1eUmzzQu8a5o0hG7jybwr3x5Au0DzMhehJQhftFqcec=; b=W0uwU29oljMxdASLDlRAich+xt9PeUmA3121RuoroAsK+0HIpxN0vXNdIZrKnZ5cOPHOYS whaWouopA0JjDJBKmS66jVRezUfRdHxxE3V/iOFC8T/KKgX/G4xVO1zca4xlVaFJLGOAGc D8q85c2yUlaImj7hjvoI7swvy827naM= X-MC-Unique: PJwNSWEuM1utyleX3BIXag-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 17/32] python//qmp.py: Do not return None from cmd_obj Date: Thu, 14 May 2020 01:53:48 -0400 Message-Id: <20200514055403.18902-18-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" This makes typing the qmp library difficult, as it necessitates wrapping Optional[] around the type for every return type up the stack. At some point, it becomes difficult to discern or remember why it's None instead of the expected object. Use the python exception system to tell us exactly why we didn't get an object. Remove this special-cased return. Signed-off-by: John Snow --- python/qemu/lib/qmp.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 82f86b4e45..0036204218 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -224,22 +224,18 @@ def accept(self, timeout=3D15.0): self.__sockfile =3D self.__sock.makefile(mode=3D'r') return self.__negotiate_capabilities() =20 - def cmd_obj(self, qmp_cmd): + def cmd_obj(self, qmp_cmd: QMPMessage) -> QMPMessage: """ Send a QMP command to the QMP Monitor. =20 @param qmp_cmd: QMP command to be sent as a Python dict - @return QMP response as a Python dict or None if the connection has - been closed + @return QMP response as a Python dict """ self.logger.debug(">>> %s", qmp_cmd) - try: - self.__sock.sendall(json.dumps(qmp_cmd).encode('utf-8')) - except OSError as err: - if err.errno =3D=3D errno.EPIPE: - return None - raise err + 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") self.logger.debug("<<< %s", resp) return resp =20 --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436204; cv=none; d=zohomail.com; s=zohoarc; b=j8ZL+JcmbRqQbv88NaoFzM+Qv7HLxObXC5lxDMyK+ghO+6TCa10FibFQ+s1yUwJkd8mptJde17evHgIMfQA9NWTUddrM0zxXAmtFwvOzYhtXoWe2irLkOECI2qMNQhj/othaHB2Vt4053dQ2c092kGYuWHt/5mWDRltGY0zaOTY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436204; 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=3E++9MHe5bimFNuj9ypg0xKkcNAm0KbyJmDUib9cNmo=; b=PQ28jIewGf8Cy0tR2zuYEh2L/ck2/cUkP/+2pKDwPal51NC2DmcPynn5AxPYGtwAAAc2fJdFLoc+zqZ0qGe2+Xf2yFcYb+FOECbP8PwXoS5/9OFgnZxgtwlkyPz7R6FtyW/depf9PufWZtLFdpwfcr/qIDbWcgAg3LYq1bJuxPs= 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 1589436204953977.4185657921216; Wed, 13 May 2020 23:03:24 -0700 (PDT) Received: from localhost ([::1]:37060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6xn-0007X2-Lj for importer@patchew.org; Thu, 14 May 2020 02:03:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pT-0005YM-SO for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:47 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:27978 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pS-0001gH-VI for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:47 -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-86-rAUj0_IrP0KtGygylZKPrg-1; Thu, 14 May 2020 01:54:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A72B1107ACCA; Thu, 14 May 2020 05:54:42 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20AF66A977; Thu, 14 May 2020 05:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435686; 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=3E++9MHe5bimFNuj9ypg0xKkcNAm0KbyJmDUib9cNmo=; b=QHIlKe6/gzPz4Jzsc6kPjFb75iOhq2MUK/hchsFjQEJSo8clIiEwzsUgPkrgFh6d3nnyYk hMRp0xGYL0vkT5o4B0c0+vJWL9h/0lT5Mu9UH5GQgFSZ2vDugayOnPrip7rno/Y11XAHud h7noU3iHORRGJdTufBclgs1FGnF3H50= X-MC-Unique: rAUj0_IrP0KtGygylZKPrg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 18/32] python//qmp.py: add casts to JSON deserialization Date: Thu, 14 May 2020 01:53:49 -0400 Message-Id: <20200514055403.18902-19-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 and python type hints are not powerful enough to properly describe JSON messages in Python 3.6. The best we can do, generally, is describe them as Dict[str, Any]. Add casts to coerce this type for static analysis; but do NOT enforce this type at runtime in any way. Note: Python 3.8 adds a TypedDict construct which allows for the description of more arbitrary Dictionary shapes. There is a third-party module, "Pydantic", which is compatible with 3.6 that can be used instead of the JSON library that parses JSON messages to fully-typed Python objects, and may be preferable in some cases. (That is well beyond the scope of this commit or series.) Signed-off-by: John Snow Acked-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qmp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 0036204218..e460234f2e 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -13,6 +13,7 @@ import logging from typing import ( Any, + cast, Dict, Optional, TextIO, @@ -129,7 +130,10 @@ def __json_read(self, only_event=3DFalse): data =3D self.__sockfile.readline() if not data: return None - resp =3D json.loads(data) + # By definition, any JSON received from QMP is a QMPMessage, + # and we are asserting only at static analysis time that it + # has a particular shape. + resp =3D cast(QMPMessage, json.loads(data)) if 'event' in resp: self.logger.debug("<<< %s", resp) self.__events.append(resp) @@ -261,7 +265,7 @@ def command(self, cmd, **kwds): ret =3D self.cmd(cmd, kwds) if 'error' in ret: raise QMPResponseError(ret) - return ret['return'] + return cast(QMPReturnValue, ret['return']) =20 def pull_event(self, wait=3DFalse): """ --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436782; cv=none; d=zohomail.com; s=zohoarc; b=VbdPcwk1ydDrnFF9RChBipgBhrp0bgvdJZc4zqBbEkYFJ/fFjNJbi5hNcBTe/um3LaYdskI4b55MFYLlasAnarDneaHPpm1Ny3sTKFB8pdnHnkKIKBUP1N6S3NF3EQGkWIcmQxIY1wY6XYPQUBfdsrh682yf1x43y/beDEOTpi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436782; 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=Cms2elH+4uyg7e8PjWNJQdMfCXIDcXzwsVXUQlKodMI=; b=fRRl+cAxHsFw97Smq+0pIgweVjR8RRyWUNEmGZ+wLxixLBFBn5gOcCRNqtGPLv2hE5BUfouhBOamnfIBKJSae7Zwdt6s7VFF5q1I5oKrv8gpgpwcOpIjrmUX+7/6iA8Nl0qoKCpZvq4YsUHhsuDc4fCeJk2aeZ26t8SWQu7GTdM= 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 1589436782833524.1674153242016; Wed, 13 May 2020 23:13:02 -0700 (PDT) Received: from localhost ([::1]:50312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ777-00011E-Kl for importer@patchew.org; Thu, 14 May 2020 02:13:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pn-0006Ag-Jg for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:07 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:44717 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pm-0001pR-Nj for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:07 -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-429-wXe8Y-HCODujVWYq8ZDegw-1; Thu, 14 May 2020 01:54:45 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A49D801504; Thu, 14 May 2020 05:54:44 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id D22286A977; Thu, 14 May 2020 05:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435706; 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=Cms2elH+4uyg7e8PjWNJQdMfCXIDcXzwsVXUQlKodMI=; b=JZf9SKSP8/KzLKpp8yXcWkUUFRG66/bcf2i73phtO8M216/v5rvW7LtB2cjshRscGtE3Qd OoSRGhvVBkC6lpCO+5o5O7h8/Q419EuR4uuYfKdTJ11YvUT+wmQrPbgDjHJNr5e4QJsq+a /GeECAY23cnE3FQj+bhksiaTLc5ZcZY= X-MC-Unique: wXe8Y-HCODujVWYq8ZDegw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 19/32] python//qmp.py: add QMPProtocolError Date: Thu, 14 May 2020 01:53:50 -0400 Message-Id: <20200514055403.18902-20-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" In the case that we receive a reply but are unable to understand it, use this exception name to indicate that case. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qmp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index e460234f2e..5fb16f4b42 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -62,6 +62,12 @@ class QMPTimeoutError(QMPError): """ =20 =20 +class QMPProtocolError(QMPError): + """ + QMP protocol error; unexpected response + """ + + class QMPResponseError(QMPError): """ Represents erroneous QMP monitor reply @@ -265,6 +271,10 @@ def command(self, cmd, **kwds): 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)) + ) return cast(QMPReturnValue, ret['return']) =20 def pull_event(self, wait=3DFalse): --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436185; cv=none; d=zohomail.com; s=zohoarc; b=eT8/JEJoaHx0vULWJF/CKi44VPgWicOsZKsve5XO9Q5tXrYjdUAa46TCYIgs8FzOM1P6+TrFzlITKOL3dag4Rt2SR9v8I/j/d4XkXODBA0NN5GG2spTQ9GJk3RShX81LtiS+NEpkU/xN8UXLkdNth00Nh2UXcZBQTpiUrZfZq3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436185; 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=bL6cC0ljly/wbLmslRqO+su0FKs1lFJp2Wid4hDE+q8=; b=WuKus/5yMxAdW5/XDu9VwJDUgzBAKX6X5T7gT/ZwqRvr+vAAvCWE7qhNDGsr3zsPFUO2hw3uLVz6JU1wEuslKTwwn1zAiw/ODGWcoN8IkDE0A20d/v33SRO4aj6IaMY/xis9B1Ls++ktGQmAhB6yVLxZMmZtRNtByEV3V5HpixE= 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 1589436185874184.25222873279313; Wed, 13 May 2020 23:03:05 -0700 (PDT) Received: from localhost ([::1]:35210 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6xU-0006lr-FC for importer@patchew.org; Thu, 14 May 2020 02:03:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pX-0005cl-BY for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:51 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51799 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pV-0001gg-Mc for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:51 -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-185-7I3zEvAlMtCmSzMHJo36Iw-1; Thu, 14 May 2020 01:54:47 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5DA4800053; Thu, 14 May 2020 05:54:45 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 656367D952; Thu, 14 May 2020 05:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435689; 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=bL6cC0ljly/wbLmslRqO+su0FKs1lFJp2Wid4hDE+q8=; b=HB3A6NxL6QtqboThhC+qUU57Nz2uGoyZBfL0Oh6NlR94Y2cO7yJEobO9trt44tNTFi0zB/ qefwC+yBQkfGE0al/1BgbYHCvh013nJBQHNAo559wHrLHMq3GWepefEg1l7VDhfBHoZFv4 AuFLTIdneOZ6zxnmp8hG6trR0UbDxC0= X-MC-Unique: 7I3zEvAlMtCmSzMHJo36Iw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 20/32] python//qmp.py: assert sockfile is not None Date: Thu, 14 May 2020 01:53:51 -0400 Message-Id: <20200514055403.18902-21-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" In truth, if you don't do this, you'll just get a TypeError exception. Now, you'll get an AssertionError. Is this tangibly better? No. Does mypy complain less? Yes. Signed-off-by: John Snow Acked-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qmp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/qemu/lib/qmp.py b/python/qemu/lib/qmp.py index 5fb16f4b42..1aefc00c93 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -132,6 +132,7 @@ def __negotiate_capabilities(self): raise QMPCapabilitiesError =20 def __json_read(self, only_event=3DFalse): + assert self.__sockfile is not None while True: data =3D self.__sockfile.readline() if not data: --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436281; cv=none; d=zohomail.com; s=zohoarc; b=mYUvT/GEdknmzY1r1nyzEYfeb1btwYhZpDyO16krmGiq4egEA1/8xETJVXQahe7MzR3vWfkTAW9PwsaG3D8E7NloG6fdaVbzShFqYHYkKCF3bpMboO3y8Uf65dqz6zuI71wzC8MTVIEx2NIiwZe3WPwSyZWJGpUNQke6ortYtUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436281; 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=/tVN0afalNgUBbGXwQsgXCGn6NurJEflGZeF3kN7Gek=; b=Vf1tibTVYpXeB/VXySpyEJ57z28O/5xUbjDKqoB9DQVNnpjt28bVmsoRXUjSz48PoN9MjTc4rmbjpp+bxqJ8nRvgY2jB3r0TgI4188ifxax5+ugZf9T8zoLMDubBWGjF6k57utYJtayvgz9TAczXXrKj/41Gk9WAAuwOldyAPr4= 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 1589436281705750.526312051442; Wed, 13 May 2020 23:04:41 -0700 (PDT) Received: from localhost ([::1]:42570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6z2-0001JO-Ao for importer@patchew.org; Thu, 14 May 2020 02:04:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pY-0005dG-4i for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:52 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:59871 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pX-0001gk-5P for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:51 -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-328-fsTI_4BEMVSSEUIoa571Pw-1; Thu, 14 May 2020 01:54:48 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5ECFF107ACF3; Thu, 14 May 2020 05:54:47 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id F16F36A977; Thu, 14 May 2020 05:54:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435690; 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=/tVN0afalNgUBbGXwQsgXCGn6NurJEflGZeF3kN7Gek=; b=XKXdom4ULknmZQzfTfoLzGp/ssk4STotexo502oqJ8xbRBUef+6+TfH3JGrPbS0XRTo43W IHWZoF1va8HdNmgbnALCPWx/So8xRhU25Ne3egc4z/2APV4UHGuTYVCr3bYIH5/eiJvQmT UUqVLwtSk9Bq06wt0BObE0UEpaSUUxA= X-MC-Unique: fsTI_4BEMVSSEUIoa571Pw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 21/32] python//machine.py: remove logging configuration Date: Thu, 14 May 2020 01:53:52 -0400 Message-Id: <20200514055403.18902-22-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Python 3.5 and above do not print a warning when logging is not configured. As a library, it's best practice to leave logging configuration to the client executable. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index c31bf7cabb..e92afe8649 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -110,9 +110,6 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, self._console_socket =3D None self._remove_files =3D [] =20 - # just in case logging wasn't configured by the main script: - logging.basicConfig() - def __enter__(self): return self =20 --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436305; cv=none; d=zohomail.com; s=zohoarc; b=guxHJu0P/O2Mq129Gqe8McJHh84pp7LuuBt9ijuWsXg2gW13iTqpIttTzkXNzRb9KW5mPlt8ARmXWT13UBeuHVHvXNUrxnmbMBqtQJMnQ6kt2cUaXhukhNl0A84NYQyDYrHpu0DyQbE6z1QG+yOI+huDJvNlQf9KWVbLIPE1DUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436305; 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=XTvCcLEcSSKlj034fIBunHGure74nzejEqOKq7vVirQ=; b=BBFv9/fAYBkAZGpZG7kV4Zxk4TFmy4QujkWLUuJuT+aht6etvayDikQNB40mEvMVuJsoxRHsV88olB8nhUcs2eiYxfvjnSpmXpE4SfKsld8Oe9eozXnxsOJIX79bwT+ffnlpDcRs3FAGnn9XQe705zwSuDcR4Ltpnv4Hp5UQKdQ= 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 1589436305293958.3679522131633; Wed, 13 May 2020 23:05:05 -0700 (PDT) Received: from localhost ([::1]:44538 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6zQ-0002PU-2F for importer@patchew.org; Thu, 14 May 2020 02:05:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pc-0005iP-Gt for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20877 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pa-0001hK-BO for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:55 -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-341-PKBE1P-WMBO_g13yVzEkTg-1; Thu, 14 May 2020 01:54:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0335380058A; Thu, 14 May 2020 05:54:49 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C5936A977; Thu, 14 May 2020 05:54:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435693; 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=XTvCcLEcSSKlj034fIBunHGure74nzejEqOKq7vVirQ=; b=MZlhAIZe+VoOQ5Dz21rdvdMStAPfuPhcXGqqsPliqcSmovvwCnFcbRD4RR3l31qfYEZ1iA 1JSwUJoAew8VdFq63XIeL/wqUlTwhJNL2Pa4i7JRMwKnIU1YHIFAhWOW2uHO0Nz8BvaCZ1 XPO4iunMekMxKXRrdYamxgo/1q5TIS0= X-MC-Unique: PKBE1P-WMBO_g13yVzEkTg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 22/32] python//machine.py: Fix monitor address typing Date: Thu, 14 May 2020 01:53:53 -0400 Message-Id: <20200514055403.18902-23-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 simply 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 --- python/qemu/lib/machine.py | 45 ++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index e92afe8649..6a4aea7725 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -24,10 +24,14 @@ import shutil import socket import tempfile -from typing import Optional, Type +from typing import ( + Optional, + Type, +) from types import TracebackType =20 from . import qmp +from .qmp import SocketAddrT =20 LOG =3D logging.getLogger(__name__) =20 @@ -61,7 +65,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): ''' Initialize a QEMUMachine @@ -84,8 +89,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 @@ -223,15 +234,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): @@ -256,14 +269,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.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436365; cv=none; d=zohomail.com; s=zohoarc; b=nOg8fjlUh/galG+fXbnZ2SpiCmdLgXnsTNT8kMOi3/QwLNOigxn5IRVrWElmn9fSK7Qt7muxIdZggivx55pVMkMXjo6kZ85wwyv/vPB5HUupevvKNM9qJWRRl0Aerp3Oot+OKK/hO+IMmyYDdMZo3Z9ewT8LGf6Njy+5AGs0RKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436365; 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=LyNnGb5wnG5ig4E783n/bEYrkUu8Fld2tzpEIGMwwYA=; b=azs77FwQsfeRr0qftAJ692EtlzCQCkIKsfefWfrDLwqZjWSLh+4bD2X0RT3UWq0trGRSl3Dlsdnm5C4CBcnkuFyLX74dboaz+xMHmNiuga50pr86Tpwc7Rea3guzj5IdEKqalJJx9XyGlI34PNgVG/3rYZJKuljf7N7GbK0WoSU= 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 1589436365933897.6961213107622; Wed, 13 May 2020 23:06:05 -0700 (PDT) Received: from localhost ([::1]:49000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ70O-0004qU-Ik for importer@patchew.org; Thu, 14 May 2020 02:06:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pb-0005hI-Qv for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:55 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49231 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pa-0001hD-5O for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:55 -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-42-NUQXSmuzPFa-UWlZDKErJg-1; Thu, 14 May 2020 01:54:51 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 949C48015CF; Thu, 14 May 2020 05:54:50 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F5CF6A977; Thu, 14 May 2020 05:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435693; 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=LyNnGb5wnG5ig4E783n/bEYrkUu8Fld2tzpEIGMwwYA=; b=Ial/gC62OMr8AqYwkXqaWe25EWVhzO/uLj7FOOaqe8C0be6l7ogW9vHzlTQdAgYuzpHMkw ugiU6/PPMO7xdv0b/BMmP/ru3gxaiYES1IrGjfA0/09g2BdvHmhSxhkfSiPPp3zPAPgwPU 9F4WVUNDx7RLpTsfSuCfGFbUPWnG+kI= X-MC-Unique: NUQXSmuzPFa-UWlZDKErJg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 23/32] python//machine.py: reorder __init__ Date: Thu, 14 May 2020 01:53:54 -0400 Message-Id: <20200514055403.18902-24-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/machine.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 6a4aea7725..beb31be453 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -80,38 +80,43 @@ def __init__(self, binary, args=3DNone, wrapper=3DNone,= name=3DNone, @param socket_scm_helper: helper program, required for send_fd_scm= () @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 + + # 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 --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436445; cv=none; d=zohomail.com; s=zohoarc; b=YzSVO8ctYbHEV10nLL7MYbv5ARQ2RuDXHm8dgxSbAEpC171v8FGWLJu5C/3QwIw50AIZIW5mckGq8q4ZQOHMPCFxi8EImtGIQ5io3yxrUDCXT5NLkzShdhZ1hP3n9rW5gZlzkL7RGF9mh4bm4Dn2mPmsSD9OQze1kiRLYCEbVUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436445; 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=xH9h79K9jzniNFwU6uOjZ7Io60DvQjvbrnAcs97s0e8=; b=nPuc/11U2nfRbBz6PhlbzZAhgpmN/Li1n9i0YPwCOGzZx36JVz6nqTvCQtCqdv+c6CDlK1eCUIbRZN72jKF31/c18R6/MQYVSBGsw9uKMzfBv+gdFTbo7BZa/uY3hKAoFNkoDZHlgS72UkXLY6UmqJBpX/Vd8TlRaqL7d/WMvvE= 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 1589436445131417.1902939282335; Wed, 13 May 2020 23:07:25 -0700 (PDT) Received: from localhost ([::1]:55396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ71f-0007QH-T3 for importer@patchew.org; Thu, 14 May 2020 02:07:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pd-0005kA-5r for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40528 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pb-0001he-VI for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:56 -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-219-_OzZzZtnO9yqgmOe5CqRpg-1; Thu, 14 May 2020 01:54:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 258CA107ACCA; Thu, 14 May 2020 05:54:52 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE46F7D930; Thu, 14 May 2020 05:54:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435694; 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=xH9h79K9jzniNFwU6uOjZ7Io60DvQjvbrnAcs97s0e8=; b=H1MqDOWSx++SPBUZ6s3SlkC+VfJESqCNRk94I++kVvwvNwYZphcVXm81EyZFzpgXNW3s32 TJ1ZsEybTcW9OYRvcmiZQgA4hEwkFyb9XOS95IKZh9vLfL5Mu/Zpo0OGwUAe+v7LYJtil4 dd3hwX6JfBB27KnRRwfzJtmh7SxHbWI= X-MC-Unique: _OzZzZtnO9yqgmOe5CqRpg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 24/32] python//machine.py: Don't modify state in _base_args() Date: Thu, 14 May 2020 01:53:55 -0400 Message-Id: <20200514055403.18902-25-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 16 ++++++++++------ python/qemu/lib/qtest.py | 11 ++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index beb31be453..8548c7c32d 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -25,6 +25,7 @@ import socket import tempfile from typing import ( + List, Optional, Type, ) @@ -122,7 +123,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 [] =20 @@ -237,7 +240,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: @@ -255,9 +259,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]) @@ -273,6 +274,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) @@ -332,7 +336,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/lib/qtest.py b/python/qemu/lib/qtest.py index 4c88590eb0..a8be0c782f 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -19,7 +19,11 @@ =20 import socket import os -from typing import Optional, TextIO +from typing import ( + List, + Optional, + TextIO, +) =20 from .machine import QEMUMachine =20 @@ -111,8 +115,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.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436466; cv=none; d=zohomail.com; s=zohoarc; b=kQ4yUG0DHohkF5V//gW3FaaaSX/lBW/PxvuBpslxWjhrmDgw9WjXHZMWJ83OdBClQypyEThoWTwNN73t/Exx3BJHVGv7FN48rtZu2Fp6iclGranpRV/YjJckFMZmffQ4x/NWyQQNPHxoq8TpDJmcpyUlIVh+6NbZIGHiU8YVrvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436466; 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=r78YIUi5EF3+10yAnst7esoBjnzAwGVfqgCglUH45E4=; b=k7W/VGKbrWbJa617phrVo20ps2I9GeK7myyEbScUyrTbG3sSUpx+NktckKk+/1a86hudtIL2tGLjTDtjtTff/FqbS6eCtjGrszEKIps2ynoO6LNTI5ZeGEX2F7dAkje2Xy31/SA0e8/BDGsrweZeix9EVkqbzZWvA9+WFB8fiEU= 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 1589436466868990.8811675264179; Wed, 13 May 2020 23:07:46 -0700 (PDT) Received: from localhost ([::1]:57268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ721-0008A6-L2 for importer@patchew.org; Thu, 14 May 2020 02:07:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pf-0005o7-2C for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:59 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:53114 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pe-0001iv-8X for qemu-devel@nongnu.org; Thu, 14 May 2020 01:54:58 -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-332-0KkirazrNSCimaZB9Sv-6w-1; Thu, 14 May 2020 01:54:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2F76107ACF5; Thu, 14 May 2020 05:54:53 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5189B6A977; Thu, 14 May 2020 05:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435697; 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=r78YIUi5EF3+10yAnst7esoBjnzAwGVfqgCglUH45E4=; b=EV6JOPg31MTS4xvojjAX6T6vQXDvJq3d+4eB09LvtRIS4Oe37hv/0vAWLiH67txfSfCwgn s/brRdiZFNJpiDc1QQloHVVZ9CFQl1goKYb6Wbh1oH3DeRDkbOBlSZV9hB0jr+VoskwFRx XkyDJ0KcclrUShF14FdMwN8btj4SrUA= X-MC-Unique: 0KkirazrNSCimaZB9Sv-6w-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 25/32] python//machine.py: Handle None events in event_wait Date: Thu, 14 May 2020 01:53:56 -0400 Message-Id: <20200514055403.18902-26-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 8548c7c32d..61ee3a0e81 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -32,7 +32,7 @@ from types import TracebackType =20 from . import qmp -from .qmp import SocketAddrT +from .qmp import SocketAddrT, QMPMessage =20 LOG =3D logging.getLogger(__name__) =20 @@ -519,6 +519,8 @@ def _match(event): return True return False =20 + event: Optional[QMPMessage] + # Search cached events for event in self._events: if _match(event): @@ -528,6 +530,8 @@ def _match(event): # Poll for new events while True: event =3D self._qmp.pull_event(wait=3Dtimeout) + if event is None: + break if _match(event): return event self._events.append(event) --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436035; cv=none; d=zohomail.com; s=zohoarc; b=NXZ9pgVgFWWpdFrAfg4m1Bo5dvsCxbRdvxIT8swyMOFVXo8vVCXJPEcR4C41xTCw50lGkoQ+RNSzNL5wztcLbrxtBW17qlS/j6p57nMRZXU14HQJRisjuQYOyEyr4LBpTWPQuUamWuevZNg4QA4b/02vGUeTjpxj1alMzB+IYt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436035; 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=uumDVo9FnEv61j8m5KShndosRNbqze6oP9Q3Z3/w+KU=; b=PO+QNGwT86hCniPLi4v1eqPDifNEgCgD+4NYjZRCsaIJv9ZjgyPlCbQRv8NP8iK0HYjXa5GPEDFvTESuFYtus6lOqvYUCH8dqt18x2iA6FEw4cZWaO+kZrgFy3yvubrNRp0x6LAJGBWrVdxk4iwBc7eSAPbhX/gFbJnwPZMAwRc= 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 1589436035268396.0185739987703; Wed, 13 May 2020 23:00:35 -0700 (PDT) Received: from localhost ([::1]:53084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6v4-0001hX-0j for importer@patchew.org; Thu, 14 May 2020 02:00:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ph-0005ty-4W for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:01 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:52371 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pg-0001k8-78 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:00 -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-351-r54TSQmtPPWggm9pg6Bk8w-1; Thu, 14 May 2020 01:54:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BE91BFC2; Thu, 14 May 2020 05:54:55 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF9DE7D951; Thu, 14 May 2020 05:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435699; 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=uumDVo9FnEv61j8m5KShndosRNbqze6oP9Q3Z3/w+KU=; b=U4L8GZykgwxFi/ZbByDLLy+3wEcI98SYUq3HFGiZmlFFq61QXJ+d9hgFNDt3wT4bMokSnZ RB2ATg2jdWqBbR/H+cYciu+mhiBA1IULi8LmRAEH7wn+z2jBAY4R4G373ypTuMD/j86X/B 0v8q4udhOy5QzL7OczFVHfEC4iZ0EAI= X-MC-Unique: r54TSQmtPPWggm9pg6Bk8w-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 26/32] python//machine.py: use qmp.command Date: Thu, 14 May 2020 01:53:57 -0400 Message-Id: <20200514055403.18902-27-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 61ee3a0e81..34e6b6f9e9 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -25,6 +25,8 @@ import socket import tempfile from typing import ( + Any, + Dict, List, Optional, Type, @@ -416,17 +418,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): @@ -435,12 +443,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.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436707; cv=none; d=zohomail.com; s=zohoarc; b=YStHp6xd6FM1b9lZfRNqSCZs/Ubd9EMm75ZDgf8VBREiQTyY8Nx+vEyPuB40rs+YBzlxpsJeu/1S/nO7QA027klp6FLkTKTuEoWicD+lX1AEq2HORlSn6KphJhIFunLEwEhoDW1ML8iE63/uD+jUQiOxEsBDklSqN+TNvMgLWaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436707; 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=lQgTC1NAlLzyKabzDAvHVB05mAI15cmOJ+EmihX/nkQ=; b=TnmgRTJEZpJkc9FKR5E6PssTnjWggw69t6bX1rpdd/rw9Vk0mLYE+Fv3igZAbt3pSLuGrKYqg14Mu+FVLBRPrgN10OL2kLBnton1i3FbaiDAhxdRfQjtMtjVXVQjNRkWvIUJgcH3/WSfmh+s6GYQ+40/0LSPTKjciWeHG8rNwOo= 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 1589436707742722.2764181236333; Wed, 13 May 2020 23:11:47 -0700 (PDT) Received: from localhost ([::1]:44368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ75u-0006ae-F7 for importer@patchew.org; Thu, 14 May 2020 02:11:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pk-00063V-T4 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:04 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:51630 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pi-0001mj-Rl for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:04 -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-496-BEoKkuYpMfaWbFsVQezdLg-1; Thu, 14 May 2020 01:54:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E59401841958; Thu, 14 May 2020 05:54:56 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 890C06A977; Thu, 14 May 2020 05:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435702; 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=lQgTC1NAlLzyKabzDAvHVB05mAI15cmOJ+EmihX/nkQ=; b=gA5qrAYFr8Y60qdQXh+Pi4EkK1O9sdDKY/wVXl84UhS7bFCgK27Qor2787JeiW/HA3tOgm v2cYduC5nwrHTmvb75wrBchUNc0DDIP4LwJ6IdxEEwzH6voSBBrEEGMlh/Si8GEL6y5hnx 0Cge3tivohBQ1dvhEBUg4e/deBrXtIQ= X-MC-Unique: BEoKkuYpMfaWbFsVQezdLg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 27/32] python//machine.py: Add _qmp access shim Date: Thu, 14 May 2020 01:53:58 -0400 Message-Id: <20200514055403.18902-28-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index 34e6b6f9e9..dfa8449b62 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -117,7 +117,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 @@ -283,7 +283,7 @@ 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 @@ -416,7 +416,13 @@ def set_qmp_monitor(self, enabled=3DTrue): self._qmp_set =3D True else: self._qmp_set =3D False - self._qmp =3D None + self._qmp_connection =3D None + + @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.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436435; cv=none; d=zohomail.com; s=zohoarc; b=QrbPVfUEytMVwaMPvEyOFhtcg/OzJLBOZbL1ut9ZaYpnnJBAdPGP1h52pihXPVYiKs14JDocFRLueErV+NeKm2EdXBgtToK322im4MbXHRwM1frsyMhV/OG0u2jVnvh4B+mH5NLhOi/sZBgUxYZ+Oxrh6Oo5Q1a/QyvIba5WBPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436435; 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=NtyIgPk9yeUBNgcGHwYRKWI3MzB5gYb3CrJMmsMyxXo=; b=eE/VvM6gQvrTpSdndj0G1mAzynmNZNLXApKKm3QPXcyPYdB1+LbA8djJcCwboAxMx2dZNxcc6fiuNVgy9iMAwiCpgkQjifUzBxk4/YA3A1/Q9DJVPQ6rAmqeSYtUKa1DvBZf39GGfqNZ02oR/nm7bG2n2a6MDoHNinSZHIkb5jE= 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 1589436435991265.9676247654884; Wed, 13 May 2020 23:07:15 -0700 (PDT) Received: from localhost ([::1]:54580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ71W-00074p-MY for importer@patchew.org; Thu, 14 May 2020 02:07:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pj-0005zF-4G for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43098 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pi-0001ls-00 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:02 -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-357-QADHVBuoODisHZU7Oz8InQ-1; Thu, 14 May 2020 01:54:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AA45107ACCA; Thu, 14 May 2020 05:54:58 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D7D56A977; Thu, 14 May 2020 05:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435701; 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=NtyIgPk9yeUBNgcGHwYRKWI3MzB5gYb3CrJMmsMyxXo=; b=S6hSpnK2veEzdxxqmfhUZVVrh/CMRc6noIyhTtuiVMy+nm1As639jL4wwdl6Mbuhq9iH5/ Splo7KRG0CUOYsMYvV9fcaf+sIFf2K1B//cH/3sivpw1ksi18xK9bdtkAS+KfaCyyU2J4m AYkVbAcDu6jHQHZXiHIw9+/YGp7NzHA= X-MC-Unique: QADHVBuoODisHZU7Oz8InQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 28/32] python//machine.py: fix _popen access Date: Thu, 14 May 2020 01:53:59 -0400 Message-Id: <20200514055403.18902-29-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index dfa8449b62..fb1a02b53c 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -113,7 +113,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. @@ -225,6 +225,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: @@ -235,7 +241,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: @@ -352,7 +358,7 @@ def wait(self): """ Wait for the VM to power off """ - self._popen.wait() + self._subp.wait() if self._qmp: self._qmp.close() self._load_io_log() @@ -371,11 +377,11 @@ def _issue_shutdown(self, has_quit: bool =3D False) -= > None: self._qmp.close() =20 try: - self._popen.wait(timeout=3D3) + self._subp.wait(timeout=3D3) except subprocess.TimeoutExpired: - self._popen.kill() + self._subp.kill() =20 - self._popen.wait() + self._subp.wait() =20 def shutdown(self, has_quit: bool =3D False) -> None: """ --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436591; cv=none; d=zohomail.com; s=zohoarc; b=btcNfAV6jF8H4Yl8LBNlJOEMLfspekt8Zj/qTqqP+0VbFFth8SP3bJH+e4SopXUq/YDFJHllpPNwVLotouMQ9pTGIOXUGy0PWVDlvaeNhaqPCBBkQh8bmIsHZFIU7QyH3uVomXP7ZfPFoCxuWqD4PFlHYsINAOf+DH1R+kJugzo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436591; 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=w/Aq4olAOOh/84KeoJb1PCtrN9Rk+oFeQNlT6Jw1j3s=; b=KIiwsSpvo85TvpU17XrYsXFM0W/MnOEysR2ml1xwlJAInjiRmSHFZWDDzx6bOfucMsmiNaghn1GDdeYg4tfRbm/T805XWOpV+jf+R7eMa+xbKnnT9KR85mO2Fb7aXkGPmevUlizyjVtttO+6d38HRr6N0Xif0xxE+VX/4q+8EtA= 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 1589436591545915.1152977455785; Wed, 13 May 2020 23:09:51 -0700 (PDT) Received: from localhost ([::1]:36000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ742-0002zX-5t for importer@patchew.org; Thu, 14 May 2020 02:09:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36668) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pk-00063e-Ri for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:04 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49398 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pj-0001oE-Tl for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:04 -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-40-Z0D9B03VM4WytFAP8s4ALg-1; Thu, 14 May 2020 01:55:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 128ACBFC0; Thu, 14 May 2020 05:55:00 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id A50BE6A977; Thu, 14 May 2020 05:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435703; 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=w/Aq4olAOOh/84KeoJb1PCtrN9Rk+oFeQNlT6Jw1j3s=; b=ELcyRkPpb+EUoR/3N7b+FxQ4sHS5HnDOvbMqa+CiKcLNLlzvW0JU0zsNZkQPjQ2POyzIaq 6jFEKhWKslGf6yJUPNeb/hwNK8lUSFYaENNDpo2WGULcKDi0UQF4Z8GCqS36LXmFxwh+Bh JWIkKhwAHKn1CfII5IVJPB25RXkxaHs= X-MC-Unique: Z0D9B03VM4WytFAP8s4ALg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest Date: Thu, 14 May 2020 01:54:00 -0400 Message-Id: <20200514055403.18902-30-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" It can be None; so add assertions or exceptions where appropriate to guard the access accordingly. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- python/qemu/lib/qtest.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/python/qemu/lib/qtest.py b/python/qemu/lib/qtest.py index a8be0c782f..05c63a1d58 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -126,7 +126,8 @@ def _pre_launch(self): super()._pre_launch() self._qtest =3D QEMUQtestProtocol(self._qtest_path, server=3DTrue) =20 - def _post_launch(self): + def _post_launch(self) -> None: + assert self._qtest is not None super()._post_launch() self._qtest.accept() =20 @@ -134,6 +135,13 @@ def _post_shutdown(self): super()._post_shutdown() self._remove_if_exists(self._qtest_path) =20 - def qtest(self, cmd): - '''Send a qtest command to guest''' + def qtest(self, cmd: str) -> str: + """ + Send a qtest command to the guest. + + :param cmd: qtest command to send + :return: qtest server response + """ + if self._qtest is None: + raise RuntimeError("qtest socket not available") return self._qtest.cmd(cmd) --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436166; cv=none; d=zohomail.com; s=zohoarc; b=ZNSh/BG6QyrgdS/qmvBdZp5FGEQzYnFHCa7IyX7JeChZptAwUvVCL8YYLekW4RPw99LyPkU7rRCoop3Ip3doXrYkiuvBGfoHHXXC6BoB/0zBEeNXfAOmk6G0uWYknt1KO2aw7GmH82/fEs56K3yJb5PBp5DFsjEfTVHSPniT2jU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436166; 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=qAjh6Nw65iVmFi5ZvQEKe7Hzst3+3DUhD23waIF+BD4=; b=KzGqLoSMn2WyJS2xKZ3Yv+6JlhrXe/8pz9BklFh36Oo3cQPUWNbecrL0Zk0F0G/a3oVQbWFQc6fFm6fzXTICKx1Ll2N1lMN0AFYHJZS0XViRGPFO+nZ5mXLtffPwMEh/janOMsDpCWNBWTaDmm37YnGCGDl8PkB76v+Ps4cn2J8= 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 1589436166496738.875986676358; Wed, 13 May 2020 23:02:46 -0700 (PDT) Received: from localhost ([::1]:33356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ6xB-00062V-45 for importer@patchew.org; Thu, 14 May 2020 02:02:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pm-00067v-Gb for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:06 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51729 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pl-0001ox-E6 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:06 -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-181-FTgmNXz1NDeUt3KrOWLf5A-1; Thu, 14 May 2020 01:55:02 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A8F09BFC2; Thu, 14 May 2020 05:55:01 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CC7B6A977; Thu, 14 May 2020 05:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435704; 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=qAjh6Nw65iVmFi5ZvQEKe7Hzst3+3DUhD23waIF+BD4=; b=M6Iltt/2lZ1S/8CrpGP0w1ESUUrKRyoOuPOqBo+WyEkTIk1p0UQZtU3A9TZJfoeo73lXQn fN8p8BX9zZrsad3EPXEndJ1eLGY5zXkG9Y9Lwpq7IbvjMzseoS1dJ40RDGGyV20pn3zSTP lEWHLmx+I0Mu98TZPjwxF7vLjNEFt4c= X-MC-Unique: FTgmNXz1NDeUt3KrOWLf5A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 30/32] python/qemu/lib: make 'args' style arguments immutable Date: Thu, 14 May 2020 01:54:01 -0400 Message-Id: <20200514055403.18902-31-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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 --- python/qemu/lib/machine.py | 30 +++++++++++++++++------------- python/qemu/lib/qtest.py | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/python/qemu/lib/machine.py b/python/qemu/lib/machine.py index fb1a02b53c..ec2bb28b86 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -18,6 +18,7 @@ # =20 import errno +from itertools import chain import logging import os import subprocess @@ -29,6 +30,8 @@ Dict, List, Optional, + Sequence, + Tuple, Type, ) from types import TracebackType @@ -67,8 +70,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): ''' @@ -86,14 +93,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() @@ -118,7 +118,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 @@ -323,7 +323,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 @@ -343,8 +343,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/lib/qtest.py b/python/qemu/lib/qtest.py index 05c63a1d58..ae4661d4d3 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -22,6 +22,7 @@ from typing import ( List, Optional, + Sequence, TextIO, ) =20 @@ -103,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: @@ -118,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.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436877; cv=none; d=zohomail.com; s=zohoarc; b=chwFSoTKwxzWy2jCDihjMbOY50INW67sC5Ioh88VxFv+EHn3zTjiaPvbslsTm1eXPZ7APCs9RX38SgnvbXqi2aKIHJYSFogy6G1XEPCUV9xUOPDBWSvNs4zywtbQ3KTjAqaD7aCRfcUNXM/iffV1C8ZXOKYIc6VepMVWooiMTBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436877; 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=2iMQPqEdXKj37G1Gsxqv6/OjI7WeI3/6pF7Qq/RZtcQ=; b=Qj5+GhxXPQWTqTzR+zEFgVYtaOzBag03rklEUah48t9l9Wlh4VSjHBnFIoLgUkEiLlmm9ZQdGxuyKdiLyBScD7lVU9Z28iqo3Beh+hiDew702Ewu2WCerTYnMFX1gblpmQU0bv9msQLehlmdJubFTVDCe+kzZEjOt31McS7rLzo= 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 1589436877960266.6505710462312; Wed, 13 May 2020 23:14:37 -0700 (PDT) Received: from localhost ([::1]:54642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ78e-0003Ql-Pl for importer@patchew.org; Thu, 14 May 2020 02:14:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pr-0006KV-5b for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:11 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57365 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pq-0001qL-B5 for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:10 -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-162-exeRrRpUMNuCCLWu5SSvUw-1; Thu, 14 May 2020 01:55:04 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 489C41054F8F; Thu, 14 May 2020 05:55:03 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6BDD6A977; Thu, 14 May 2020 05:55:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435709; 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=2iMQPqEdXKj37G1Gsxqv6/OjI7WeI3/6pF7Qq/RZtcQ=; b=M8XBv00zXq5vs8kRmmcYvW4anQPFwr4P+VO4K8JAgCnsii4ngADWDmJ6wjuZD2fXwbeg/1 HgcvBN166sTkJBca9PDtActYRQyoa23g1oXeA28KJL5ib0xaUM7CgOxEd2aHUb/sDUwEj6 S18MyRiXyTQVpFpPciU3R5pWSQzryMM= X-MC-Unique: exeRrRpUMNuCCLWu5SSvUw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 31/32] python/qemu: add mypy to Pipfile Date: Thu, 14 May 2020 01:54:02 -0400 Message-Id: <20200514055403.18902-32-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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" Signed-off-by: John Snow --- python/Pipfile | 1 + python/Pipfile.lock | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/python/Pipfile b/python/Pipfile index e396e56e06..80bd6c3188 100644 --- a/python/Pipfile +++ b/python/Pipfile @@ -6,6 +6,7 @@ verify_ssl =3D true [dev-packages] pylint =3D "=3D=3D2.5.0" flake8 =3D "*" +mypy =3D "*" =20 [packages] =20 diff --git a/python/Pipfile.lock b/python/Pipfile.lock index 15cd8a918f..085f23fe8a 100644 --- a/python/Pipfile.lock +++ b/python/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "58115144ace0f646b5c62da260fb4867ac0a0e485de3f5b0a56= c7854afa21f5b" + "sha256": "17a30ead8719d80349ff5473bda3133fd4559a4e83d3f9d6696= 31ac4b2171502" }, "pipfile-spec": 6, "requires": { @@ -79,6 +79,33 @@ ], "version": "=3D=3D0.6.1" }, + "mypy": { + "hashes": [ + "sha256:15b948e1302682e3682f11f50208b726a246ab4e6c1b39f926= 4a8796bb416aa2", + "sha256:219a3116ecd015f8dca7b5d2c366c973509dfb9a8fc97ef044= a36e3da66144a1", + "sha256:3b1fc683fb204c6b4403a1ef23f0b1fac8e4477091585e0c8c= 54cbdf7d7bb164", + "sha256:3beff56b453b6ef94ecb2996bea101a08f1f8a9771d3cbf498= 8a61e4d9973761", + "sha256:7687f6455ec3ed7649d1ae574136835a4272b65b3ddcf01ab8= 704ac65616c5ce", + "sha256:7ec45a70d40ede1ec7ad7f95b3c94c9cf4c186a32f6bacb179= 5b60abd2f9ef27", + "sha256:86c857510a9b7c3104cf4cde1568f4921762c8f9842e987bc0= 3ed4f160925754", + "sha256:8a627507ef9b307b46a1fea9513d5c98680ba09591253082b4= c48697ba05a4ae", + "sha256:8dfb69fbf9f3aeed18afffb15e319ca7f8da9642336348ddd6= cab2713ddcf8f9", + "sha256:a34b577cdf6313bf24755f7a0e3f3c326d5c1f4fe7422d1d06= 498eb25ad0c600", + "sha256:a8ffcd53cb5dfc131850851cc09f1c44689c2812d0beb954d8= 138d4f5fc17f65", + "sha256:b90928f2d9eb2f33162405f32dde9f6dcead63a0971ca8a1b5= 0eb4ca3e35ceb8", + "sha256:c56ffe22faa2e51054c5f7a3bc70a370939c2ed4de308c690e= 7949230c995913", + "sha256:f91c7ae919bbc3f96cd5e5b2e786b2b108343d1d7972ea130f= 7de27fdd547cf3" + ], + "index": "pypi", + "version": "=3D=3D0.770" + }, + "mypy-extensions": { + "hashes": [ + "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a= 299250a846f15d", + "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5= 343488a6c604a8" + ], + "version": "=3D=3D0.4.3" + }, "pycodestyle": { "hashes": [ "sha256:95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe= 3f6fac3491ae56", @@ -142,6 +169,14 @@ "markers": "implementation_name =3D=3D 'cpython' and python_ve= rsion < '3.8'", "version": "=3D=3D1.4.1" }, + "typing-extensions": { + "hashes": [ + "sha256:6e95524d8a547a91e08f404ae485bbb71962de46967e1b71a0= cb89af24e761c5", + "sha256:79ee589a3caca649a9bfd2a8de4709837400dfa00b6cc81962= a1e6a1815969ae", + "sha256:f8d2bd89d25bc39dabe7d23df520442fa1d8969b82544370e0= 3d88b5a591c392" + ], + "version": "=3D=3D3.7.4.2" + }, "wrapt": { "hashes": [ "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec= 1eb88e6d9b97d7" --=20 2.21.1 From nobody Fri Nov 14 16:37:27 2025 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=1589436954; cv=none; d=zohomail.com; s=zohoarc; b=RreLoTWKvFv12Bo5gwsP6tvVkAMhFVCxUefgDZszTDQ796yVatrGwrJ/RMH0xlwetKbik7U207celmnMBPJK+Mu+IWEb3fegjeGrUI2kCyiZ74zE5f74C5nEuLv7pmE5xChPSFpvE6+gP1I0KTuDALLMdTIzWaTiN+H83m5kwzE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589436954; 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=aZECHhV+TqMBrIwTO7CtRiDUPW4cHqkvQIRGtpY5qcc=; b=UubtbTTkr7gonFGAfuvSM4lytlIunzhOUr11EkaYtC/Mu52omBffHmuSFllLG1hG40ezjOXyq7CXnl8Z4SsPcttm1NJxj385f5N1GTDIKKHRcDQlVAf0IJ3rtLSNYHwBcmcwySfh3ABuLHJIrdGbiSoitD5EqQqkfXKQIs8cRRQ= 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 1589436954274369.6199655137848; Wed, 13 May 2020 23:15:54 -0700 (PDT) Received: from localhost ([::1]:58990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jZ79s-0005HG-1H for importer@patchew.org; Thu, 14 May 2020 02:15:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ6pu-0006V8-Tp for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55:14 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40870 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jZ6ps-0001r1-QG for qemu-devel@nongnu.org; Thu, 14 May 2020 01:55: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-209-NGbBqpWQOgOnsr5ZaCTvWw-1; Thu, 14 May 2020 01:55:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CEE6107ACF3; Thu, 14 May 2020 05:55:06 +0000 (UTC) Received: from probe.redhat.com (ovpn-113-9.rdu2.redhat.com [10.10.113.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75B706A977; Thu, 14 May 2020 05:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589435712; 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=aZECHhV+TqMBrIwTO7CtRiDUPW4cHqkvQIRGtpY5qcc=; b=ibPb0EOi30/Rv5/7rwAgry4NN28lGzYzACPpzXf9094U9LGTT++bYdMwi44QxhCbDrbofj RNT6ORX8/2VKutg3vJT4arOb6ZTdzXLBz69aRvaxrkpgjsSTrQo0mxqP4AvJzeRLKuvYom 9xvHbwEsftKtWAZkWgnAp+UbImL8/eU= X-MC-Unique: NGbBqpWQOgOnsr5ZaCTvWw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH RFC 32/32] python/qemu/lib: Add mypy type annotations Date: Thu, 14 May 2020 01:54:03 -0400 Message-Id: <20200514055403.18902-33-jsnow@redhat.com> In-Reply-To: <20200514055403.18902-1-jsnow@redhat.com> References: <20200514055403.18902-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/13 22:25:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, 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_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: Fam Zheng , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Markus Armbruster , Max Reitz , John Snow , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= 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. Signed-off-by: John Snow --- python/qemu/lib/accel.py | 8 ++-- python/qemu/lib/machine.py | 94 +++++++++++++++++++++----------------- python/qemu/lib/qmp.py | 44 ++++++++++-------- python/qemu/lib/qtest.py | 27 ++++++----- 4 files changed, 99 insertions(+), 74 deletions(-) diff --git a/python/qemu/lib/accel.py b/python/qemu/lib/accel.py index 7fabe62920..4325114e51 100644 --- a/python/qemu/lib/accel.py +++ b/python/qemu/lib/accel.py @@ -17,6 +17,7 @@ import logging import os import subprocess +from typing import List, Optional =20 LOG =3D logging.getLogger(__name__) =20 @@ -29,7 +30,7 @@ } =20 =20 -def list_accel(qemu_bin): +def list_accel(qemu_bin: str) -> List[str]: """ List accelerators enabled in the QEMU binary. =20 @@ -49,7 +50,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; @@ -72,7 +74,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/lib/machine.py b/python/qemu/lib/machine.py index ec2bb28b86..c84db2bf8f 100644 --- a/python/qemu/lib/machine.py +++ b/python/qemu/lib/machine.py @@ -27,6 +27,7 @@ import tempfile from typing import ( Any, + BinaryIO, Dict, List, Optional, @@ -37,7 +38,7 @@ from types import TracebackType =20 from . import qmp -from .qmp import SocketAddrT, QMPMessage +from .qmp import QMPMessage, QMPReturnValue, SocketAddrT =20 LOG =3D logging.getLogger(__name__) =20 @@ -60,7 +61,7 @@ class QEMUMachineAddDeviceError(QEMUMachineError): =20 class QEMUMachine: """ - A QEMU VM + A QEMU VM. =20 Use this object as a context manager to ensure the QEMU process terminates:: @@ -77,7 +78,8 @@ 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): + socket_scm_helper: Optional[str] =3D None, + sock_dir: Optional[str] =3D None): ''' Initialize a QEMUMachine =20 @@ -111,27 +113,27 @@ def __init__(self, self._remove_monitor_sockfile =3D True =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 [] =20 - def __enter__(self): + def __enter__(self) -> 'QEMUMachine': return self =20 def __exit__(self, @@ -140,14 +142,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 """ @@ -166,7 +169,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 @@ -210,7 +214,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 """ @@ -221,7 +225,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 @@ -231,19 +235,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() @@ -277,7 +281,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') @@ -295,11 +299,11 @@ def _pre_launch(self): nickname=3Dself._name ) =20 - def _post_launch(self): + def _post_launch(self) -> None: if self._qmp: self._qmp.accept() =20 - def _post_shutdown(self): + def _post_shutdown(self) -> None: if self._qemu_log_file is not None: self._qemu_log_file.close() self._qemu_log_file =3D None @@ -313,7 +317,7 @@ def _post_shutdown(self): while len(self._remove_files) > 0: self._remove_if_exists(self._remove_files.pop()) =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 @@ -337,7 +341,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 """ @@ -358,7 +362,7 @@ def _launch(self): close_fds=3DFalse) self._post_launch() =20 - def wait(self): + def wait(self) -> None: """ Wait for the VM to power off """ @@ -413,7 +417,7 @@ def shutdown(self, has_quit: bool =3D False) -> None: =20 self._launched =3D False =20 - def set_qmp_monitor(self, enabled=3DTrue): + def set_qmp_monitor(self, enabled: bool =3D True) -> None: """ Set the QMP monitor. =20 @@ -453,7 +457,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. @@ -462,7 +468,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 """ @@ -470,7 +476,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 """ @@ -481,7 +487,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 @@ -511,9 +517,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 @@ -523,7 +531,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 named event from QMP with a timeout. @@ -533,7 +543,7 @@ def events_wait(self, events, timeout=3D60.0): See event_match for details. timeout: QEMUMonitorProtocol.pull_event timeout parameter. """ - 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 @@ -558,20 +568,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 @@ -580,7 +590,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 @@ -611,7 +623,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/lib/qmp.py b/python/qemu/lib/qmp.py index 1aefc00c93..1ae535ddb3 100644 --- a/python/qemu/lib/qmp.py +++ b/python/qemu/lib/qmp.py @@ -15,6 +15,7 @@ Any, cast, Dict, + List, Optional, TextIO, Type, @@ -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/lib/qtest.py b/python/qemu/lib/qtest.py index ae4661d4d3..df6300cd4f 100644 --- a/python/qemu/lib/qtest.py +++ b/python/qemu/lib/qtest.py @@ -24,6 +24,8 @@ Optional, Sequence, TextIO, + Tuple, + Union, ) =20 from .machine import QEMUMachine @@ -43,7 +45,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: Union[Tuple[str, str], str], + server: bool =3D False): self._address =3D address self._sock =3D self._get_sock() self._sockfile: Optional[TextIO] =3D None @@ -51,14 +54,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 +70,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 +79,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 +90,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 +123,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 +135,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 +144,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.21.1