From nobody Wed Oct 29 17:10:19 2025 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 1526651722797256.23458307488306; Fri, 18 May 2018 06:55:22 -0700 (PDT) Received: from localhost ([::1]:39094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfqr-0004F2-PY for importer@patchew.org; Fri, 18 May 2018 09:55:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fJfL1-0000Xl-P0 for qemu-devel@nongnu.org; Fri, 18 May 2018 09:22:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fJfL0-0006VZ-JI for qemu-devel@nongnu.org; Fri, 18 May 2018 09:22:27 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40294 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 1fJfKx-0006Sn-O8; Fri, 18 May 2018 09:22:23 -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 59FA54023112; Fri, 18 May 2018 13:22:23 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-149.ams2.redhat.com [10.36.117.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DAA52024CBF; Fri, 18 May 2018 13:22:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 18 May 2018 15:21:13 +0200 Message-Id: <20180518132114.4070-40-kwolf@redhat.com> In-Reply-To: <20180518132114.4070-1-kwolf@redhat.com> References: <20180518132114.4070-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.6]); Fri, 18 May 2018 13:22:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 18 May 2018 13:22:23 +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 v2 39/40] 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, jsnow@redhat.com, jcody@redhat.com, armbru@redhat.com, mreitz@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 Reviewed-by: Max Reitz --- 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 ed08e06e1f..28159d837a 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