From patchwork Wed Nov 4 00:34:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A537CC4742C for ; Wed, 4 Nov 2020 00:44:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18646223C7 for ; Wed, 4 Nov 2020 00:44:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CTavUqjE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18646223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6uT-0006nr-24 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:44:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6mm-00061b-VA for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mi-0004ms-7h for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450179; 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=aRs9bWy/l+OS7Dmw/otXBWJQ78D/TeE5mmlSCOg0PRA=; b=CTavUqjEqnR4f93Wh53JJVMUfO+zmcirk5ob7AY3IYFUgGZsQ1ArSDq4VW7wILGFv/sYqU R8yWZA080pRa6daDqD/p4MbqPT9u9g2ZGkoCr7eAmQBBKnTiSVRehJkvCnwc8tJI9Uywt1 lS+ELpfWFEyq7tRwlEg5PWR4Wqbhc3c= 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-189-lbBUdxKmOVCwyaYgRb2fsA-1; Tue, 03 Nov 2020 19:36:14 -0500 X-MC-Unique: lbBUdxKmOVCwyaYgRb2fsA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 819366D596 for ; Wed, 4 Nov 2020 00:36:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EDAA55766; Wed, 4 Nov 2020 00:36:12 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 01/72] python/qmp: Add qom script rewrites Date: Tue, 3 Nov 2020 19:34:51 -0500 Message-Id: <20201104003602.1293560-2-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Inspired by qom-set, qom-get, qom-tree and qom-list; combine all four of those scripts into one script. A later addition of qom-fuse necessitates that some common features are split out and shared between them. Signed-off-by: John Snow --- python/qemu/qmp/qom.py | 207 ++++++++++++++++++++++++++++++++++ python/qemu/qmp/qom_common.py | 153 +++++++++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 python/qemu/qmp/qom.py create mode 100644 python/qemu/qmp/qom_common.py diff --git a/python/qemu/qmp/qom.py b/python/qemu/qmp/qom.py new file mode 100644 index 000000000000..912d1809e60d --- /dev/null +++ b/python/qemu/qmp/qom.py @@ -0,0 +1,207 @@ +""" +QEMU Object Model testing tools. + +usage: qom.py [-h] {set,get,list,tree} ... + +Query and manipulate QOM data + +optional arguments: + -h, --help show this help message and exit + +QOM commands: + {set,get,list,tree,fuse} + set Set a QOM property value + get Get a QOM property value + list List QOM properties at a given path + tree Show QOM tree from a given path +""" +## +# Copyright John Snow 2020, for Red Hat, Inc. +# Copyright IBM, Corp. 2011 +# +# Authors: +# John Snow +# Anthony Liguori +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +# +# Based on ./scripts/qmp/qom-[set|get|tree|list] +## + +import argparse +import sys + +from . import QMPResponseError +from .qom_common import QOMCommand + + +class QOMSet(QOMCommand): + """QOM Command - Set a property to a given value.""" + name = 'set' + help = 'Set a QOM property value' + + @classmethod + def configure_parser(cls, parser: argparse.ArgumentParser) -> None: + super().configure_parser(parser) + cls.add_path_prop_arg(parser) + parser.add_argument( + 'value', + metavar='', + action='store', + help='new QOM property value' + ) + + def __init__(self, args: argparse.Namespace): + super().__init__(args) + self.path, self.prop = args.path_prop.rsplit('.', 1) + self.value = args.value + + def run(self) -> int: + rsp = self.qmp.command( + 'qom-set', + path=self.path, + property=self.prop, + value=self.value + ) + print(rsp) + return 0 + + +class QOMGet(QOMCommand): + """QOM Command - Get a property's current value.""" + name = 'get' + help = 'Get a QOM property value' + + @classmethod + def configure_parser(cls, parser: argparse.ArgumentParser) -> None: + super().configure_parser(parser) + cls.add_path_prop_arg(parser) + + def __init__(self, args: argparse.Namespace): + super().__init__(args) + try: + tmp = args.path_prop.rsplit('.', 1) + except ValueError as err: + raise ValueError('Invalid format for .') from err + self.path = tmp[0] + self.prop = tmp[1] + + def run(self) -> int: + rsp = self.qmp.command( + 'qom-get', + path=self.path, + property=self.prop + ) + if isinstance(rsp, dict): + for key, value in rsp.items(): + print(f"{key}: {value}") + else: + print(rsp) + return 0 + + +class QOMList(QOMCommand): + """QOM Command - List the properties at a given path.""" + name = 'list' + help = 'List QOM properties at a given path' + + @classmethod + def configure_parser(cls, parser: argparse.ArgumentParser) -> None: + super().configure_parser(parser) + parser.add_argument( + 'path', + metavar='', + action='store', + help='QOM path', + ) + + def __init__(self, args: argparse.Namespace): + super().__init__(args) + self.path = args.path + + def run(self) -> int: + rsp = self.qom_list(self.path) + for item in rsp: + if item.child: + print(f"{item.name}/") + elif item.link: + print(f"@{item.name}/") + else: + print(item.name) + return 0 + + +class QOMTree(QOMCommand): + """QOM Command - Show the full tree below a given path.""" + name = 'tree' + help = 'Show QOM tree from a given path' + + @classmethod + def configure_parser(cls, parser: argparse.ArgumentParser) -> None: + super().configure_parser(parser) + parser.add_argument( + 'path', + metavar='', + action='store', + help='QOM path', + nargs='?', + default='/' + ) + + def __init__(self, args: argparse.Namespace): + super().__init__(args) + self.path = args.path + + def _list_node(self, path: str) -> None: + print(path) + items = self.qom_list(path) + for item in items: + if item.child: + continue + try: + rsp = self.qmp.command('qom-get', path=path, + property=item.name) + print(f" {item.name}: {rsp} ({item.type})") + except QMPResponseError as err: + print(f" {item.name}: ({item.type})") + print('') + for item in items: + if not item.child: + continue + if path == '/': + path = '' + self._list_node(f"{path}/{item.name}") + + def run(self) -> int: + self._list_node(self.path) + return 0 + + +def main() -> int: + """QOM script main entry point.""" + parser = argparse.ArgumentParser( + description='Query and manipulate QOM data' + ) + subparsers = parser.add_subparsers( + title='QOM commands', + dest='command' + ) + + for command in QOMCommand.__subclasses__(): + command.register(subparsers) + + args = parser.parse_args() + + if args.command is None: + parser.error('Command not specified.') + return 1 + + assert issubclass(args.cmd_class, QOMCommand) + cmd = args.cmd_class(args) + assert isinstance(cmd, QOMCommand) + return cmd.run() + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/python/qemu/qmp/qom_common.py b/python/qemu/qmp/qom_common.py new file mode 100644 index 000000000000..3890b247ae68 --- /dev/null +++ b/python/qemu/qmp/qom_common.py @@ -0,0 +1,153 @@ +""" +QOM Command abstractions. +""" +## +# Copyright John Snow 2020, for Red Hat, Inc. +# Copyright IBM, Corp. 2011 +# +# Authors: +# John Snow +# Anthony Liguori +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. +# +# Based on ./scripts/qmp/qom-[set|get|tree|list] +## + +import argparse +import os +from typing import ( + Any, + Dict, + List, + Optional, +) + +from . import QEMUMonitorProtocol + + +Subparsers = argparse._SubParsersAction # pylint: disable=protected-access + + +class ObjectPropertyInfo: + """ + Represents the return type from e.g. qom-list. + """ + def __init__(self, name: str, type_: str, + description: Optional[str] = None, + default_value: Optional[object] = None): + self.name = name + self.type = type_ + self.description = description + self.default_value = default_value + + @classmethod + def make(cls, value: Dict[str, Any]) -> 'ObjectPropertyInfo': + """ + Build an ObjectPropertyInfo from a Dict with an unknown shape. + """ + assert value.keys() >= {'name', 'type'} + assert value.keys() <= {'name', 'type', 'description', 'default-value'} + return cls(value['name'], value['type'], + value.get('description'), + value.get('default-value')) + + @property + def child(self) -> bool: + """Is this property a child property?""" + return self.type.startswith('child<') + + @property + def link(self) -> bool: + """Is this property a link property?""" + return self.type.startswith('link<') + + +class QOMCommand: + """ + Represents a QOM sub-command. + + :param args: Parsed arguments, as returned from parser.parse_args. + """ + name: str + help: str + + def __init__(self, args: argparse.Namespace): + if args.socket is None: + raise Exception("No QMP socket path or address given") + self.qmp = QEMUMonitorProtocol(args.socket) + self.qmp.connect() + + @classmethod + def register(cls, subparsers: Subparsers) -> None: + """ + Register this command with the argument parser. + + :param subparsers: argparse subparsers object, from "add_subparsers". + """ + subparser = subparsers.add_parser(cls.name, help=cls.help, + description=cls.help) + cls.configure_parser(subparser) + + @classmethod + def configure_parser(cls, parser: argparse.ArgumentParser) -> None: + """ + Configure a parser with this command's arguments. + + :param parser: argparse parser or subparser object. + """ + default_path = os.environ.get('QMP_SOCKET') + parser.add_argument( + '--socket', '-s', + dest='socket', + action='store', + help='QMP socket path or address (addr:port).' + ' May also be set via QMP_SOCKET environment variable.', + default=default_path + ) + parser.set_defaults(cmd_class=cls) + + @classmethod + def add_path_prop_arg(cls, parser: argparse.ArgumentParser) -> None: + """ + Add the . positional argument to this command. + + :param parser: The parser to add the argument to. + """ + parser.add_argument( + 'path_prop', + metavar='.', + action='store', + help="QOM path and property, separated by a period '.'" + ) + + def run(self) -> int: + """ + Run this command. + + :return: 0 on success, 1 otherwise. + """ + raise NotImplementedError + + def qom_list(self, path: str) -> List[ObjectPropertyInfo]: + """ + :return: a strongly typed list from the 'qom-list' command. + """ + rsp = self.qmp.command('qom-list', path=path) + # qom-list returns List[ObjectPropertyInfo] + assert isinstance(rsp, list) + return [ObjectPropertyInfo.make(x) for x in rsp] + + @classmethod + def entry_point(cls) -> int: + """ + Build this command's parser, parse arguments, and run the command. + + :return: `run`'s return code. + """ + parser = argparse.ArgumentParser(description=cls.help) + cls.configure_parser(parser) + args = parser.parse_args() + cmd = cls(args) + return cmd.run() From patchwork Wed Nov 4 00:34:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C1F3C2D0A3 for ; Wed, 4 Nov 2020 00:38:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBDF4223C7 for ; Wed, 4 Nov 2020 00:38:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P6htm2sO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBDF4223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6oa-0007t8-MX for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:38:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6ml-00060S-30 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29646) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mi-0004mp-BV for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450178; 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=DwvcW7jNpBKcFtSfGFunStKf7oby9QF8aWFLGmTigZ8=; b=P6htm2sO2nJh+hjh1MSjDaja2YdKdI0JZ5BPOM3T64CIKkh9Z0Aar62TcJypFVUkfnq6yG xNCPsdenOwVXdx47/enVzIt/b//Xw3Q46eEKer9y68oaP7MRnUXvfykXX7k5YYmimQ1ujq dq5l+ri28vGCcuuT3ZcyHyoDL84Xj2c= 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-547-3GElkm8JOMSGv7CsPXMHqA-1; Tue, 03 Nov 2020 19:36:15 -0500 X-MC-Unique: 3GElkm8JOMSGv7CsPXMHqA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E41B1804774 for ; Wed, 4 Nov 2020 00:36:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE0C855766; Wed, 4 Nov 2020 00:36:13 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 02/72] python/qmp: add qom script entry points Date: Tue, 3 Nov 2020 19:34:52 -0500 Message-Id: <20201104003602.1293560-3-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add the 'qom', 'qom-set', 'qom-get', 'qom-list', and 'qom-tree' scripts to the qemu.qmp package. When you install this package, these scripts will become available on your command line. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daudé --- python/setup.cfg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/setup.cfg b/python/setup.cfg index 2c12d9ab89b4..c8b7215996e9 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -28,6 +28,13 @@ devel = pylint >= 2.6.0 pytest >= 3.0.0 +[options.entry_points] +console_scripts = + qom = qemu.qmp.qom:main + qom-set = qemu.qmp.qom:QOMSet.entry_point + qom-get = qemu.qmp.qom:QOMGet.entry_point + qom-list = qemu.qmp.qom:QOMList.entry_point + qom-tree = qemu.qmp.qom:QOMTree.entry_point [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's From patchwork Wed Nov 4 00:34:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F7D2C2D0A3 for ; Wed, 4 Nov 2020 00:38:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85A3D223C7 for ; Wed, 4 Nov 2020 00:38:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IuLHDz0h" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85A3D223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6of-00084q-Cf for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:38:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6mn-00062q-LA for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mk-0004nS-Tx for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450182; 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=NtPqYDlMwDVDZ/3ryxoYSA5f/GpDjZdGVM7WpES8EFc=; b=IuLHDz0hB2SwydZrO0fVk/PLROJTmrbmOFSDPZ7now63q3ZsCIQRioWD7lj3CGN/OTOFHK WGVnWI9+J/kYFsfkwLoI+/Erg5fKef1m1IgnPwg6m2qPcUQCUKCLWyZ4vMtX5iu1+ZUwC6 wo/3J9EH56HCWHvDqsf4q1PTznRyiwg= 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-552-fjX5GEaMOs2HUcWIZUacmQ-1; Tue, 03 Nov 2020 19:36:20 -0500 X-MC-Unique: fjX5GEaMOs2HUcWIZUacmQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 180441028D50 for ; Wed, 4 Nov 2020 00:36:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CBE055766; Wed, 4 Nov 2020 00:36:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 04/72] scripts/qom-fuse: apply isort rules Date: Tue, 3 Nov 2020 19:34:54 -0500 Message-Id: <20201104003602.1293560-5-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hint: you can use symlinks to create qom_fuse.py in python/qemu/qmp/ and point to scripts/qom-fuse to apply the standard linting rules to this script. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daudé --- scripts/qmp/qom-fuse | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index 7c7cff8edfba..62deb9adb12d 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -13,14 +13,20 @@ # the COPYING file in the top-level directory. ## -import fuse, stat -from fuse import FUSE, FuseOSError, Operations -import os, posix, sys from errno import * +import os +import posix +import stat +import sys + +import fuse +from fuse import FUSE, FuseOSError, Operations + sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu.qmp import QEMUMonitorProtocol + fuse.fuse_python_api = (0, 2) class QOMFS(Operations): From patchwork Wed Nov 4 00:34:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38A19C2D0A3 for ; Wed, 4 Nov 2020 00:41:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B98ED223C7 for ; Wed, 4 Nov 2020 00:41:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GhqguQEk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B98ED223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6rO-00033A-G0 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:41:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6mo-00064p-J4 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mm-0004np-NP for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450183; 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=GoN6FiR7SXqCjEjgaiCivn1MHyl3p6NfHJ/cTW8wnyM=; b=GhqguQEkoWPfQILduoqDzHcK5vVTMjEVoTACadyZlWT2favFYaR1qFR2Fde38o4QhYjLmJ /dFqpSxJ7dv4Kh0C5JlneVeGJsD76VvDrTEkzJ6FnYdNWJp3LOK/AqgkALMv+WkaFGD1f4 luInRNoKstXDikpJ2bTktgZpcSsYFIM= 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-590-4gATjyqCMyehv5r0C8SepA-1; Tue, 03 Nov 2020 19:36:22 -0500 X-MC-Unique: 4gATjyqCMyehv5r0C8SepA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8671D1052519 for ; Wed, 4 Nov 2020 00:36:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4528255766; Wed, 4 Nov 2020 00:36:17 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 05/72] scripts/qom-fuse: apply flake8 rules Date: Tue, 3 Nov 2020 19:34:55 -0500 Message-Id: <20201104003602.1293560-6-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" flake8 still has one warning because of the sys.path hack, but that will be going away by the end of this patch series. Signed-off-by: John Snow --- scripts/qmp/qom-fuse | 81 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index 62deb9adb12d..ca30e928679e 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -9,13 +9,12 @@ # Anthony Liguori # Markus Armbruster # -# This work is licensed under the terms of the GNU GPL, version 2 or later. See -# the COPYING file in the top-level directory. +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. ## -from errno import * +from errno import ENOENT, EPERM import os -import posix import stat import sys @@ -29,6 +28,7 @@ from qemu.qmp import QEMUMonitorProtocol fuse.fuse_python_api = (0, 2) + class QOMFS(Operations): def __init__(self, qmp): self.qmp = qmp @@ -45,7 +45,7 @@ class QOMFS(Operations): def is_object(self, path): try: - items = self.qmp.command('qom-list', path=path) + self.qmp.command('qom-list', path=path) return True except: return False @@ -85,7 +85,7 @@ class QOMFS(Operations): path = '/' try: data = self.qmp.command('qom-get', path=path, property=prop) - data += '\n' # make values shell friendly + data += '\n' # make values shell friendly except: raise FuseOSError(EPERM) @@ -104,38 +104,44 @@ class QOMFS(Operations): def getattr(self, path, fh=None): if self.is_link(path): - value = { 'st_mode': 0o755 | stat.S_IFLNK, - 'st_ino': self.get_ino(path), - 'st_dev': 0, - 'st_nlink': 2, - 'st_uid': 1000, - 'st_gid': 1000, - 'st_size': 4096, - 'st_atime': 0, - 'st_mtime': 0, - 'st_ctime': 0 } + value = { + 'st_mode': 0o755 | stat.S_IFLNK, + 'st_ino': self.get_ino(path), + 'st_dev': 0, + 'st_nlink': 2, + 'st_uid': 1000, + 'st_gid': 1000, + 'st_size': 4096, + 'st_atime': 0, + 'st_mtime': 0, + 'st_ctime': 0 + } elif self.is_object(path): - value = { 'st_mode': 0o755 | stat.S_IFDIR, - 'st_ino': self.get_ino(path), - 'st_dev': 0, - 'st_nlink': 2, - 'st_uid': 1000, - 'st_gid': 1000, - 'st_size': 4096, - 'st_atime': 0, - 'st_mtime': 0, - 'st_ctime': 0 } + value = { + 'st_mode': 0o755 | stat.S_IFDIR, + 'st_ino': self.get_ino(path), + 'st_dev': 0, + 'st_nlink': 2, + 'st_uid': 1000, + 'st_gid': 1000, + 'st_size': 4096, + 'st_atime': 0, + 'st_mtime': 0, + 'st_ctime': 0 + } elif self.is_property(path): - value = { 'st_mode': 0o644 | stat.S_IFREG, - 'st_ino': self.get_ino(path), - 'st_dev': 0, - 'st_nlink': 1, - 'st_uid': 1000, - 'st_gid': 1000, - 'st_size': 4096, - 'st_atime': 0, - 'st_mtime': 0, - 'st_ctime': 0 } + value = { + 'st_mode': 0o644 | stat.S_IFREG, + 'st_ino': self.get_ino(path), + 'st_dev': 0, + 'st_nlink': 1, + 'st_uid': 1000, + 'st_gid': 1000, + 'st_size': 4096, + 'st_atime': 0, + 'st_mtime': 0, + 'st_ctime': 0 + } else: raise FuseOSError(ENOENT) return value @@ -146,8 +152,7 @@ class QOMFS(Operations): for item in self.qmp.command('qom-list', path=path): yield str(item['name']) + if __name__ == '__main__': - import os - fuse = FUSE(QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])), sys.argv[1], foreground=True) From patchwork Wed Nov 4 00:34:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F854C2D0A3 for ; Wed, 4 Nov 2020 00:46:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AE925223C7 for ; Wed, 4 Nov 2020 00:46:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hhjRIzzt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AE925223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6w3-0001gh-LW for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:45:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6ms-0006Bo-23 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mq-0004oP-9j for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450187; 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=fB1rH87GsDpMYD9z/NEMczfG2TJxteUGF9x5BkNa1OY=; b=hhjRIzztpRRXx76SitCnufDBv70LZ1rWZKwBzCW9VACx6yxlpQRofE0xgvdHr9m5ad2MwZ Zp937b6lExzZq2tyZnHWU+5QzWkSnWWfzeTHO4IyNPM4cuO0c3gaQBV5a3lRcKUnlbOUDL QKVDxAjHS0YFevBwtxuamkmpEMeWm98= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-529-ap_egA23MsC9IgMjNxH5FA-1; Tue, 03 Nov 2020 19:36:25 -0500 X-MC-Unique: ap_egA23MsC9IgMjNxH5FA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56AB0186842A for ; Wed, 4 Nov 2020 00:36:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D7A155766; Wed, 4 Nov 2020 00:36:20 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 07/72] scripts/qom-fuse: Apply pylint rules Date: Tue, 3 Nov 2020 19:34:57 -0500 Message-Id: <20201104003602.1293560-8-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" - Catch specific exceptions from QMP - Reraise errors with explicit context - method parameters should match parent's names Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daudé --- scripts/qmp/qom-fuse | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index ca30e928679e..805e99c8ecde 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -23,7 +23,7 @@ from fuse import FUSE, FuseOSError, Operations sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) -from qemu.qmp import QEMUMonitorProtocol +from qemu.qmp import QEMUMonitorProtocol, QMPResponseError fuse.fuse_python_api = (0, 2) @@ -47,7 +47,7 @@ class QOMFS(Operations): try: self.qmp.command('qom-list', path=path) return True - except: + except QMPResponseError: return False def is_property(self, path): @@ -59,7 +59,7 @@ class QOMFS(Operations): if item['name'] == prop: return True return False - except: + except QMPResponseError: return False def is_link(self, path): @@ -73,10 +73,10 @@ class QOMFS(Operations): return True return False return False - except: + except QMPResponseError: return False - def read(self, path, length, offset, fh): + def read(self, path, size, offset, fh): if not self.is_property(path): return -ENOENT @@ -86,13 +86,13 @@ class QOMFS(Operations): try: data = self.qmp.command('qom-get', path=path, property=prop) data += '\n' # make values shell friendly - except: - raise FuseOSError(EPERM) + except QMPResponseError as err: + raise FuseOSError(EPERM) from err if offset > len(data): return '' - return bytes(data[offset:][:length], encoding='utf-8') + return bytes(data[offset:][:size], encoding='utf-8') def readlink(self, path): if not self.is_link(path): From patchwork Wed Nov 4 00:34:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 471ECC2D0A3 for ; Wed, 4 Nov 2020 00:44:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB070223C7 for ; Wed, 4 Nov 2020 00:44:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gf5T5cSH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB070223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6uO-0006bf-L7 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:44:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6mr-0006Ap-BX for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mp-0004oI-HS for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450186; 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=DiMgE0UtyeBtSOs2ViahvnsUVOSuIpj0nZaYzc/xmlg=; b=Gf5T5cSH8NB3iJs9NFeT1Ev7K0NFULWv5S8976LGoBmwOSU4hak7pnbNhnCBQtaMiVD5MS QSakOesaDeQKyZy6X2NU673qZhbO9JSyS5FS3IZ6O/6l0S+Xi2xbd6ATUinNe/xhS+pRv6 4r4TS3keT0GYhY+k9LZvoEsBX+LKjhQ= 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-468-OzsU2WcHNFORJ4w_CEHVMQ-1; Tue, 03 Nov 2020 19:36:25 -0500 X-MC-Unique: OzsU2WcHNFORJ4w_CEHVMQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 321051016CF5 for ; Wed, 4 Nov 2020 00:36:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66FAC55766; Wed, 4 Nov 2020 00:36:21 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 08/72] scripts/qom-fuse: Add docstrings Date: Tue, 3 Nov 2020 19:34:58 -0500 Message-Id: <20201104003602.1293560-9-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The methods inherited from fuse don't need docstrings; that's up to fusepy to handle. Signed-off-by: John Snow --- scripts/qmp/qom-fuse | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index 805e99c8ecde..5b80da9df66b 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -1,7 +1,20 @@ #!/usr/bin/env python3 +""" +QEMU Object Model FUSE filesystem tool + +This script offers a simple FUSE filesystem within which the QOM tree +may be browsed, queried and edited using traditional shell tooling. + +This script requires the 'fusepy' python package; +you may install it by using ``pip3 install --user fusepy``. + +ENV: + QMP_SOCKET: Path to the QMP server socket + +Usage: + qom-fuse /mount/to/here +""" ## -# QEMU Object Model test tools -# # Copyright IBM, Corp. 2012 # Copyright (C) 2020 Red Hat, Inc. # @@ -30,6 +43,7 @@ fuse.fuse_python_api = (0, 2) class QOMFS(Operations): + """QOMFS implements fuse.Operations to provide a QOM filesystem.""" def __init__(self, qmp): self.qmp = qmp self.qmp.connect() @@ -37,6 +51,7 @@ class QOMFS(Operations): self.ino_count = 1 def get_ino(self, path): + """Get an inode number for a given QOM path.""" if path in self.ino_map: return self.ino_map[path] self.ino_map[path] = self.ino_count @@ -44,6 +59,7 @@ class QOMFS(Operations): return self.ino_map[path] def is_object(self, path): + """Is the given QOM path an object?""" try: self.qmp.command('qom-list', path=path) return True @@ -51,6 +67,7 @@ class QOMFS(Operations): return False def is_property(self, path): + """Is the given QOM path a property?""" path, prop = path.rsplit('/', 1) if path == '': path = '/' @@ -63,6 +80,7 @@ class QOMFS(Operations): return False def is_link(self, path): + """Is the given QOM path a link?""" path, prop = path.rsplit('/', 1) if path == '': path = '/' From patchwork Wed Nov 4 00:35:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15D8CC55179 for ; Wed, 4 Nov 2020 00:41:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A2A4B2242E for ; Wed, 4 Nov 2020 00:41:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OmRf2EQu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2A4B2242E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6rc-0003GF-NH for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:41:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6mz-0006I4-V5 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56807) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6mx-0004oy-CZ for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450194; 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=GGcU+WiqYF3cUrhrW7XyOR5inrltfoG0DI+PJ1gIrXQ=; b=OmRf2EQu+cuZgVnGPu6kVlkwJQaTwMEka5L74TmTq11lFujNbrxNihrYxxW9Q3obmNxTZc RDM0FGDxuGejwCp4EZLV9SE6mAvWe59WnBJF6T/M9zze/ASOP/f05NidCA3oSxIPBnKlbV j6+aDCH/vzTPMspsRbfCHr8jJfMKtrQ= 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-445-CXKWxVIJMkiP9Z5JPaeMZA-1; Tue, 03 Nov 2020 19:36:32 -0500 X-MC-Unique: CXKWxVIJMkiP9Z5JPaeMZA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B240876E3A for ; Wed, 4 Nov 2020 00:36:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 875DF55766; Wed, 4 Nov 2020 00:36:26 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 12/72] scripts/qom-fuse: add static type hints Date: Tue, 3 Nov 2020 19:35:02 -0500 Message-Id: <20201104003602.1293560-13-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Because fusepy does not have type hints, add some targeted warning suppressions. NOTE: Prior to this change, running 'mypy qemu' from the python directory worked OK, but only coincidentally. Going forward, you will need to run 'mypy -p qemu' instead. These invocation forms will be codified in a CI test soon. Signed-off-by: John Snow --- python/setup.cfg | 8 ++++++++ scripts/qmp/qom-fuse | 26 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/python/setup.cfg b/python/setup.cfg index c963d05527aa..831555552f16 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -47,6 +47,14 @@ python_version = 3.6 warn_unused_configs = True namespace_packages = True +[mypy-qemu.qmp.qom_fuse] +# fusepy has no type stubs: +allow_subclassing_any = True + +[mypy-fuse] +# fusepy has no type stubs: +ignore_missing_imports = True + [pylint.messages control] # Disable the message, report, category or checker with the given id(s). You # can either give multiple identifiers separated by comma (,) or put this diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse index b120b93391ba..22be36634967 100755 --- a/scripts/qmp/qom-fuse +++ b/scripts/qmp/qom-fuse @@ -39,7 +39,14 @@ from errno import ENOENT, EPERM import os import stat import sys -from typing import Dict +from typing import ( + IO, + Dict, + Iterator, + Mapping, + Optional, + Union, +) import fuse from fuse import FUSE, FuseOSError, Operations @@ -84,7 +91,7 @@ class QOMFuse(QOMCommand, Operations): self.fuse = FUSE(self, self.mount, foreground=True) return 0 - def get_ino(self, path): + def get_ino(self, path: str) -> int: """Get an inode number for a given QOM path.""" if path in self.ino_map: return self.ino_map[path] @@ -92,7 +99,7 @@ class QOMFuse(QOMCommand, Operations): self.ino_count += 1 return self.ino_map[path] - def is_object(self, path): + def is_object(self, path: str) -> bool: """Is the given QOM path an object?""" try: self.qom_list(path) @@ -100,7 +107,7 @@ class QOMFuse(QOMCommand, Operations): except QMPResponseError: return False - def is_property(self, path): + def is_property(self, path: str) -> bool: """Is the given QOM path a property?""" path, prop = path.rsplit('/', 1) if path == '': @@ -113,7 +120,7 @@ class QOMFuse(QOMCommand, Operations): except QMPResponseError: return False - def is_link(self, path): + def is_link(self, path: str) -> bool: """Is the given QOM path a link?""" path, prop = path.rsplit('/', 1) if path == '': @@ -126,7 +133,7 @@ class QOMFuse(QOMCommand, Operations): except QMPResponseError: return False - def read(self, path, size, offset, fh): + def read(self, path: str, size: int, offset: int, fh: IO[bytes]) -> bytes: if not self.is_property(path): raise FuseOSError(ENOENT) @@ -144,7 +151,7 @@ class QOMFuse(QOMCommand, Operations): return bytes(data[offset:][:size], encoding='utf-8') - def readlink(self, path): + def readlink(self, path: str) -> Union[bool, str]: if not self.is_link(path): return False path, prop = path.rsplit('/', 1) @@ -152,7 +159,8 @@ class QOMFuse(QOMCommand, Operations): return prefix + str(self.qmp.command('qom-get', path=path, property=prop)) - def getattr(self, path, fh=None): + def getattr(self, path: str, + fh: Optional[IO[bytes]] = None) -> Mapping[str, object]: if self.is_link(path): value = { 'st_mode': 0o755 | stat.S_IFLNK, @@ -196,7 +204,7 @@ class QOMFuse(QOMCommand, Operations): raise FuseOSError(ENOENT) return value - def readdir(self, path, fh): + def readdir(self, path: str, fh: IO[bytes]) -> Iterator[str]: yield '.' yield '..' for item in self.qom_list(path): From patchwork Wed Nov 4 00:35:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 319AEC2D0A3 for ; Wed, 4 Nov 2020 00:52:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 90399223C7 for ; Wed, 4 Nov 2020 00:52:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Uya+ymPn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90399223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka71z-0003iq-Gy for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:52:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nA-0006Lp-Cx for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54748) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6n1-0004pJ-5I for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450197; 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=8OUsqD1A5AmHCSv1ZS7ONZ7SFH5PBswPDcfSyVuf8AE=; b=Uya+ymPnmBUBShPYOVM6wuv2QxKxKcU3rRsTKSWFoftX1LZiyi2yfgrB5nvud/1i0pv7WA Me0I4OMlBJl7kGzLJk38ZA3EwdTw1pamHrukBbbIylOlxq04OVJOqZHSm308hc+HMKycAF /PTupmmjIESx1/BsJrq1tC+07WDWcPI= 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-193-VQN2NIf2POOQ-pBPfauNZA-1; Tue, 03 Nov 2020 19:36:35 -0500 X-MC-Unique: VQN2NIf2POOQ-pBPfauNZA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D6756D59C for ; Wed, 4 Nov 2020 00:36:29 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C6D1747C6; Wed, 4 Nov 2020 00:36:28 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 14/72] scripts/qom-fuse: add redirection shim to python/qemu/qmp/qom-fuse.py Date: Tue, 3 Nov 2020 19:35:04 -0500 Message-Id: <20201104003602.1293560-15-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" By leaving the script absent for a commit, git-blame travels to the new file instead of staying on the shim. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daudé --- scripts/qmp/qom-fuse | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 scripts/qmp/qom-fuse diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse new file mode 100755 index 000000000000..a58c8ef9793b --- /dev/null +++ b/scripts/qmp/qom-fuse @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) +from qemu.qmp.qom_fuse import QOMFuse + + +if __name__ == '__main__': + sys.exit(QOMFuse.entry_point()) From patchwork Wed Nov 4 00:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4D54C2D0A3 for ; Wed, 4 Nov 2020 00:48:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5BEC3223C7 for ; Wed, 4 Nov 2020 00:48:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iaDNhD9B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BEC3223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38542 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6y8-00057z-Ec for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:48:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6n5-0006KJ-7a for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6n1-0004pS-7o for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450198; 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=3QuQaF6iiaUBvHFsB5tFzilcDmfaadSV7wQWEbVMWB8=; b=iaDNhD9BuZGPs3onPDNs+IKETFmDHx71wFF7KG9iciE6wAtbwpWgXrGBjk8CxMdSVrqICi ACxJAsrbGiFKweTGx4ugk8Dl716cpa1vmGPCqFWgC6hc4XJC3lcGN7Xq/tsh5R2BAT4Vcb I7stQgov5LCWMqtefJP9esL9larYLeo= 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-514-UNPloPR3PwGBYVc2FyC8gg-1; Tue, 03 Nov 2020 19:36:36 -0500 X-MC-Unique: UNPloPR3PwGBYVc2FyC8gg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D396D9CC08 for ; Wed, 4 Nov 2020 00:36:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE03655766; Wed, 4 Nov 2020 00:36:29 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 15/72] python: add fuse command to 'qom' tools Date: Tue, 3 Nov 2020 19:35:05 -0500 Message-Id: <20201104003602.1293560-16-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- python/qemu/qmp/qom.py | 12 +++++++++++- python/setup.cfg | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/qemu/qmp/qom.py b/python/qemu/qmp/qom.py index 912d1809e60d..52e06a949ab3 100644 --- a/python/qemu/qmp/qom.py +++ b/python/qemu/qmp/qom.py @@ -1,7 +1,7 @@ """ QEMU Object Model testing tools. -usage: qom.py [-h] {set,get,list,tree} ... +usage: qom.py [-h] {set,get,list,tree,fuse} ... Query and manipulate QOM data @@ -14,6 +14,7 @@ get Get a QOM property value list List QOM properties at a given path tree Show QOM tree from a given path + fuse Mount a QOM tree as a FUSE filesystem """ ## # Copyright John Snow 2020, for Red Hat, Inc. @@ -36,6 +37,15 @@ from .qom_common import QOMCommand +try: + from .qom_fuse import QOMFuse +except ImportError: + # either fusepy isn't installed, or qom_fuse itself is broken. + pass +else: + assert issubclass(QOMFuse, QOMCommand) + + class QOMSet(QOMCommand): """QOM Command - Set a property to a given value.""" name = 'set' diff --git a/python/setup.cfg b/python/setup.cfg index a9a76784d45a..908e53527ddc 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -36,6 +36,7 @@ console_scripts = qom-get = qemu.qmp.qom:QOMGet.entry_point qom-list = qemu.qmp.qom:QOMList.entry_point qom-tree = qemu.qmp.qom:QOMTree.entry_point + qom-fuse = qemu.qmp.qom_fuse:QOMFuse.entry_point [flake8] extend-ignore = E722 # Prefer pylint's bare-except checks to flake8's From patchwork Wed Nov 4 00:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0485CC2D0A3 for ; Wed, 4 Nov 2020 00:46:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 693D9223C7 for ; Wed, 4 Nov 2020 00:46:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="g4lIx8Bg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 693D9223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6wB-00022c-BE for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:46:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6n7-0006Kq-C1 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:47 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27812) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6n3-0004pb-2t for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450198; 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=GEyKfqCOMtTbCFwo/NxuRRQTpPJP7N2yFgtZYCeRkL0=; b=g4lIx8BgGXgknqRUbpqoVFlIGuPMpotAtg5pBzwgpZB1FFsWcj044oKBfsPnF0+zgUbn/a JALh1POfiYL1BkfvAPRL919zFmd6OFnvOXnbNXcBzZFBLTjSja2kiZdARMMNfApoJxIExR rA+Dneecj9LNvnME3kLfnFnIfFUuGWQ= 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-241-D6a73BdXOxiYsKGaNoEzPg-1; Tue, 03 Nov 2020 19:36:37 -0500 X-MC-Unique: D6a73BdXOxiYsKGaNoEzPg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03A1B890771 for ; Wed, 4 Nov 2020 00:36:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E9055766; Wed, 4 Nov 2020 00:36:31 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 16/72] python: add optional fuse dependency Date: Tue, 3 Nov 2020 19:35:06 -0500 Message-Id: <20201104003602.1293560-17-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This can be opted into by installing "qemu[fuse]" instead of just "qemu". The package ought to work perfectly well with or without it. Signed-off-by: John Snow --- python/setup.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/setup.cfg b/python/setup.cfg index 908e53527ddc..4e1c638d72d5 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -29,6 +29,10 @@ devel = pytest >= 3.0.0 fusepy >= 2.0.4 +# Provides qom-fuse functionality +fuse = + fusepy >= 2.0.4 + [options.entry_points] console_scripts = qom = qemu.qmp.qom:main From patchwork Wed Nov 4 00:35:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1754FC2D0A3 for ; Wed, 4 Nov 2020 00:50:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 75F8F223C7 for ; Wed, 4 Nov 2020 00:50:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gZbWZzwu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 75F8F223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka70M-00009F-Fa for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:50:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nA-0006Ln-9s for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6n5-0004pp-0i for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450201; 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=R+u+kSqbdZS8FFJfGmxFCCtl4DlAAKyVCV72nA5+Fag=; b=gZbWZzwuXFrMYnmZeftM3u8X9b/vFySLqNSF90fcwd8ShV9i1BqlQGup6ej1fRSh7ZD98C OP5D9Y4gdMzGHBocZaqB9GVPjGo6FMYv9CyvGep7V4tPxRMX3bKZVXblgEsxxh1Uq4dQc9 CJMV0vM8p/8DKkb6VPRBNiCzSUo9JIk= 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-580-KDgQvT3GO4qZfRwQXeuUXQ-1; Tue, 03 Nov 2020 19:36:38 -0500 X-MC-Unique: KDgQvT3GO4qZfRwQXeuUXQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBF338BAF50 for ; Wed, 4 Nov 2020 00:36:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33FA255766; Wed, 4 Nov 2020 00:36:32 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 17/72] scripts/qemu-ga-client: apply isort rules Date: Tue, 3 Nov 2020 19:35:07 -0500 Message-Id: <20201104003602.1293560-18-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Hint: > ln -s scripts/qmp/qemu-ga-client python/qemu/qmp/qemu_ga_client.py > cd python > isort qemu Signed-off-by: John Snow --- scripts/qmp/qemu-ga-client | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index ce122984a9ca..ae71b30dfa43 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -36,10 +36,11 @@ # See also: https://wiki.qemu.org/Features/QAPI/GuestAgent # -import os -import sys import base64 +import os import random +import sys + sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp @@ -279,9 +280,9 @@ def main(address, cmd, args): if __name__ == '__main__': - import sys - import os import optparse + import os + import sys address = os.environ['QGA_CLIENT_ADDRESS'] if 'QGA_CLIENT_ADDRESS' in os.environ else None From patchwork Wed Nov 4 00:35:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6298C2D0A3 for ; Wed, 4 Nov 2020 00:54:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44C78223C7 for ; Wed, 4 Nov 2020 00:54:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BQgVyXkw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44C78223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35610 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka74F-0007Bh-C9 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:54:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nD-0006NY-Rq for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6n9-0004qD-Av for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450206; 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=zH9F/fE1H6BjT8CUqtLBJlNwoRHK1EiDge4D1sOBwrM=; b=BQgVyXkwYwaGIukNmGjI70QIrqu7o7LmehlUHZiUgS6CVEq05eUjg6oL8DwJ+fUB4seNkQ DoawepNI7OMWLwxLs6McxgQPSzUrJnmFpmnVnPKHAa9tS7d3ELT2CNLQwN0rtkeP41/wOu WXzV0as7jyCs8qEbXbEFDDN1jpMXceA= 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-24-ZRRLyHcnMlGGQXMCWDyWHg-1; Tue, 03 Nov 2020 19:36:44 -0500 X-MC-Unique: ZRRLyHcnMlGGQXMCWDyWHg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8AC541902EB1 for ; Wed, 4 Nov 2020 00:36:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70BC155766; Wed, 4 Nov 2020 00:36:35 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 20/72] scripts/qemu-ga-client: replace deprecated optparse with argparse Date: Tue, 3 Nov 2020 19:35:10 -0500 Message-Id: <20201104003602.1293560-21-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- scripts/qmp/qemu-ga-client | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index c4fbb6165d54..73d262e8beb4 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -37,8 +37,8 @@ # See also: https://wiki.qemu.org/Features/QAPI/GuestAgent # +import argparse import base64 -import optparse import os import random import sys @@ -255,7 +255,7 @@ def _cmd_reboot(client, args): commands = [m.replace('_cmd_', '') for m in dir() if '_cmd_' in m] -def main(address, cmd, args): +def send_command(address, cmd, args): if not os.path.exists(address): print('%s not found' % address) sys.exit(1) @@ -283,25 +283,23 @@ def main(address, cmd, args): globals()['_cmd_' + cmd](client, args) -if __name__ == '__main__': +def main(): address = os.environ.get('QGA_CLIENT_ADDRESS') - usage = ("%prog [--address=|]" - " [args...]\n") - usage += ': ' + ', '.join(commands) - parser = optparse.OptionParser(usage=usage) - parser.add_option('--address', action='store', type='string', - default=address, - help='Specify a ip:port pair or a unix socket path') - options, args = parser.parse_args() + parser = argparse.ArgumentParser() + parser.add_argument('--address', action='store', + default=address, + help='Specify a ip:port pair or a unix socket path') + parser.add_argument('command', choices=commands) + parser.add_argument('args', nargs='*') - address = options.address - if address is None: + args = parser.parse_args() + if args.address is None: parser.error('address is not specified') sys.exit(1) - if len(args) == 0: - parser.error('Less argument') - sys.exit(1) + send_command(args.address, args.command, args.args) - main(address, args[0], args[1:]) + +if __name__ == '__main__': + main() From patchwork Wed Nov 4 00:35:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E822C2D0A3 for ; Wed, 4 Nov 2020 00:56:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C2526206DF for ; Wed, 4 Nov 2020 00:56:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VUR0iSMh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2526206DF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka76M-0002Hh-RI for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:56:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nH-0006Q4-O3 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nB-0004qT-SW for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:36:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450209; 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=dMO+7r18+Q3UhJY6oz0UqEMA/RbbAsgceTEHl6F+zUU=; b=VUR0iSMh0N87jaTXxpLwe49O0yyLoQQKYmhV+IDu7lVCGFiC8T/aydUwVLCWklZzxK1ahC MuCY611VoUtLVChEr7NR97tFcwoFijRQZQcNuU2AhPWvBCwoVCpey/Yx6Pb1mvAJB8G7xZ EEJX+bc4x0W+5mNIx+Ylqr61mYs6KwM= 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-585-xPCAocIWMGqddjo95UrZ2g-1; Tue, 03 Nov 2020 19:36:46 -0500 X-MC-Unique: xPCAocIWMGqddjo95UrZ2g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AACB0102C7D2 for ; Wed, 4 Nov 2020 00:36:38 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EE8355766; Wed, 4 Nov 2020 00:36:37 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 22/72] scripts/qemu-ga-client: apply (most) pylint rules Date: Tue, 3 Nov 2020 19:35:12 -0500 Message-Id: <20201104003602.1293560-23-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" I'm only doing a very quick best-effort to preserve this script, to help keep it from breaking further. I think there are pending ideas swirling on the right way to implement better SDKs and better clients, and this script might be a handy reference for those discussions. It presents some interesting design problems, like static type safety when using an RPC-like mechanism. So; disable docstrings for now. If you would like to help improve this script, please add docstrings alongside any refactors or rejuvenations you might apply at that time. Signed-off-by: John Snow --- scripts/qmp/qemu-ga-client | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index 1061d2eb1437..59b91c78d884 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -40,6 +40,7 @@ See also: https://wiki.qemu.org/Features/QAPI/GuestAgent import argparse import base64 +import errno import os import random import sys @@ -49,6 +50,13 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp +# This script has not seen many patches or careful attention in quite +# some time. If you would like to improve it, please review the design +# carefully and add docstrings at that point in time. Until then: + +# pylint: disable=missing-docstring + + class QemuGuestAgent(qmp.QEMUMonitorProtocol): def __getattr__(self, name): def wrapper(**kwds): @@ -104,7 +112,8 @@ class QemuGuestAgentClient: return '\n'.join(msgs) - def __gen_ipv4_netmask(self, prefixlen): + @classmethod + def __gen_ipv4_netmask(cls, prefixlen): mask = int('1' * prefixlen + '0' * (32 - prefixlen), 2) return '.'.join([str(mask >> 24), str((mask >> 16) & 0xff), @@ -207,10 +216,12 @@ def _cmd_fstrim(client, args): def _cmd_ifconfig(client, args): + assert not args print(client.ifconfig()) def _cmd_info(client, args): + assert not args print(client.info()) @@ -239,6 +250,7 @@ def _cmd_suspend(client, args): def _cmd_shutdown(client, args): + assert not args client.shutdown() @@ -246,10 +258,12 @@ _cmd_powerdown = _cmd_shutdown def _cmd_halt(client, args): + assert not args client.shutdown('halt') def _cmd_reboot(client, args): + assert not args client.shutdown('reboot') @@ -269,8 +283,6 @@ def send_command(address, cmd, args): try: client = QemuGuestAgentClient(address) except OSError as err: - import errno - print(err) if err.errno == errno.ECONNREFUSED: print('Hint: qemu is not running?') From patchwork Wed Nov 4 00:35:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFB72C4742C for ; Wed, 4 Nov 2020 00:48:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 33C16223C7 for ; Wed, 4 Nov 2020 00:48:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TEmsIo21" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33C16223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka6yH-0005S0-8s for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:48:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nO-0006Wq-NF for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nG-0004qp-9Y for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450212; 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=J1bOwRUYZLBKMVaPFoMxnDf94dgyrlB8ksOfGc+OLXM=; b=TEmsIo212ogLMoxj7tVzi9IF8nK531fNe2JtXgMHJ44qa6RjycSq0Vnc9nhr53Qd/WcQtr W0lIvcanoHiIHO8uQj3i+zW37gIcYL1/3fp4TTWuQ0tIBqmc63sGik3SMXwveU3KP2o9ZO WbadpGYJZkhDW5pqEptuFubcpAGqB34= 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-19-jtcbjiIzNfShYGtSizN8zA-1; Tue, 03 Nov 2020 19:36:50 -0500 X-MC-Unique: jtcbjiIzNfShYGtSizN8zA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5FA2B1018F7D for ; Wed, 4 Nov 2020 00:36:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51E2955766; Wed, 4 Nov 2020 00:36:40 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 24/72] scripts/qmp/qemu-ga-client: add mypy type hints Date: Tue, 3 Nov 2020 19:35:14 -0500 Message-Id: <20201104003602.1293560-25-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This script is in slightly rough shape, but it still works. A lot of care went into its initial development. In good faith, I'm updating it to the latest Python coding standards. If there is in interest in this script, though, I'll be asking for a contributor to take care of it further. Signed-off-by: John Snow --- scripts/qmp/qemu-ga-client | 89 +++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/scripts/qmp/qemu-ga-client b/scripts/qmp/qemu-ga-client index 59b91c78d884..3e617e7e7abe 100755 --- a/scripts/qmp/qemu-ga-client +++ b/scripts/qmp/qemu-ga-client @@ -44,10 +44,18 @@ import errno import os import random import sys +from typing import ( + Any, + Callable, + Dict, + Optional, + Sequence, +) sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp +from qemu.qmp import SocketAddrT # This script has not seen many patches or careful attention in quite @@ -58,18 +66,18 @@ from qemu import qmp class QemuGuestAgent(qmp.QEMUMonitorProtocol): - def __getattr__(self, name): - def wrapper(**kwds): + def __getattr__(self, name: str) -> Callable[..., Any]: + def wrapper(**kwds: object) -> object: return self.command('guest-' + name.replace('_', '-'), **kwds) return wrapper class QemuGuestAgentClient: - def __init__(self, address): + def __init__(self, address: SocketAddrT): self.qga = QemuGuestAgent(address) self.qga.connect(negotiate=False) - def sync(self, timeout=3): + def sync(self, timeout: Optional[float] = 3) -> None: # Avoid being blocked forever if not self.ping(timeout): raise EnvironmentError('Agent seems not alive') @@ -79,9 +87,9 @@ class QemuGuestAgentClient: if isinstance(ret, int) and int(ret) == uid: break - def __file_read_all(self, handle): + def __file_read_all(self, handle: int) -> bytes: eof = False - data = '' + data = b'' while not eof: ret = self.qga.file_read(handle=handle, count=1024) _data = base64.b64decode(ret['buf-b64']) @@ -89,7 +97,7 @@ class QemuGuestAgentClient: eof = ret['eof'] return data - def read(self, path): + def read(self, path: str) -> bytes: handle = self.qga.file_open(path=path) try: data = self.__file_read_all(handle) @@ -97,7 +105,7 @@ class QemuGuestAgentClient: self.qga.file_close(handle=handle) return data - def info(self): + def info(self) -> str: info = self.qga.info() msgs = [] @@ -113,14 +121,14 @@ class QemuGuestAgentClient: return '\n'.join(msgs) @classmethod - def __gen_ipv4_netmask(cls, prefixlen): + def __gen_ipv4_netmask(cls, prefixlen: int) -> str: mask = int('1' * prefixlen + '0' * (32 - prefixlen), 2) return '.'.join([str(mask >> 24), str((mask >> 16) & 0xff), str((mask >> 8) & 0xff), str(mask & 0xff)]) - def ifconfig(self): + def ifconfig(self) -> str: nifs = self.qga.network_get_interfaces() msgs = [] @@ -141,7 +149,7 @@ class QemuGuestAgentClient: return '\n'.join(msgs) - def ping(self, timeout): + def ping(self, timeout: Optional[float]) -> bool: self.qga.settimeout(timeout) try: self.qga.ping() @@ -149,37 +157,40 @@ class QemuGuestAgentClient: return False return True - def fsfreeze(self, cmd): + def fsfreeze(self, cmd: str) -> object: if cmd not in ['status', 'freeze', 'thaw']: raise Exception('Invalid command: ' + cmd) - + # Can be int (freeze, thaw) or GuestFsfreezeStatus (status) return getattr(self.qga, 'fsfreeze' + '_' + cmd)() - def fstrim(self, minimum=0): - return getattr(self.qga, 'fstrim')(minimum=minimum) + def fstrim(self, minimum: int) -> Dict[str, object]: + # returns GuestFilesystemTrimResponse + ret = getattr(self.qga, 'fstrim')(minimum=minimum) + assert isinstance(ret, dict) + return ret - def suspend(self, mode): + def suspend(self, mode: str) -> None: if mode not in ['disk', 'ram', 'hybrid']: raise Exception('Invalid mode: ' + mode) try: getattr(self.qga, 'suspend' + '_' + mode)() # On error exception will raise - except self.qga.timeout: + except TimeoutError: # On success command will timed out return - def shutdown(self, mode='powerdown'): + def shutdown(self, mode: str = 'powerdown') -> None: if mode not in ['powerdown', 'halt', 'reboot']: raise Exception('Invalid mode: ' + mode) try: self.qga.shutdown(mode=mode) - except self.qga.timeout: - return + except TimeoutError: + pass -def _cmd_cat(client, args): +def _cmd_cat(client: QemuGuestAgentClient, args: Sequence[str]) -> None: if len(args) != 1: print('Invalid argument') print('Usage: cat ') @@ -187,7 +198,7 @@ def _cmd_cat(client, args): print(client.read(args[0])) -def _cmd_fsfreeze(client, args): +def _cmd_fsfreeze(client: QemuGuestAgentClient, args: Sequence[str]) -> None: usage = 'Usage: fsfreeze status|freeze|thaw' if len(args) != 1: print('Invalid argument') @@ -201,13 +212,14 @@ def _cmd_fsfreeze(client, args): ret = client.fsfreeze(cmd) if cmd == 'status': print(ret) - elif cmd == 'freeze': - print("%d filesystems frozen" % ret) - else: - print("%d filesystems thawed" % ret) + return + assert isinstance(ret, int) + verb = 'frozen' if cmd == 'freeze' else 'thawed' + print(f"{ret:d} filesystems {verb}") -def _cmd_fstrim(client, args): + +def _cmd_fstrim(client: QemuGuestAgentClient, args: Sequence[str]) -> None: if len(args) == 0: minimum = 0 else: @@ -215,28 +227,25 @@ def _cmd_fstrim(client, args): print(client.fstrim(minimum)) -def _cmd_ifconfig(client, args): +def _cmd_ifconfig(client: QemuGuestAgentClient, args: Sequence[str]) -> None: assert not args print(client.ifconfig()) -def _cmd_info(client, args): +def _cmd_info(client: QemuGuestAgentClient, args: Sequence[str]) -> None: assert not args print(client.info()) -def _cmd_ping(client, args): - if len(args) == 0: - timeout = 3 - else: - timeout = float(args[0]) +def _cmd_ping(client: QemuGuestAgentClient, args: Sequence[str]) -> None: + timeout = 3.0 if len(args) == 0 else float(args[0]) alive = client.ping(timeout) if not alive: print("Not responded in %s sec" % args[0]) sys.exit(1) -def _cmd_suspend(client, args): +def _cmd_suspend(client: QemuGuestAgentClient, args: Sequence[str]) -> None: usage = 'Usage: suspend disk|ram|hybrid' if len(args) != 1: print('Less argument') @@ -249,7 +258,7 @@ def _cmd_suspend(client, args): client.suspend(args[0]) -def _cmd_shutdown(client, args): +def _cmd_shutdown(client: QemuGuestAgentClient, args: Sequence[str]) -> None: assert not args client.shutdown() @@ -257,12 +266,12 @@ def _cmd_shutdown(client, args): _cmd_powerdown = _cmd_shutdown -def _cmd_halt(client, args): +def _cmd_halt(client: QemuGuestAgentClient, args: Sequence[str]) -> None: assert not args client.shutdown('halt') -def _cmd_reboot(client, args): +def _cmd_reboot(client: QemuGuestAgentClient, args: Sequence[str]) -> None: assert not args client.shutdown('reboot') @@ -270,7 +279,7 @@ def _cmd_reboot(client, args): commands = [m.replace('_cmd_', '') for m in dir() if '_cmd_' in m] -def send_command(address, cmd, args): +def send_command(address: str, cmd: str, args: Sequence[str]) -> None: if not os.path.exists(address): print('%s not found' % address) sys.exit(1) @@ -296,7 +305,7 @@ def send_command(address, cmd, args): globals()['_cmd_' + cmd](client, args) -def main(): +def main() -> None: address = os.environ.get('QGA_CLIENT_ADDRESS') parser = argparse.ArgumentParser() From patchwork Wed Nov 4 00:35:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA07EC2D0A3 for ; Wed, 4 Nov 2020 00:50:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 25647223C7 for ; Wed, 4 Nov 2020 00:50:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UrKYLltT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 25647223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka70V-0000Vr-5p for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:50:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nO-0006XW-Uf for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29392) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nL-0004s1-Uw for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450219; 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=Xk2DkEIlZ+iczJ/YzPivEFw8SkHzwnuTgTlMET5+zx8=; b=UrKYLltT/M9byynTDqJ/77acPN+iEOeUiqUgvF9XpK5ACJU9PGmQVKzdOFUolPSL5Lw+iV vUjCNZ3ULocCPtvtEgHTQ8NrtMDfMrCXEZTTs05GqGnjNrQw3OwtQm5czT1oyOXWB7Gv0u yqwds7MbBgOdMVRYr+dPl3nSMRFht3U= 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--6B8GRSJN66AE5wYCPdUng-1; Tue, 03 Nov 2020 19:36:57 -0500 X-MC-Unique: -6B8GRSJN66AE5wYCPdUng-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AF5D1054FA2 for ; Wed, 4 Nov 2020 00:36:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C43755766; Wed, 4 Nov 2020 00:36:48 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 32/72] scripts/qmp-shell: fix connect method signature Date: Tue, 3 Nov 2020 19:35:22 -0500 Message-Id: <20201104003602.1293560-33-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It needs to match the parent's. (The negotiate parameter must be optional.) Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 330f8b32f9c2..27632ed5fee7 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -297,7 +297,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): self._print(resp) return True - def connect(self, negotiate): + def connect(self, negotiate: bool = True): self._greeting = super(QMPShell, self).connect(negotiate) self.__completer_setup() From patchwork Wed Nov 4 00:35:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B31BC2D0A3 for ; Wed, 4 Nov 2020 00:58:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6D31223C7 for ; Wed, 4 Nov 2020 00:58:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZQi46AsI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6D31223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka77j-0005jK-Kc for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:58:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nS-0006gp-9T for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22076) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nP-0004to-Rx for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450223; 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=bV7rjoOGdrBoWybEf7CQupU8d6G60XJruZ5XB4Mr7DU=; b=ZQi46AsIMw2ZKOKyEx9dGzEKiAEB2Fj6Zq3Sj7U0nu+L50k0GOBbVlhOzOkSGoNBgVDuGL 2h351s/9/I5DnCqdgYvFVzL8i2yPY7xkGivPl35DF8vd+5kPJTtkfYYtV/Do/8FRgg0LSk eSv8RedJC+1wg8w8U1nqXjrwPnVtR3I= 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-117-rgta2XnUMMy8ew_zC0FSEQ-1; Tue, 03 Nov 2020 19:37:01 -0500 X-MC-Unique: rgta2XnUMMy8ew_zC0FSEQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE19780A1B6 for ; Wed, 4 Nov 2020 00:36:52 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C906655766; Wed, 4 Nov 2020 00:36:51 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 34/72] scripts/qmp-shell: use @classmethod where appropriate Date: Tue, 3 Nov 2020 19:35:24 -0500 Message-Id: <20201104003602.1293560-35-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Methods with no self-use should belong to the class. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 6767a01eaaed..69359ec8ad7f 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -101,7 +101,8 @@ class FuzzyJSON(ast.NodeTransformer): '''This extension of ast.NodeTransformer filters literal "true/false/null" values in an AST and replaces them by proper "True/False/None" values that Python can properly evaluate.''' - def visit_Name(self, node): + @classmethod + def visit_Name(cls, node): if node.id == 'true': node.id = 'True' if node.id == 'false': @@ -124,7 +125,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): self._histfile = os.path.join(os.path.expanduser('~'), '.qmp-shell_history') - def __get_address(self, arg): + @classmethod + def __get_address(cls, arg): """ Figure out if the argument is in the port:host form, if it's not it's probably a file path. @@ -171,7 +173,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): except Exception as e: print("Failed to save history file '%s'; %s" % (self._histfile, e)) - def __parse_value(self, val): + @classmethod + def __parse_value(cls, val): try: return int(val) except ValueError: From patchwork Wed Nov 4 00:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73F76C4742C for ; Wed, 4 Nov 2020 00:54:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 08316223C7 for ; Wed, 4 Nov 2020 00:54:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HylTCZQ7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08316223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka74N-0007VX-41 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:54:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nX-0006wZ-Vn for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35138) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nT-0004ut-KN for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450226; 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=ePl9uGgGQJd8ZpUc91/N3dU2eHmOACuZljeQ8+uIa3Q=; b=HylTCZQ712w4pkHuojF6NQpfXxCnlt566XgGzTkrkeFcPZV98nllCWz2L5wjSA+Dat6MQz fsefP4XUZ+L1ayE5Bivv9yEdW9yJumpA9BcV5+bwjZrbWiJE3A28t23+haqmsyjGOj6Qfr NeyMFd3OGFOS19t1Sat8t0CjUtP0+Ro= 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-421-NDBOMz4gPNeqvakzs_uF5A-1; Tue, 03 Nov 2020 19:37:04 -0500 X-MC-Unique: NDBOMz4gPNeqvakzs_uF5A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CAA1456C91 for ; Wed, 4 Nov 2020 00:36:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120A955766; Wed, 4 Nov 2020 00:36:55 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 38/72] scripts/qmp-shell: ignore visit_Name name Date: Tue, 3 Nov 2020 19:35:28 -0500 Message-Id: <20201104003602.1293560-39-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Not something I control, sorry, pylint. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 73b2c099f0f0..0f03c6c89575 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -105,7 +105,7 @@ class FuzzyJSON(ast.NodeTransformer): """ @classmethod - def visit_Name(cls, node): + def visit_Name(cls, node): # pylint: disable=invalid-name if node.id == 'true': node.id = 'True' if node.id == 'false': From patchwork Wed Nov 4 00:35:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57E22C2D0A3 for ; Wed, 4 Nov 2020 01:02:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3E8F223AB for ; Wed, 4 Nov 2020 01:02:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="i9ZcCXTk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3E8F223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7C2-000293-2U for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:02:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nU-0006ob-Ue for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40826) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nR-0004uJ-Uv for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450224; 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=La8LA7rAWBOZRtdJ7hAQXXLbNavMknquY2yV0eFl5mM=; b=i9ZcCXTkG2FR1PsAcwfW4sLHGJxAO35e/ltzMRrPYMap+Y6NP2X1L5j4KLBSPfhLK8424A Matfh54lFQQbOosJkZnP9cj8ln3Qd64nXBJ6daqWjsfPC4N5d4AiQ4ECDqB8qQrPGncEXC 9Z3saEev7na8E+R765CcYHyp8spwPxE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-53BI0lz9M4SGp9hs7n25dA-1; Tue, 03 Nov 2020 19:37:03 -0500 X-MC-Unique: 53BI0lz9M4SGp9hs7n25dA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7139F1891E82 for ; Wed, 4 Nov 2020 00:37:02 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB5055766; Wed, 4 Nov 2020 00:37:01 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 43/72] scripts/qmp-shell: remove if-raise-else patterns Date: Tue, 3 Nov 2020 19:35:33 -0500 Message-Id: <20201104003602.1293560-44-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index b3ab735397d4..47863a604f51 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -224,8 +224,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): if type(parent[optpath[-1]]) is dict: msg = 'Cannot use "{:s}" as both leaf and non-leaf key' raise QMPShellError(msg.format('.'.join(curpath))) - else: - raise QMPShellError(f'Cannot set "{key}" multiple times') + raise QMPShellError(f'Cannot set "{key}" multiple times') parent[optpath[-1]] = value def __build_cmd(self, cmdline): @@ -329,13 +328,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): except EOFError: print() return False + if cmdline == '': for event in self.get_events(): print(event) self.clear_events() return True - else: - return self._execute_cmd(cmdline) + + return self._execute_cmd(cmdline) def set_verbosity(self, verbose): self._verbose = verbose From patchwork Wed Nov 4 00:35:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D205AC4742C for ; Wed, 4 Nov 2020 00:52:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 55E70223C7 for ; Wed, 4 Nov 2020 00:52:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OadDj5ua" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 55E70223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka727-00042y-DQ for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:52:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nW-0006tD-KE for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nU-0004v4-0F for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450227; 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=GMqE1AyxFYAnSfxpx9j63puyEBG10ftch/58FhUYqHA=; b=OadDj5uafHYr+SfS48Siz1ZVMHaA/iETgBhNLi52ONFI/Q5i6I+ZN6o0IFhCBDXNmJMo4L kYRHN+o65XXkR0nCQQDOezVn2oleqTHkduucuRt+yyV3M84+qiRzx2+wrde+enWDdVRDBH b2vOoj8IhAO5m8gAaW53mM/tiJ/rNuE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-589-6LG_tDASOayNRU28llR5uA-1; Tue, 03 Nov 2020 19:37:05 -0500 X-MC-Unique: 6LG_tDASOayNRU28llR5uA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B3B3980474F for ; Wed, 4 Nov 2020 00:37:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE21F747C6; Wed, 4 Nov 2020 00:37:03 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 45/72] scripts/qmp-shell: use argparse Date: Tue, 3 Nov 2020 19:35:35 -0500 Message-Id: <20201104003602.1293560-46-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use argparse instead of an open-coded CLI parser, for consistency with everything else. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 82 +++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 50 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 0cd3ed7d43c7..d5496aeac0bd 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -64,7 +64,7 @@ # Use the -v and -p options to activate the verbose and pretty-print options, # which will echo back the properly formatted JSON-compliant QMP that is being # sent to QEMU, which is useful for debugging and documentation generation. - +import argparse import ast import atexit import json @@ -421,65 +421,47 @@ def die(msg): sys.exit(1) -def fail_cmdline(option=None): - if option: - sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % option) - sys.stderr.write( - 'qmp-shell [ -v ] [ -p ] [ -H ] [ -N ] ' - '< UNIX socket path> | < TCP address:port >\n' - ) - sys.stderr.write(' -v Verbose (echo command sent and received)\n') - sys.stderr.write(' -p Pretty-print JSON\n') - sys.stderr.write(' -H Use HMP interface\n') - sys.stderr.write(' -N Skip negotiate (for qemu-ga)\n') - sys.exit(1) - - def main(): - addr = '' - qemu = None - hmp = False - pretty = False - verbose = False - negotiate = True + parser = argparse.ArgumentParser() + parser.add_argument('-H', '--hmp', action='store_true', + help='Use HMP interface') + parser.add_argument('-N', '--skip-negotiation', action='store_true', + help='Skip negotiate (for qemu-ga)') + parser.add_argument('-v', '--verbose', action='store_true', + help='Verbose (echo commands sent and received)') + parser.add_argument('-p', '--pretty', action='store_true', + help='Pretty-print JSON') + default_server = os.environ.get('QMP_SOCKET') + parser.add_argument('qmp_server', action='store', + default=default_server, + help='< UNIX socket path | TCP address:port >') + + args = parser.parse_args() + if args.qmp_server is None: + parser.error("QMP socket or TCP address must be specified") + + qemu: QMPShell try: - for arg in sys.argv[1:]: - if arg == "-H": - if qemu is not None: - fail_cmdline(arg) - hmp = True - elif arg == "-p": - pretty = True - elif arg == "-N": - negotiate = False - elif arg == "-v": - verbose = True - else: - if qemu is not None: - fail_cmdline(arg) - if hmp: - qemu = HMPShell(arg) - else: - qemu = QMPShell(arg, pretty) - addr = arg - - if qemu is None: - fail_cmdline() + if args.hmp: + qemu = HMPShell(args.qmp_server) + else: + qemu = QMPShell(args.qmp_server, args.pretty) except QMPShellBadPort: - die('bad port number in command-line') + parser.error(f"Bad port number: {args.qmp_server}") + return # pycharm doesn't know error() is noreturn try: - qemu.connect(negotiate) + qemu.connect(negotiate=not args.skip_negotiation) except qmp.QMPConnectError: - die('Didn\'t get QMP greeting message') + die("Didn't get QMP greeting message") except qmp.QMPCapabilitiesError: - die('Could not negotiate capabilities') - except OSError: - die('Could not connect to %s' % addr) + die("Couldn't negotiate capabilities") + except OSError as err: + die(f"Couldn't connect to {args.qmp_server}: {err!s}") qemu.show_banner() - qemu.set_verbosity(verbose) + qemu.set_verbosity(args.verbose) while qemu.read_exec_command(qemu.get_prompt()): pass qemu.close() From patchwork Wed Nov 4 00:35:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316234 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F13C388F7 for ; Wed, 4 Nov 2020 01:06:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C435223AB for ; Wed, 4 Nov 2020 01:06:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EArcuoQD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C435223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7GH-0008Eq-25 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:06:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nc-00078i-40 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51801) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6na-0004vh-6N for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450233; 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=67hPomjxNLOBu5xnnDcvEm19yDZAmkXyoM6jA1VmJsY=; b=EArcuoQDSav0lECru5ASNW9upmRMaatese0JPR90+EBaBT//zT9CwGAyzUIh3ED7RXK/Gz 2I/Wb4l5+JvnBvLGhkfFR0hlNq6RrCSuVI7JZwGGZMxzUw66pw/ZfmPLdSSWum6+uPLzpD Mq1GLcSbBO5Iu5phfduWDnqE3mBsKnk= 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-360-0xe8iIbpPAGRIsVXMv8yXg-1; Tue, 03 Nov 2020 19:37:11 -0500 X-MC-Unique: 0xe8iIbpPAGRIsVXMv8yXg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C820B8015C3 for ; Wed, 4 Nov 2020 00:37:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5366C55766; Wed, 4 Nov 2020 00:37:06 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 47/72] python/qmp: add parse_address classmethod Date: Tue, 3 Nov 2020 19:35:37 -0500 Message-Id: <20201104003602.1293560-48-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This takes the place of qmp-shell's __get_address function. Signed-off-by: John Snow --- python/qemu/qmp/__init__.py | 26 ++++++++++++++++++++++++++ scripts/qmp/qmp-shell | 27 ++------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py index dd211e3f6511..a6e1a7b85775 100644 --- a/python/qemu/qmp/__init__.py +++ b/python/qemu/qmp/__init__.py @@ -97,6 +97,12 @@ def __init__(self, reply: QMPMessage): self.reply = reply +class QMPBadPortError(QMPError): + """ + Unable to parse socket address: Port was non-numerical. + """ + + class QEMUMonitorProtocol: """ Provide an API to connect to QEMU via QEMU Monitor Protocol (QMP) and then @@ -224,6 +230,26 @@ def __exit__(self, # Implement context manager exit function. self.close() + @classmethod + def parse_address(cls, address: str) -> SocketAddrT: + """ + Parse a string into a QMP address. + + Figure out if the argument is in the port:host form. + If it's not, it's probably a file path. + """ + components = address.split(':') + if len(components) == 2: + try: + port = int(components[1]) + except ValueError: + msg = f"Bad port: '{components[1]}' in '{address}'." + raise QMPBadPortError(msg) from None + return (components[0], port) + + # Treat as filepath. + return address + def connect(self, negotiate: bool = True) -> Optional[QMPMessage]: """ Connect to the QMP Monitor and perform capabilities negotiation. diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index d5496aeac0bd..5a72b9d39502 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -92,10 +92,6 @@ class QMPShellError(Exception): pass -class QMPShellBadPort(QMPShellError): - pass - - class FuzzyJSON(ast.NodeTransformer): """ This extension of ast.NodeTransformer filters literal "true/false/null" @@ -118,7 +114,7 @@ class FuzzyJSON(ast.NodeTransformer): # _execute_cmd()). Let's design a better one. class QMPShell(qmp.QEMUMonitorProtocol): def __init__(self, address, pretty=False): - super().__init__(self.__get_address(address)) + super().__init__(self.parse_address(address)) self._greeting = None self._completer = None self._pretty = pretty @@ -128,22 +124,6 @@ class QMPShell(qmp.QEMUMonitorProtocol): '.qmp-shell_history') self._verbose = False - @classmethod - def __get_address(cls, arg): - """ - Figure out if the argument is in the port:host form, if it's not it's - probably a file path. - """ - addr = arg.split(':') - if len(addr) == 2: - try: - port = int(addr[1]) - except ValueError as err: - raise QMPShellBadPort from err - return addr[0], port - # socket path - return arg - def _fill_completion(self): cmds = self.cmd('query-commands') if 'error' in cmds: @@ -337,9 +317,6 @@ class QMPShell(qmp.QEMUMonitorProtocol): return self._execute_cmd(cmdline) - def set_verbosity(self, verbose): - self._verbose = verbose - class HMPShell(QMPShell): def __init__(self, address): @@ -447,7 +424,7 @@ def main(): qemu = HMPShell(args.qmp_server) else: qemu = QMPShell(args.qmp_server, args.pretty) - except QMPShellBadPort: + except qmp.QMPBadPortError: parser.error(f"Bad port number: {args.qmp_server}") return # pycharm doesn't know error() is noreturn From patchwork Wed Nov 4 00:35:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316232 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF36AC2D0A3 for ; Wed, 4 Nov 2020 01:09:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7553C223AB for ; Wed, 4 Nov 2020 01:09:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z2pbJY5q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7553C223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7IQ-0003Eq-Id for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:09:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nd-0007B2-22 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21798) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nb-0004vm-Di for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450234; 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=a1XHIBeG+DluaONg2ht+r/5cfSSpprDO9b+48DgbMW0=; b=Z2pbJY5qODgn1YoQPodd7lsdvQlZjofXYFr0r8a8oja9K1n8U88ACEQvLG4GLtiJsL1632 KjH9gr3VOwpGWaJpc6pyPzTfZlp5zUTxxCVHskfBNX4DEzC+jKlA7tSycY4yaxB4up7fD9 kWThENCbFiv2ULkYsggsUoAmgSB9Uac= 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-116-zDAp5zeNPue1HcQePq7_Jw-1; Tue, 03 Nov 2020 19:37:13 -0500 X-MC-Unique: zDAp5zeNPue1HcQePq7_Jw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 33831802B56 for ; Wed, 4 Nov 2020 00:37:12 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AA9C55766; Wed, 4 Nov 2020 00:37:11 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 48/72] scripts/qmp-shell: Add pretty attribute to HMP shell Date: Tue, 3 Nov 2020 19:35:38 -0500 Message-Id: <20201104003602.1293560-49-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It's less useful, but it makes the initialization methods LSP consistent. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 5a72b9d39502..ba27e9801c68 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -319,8 +319,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): class HMPShell(QMPShell): - def __init__(self, address): - super().__init__(address) + def __init__(self, address, pretty=False): + super().__init__(address, pretty) self.__cpu_index = 0 def __cmd_completion(self): @@ -418,12 +418,9 @@ def main(): if args.qmp_server is None: parser.error("QMP socket or TCP address must be specified") - qemu: QMPShell + shell_class = HMPShell if args.hmp else QMPShell try: - if args.hmp: - qemu = HMPShell(args.qmp_server) - else: - qemu = QMPShell(args.qmp_server, args.pretty) + qemu = shell_class(args.qmp_server, args.pretty) except qmp.QMPBadPortError: parser.error(f"Bad port number: {args.qmp_server}") return # pycharm doesn't know error() is noreturn From patchwork Wed Nov 4 00:35:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B26AC4742C for ; Wed, 4 Nov 2020 00:56:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2388F223C7 for ; Wed, 4 Nov 2020 00:56:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gQ/CCJIb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2388F223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka76Z-0002bi-7n for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:56:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6ne-0007CJ-NU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38968) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nc-0004vw-UN for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450236; 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=pIMjZAoZPo6ny5PBtyWC0I9lcIqZo7oz/v3yVY473cQ=; b=gQ/CCJIbLIS9kPxO1/QnmOGHFni7vWkl8wqVYgUMyKR/GnqhRHUMY5C2RR8/9FYDMJ2FuI m+LYzsHQIEW6YICF8huIcBiDG5d3dDbeYXqg6HHSmrX3kW5l3idSSwMOm5j7CvWIqk0ZEe 88mtlv85NC03DJL4G7WnPft0gplf08Y= 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-434-oYFDkvcLNiKt-AmOUD4grw-1; Tue, 03 Nov 2020 19:37:14 -0500 X-MC-Unique: oYFDkvcLNiKt-AmOUD4grw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A85964151 for ; Wed, 4 Nov 2020 00:37:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7958B55766; Wed, 4 Nov 2020 00:37:12 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 49/72] scripts/qmp-shell: Make verbose a public attribute Date: Tue, 3 Nov 2020 19:35:39 -0500 Message-Id: <20201104003602.1293560-50-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" No real reason to hide this behind an underscore; make it part of the initializer and make it a regular RW attribute. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index ba27e9801c68..cfcefb95f9da 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -113,7 +113,7 @@ class FuzzyJSON(ast.NodeTransformer): # TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and # _execute_cmd()). Let's design a better one. class QMPShell(qmp.QEMUMonitorProtocol): - def __init__(self, address, pretty=False): + def __init__(self, address, pretty=False, verbose=False): super().__init__(self.parse_address(address)) self._greeting = None self._completer = None @@ -122,7 +122,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): self._actions = list() self._histfile = os.path.join(os.path.expanduser('~'), '.qmp-shell_history') - self._verbose = False + self.verbose = verbose def _fill_completion(self): cmds = self.cmd('query-commands') @@ -271,7 +271,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): # For transaction mode, we may have just cached the action: if qmpcmd is None: return True - if self._verbose: + if self.verbose: self._print(qmpcmd) resp = self.cmd_obj(qmpcmd) if resp is None: @@ -319,8 +319,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): class HMPShell(QMPShell): - def __init__(self, address, pretty=False): - super().__init__(address, pretty) + def __init__(self, address, pretty=False, verbose=False): + super().__init__(address, pretty, verbose) self.__cpu_index = 0 def __cmd_completion(self): @@ -420,7 +420,7 @@ def main(): shell_class = HMPShell if args.hmp else QMPShell try: - qemu = shell_class(args.qmp_server, args.pretty) + qemu = shell_class(args.qmp_server, args.pretty, args.verbose) except qmp.QMPBadPortError: parser.error(f"Bad port number: {args.qmp_server}") return # pycharm doesn't know error() is noreturn @@ -435,7 +435,6 @@ def main(): die(f"Couldn't connect to {args.qmp_server}: {err!s}") qemu.show_banner() - qemu.set_verbosity(args.verbose) while qemu.read_exec_command(qemu.get_prompt()): pass qemu.close() From patchwork Wed Nov 4 00:35:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4160CC388F7 for ; Wed, 4 Nov 2020 00:58:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBEF6223C7 for ; Wed, 4 Nov 2020 00:58:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ce4ukbwL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBEF6223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka784-00063D-W2 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 19:58:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nf-0007DE-Cm for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nd-0004w4-Mm for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450237; 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=l0geWX4GnzvjPC2sg3cL9qk3gkNtLddwm2qUwTAz6/I=; b=ce4ukbwLO1au1cpTanbBUUPmE9FUbQ7/BK5PTZzOOsUgR83UNxIxy9BUJaxXiTorrMsspn zpkiQZYE5EiVjdtEyxiCIZvufug40Ck9DzDARztNa/Dbg8N1IpDyhEaYWpkWx2JJdNd52s IXwcthLTxbCjA9lN+HXg3VksHIkaVOc= 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-449-ZxGpM_vVPnaViecvq_q7hw-1; Tue, 03 Nov 2020 19:37:15 -0500 X-MC-Unique: ZxGpM_vVPnaViecvq_q7hw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BE9A8015C3 for ; Wed, 4 Nov 2020 00:37:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89954747C6; Wed, 4 Nov 2020 00:37:13 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 50/72] scripts/qmp-shell: move get_prompt() to prompt property Date: Tue, 3 Nov 2020 19:35:40 -0500 Message-Id: <20201104003602.1293560-51-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Small tidying; treat "prompt" like an immutable property instead of function/method/routine. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index cfcefb95f9da..3b86ef7d8844 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -292,10 +292,11 @@ class QMPShell(qmp.QEMUMonitorProtocol): version = self._greeting['QMP']['version']['qemu'] print("Connected to QEMU {major}.{minor}.{micro}\n".format(**version)) - def get_prompt(self): + @property + def prompt(self): if self._transmode: - return "TRANS> " - return "(QEMU) " + return 'TRANS> ' + return '(QEMU) ' def read_exec_command(self, prompt): """ @@ -435,7 +436,7 @@ def main(): die(f"Couldn't connect to {args.qmp_server}: {err!s}") qemu.show_banner() - while qemu.read_exec_command(qemu.get_prompt()): + while qemu.read_exec_command(qemu.prompt): pass qemu.close() From patchwork Wed Nov 4 00:35:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316238 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D5D7C2D0A3 for ; Wed, 4 Nov 2020 01:01:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9A57223AB for ; Wed, 4 Nov 2020 01:01:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QZJPviMl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9A57223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7BV-0001DG-3s for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:01:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6ni-0007GW-51 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6ne-0004w9-R1 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450238; 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=iskghmMZ9Cu+o7H8nn+qox8VkTJEOcWFJKDnEwqu+FQ=; b=QZJPviMlBHrDAkFTz0AykgDYdwMmcHpJll0F3o8A559wIaKabvxkx944P4gXkYjIlGMDZX LZIkkxcRXV+MbGfblhVRW+jIGb3eAPF95klVmQq89+FEYlZ6dZ+4GWn8/ORpN0RF9h++o+ 6VupRhKN1ygBuJsF0W5GRqx/5DPuUXU= 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-113-k4vPhkd8PVKpgUT_nNwbCw-1; Tue, 03 Nov 2020 19:37:16 -0500 X-MC-Unique: k4vPhkd8PVKpgUT_nNwbCw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1679108E1AF for ; Wed, 4 Nov 2020 00:37:15 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C07B055766; Wed, 4 Nov 2020 00:37:14 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 51/72] scripts/qmp-shell: remove prompt argument from read_exec_command Date: Tue, 3 Nov 2020 19:35:41 -0500 Message-Id: <20201104003602.1293560-52-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It's only ever used by one caller, we can just absorb that logic. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 3b86ef7d8844..31269859c4c4 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -298,14 +298,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): return 'TRANS> ' return '(QEMU) ' - def read_exec_command(self, prompt): + def read_exec_command(self): """ Read and execute a command. @return True if execution was ok, return False if disconnected. """ try: - cmdline = input(prompt) + cmdline = input(self.prompt) except EOFError: print() return False @@ -436,7 +436,7 @@ def main(): die(f"Couldn't connect to {args.qmp_server}: {err!s}") qemu.show_banner() - while qemu.read_exec_command(qemu.prompt): + while qemu.read_exec_command(): pass qemu.close() From patchwork Wed Nov 4 00:35:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3E16C2D0A3 for ; Wed, 4 Nov 2020 01:04:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6602B223AB for ; Wed, 4 Nov 2020 01:04:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KSKjwHxR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6602B223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7EN-0005a9-FB for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:04:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nl-0007Iq-Rm for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nh-0004wM-RW for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450239; 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=YAg08pyT30kqE06g+2YSuEIio763R2gtwKP+pBI5q70=; b=KSKjwHxRTILSWz8RUHfzjmg0vnMkHzCYKqIStKfTJGjgUqu1SgjF8lkNOjzjECvig0sQ+v +vi+mRayAzIcwlZSGD0ev51MyaYtibSq+uUwRnj93X/0kp1iJbFgQJoWRICAxW3U0iXCP2 Zoi+miZxLj8FM9Ya/iHFTpXOUR7FlJQ= 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-FIt2fiAbPGSVzV4SVrq18w-1; Tue, 03 Nov 2020 19:37:17 -0500 X-MC-Unique: FIt2fiAbPGSVzV4SVrq18w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5DE36414C for ; Wed, 4 Nov 2020 00:37:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD4ED55766; Wed, 4 Nov 2020 00:37:15 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 52/72] scripts/qmp-shell: move the REPL functionality into QMPShell Date: Tue, 3 Nov 2020 19:35:42 -0500 Message-Id: <20201104003602.1293560-53-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Instead of doing this in main, move it into the class. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 31269859c4c4..aa148517a864 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -318,6 +318,12 @@ class QMPShell(qmp.QEMUMonitorProtocol): return self._execute_cmd(cmdline) + def repl(self): + self.show_banner() + while self.read_exec_command(): + yield + self.close() + class HMPShell(QMPShell): def __init__(self, address, pretty=False, verbose=False): @@ -435,10 +441,8 @@ def main(): except OSError as err: die(f"Couldn't connect to {args.qmp_server}: {err!s}") - qemu.show_banner() - while qemu.read_exec_command(): + for _ in qemu.repl(): pass - qemu.close() if __name__ == '__main__': From patchwork Wed Nov 4 00:35:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2381DC2D0A3 for ; Wed, 4 Nov 2020 01:07:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AF7CD223AB for ; Wed, 4 Nov 2020 01:07:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cy6hZFJe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AF7CD223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7Gt-0000k7-RH for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:07:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nn-0007Jh-U2 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42734) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nh-0004wT-RU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450241; 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=/HV2sRxuoFz1HvSs6hteE0GNcYJLYO0K0NRKl1Vz7YA=; b=cy6hZFJeBy8+4tkNSvVMT8/6ewz6aJDH7vxb7sbjAQB4WOC1z468nopeCy82NJ70qLDRnw hNNzOTSqNOnvGdMPJwhClXYgoORbm9hVhRgPHbvmokvKlsNrABdvtvzYcWbKJaGloqc9VV xV+79psfrktglHu05sFaZg6fn2qe5Js= 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-335-0ytIZ5k2N52LVveGeyiUnA-1; Tue, 03 Nov 2020 19:37:19 -0500 X-MC-Unique: 0ytIZ5k2N52LVveGeyiUnA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 236121891E84 for ; Wed, 4 Nov 2020 00:37:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A41955766; Wed, 4 Nov 2020 00:37:16 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 53/72] scripts/qmp-shell: Fix "FuzzyJSON" parser Date: Tue, 3 Nov 2020 19:35:43 -0500 Message-Id: <20201104003602.1293560-54-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" I'm not sure when this regressed (Or maybe if it was ever working right to begin with?), but the Python AST requires you to change "Names" to "Constants" in order to truly convert `false` to `False`. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index aa148517a864..847d34890f97 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -95,18 +95,19 @@ class QMPShellError(Exception): class FuzzyJSON(ast.NodeTransformer): """ This extension of ast.NodeTransformer filters literal "true/false/null" - values in an AST and replaces them by proper "True/False/None" values that - Python can properly evaluate. + values in a Python AST and replaces them by proper "True/False/None" values + that Python can properly evaluate. """ @classmethod - def visit_Name(cls, node): # pylint: disable=invalid-name + def visit_Name(cls, # pylint: disable=invalid-name + node: ast.Name) -> ast.AST: if node.id == 'true': - node.id = 'True' + return ast.Constant(value=True) if node.id == 'false': - node.id = 'False' + return ast.Constant(value=False) if node.id == 'null': - node.id = 'None' + return ast.Constant(value=None) return node @@ -174,10 +175,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): # Try once again as FuzzyJSON: try: tree = ast.parse(val, mode='eval') - return ast.literal_eval(FuzzyJSON().visit(tree)) - except SyntaxError: - pass - except ValueError: + transformed = FuzzyJSON().visit(tree) + return ast.literal_eval(transformed) + except (SyntaxError, ValueError): pass return val From patchwork Wed Nov 4 00:35:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D79A2C388F7 for ; Wed, 4 Nov 2020 01:19:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6CE522242C for ; Wed, 4 Nov 2020 01:19:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aiHi661J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CE522242C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7Sl-0006OV-A6 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:19:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nn-0007Ji-Vt for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27224) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nj-0004wa-CD for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450241; 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=dW8nv3mseuwyKhX4fJQG2TcuQYo/mf67EOtBCsNnqNQ=; b=aiHi661JuY/Uo3XgMO4czscmsAan+7GVpw47pGWgdfVR1P2acb2V2nisEC+docH5Tcb17L QYKPgdAb/UOjqRgt8U0g6CGg0QBRnRdWcSrYNLn+s96jAHQos0DQ/AIw2uNTYHHHCiCU6K aEN3RHKPALr+gD9qENng9rm6W1cA1oM= 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-81-Zdz07CrDN_uDKHqLcttwiw-1; Tue, 03 Nov 2020 19:37:20 -0500 X-MC-Unique: Zdz07CrDN_uDKHqLcttwiw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22F4A6417E for ; Wed, 4 Nov 2020 00:37:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 623CC747C6; Wed, 4 Nov 2020 00:37:18 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 54/72] scripts/qmp-shell: refactor QMPCompleter Date: Tue, 3 Nov 2020 19:35:44 -0500 Message-Id: <20201104003602.1293560-55-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" list is a generic type, but we expect to use strings directly. We could subclass list[str], but pylint does not presently understand that invocation. Change this class to envelop a list instead of *being* a list, for simpler typing. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 847d34890f97..73694035b203 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -78,9 +78,17 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp -class QMPCompleter(list): - def complete(self, text, state): - for cmd in self: +class QMPCompleter: + # NB: Python 3.9+ will probably allow us to subclass list[str] directly, + # but pylint as of today does not know that List[str] is simply 'list'. + def __init__(self) -> None: + self._matches: List[str] = [] + + def append(self, value: str) -> None: + return self._matches.append(value) + + def complete(self, text: str, state: int) -> Optional[str]: + for cmd in self._matches: if cmd.startswith(text): if state == 0: return cmd From patchwork Wed Nov 4 00:35:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDCFDC2D0A3 for ; Wed, 4 Nov 2020 01:22:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2465C2242A for ; Wed, 4 Nov 2020 01:22:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TSpYNPNH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2465C2242A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7V8-00019I-06 for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:22:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6np-0007KZ-Ox for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:31 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nl-0004ws-I7 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450244; 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=08ilLdlAvTCW/NaILyV93iS4vcfYIx6F11xRdLB9EGw=; b=TSpYNPNHR5DRlcBX5DMkrYx40SLnNNOlPCLv7InhIZM6Pa6Bfmpxer9OYkuzkZri/2vaRm E+x60agZleHrWHsHo+4SQ0orq+FDE+P+aDUYPTAj0iBN0mt6HqPvZG791n02qtztmLwNI1 sMUsO19zY2d7j1VUatOGYnxmQOceGAA= 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-472-CHVNiXagN0a7b4UFg0eX5Q-1; Tue, 03 Nov 2020 19:37:22 -0500 X-MC-Unique: CHVNiXagN0a7b4UFg0eX5Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A294A803F78 for ; Wed, 4 Nov 2020 00:37:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C3BA255766; Wed, 4 Nov 2020 00:37:20 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 56/72] python/qmp: add QMPObject type alias Date: Tue, 3 Nov 2020 19:35:46 -0500 Message-Id: <20201104003602.1293560-57-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is meant to represent any generic object seen in a QMPMessage, not just the root object itself. Signed-off-by: John Snow --- python/qemu/qmp/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py index a6e1a7b85775..ba0d2281d678 100644 --- a/python/qemu/qmp/__init__.py +++ b/python/qemu/qmp/__init__.py @@ -41,6 +41,9 @@ #: QMPReturnValue is the 'return' value of a command. QMPReturnValue = object +#: QMPObject is any object in a QMP message. +QMPObject = Dict[str, object] + # QMPMessage can be outgoing commands or incoming events/returns. # QMPReturnValue is usually a dict/json object, but due to QAPI's # 'returns-whitelist', it can actually be anything. From patchwork Wed Nov 4 00:35:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44A4EC4742C for ; Wed, 4 Nov 2020 01:26:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8FE1E22409 for ; Wed, 4 Nov 2020 01:26:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iUIMzYRw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8FE1E22409 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7ZZ-00059a-Ll for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:26:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35978) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nv-0007MT-E5 for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nn-0004wz-Ni for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450245; 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=CLH3MBije1XSDJtFct1JQ4vpdKKI3TcUrJV5Rs/2+1g=; b=iUIMzYRwN3xmfH2eo4sjnAlCEy1oAfh5OvlDQDdYsIUqx31lNqLVHcoiz7jPeW9dGxyEpi tYUCoE+8FvOQh7bYqQwxrEB7C+YzuZkvS8rxlWP5OuGsKImvGKyhBQpV7UKSzCG8ZTBMXv BNYGh+Gdr2+wpS0PhWqghkVXxXbrzw8= 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-506-8INIGRaCM962WlzJLTuEVA-1; Tue, 03 Nov 2020 19:37:23 -0500 X-MC-Unique: 8INIGRaCM962WlzJLTuEVA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8FB231891E87 for ; Wed, 4 Nov 2020 00:37:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id D123655766; Wed, 4 Nov 2020 00:37:21 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 57/72] scripts/qmp-shell: add mypy types Date: Tue, 3 Nov 2020 19:35:47 -0500 Message-Id: <20201104003602.1293560-58-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As per my usual, this patch is annotations only. Any changes with side effects are done elsewhere. Note: pylint does not understand the subscripts for Collection in Python 3.6, so use the stronger Sequence type as a workaround. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 67 ++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 670361322c51..2d0e85b5f723 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -72,10 +72,18 @@ import os import re import readline import sys +from typing import ( + Iterator, + List, + NoReturn, + Optional, + Sequence, +) sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python')) from qemu import qmp +from qemu.qmp import QMPMessage class QMPCompleter: @@ -122,25 +130,26 @@ class FuzzyJSON(ast.NodeTransformer): # TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and # _execute_cmd()). Let's design a better one. class QMPShell(qmp.QEMUMonitorProtocol): - def __init__(self, address, pretty=False, verbose=False): + def __init__(self, address: str, pretty: bool = False, + verbose: bool = False): super().__init__(self.parse_address(address)) - self._greeting = None + self._greeting: Optional[QMPMessage] = None self._completer = QMPCompleter() self._pretty = pretty self._transmode = False - self._actions = list() + self._actions: List[QMPMessage] = [] self._histfile = os.path.join(os.path.expanduser('~'), '.qmp-shell_history') self.verbose = verbose - def _fill_completion(self): + def _fill_completion(self) -> None: cmds = self.cmd('query-commands') if 'error' in cmds: return for cmd in cmds['return']: self._completer.append(cmd['name']) - def __completer_setup(self): + def __completer_setup(self) -> None: self._completer = QMPCompleter() self._fill_completion() readline.set_history_length(1024) @@ -157,14 +166,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): print(f"Failed to read history '{self._histfile}': {err!s}") atexit.register(self.__save_history) - def __save_history(self): + def __save_history(self) -> None: try: readline.write_history_file(self._histfile) except IOError as err: print(f"Failed to save history file '{self._histfile}': {err!s}") @classmethod - def __parse_value(cls, val): + def __parse_value(cls, val: str) -> object: try: return int(val) except ValueError: @@ -189,7 +198,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): pass return val - def __cli_expr(self, tokens, parent): + def __cli_expr(self, + tokens: Sequence[str], + parent: qmp.QMPObject) -> None: for arg in tokens: (key, sep, val) = arg.partition('=') if sep != '=': @@ -215,7 +226,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): raise QMPShellError(f'Cannot set "{key}" multiple times') parent[optpath[-1]] = value - def __build_cmd(self, cmdline): + def __build_cmd(self, cmdline: str) -> Optional[QMPMessage]: """ Build a QMP input object from a user provided command-line in the following format: @@ -224,6 +235,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): """ argument_regex = r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''' cmdargs = re.findall(argument_regex, cmdline) + qmpcmd: QMPMessage # Transactional CLI entry/exit: if cmdargs[0] == 'transaction(': @@ -261,14 +273,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): self.__cli_expr(cmdargs[1:], qmpcmd['arguments']) return qmpcmd - def _print(self, qmp_message): + def _print(self, qmp_message: object) -> None: indent = None if self._pretty: indent = 4 jsobj = json.dumps(qmp_message, indent=indent, sort_keys=self._pretty) print(str(jsobj)) - def _execute_cmd(self, cmdline): + def _execute_cmd(self, cmdline: str) -> bool: try: qmpcmd = self.__build_cmd(cmdline) except Exception as err: @@ -288,11 +300,12 @@ class QMPShell(qmp.QEMUMonitorProtocol): self._print(resp) return True - def connect(self, negotiate: bool = True): + def connect(self, negotiate: bool = True) -> None: self._greeting = super().connect(negotiate) self.__completer_setup() - def show_banner(self, msg='Welcome to the QMP low-level shell!'): + def show_banner(self, + msg: str = 'Welcome to the QMP low-level shell!') -> None: print(msg) if not self._greeting: print('Connected') @@ -301,12 +314,12 @@ class QMPShell(qmp.QEMUMonitorProtocol): print("Connected to QEMU {major}.{minor}.{micro}\n".format(**version)) @property - def prompt(self): + def prompt(self) -> str: if self._transmode: return 'TRANS> ' return '(QEMU) ' - def read_exec_command(self): + def read_exec_command(self) -> bool: """ Read and execute a command. @@ -326,7 +339,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): return self._execute_cmd(cmdline) - def repl(self): + def repl(self) -> Iterator[None]: self.show_banner() while self.read_exec_command(): yield @@ -334,11 +347,12 @@ class QMPShell(qmp.QEMUMonitorProtocol): class HMPShell(QMPShell): - def __init__(self, address, pretty=False, verbose=False): + def __init__(self, address: str, + pretty: bool = False, verbose: bool = False): super().__init__(address, pretty, verbose) self.__cpu_index = 0 - def __cmd_completion(self): + def __cmd_completion(self) -> None: for cmd in self.__cmd_passthrough('help')['return'].split('\r\n'): if cmd and cmd[0] != '[' and cmd[0] != '\t': name = cmd.split()[0] # drop help text @@ -355,21 +369,22 @@ class HMPShell(QMPShell): self._completer.append(name) self._completer.append('help ' + name) # help completion - def __info_completion(self): + def __info_completion(self) -> None: for cmd in self.__cmd_passthrough('info')['return'].split('\r\n'): if cmd: self._completer.append('info ' + cmd.split()[1]) - def __other_completion(self): + def __other_completion(self) -> None: # special cases self._completer.append('help info') - def _fill_completion(self): + def _fill_completion(self) -> None: self.__cmd_completion() self.__info_completion() self.__other_completion() - def __cmd_passthrough(self, cmdline, cpu_index=0): + def __cmd_passthrough(self, cmdline: str, + cpu_index: int = 0) -> QMPMessage: return self.cmd_obj({ 'execute': 'human-monitor-command', 'arguments': { @@ -378,7 +393,7 @@ class HMPShell(QMPShell): } }) - def _execute_cmd(self, cmdline): + def _execute_cmd(self, cmdline: str) -> bool: if cmdline.split()[0] == "cpu": # trap the cpu command, it requires special setting try: @@ -404,16 +419,16 @@ class HMPShell(QMPShell): print('%s: %s' % (resp['error']['class'], resp['error']['desc'])) return True - def show_banner(self, msg='Welcome to the HMP shell!'): + def show_banner(self, msg: str = 'Welcome to the HMP shell!') -> None: QMPShell.show_banner(self, msg) -def die(msg): +def die(msg: str) -> NoReturn: sys.stderr.write('ERROR: %s\n' % msg) sys.exit(1) -def main(): +def main() -> None: parser = argparse.ArgumentParser() parser.add_argument('-H', '--hmp', action='store_true', help='Use HMP interface') From patchwork Wed Nov 4 00:35:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316231 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7CB2C2D0A3 for ; Wed, 4 Nov 2020 01:10:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4F96D223C7 for ; Wed, 4 Nov 2020 01:10:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Iiemx1/n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4F96D223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7JJ-0004As-Dx for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:10:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nt-0007Lv-In for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6np-0004xG-Fd for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450246; 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=W2iHjqkIKG0cOWnHmRr1gY05wStFxbfX6F6YUEQDMNg=; b=Iiemx1/n1ABYKFexztEC52s6chDUD9YwQxuTi22pZkkgIQh00Fjkn8P9p4LehYYVixk7o8 fw/JwjRjtk/JLxdHe28KZPNbzUVsSI8V0Khl9BOScMiPCQ44M3/0TRrPkiR7xByfFGCv8Y bfzN/rs+m5a1qM3gq9eWGCyvFq87p3E= 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-572-Co7zQxJaPVawPMw0uyVL-g-1; Tue, 03 Nov 2020 19:37:25 -0500 X-MC-Unique: Co7zQxJaPVawPMw0uyVL-g-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AAA18030B1 for ; Wed, 4 Nov 2020 00:37:24 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C976F55766; Wed, 4 Nov 2020 00:37:22 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 58/72] scripts/qmp-shell: Accept SocketAddrT instead of string Date: Tue, 3 Nov 2020 19:35:48 -0500 Message-Id: <20201104003602.1293560-59-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Don't extend QEMUMonitorProtocol but change the argument types; move the string parsing just outside of the class. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 2d0e85b5f723..b465c7f9e2d6 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -130,9 +130,9 @@ class FuzzyJSON(ast.NodeTransformer): # TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and # _execute_cmd()). Let's design a better one. class QMPShell(qmp.QEMUMonitorProtocol): - def __init__(self, address: str, pretty: bool = False, - verbose: bool = False): - super().__init__(self.parse_address(address)) + def __init__(self, address: qmp.SocketAddrT, + pretty: bool = False, verbose: bool = False): + super().__init__(address) self._greeting: Optional[QMPMessage] = None self._completer = QMPCompleter() self._pretty = pretty @@ -347,7 +347,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): class HMPShell(QMPShell): - def __init__(self, address: str, + def __init__(self, address: qmp.SocketAddrT, pretty: bool = False, verbose: bool = False): super().__init__(address, pretty, verbose) self.__cpu_index = 0 @@ -450,11 +450,13 @@ def main() -> None: shell_class = HMPShell if args.hmp else QMPShell try: - qemu = shell_class(args.qmp_server, args.pretty, args.verbose) + address = shell_class.parse_address(args.qmp_server) except qmp.QMPBadPortError: parser.error(f"Bad port number: {args.qmp_server}") return # pycharm doesn't know error() is noreturn + qemu = shell_class(address, args.pretty, args.verbose) + try: qemu.connect(negotiate=not args.skip_negotiation) except qmp.QMPConnectError: From patchwork Wed Nov 4 00:35:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316236 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D4DFC2D0A3 for ; Wed, 4 Nov 2020 01:04:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B807E223AB for ; Wed, 4 Nov 2020 01:04:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NLKsDd5j" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B807E223AB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7DU-0004fk-PA for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:04:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nr-0007Km-EU for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6np-0004xS-Ew for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450248; 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=tyMp/WUkbkDPOvDMuuseh09FZ8+pmQhhXtOyGTRegsI=; b=NLKsDd5jxChADc2Dp+BRRaEHHsP4XU3oVgTvRpic8HqwupdNpJR751P1uGz6pB5x45ev/Q VXYh1ApOYcwkyBgWGJYcQ1YxQ/0VY9zE9Rq45HQGLMQDEvTmF+44qouGM8ioTcFmRLX3F8 jqXLBokaMTHba8AWrzhj+4cRvCoiK1M= 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-257-L0qAOpe1OOiH19s5zOqXWQ-1; Tue, 03 Nov 2020 19:37:26 -0500 X-MC-Unique: L0qAOpe1OOiH19s5zOqXWQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F28F1009E26 for ; Wed, 4 Nov 2020 00:37:25 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7562F55766; Wed, 4 Nov 2020 00:37:24 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 59/72] scripts/qmp-shell: unprivatize 'pretty' property Date: Tue, 3 Nov 2020 19:35:49 -0500 Message-Id: <20201104003602.1293560-60-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Similar to verbose, there's no reason this needs to be hidden. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index b465c7f9e2d6..f14fe211cca4 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -135,11 +135,11 @@ class QMPShell(qmp.QEMUMonitorProtocol): super().__init__(address) self._greeting: Optional[QMPMessage] = None self._completer = QMPCompleter() - self._pretty = pretty self._transmode = False self._actions: List[QMPMessage] = [] self._histfile = os.path.join(os.path.expanduser('~'), '.qmp-shell_history') + self.pretty = pretty self.verbose = verbose def _fill_completion(self) -> None: @@ -274,10 +274,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): return qmpcmd def _print(self, qmp_message: object) -> None: - indent = None - if self._pretty: - indent = 4 - jsobj = json.dumps(qmp_message, indent=indent, sort_keys=self._pretty) + jsobj = json.dumps(qmp_message, + indent=4 if self.pretty else None, + sort_keys=self.pretty) print(str(jsobj)) def _execute_cmd(self, cmdline: str) -> bool: From patchwork Wed Nov 4 00:35:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316230 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF6FAC388F7 for ; Wed, 4 Nov 2020 01:12:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4EB3D2074F for ; Wed, 4 Nov 2020 01:12:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KGBfX/Bq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EB3D2074F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7LD-0006ng-1M for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:11:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35992) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nw-0007OD-2s for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59972) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nr-0004xa-3p for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450250; 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=BjOVoF9IAQEpgMWUVUzthZy3hghyNPSDDg5CUOiAI4c=; b=KGBfX/Bqg6adGF0Xwmth6zbHEPl3J4IAkiUb5CbVFZwvFrpllepwda0yE/ABp6h3z0OG7h TsdZiHNSUbips5IHzw8gzmxrgdGJRaPXFYAmRhy4bxj1p1V1hkevQrlxyQKlZ+s+fSHPW8 TXPESC7ZM7zQZFaluZUX2w2JYXkFSl4= 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-401-JKMZM7EgMEapCK6iTthzug-1; Tue, 03 Nov 2020 19:37:28 -0500 X-MC-Unique: JKMZM7EgMEapCK6iTthzug-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 894958030DF for ; Wed, 4 Nov 2020 00:37:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 435D355766; Wed, 4 Nov 2020 00:37:25 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 60/72] python/qmp: return generic type from context manager Date: Tue, 3 Nov 2020 19:35:50 -0500 Message-Id: <20201104003602.1293560-61-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" __enter__ can be invoked from a subclass, so it needs a more specific type. Signed-off-by: John Snow --- python/qemu/qmp/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py index ba0d2281d678..376954cb6d27 100644 --- a/python/qemu/qmp/__init__.py +++ b/python/qemu/qmp/__init__.py @@ -30,6 +30,7 @@ TextIO, Tuple, Type, + TypeVar, Union, cast, ) @@ -220,7 +221,9 @@ def __get_events(self, wait: Union[bool, float] = False) -> None: if ret is None: raise QMPConnectError("Error while reading from socket") - def __enter__(self) -> 'QEMUMonitorProtocol': + T = TypeVar('T') + + def __enter__(self: T) -> T: # Implement context manager enter function. return self From patchwork Wed Nov 4 00:35:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6BC18C2D0A3 for ; Wed, 4 Nov 2020 01:14:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB08E223C7 for ; Wed, 4 Nov 2020 01:14:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I7tuQP2q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB08E223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7O5-0002jB-WE for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:14:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nw-0007P3-DD for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26386) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nt-0004xk-9m for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450251; 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=B9FRDK9RDXP1gvYcLKnDz5U4uhB4JEcP2LMYKIEAfCM=; b=I7tuQP2qUJQaLHe58S5shN6iNyL48a4aNiQdQtrO8jAXyfRoVhAE9i2MSFv9qbiMqFBP37 dzj8KnJZKc+hKXQNSb7wx5ykv85xIfwdxQkvVKXafKeZkACtg6Bd4AIQxuRr70z2fyqj+o m27A+mEgELc4s9Np5NUmler+jmTArHw= 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-noO3gqbbOrWcxtyHMvo6gg-1; Tue, 03 Nov 2020 19:37:29 -0500 X-MC-Unique: noO3gqbbOrWcxtyHMvo6gg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA075108E1A8 for ; Wed, 4 Nov 2020 00:37:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00CD855766; Wed, 4 Nov 2020 00:37:27 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 61/72] scripts/qmp-shell: Use context manager instead of atexit Date: Tue, 3 Nov 2020 19:35:51 -0500 Message-Id: <20201104003602.1293560-62-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We can invoke the shell history writing when we leave the QMPShell scope instead of relying on atexit. Doing so may be preferable to avoid global state being registered from within a class instead of from the application logic directly. Use QMP's context manager to hook this history saving at close time, which gets invoked when we leave the context block. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index f14fe211cca4..ec028d662e8e 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -66,7 +66,6 @@ # sent to QEMU, which is useful for debugging and documentation generation. import argparse import ast -import atexit import json import os import re @@ -142,6 +141,11 @@ class QMPShell(qmp.QEMUMonitorProtocol): self.pretty = pretty self.verbose = verbose + def close(self) -> None: + # Hook into context manager of parent to save shell history. + self._save_history() + super().close() + def _fill_completion(self) -> None: cmds = self.cmd('query-commands') if 'error' in cmds: @@ -164,9 +168,8 @@ class QMPShell(qmp.QEMUMonitorProtocol): pass except IOError as err: print(f"Failed to read history '{self._histfile}': {err!s}") - atexit.register(self.__save_history) - def __save_history(self) -> None: + def _save_history(self) -> None: try: readline.write_history_file(self._histfile) except IOError as err: @@ -448,25 +451,25 @@ def main() -> None: parser.error("QMP socket or TCP address must be specified") shell_class = HMPShell if args.hmp else QMPShell + try: address = shell_class.parse_address(args.qmp_server) except qmp.QMPBadPortError: parser.error(f"Bad port number: {args.qmp_server}") return # pycharm doesn't know error() is noreturn - qemu = shell_class(address, args.pretty, args.verbose) + with shell_class(address, args.pretty, args.verbose) as qemu: + try: + qemu.connect(negotiate=not args.skip_negotiation) + except qmp.QMPConnectError: + die("Didn't get QMP greeting message") + except qmp.QMPCapabilitiesError: + die("Couldn't negotiate capabilities") + except OSError as err: + die(f"Couldn't connect to {args.qmp_server}: {err!s}") - try: - qemu.connect(negotiate=not args.skip_negotiation) - except qmp.QMPConnectError: - die("Didn't get QMP greeting message") - except qmp.QMPCapabilitiesError: - die("Couldn't negotiate capabilities") - except OSError as err: - die(f"Couldn't connect to {args.qmp_server}: {err!s}") - - for _ in qemu.repl(): - pass + for _ in qemu.repl(): + pass if __name__ == '__main__': From patchwork Wed Nov 4 00:35:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316229 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06584C2D0A3 for ; Wed, 4 Nov 2020 01:12:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5BD4223C7 for ; Wed, 4 Nov 2020 01:12:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IvRImPQv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5BD4223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7LZ-0007ir-Qn for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:12:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nv-0007NR-Pc for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nt-0004xp-9u for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450252; 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=TIFuMouv3BevsTrVSomuc/EthhkE99OcgJhVE2XMzY8=; b=IvRImPQvAHmzTxlHhwT8QN0hfiomj2uDij75/m8vn4bpT4hTSVhJh2CUv71xyNkNMng+qb c8MSup/zoYTny8nYlHABAfCY9Yqg8XVFSbirmZFPpA8DIhhSGTF/AQDCgimSrqqwxSpxDG wGBEfGjFzTQuRF7SC+zSmSILuXE0jJY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-343-qEaK0t9-Peei9aKrMiv0tg-1; Tue, 03 Nov 2020 19:37:31 -0500 X-MC-Unique: qEaK0t9-Peei9aKrMiv0tg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 29E301009E26 for ; Wed, 4 Nov 2020 00:37:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36C7E55766; Wed, 4 Nov 2020 00:37:29 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 62/72] scripts/qmp-shell: use logging to show warnings Date: Tue, 3 Nov 2020 19:35:52 -0500 Message-Id: <20201104003602.1293560-63-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Perfect candidate is non-fatal shell history messages. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index ec028d662e8e..0199a13a3428 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -67,6 +67,7 @@ import argparse import ast import json +import logging import os import re import readline @@ -85,6 +86,9 @@ from qemu import qmp from qemu.qmp import QMPMessage +LOG = logging.getLogger(__name__) + + class QMPCompleter: # NB: Python 3.9+ will probably allow us to subclass list[str] directly, # but pylint as of today does not know that List[str] is simply 'list'. @@ -167,13 +171,15 @@ class QMPShell(qmp.QEMUMonitorProtocol): except FileNotFoundError: pass except IOError as err: - print(f"Failed to read history '{self._histfile}': {err!s}") + msg = f"Failed to read history '{self._histfile}': {err!s}" + LOG.warning(msg) def _save_history(self) -> None: try: readline.write_history_file(self._histfile) except IOError as err: - print(f"Failed to save history file '{self._histfile}': {err!s}") + msg = f"Failed to save history file '{self._histfile}': {err!s}" + LOG.warning(msg) @classmethod def __parse_value(cls, val: str) -> object: From patchwork Wed Nov 4 00:35:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7351C2D0A3 for ; Wed, 4 Nov 2020 01:13:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C184223C7 for ; Wed, 4 Nov 2020 01:13:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RwdlGnD0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C184223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:47454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7N3-0001oS-CP for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:13:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6nx-0007SP-DG for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6nv-0004y2-Iu for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450254; 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=wzRB4cjrp4u7lt1vcXzG7IhYHDqdOiEuFhG6Dq+h9EY=; b=RwdlGnD0f+k8MZ7ry2fWLiCflv2kMb7ma4vQX+8xbtHoqOI9mTXiICcMoyJqBL/bcbd+9p MVrGCzJNPaubTmB4Lhanwx4RQme4zE/iaZrtbiaeulkUI/bmwwIhV0mNNQjq1r9YKfQvJP ZJTkVXTjH8Sjo/bhyHbofiTXTfLTx0I= 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-443-MblLetRpM7a0Ve_uZxc5qA-1; Tue, 03 Nov 2020 19:37:33 -0500 X-MC-Unique: MblLetRpM7a0Ve_uZxc5qA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3ED7A6D243 for ; Wed, 4 Nov 2020 00:37:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8255E747C6; Wed, 4 Nov 2020 00:37:31 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 64/72] scripts/qmp-shell: Fix empty-transaction invocation Date: Tue, 3 Nov 2020 19:35:54 -0500 Message-Id: <20201104003602.1293560-65-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 00:03:41 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" calling "transaction( )" is pointless, but valid. Rework the parser to allow this kind of invocation. This helps clean up exception handling later by removing accidental breakages of the parser that aren't explicitly forbidden. Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 3c32b576a37d..78e4eae00754 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -244,11 +244,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): cmdargs = re.findall(argument_regex, cmdline) qmpcmd: QMPMessage - # Transactional CLI entry/exit: - if cmdargs[0] == 'transaction(': + # Transactional CLI entry: + if cmdargs and cmdargs[0] == 'transaction(': self._transmode = True + self._actions = [] cmdargs.pop(0) - elif cmdargs[0] == ')' and self._transmode: + + # Transactional CLI exit: + if cmdargs and cmdargs[0] == ')' and self._transmode: self._transmode = False if len(cmdargs) > 1: msg = 'Unexpected input after close of Transaction sub-shell' @@ -257,15 +260,14 @@ class QMPShell(qmp.QEMUMonitorProtocol): 'execute': 'transaction', 'arguments': {'actions': self._actions} } - self._actions = list() return qmpcmd - # Nothing to process? + # No args, or no args remaining if not cmdargs: return None - # Parse and then cache this Transactional Action if self._transmode: + # Parse and cache this Transactional Action finalize = False action = {'type': cmdargs[0], 'data': {}} if cmdargs[-1] == ')': From patchwork Wed Nov 4 00:35:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 316223 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E91AC2D0A3 for ; Wed, 4 Nov 2020 01:31:07 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88E1120870 for ; Wed, 4 Nov 2020 01:31:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EAjmUQNb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88E1120870 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:56876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ka7dh-0000ul-Hd for qemu-devel@archiver.kernel.org; Tue, 03 Nov 2020 20:31:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ka6o5-0007ef-LM for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36167) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1ka6o0-0004z6-Kd for qemu-devel@nongnu.org; Tue, 03 Nov 2020 19:37:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604450259; 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=6Q7qh9uMxQEd1ERc+PLZ2ut7YmMhXW1F3j7R0pQeAnU=; b=EAjmUQNbN4iZ+D347YGge2iZPvu0jS3bgKaJ5cegY4+8XyXmKQeOG06a0qUAPiHSvASJjh +0xOZGBwZWCApxpYgCm0GD1+XMGerIzr33nSKipToJGdY3AMHxUU6FehVDKzZjHeiP2RyJ IZ2+USjcpWUmTMFIK+xNFYe1dpx6EVc= 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-446-0rnVFqecMruZCXMFDwzIrA-1; Tue, 03 Nov 2020 19:37:38 -0500 X-MC-Unique: 0rnVFqecMruZCXMFDwzIrA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1468F835B8C for ; Wed, 4 Nov 2020 00:37:37 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-97.rdu2.redhat.com [10.10.119.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B35575127; Wed, 4 Nov 2020 00:37:36 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v2 69/72] scripts/qmp-shell: add docstrings Date: Tue, 3 Nov 2020 19:35:59 -0500 Message-Id: <20201104003602.1293560-70-jsnow@redhat.com> In-Reply-To: <20201104003602.1293560-1-jsnow@redhat.com> References: <20201104003602.1293560-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/03 01:02:05 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , Markus Armbruster , Eduardo Habkost Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- scripts/qmp/qmp-shell | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 1a8a4ba18ab4..15aedb80c2af 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -106,15 +106,20 @@ LOG = logging.getLogger(__name__) class QMPCompleter: + """ + QMPCompleter provides a readline library tab-complete behavior. + """ # NB: Python 3.9+ will probably allow us to subclass list[str] directly, # but pylint as of today does not know that List[str] is simply 'list'. def __init__(self) -> None: self._matches: List[str] = [] def append(self, value: str) -> None: + """Append a new valid completion to the list of possibilities.""" return self._matches.append(value) def complete(self, text: str, state: int) -> Optional[str]: + """readline.set_completer() callback implementation.""" for cmd in self._matches: if cmd.startswith(text): if state == 0: @@ -124,7 +129,9 @@ class QMPCompleter: class QMPShellError(qmp.QMPError): - pass + """ + QMP Shell Base error class. + """ class FuzzyJSON(ast.NodeTransformer): @@ -137,6 +144,9 @@ class FuzzyJSON(ast.NodeTransformer): @classmethod def visit_Name(cls, # pylint: disable=invalid-name node: ast.Name) -> ast.AST: + """ + Transform Name nodes with certain values into Constant (keyword) nodes. + """ if node.id == 'true': return ast.Constant(value=True) if node.id == 'false': @@ -147,6 +157,13 @@ class FuzzyJSON(ast.NodeTransformer): class QMPShell(qmp.QEMUMonitorProtocol): + """ + QMPShell provides a basic readline-based QMP shell. + + :param address: Address of the QMP server. + :param pretty: Pretty-print QMP messages. + :param verbose: Echo outgoing QMP messages to console. + """ def __init__(self, address: qmp.SocketAddrT, pretty: bool = False, verbose: bool = False): super().__init__(address) @@ -333,6 +350,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): def show_banner(self, msg: str = 'Welcome to the QMP low-level shell!') -> None: + """ + Print to stdio a greeting, and the QEMU version if available. + """ print(msg) if not self._greeting: print('Connected') @@ -342,6 +362,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): @property def prompt(self) -> str: + """ + Return the current shell prompt, including a trailing space. + """ if self._transmode: return 'TRANS> ' return '(QEMU) ' @@ -367,6 +390,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): return self._execute_cmd(cmdline) def repl(self) -> Iterator[None]: + """ + Return an iterator that implements the REPL. + """ self.show_banner() while self.read_exec_command(): yield @@ -374,6 +400,13 @@ class QMPShell(qmp.QEMUMonitorProtocol): class HMPShell(QMPShell): + """ + HMPShell provides a basic readline-based HMP shell, tunnelled via QMP. + + :param address: Address of the QMP server. + :param pretty: Pretty-print QMP messages. + :param verbose: Echo outgoing QMP messages to console. + """ def __init__(self, address: qmp.SocketAddrT, pretty: bool = False, verbose: bool = False): super().__init__(address, pretty, verbose) @@ -451,11 +484,15 @@ class HMPShell(QMPShell): def die(msg: str) -> NoReturn: + """Write an error to stderr, then exit with a return code of 1.""" sys.stderr.write('ERROR: %s\n' % msg) sys.exit(1) def main() -> None: + """ + qmp-shell entry point: parse command line arguments and start the REPL. + """ parser = argparse.ArgumentParser() parser.add_argument('-H', '--hmp', action='store_true', help='Use HMP interface')