diff mbox

[for-2.6,v3,2/3] iotests: Add iotests.image_size

Message ID 1461162766-907-3-git-send-email-kwolf@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kevin Wolf April 20, 2016, 2:32 p.m. UTC
From: Fam Zheng <famz@redhat.com>

This retrieves the virtual size of the image out of qemu-img info.

Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/iotests.py | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Jeff Cody April 20, 2016, 2:48 p.m. UTC | #1
On Wed, Apr 20, 2016 at 04:32:45PM +0200, Kevin Wolf wrote:
> From: Fam Zheng <famz@redhat.com>
> 
> This retrieves the virtual size of the image out of qemu-img info.
> 
> Reviewed-by: Max Reitz <mreitz@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/qemu-iotests/iotests.py | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index d9ef60e..56f988a 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -28,6 +28,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts', '
>  import qmp
>  import qtest
>  import struct
> +import json
>  
>  
>  # This will not work if arguments contain spaces but is necessary if we
> @@ -103,6 +104,11 @@ def create_image(name, size):
>          i = i + 512
>      file.close()
>  
> +def image_size(img):
> +    '''Return image's virtual size'''
> +    r = qemu_img_pipe('info', '--output=json', '-f', imgfmt, img)
> +    return json.loads(r)['virtual-size']
> +
>  test_dir_re = re.compile(r"%s" % test_dir)
>  def filter_test_dir(msg):
>      return test_dir_re.sub("TEST_DIR", msg)
> -- 
> 1.8.3.1
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>
diff mbox

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index d9ef60e..56f988a 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -28,6 +28,7 @@  sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts', '
 import qmp
 import qtest
 import struct
+import json
 
 
 # This will not work if arguments contain spaces but is necessary if we
@@ -103,6 +104,11 @@  def create_image(name, size):
         i = i + 512
     file.close()
 
+def image_size(img):
+    '''Return image's virtual size'''
+    r = qemu_img_pipe('info', '--output=json', '-f', imgfmt, img)
+    return json.loads(r)['virtual-size']
+
 test_dir_re = re.compile(r"%s" % test_dir)
 def filter_test_dir(msg):
     return test_dir_re.sub("TEST_DIR", msg)