From nobody Sun Feb 8 11:01:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525885114158458.5588121379101; Wed, 9 May 2018 09:58:34 -0700 (PDT) Received: from localhost ([::1]:57719 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGSQD-0005aD-3b for importer@patchew.org; Wed, 09 May 2018 12:58:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGRwr-00069n-4w for qemu-devel@nongnu.org; Wed, 09 May 2018 12:28:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGRwq-00039G-04 for qemu-devel@nongnu.org; Wed, 09 May 2018 12:28:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50674 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGRwn-00033e-62; Wed, 09 May 2018 12:28:09 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F0574059FE0; Wed, 9 May 2018 16:28:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-193.ams2.redhat.com [10.36.117.193]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4145B2023433; Wed, 9 May 2018 16:28:07 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 9 May 2018 18:26:36 +0200 Message-Id: <20180509162637.15575-42-kwolf@redhat.com> In-Reply-To: <20180509162637.15575-1-kwolf@redhat.com> References: <20180509162637.15575-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 09 May 2018 16:28:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 09 May 2018 16:28:08 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 41/42] iotests: Move qmp_to_opts() to VM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, jcody@redhat.com, armbru@redhat.com, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qmp_to_opts() used to be a method of QMPTestCase, but recently we started to add more Python test cases that don't make use of QMPTestCase. In order to make the method usable there, move it to VM. Signed-off-by: Kevin Wolf --- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/155 | 2 +- tests/qemu-iotests/iotests.py | 45 ++++++++++++++++++++++-----------------= ---- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index e94587950c..c20ac7da87 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1030,9 +1030,9 @@ class TestOrphanedSource(iotests.QMPTestCase): 'read-only': 'on' } =20 self.vm =3D iotests.VM() - self.vm.add_blockdev(self.qmp_to_opts(blk0)) - self.vm.add_blockdev(self.qmp_to_opts(blk1)) - self.vm.add_blockdev(self.qmp_to_opts(blk2)) + self.vm.add_blockdev(self.vm.qmp_to_opts(blk0)) + self.vm.add_blockdev(self.vm.qmp_to_opts(blk1)) + self.vm.add_blockdev(self.vm.qmp_to_opts(blk2)) self.vm.launch() =20 def tearDown(self): diff --git a/tests/qemu-iotests/155 b/tests/qemu-iotests/155 index 42dae04c83..63a5b5e2c0 100755 --- a/tests/qemu-iotests/155 +++ b/tests/qemu-iotests/155 @@ -63,7 +63,7 @@ class BaseClass(iotests.QMPTestCase): 'driver': iotests.imgfmt, 'file': {'driver': 'file', 'filename': source_img}} - self.vm.add_blockdev(self.qmp_to_opts(blockdev)) + self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev)) self.vm.add_device('virtio-blk,id=3Dqdev0,drive=3Dsource') self.vm.launch() =20 diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index b25d48a91b..7040f71b57 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -363,6 +363,27 @@ class VM(qtest.QEMUQtestMachine): return self.qmp('human-monitor-command', command_line=3D'qemu-io %s "%s"' % (drive, cmd)) =20 + def flatten_qmp_object(self, obj, output=3DNone, basestr=3D''): + if output is None: + output =3D dict() + if isinstance(obj, list): + for i in range(len(obj)): + self.flatten_qmp_object(obj[i], output, basestr + str(i) += '.') + elif isinstance(obj, dict): + for key in obj: + self.flatten_qmp_object(obj[key], output, basestr + key + = '.') + else: + output[basestr[:-1]] =3D obj # Strip trailing '.' + return output + + def qmp_to_opts(self, obj): + obj =3D self.flatten_qmp_object(obj) + output_list =3D list() + for key in obj: + output_list +=3D [key + '=3D' + obj[key]] + return ','.join(output_list) + + =20 index_re =3D re.compile(r'([^\[]+)\[([^\]]+)\]') =20 @@ -390,26 +411,6 @@ class QMPTestCase(unittest.TestCase): self.fail('invalid index "%s" in path "%s" in "%s"' % = (idx, path, str(d))) return d =20 - def flatten_qmp_object(self, obj, output=3DNone, basestr=3D''): - if output is None: - output =3D dict() - if isinstance(obj, list): - for i in range(len(obj)): - self.flatten_qmp_object(obj[i], output, basestr + str(i) += '.') - elif isinstance(obj, dict): - for key in obj: - self.flatten_qmp_object(obj[key], output, basestr + key + = '.') - else: - output[basestr[:-1]] =3D obj # Strip trailing '.' - return output - - def qmp_to_opts(self, obj): - obj =3D self.flatten_qmp_object(obj) - output_list =3D list() - for key in obj: - output_list +=3D [key + '=3D' + obj[key]] - return ','.join(output_list) - def assert_qmp_absent(self, d, path): try: result =3D self.dictpath(d, path) @@ -444,8 +445,8 @@ class QMPTestCase(unittest.TestCase): '''Asserts that the given filename is a json: filename and that its content is equal to the given reference object''' self.assertEqual(json_filename[:5], 'json:') - self.assertEqual(self.flatten_qmp_object(json.loads(json_filename[= 5:])), - self.flatten_qmp_object(reference)) + self.assertEqual(self.vm.flatten_qmp_object(json.loads(json_filena= me[5:])), + self.vm.flatten_qmp_object(reference)) =20 def cancel_and_wait(self, drive=3D'drive0', force=3DFalse, resume=3DFa= lse): '''Cancel a block job and wait for it to finish, returning the eve= nt''' --=20 2.13.6