From nobody Sat Sep 21 03:12:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647951723988826.2367555590998; Tue, 22 Mar 2022 05:22:03 -0700 (PDT) Received: from localhost ([::1]:56250 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nWdWW-0005xg-6h for importer@patchew.org; Tue, 22 Mar 2022 08:22:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWd8r-0003Vf-Fc for qemu-devel@nongnu.org; Tue, 22 Mar 2022 07:57:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29982) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWd8p-0006ZB-HQ for qemu-devel@nongnu.org; Tue, 22 Mar 2022 07:57:37 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-641-vXeJdMIwNbau2IeqP0mqTg-1; Tue, 22 Mar 2022 07:57:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E1FD811E90; Tue, 22 Mar 2022 11:57:13 +0000 (UTC) Received: from localhost (unknown [10.39.194.233]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F11F22166B2D; Tue, 22 Mar 2022 11:57:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647950255; 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=VWCrENiyWJM9cry0gGVnTJOzSRziA60ognUlZOfbQes=; b=MZm/0/E4Bvs2cbudhdJbAIAsLEHcgNrVmQyCTsV5dFWco5DsHJeTr3hwPfK6ySdaFkqO87 ipXtqCyV4ktVeXmzxR4X5Fg3lL+W57oOHk5ijY6qgiMcwR4OKkW9kK2PVq/IQyKHaqsy07 PShhVfZFrOKTXz4sNwVm4QZMK0Su/Pg= X-MC-Unique: vXeJdMIwNbau2IeqP0mqTg-1 From: Hanna Reitz To: qemu-block@nongnu.org Subject: [PULL 15/25] iotests: add qemu_img_map() function Date: Tue, 22 Mar 2022 12:56:37 +0100 Message-Id: <20220322115647.726044-16-hreitz@redhat.com> In-Reply-To: <20220322115647.726044-1-hreitz@redhat.com> References: <20220322115647.726044-1-hreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , Hanna Reitz , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647951736799100003 Content-Type: text/plain; charset="utf-8" From: John Snow Add a qemu_img_map() function by analogy with qemu_img_measure(), qemu_img_check(), and qemu_img_info() that all return JSON information. Replace calls to qemu_img_pipe('map', '--output=3Djson', ...) with this new function, which provides better diagnostic information on failure. Note: The output for iotest 211 changes, because logging JSON after it was deserialized by Python behaves a little differently than logging the raw JSON document string itself. (iotests.log() sorts the keys for Python 3.6 support.) Signed-off-by: John Snow Reviewed-by: Eric Blake Message-Id: <20220321201618.903471-11-jsnow@redhat.com> Signed-off-by: Hanna Reitz --- tests/qemu-iotests/041 | 5 ++--- tests/qemu-iotests/211 | 6 +++--- tests/qemu-iotests/211.out | 10 +++------- tests/qemu-iotests/iotests.py | 3 +++ tests/qemu-iotests/tests/block-status-cache | 11 ++++------- tests/qemu-iotests/tests/parallels-read-bitmap | 6 ++---- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index db9f5dc540..3e16acee56 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -24,7 +24,7 @@ import os import re import json import iotests -from iotests import qemu_img, qemu_img_pipe, qemu_io +from iotests import qemu_img, qemu_img_map, qemu_io =20 backing_img =3D os.path.join(iotests.test_dir, 'backing.img') target_backing_img =3D os.path.join(iotests.test_dir, 'target-backing.img') @@ -1360,8 +1360,7 @@ class TestFilters(iotests.QMPTestCase): =20 self.vm.qmp('blockdev-del', node_name=3D'target') =20 - target_map =3D qemu_img_pipe('map', '--output=3Djson', target_img) - target_map =3D json.loads(target_map) + target_map =3D qemu_img_map(target_img) =20 assert target_map[0]['start'] =3D=3D 0 assert target_map[0]['length'] =3D=3D 512 * 1024 diff --git a/tests/qemu-iotests/211 b/tests/qemu-iotests/211 index f52cadade1..1a3b4596c8 100755 --- a/tests/qemu-iotests/211 +++ b/tests/qemu-iotests/211 @@ -59,7 +59,7 @@ with iotests.FilePath('t.vdi') as disk_path, \ vm.shutdown() =20 iotests.img_info_log(disk_path) - iotests.log(iotests.qemu_img_pipe('map', '--output=3Djson', disk_path)) + iotests.log(iotests.qemu_img_map(disk_path)) =20 # # Successful image creation (explicit defaults) @@ -83,7 +83,7 @@ with iotests.FilePath('t.vdi') as disk_path, \ vm.shutdown() =20 iotests.img_info_log(disk_path) - iotests.log(iotests.qemu_img_pipe('map', '--output=3Djson', disk_path)) + iotests.log(iotests.qemu_img_map(disk_path)) =20 # # Successful image creation (with non-default options) @@ -107,7 +107,7 @@ with iotests.FilePath('t.vdi') as disk_path, \ vm.shutdown() =20 iotests.img_info_log(disk_path) - iotests.log(iotests.qemu_img_pipe('map', '--output=3Djson', disk_path)) + iotests.log(iotests.qemu_img_map(disk_path)) =20 # # Invalid BlockdevRef diff --git a/tests/qemu-iotests/211.out b/tests/qemu-iotests/211.out index c4425b5982..f02c75409c 100644 --- a/tests/qemu-iotests/211.out +++ b/tests/qemu-iotests/211.out @@ -17,8 +17,7 @@ file format: IMGFMT virtual size: 128 MiB (134217728 bytes) cluster_size: 1048576 =20 -[{ "start": 0, "length": 134217728, "depth": 0, "present": true, "zero": t= rue, "data": false}] - +[{"data": false, "depth": 0, "length": 134217728, "present": true, "start"= : 0, "zero": true}] =3D=3D=3D Successful image creation (explicit defaults) =3D=3D=3D =20 {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "file", "filename": "TEST_DIR/PID-t.vdi", "size": 0}}} @@ -36,8 +35,7 @@ file format: IMGFMT virtual size: 64 MiB (67108864 bytes) cluster_size: 1048576 =20 -[{ "start": 0, "length": 67108864, "depth": 0, "present": true, "zero": tr= ue, "data": false}] - +[{"data": false, "depth": 0, "length": 67108864, "present": true, "start":= 0, "zero": true}] =3D=3D=3D Successful image creation (with non-default options) =3D=3D=3D =20 {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "file", "filename": "TEST_DIR/PID-t.vdi", "size": 0}}} @@ -55,9 +53,7 @@ file format: IMGFMT virtual size: 32 MiB (33554432 bytes) cluster_size: 1048576 =20 -[{ "start": 0, "length": 3072, "depth": 0, "present": true, "zero": false,= "data": true, "offset": 1024}, -{ "start": 3072, "length": 33551360, "depth": 0, "present": true, "zero": = true, "data": true, "offset": 4096}] - +[{"data": true, "depth": 0, "length": 3072, "offset": 1024, "present": tru= e, "start": 0, "zero": false}, {"data": true, "depth": 0, "length": 3355136= 0, "offset": 4096, "present": true, "start": 3072, "zero": true}] =3D=3D=3D Invalid BlockdevRef =3D=3D=3D =20 {"execute": "blockdev-create", "arguments": {"job-id": "job0", "options": = {"driver": "vdi", "file": "this doesn't exist", "size": 33554432}}} diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 2a1c589b76..b3e793f78a 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -318,6 +318,9 @@ def qemu_img_check(*args: str) -> Any: def qemu_img_info(*args: str) -> Any: return qemu_img_json('info', "--output", "json", *args) =20 +def qemu_img_map(*args: str) -> Any: + return qemu_img_json('map', "--output", "json", *args) + def qemu_img_pipe(*args: str) -> str: '''Run qemu-img and return its output''' return qemu_img_pipe_and_status(*args)[0] diff --git a/tests/qemu-iotests/tests/block-status-cache b/tests/qemu-iotes= ts/tests/block-status-cache index 40e648e251..5a7bc2c149 100755 --- a/tests/qemu-iotests/tests/block-status-cache +++ b/tests/qemu-iotests/tests/block-status-cache @@ -22,7 +22,7 @@ import os import signal import iotests -from iotests import qemu_img_create, qemu_img_pipe, qemu_nbd +from iotests import qemu_img_create, qemu_img_map, qemu_nbd =20 =20 image_size =3D 1 * 1024 * 1024 @@ -76,8 +76,7 @@ class TestBscWithNbd(iotests.QMPTestCase): # to allocate the first sector to facilitate alignment probing), a= nd # then the rest to be zero. The BSC will thus contain (if anythin= g) # one range covering the first sector. - map_pre =3D qemu_img_pipe('map', '--output=3Djson', '--image-opts', - nbd_img_opts) + map_pre =3D qemu_img_map('--image-opts', nbd_img_opts) =20 # qemu:allocation-depth maps for want_zero=3Dfalse. # want_zero=3Dfalse should (with the file driver, which the server= is @@ -111,14 +110,12 @@ class TestBscWithNbd(iotests.QMPTestCase): # never loop too many times here. for _ in range(2): # (Ignore the result, this is just to contaminate the cache) - qemu_img_pipe('map', '--output=3Djson', '--image-opts', - nbd_img_opts_alloc_depth) + qemu_img_map('--image-opts', nbd_img_opts_alloc_depth) =20 # Now let's see whether the cache reports everything as data, or # whether we get correct information (i.e. the same as we got on o= ur # first attempt). - map_post =3D qemu_img_pipe('map', '--output=3Djson', '--image-opts= ', - nbd_img_opts) + map_post =3D qemu_img_map('--image-opts', nbd_img_opts) =20 if map_pre !=3D map_post: print('ERROR: Map information differs before and after queryin= g ' + diff --git a/tests/qemu-iotests/tests/parallels-read-bitmap b/tests/qemu-io= tests/tests/parallels-read-bitmap index af6b9c5db3..38ab5fa5b2 100755 --- a/tests/qemu-iotests/tests/parallels-read-bitmap +++ b/tests/qemu-iotests/tests/parallels-read-bitmap @@ -18,9 +18,8 @@ # along with this program. If not, see . # =20 -import json import iotests -from iotests import qemu_nbd_popen, qemu_img_pipe, log, file_path +from iotests import qemu_nbd_popen, qemu_img_map, log, file_path =20 iotests.script_initialize(supported_fmts=3D['parallels']) =20 @@ -36,8 +35,7 @@ iotests.unarchive_sample_image('parallels-with-bitmap', d= isk) =20 with qemu_nbd_popen('--read-only', f'--socket=3D{nbd_sock}', f'--bitmap=3D{bitmap}', '-f', iotests.imgfmt, disk): - out =3D qemu_img_pipe('map', '--output=3Djson', '--image-opts', nbd_op= ts) - chunks =3D json.loads(out) + chunks =3D qemu_img_map('--image-opts', nbd_opts) cluster =3D 64 * 1024 =20 log('dirty clusters (cluster size is 64K):') --=20 2.35.1