diff mbox series

[66/67] iotests.py: Forbid qemu_img*('create', ...)

Message ID 20191001194715.2796-67-mreitz@redhat.com
State New
Headers show
Series iotests: Honor $IMGOPTS in Python tests | expand

Commit Message

Max Reitz Oct. 1, 2019, 7:47 p.m. UTC
All tests should use create_test_image().

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/iotests.py | 36 +++++++++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index f3c80ba4e9..2e377b8379 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -82,12 +82,20 @@  luks_default_secret_object = 'secret,id=keysec0,data=' + \
 luks_default_key_secret_opt = 'key-secret=keysec0'
 
 
-def qemu_img(*args):
+# @from_create_test_image is purely for use in create_test_image
+def qemu_img(*args, from_create_test_image=False):
     '''Run qemu-img and return the exit code'''
+    args = list(args)
+
+    assert args[0] != 'create' or from_create_test_image, \
+        'Use iotests.create_test_image for image creation'
+
     devnull = open('/dev/null', 'r+')
-    exitcode = subprocess.call(qemu_img_args + list(args), stdin=devnull, stdout=devnull)
+    exitcode = subprocess.call(qemu_img_args + args,
+                               stdin=devnull, stdout=devnull)
     if exitcode < 0:
-        sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
+        sys.stderr.write('qemu-img received signal %i: %s\n' %
+                         (-exitcode, ' '.join(qemu_img_args + args)))
     return exitcode
 
 def ordered_qmp(qmsg, conv_keys=True):
@@ -162,7 +170,7 @@  def create_test_image(filename, size=None, fmt=imgfmt, opts=[],
     if size is not None:
         args.append(str(size))
 
-    return qemu_img(*args)
+    return qemu_img(*args, from_create_test_image=True)
 
 # Use this to remove images create with create_test_image in the
 # default image format (iotests.imgfmt)
@@ -180,20 +188,32 @@  def remove_test_image(filename):
 
 def qemu_img_verbose(*args):
     '''Run qemu-img without suppressing its output and return the exit code'''
-    exitcode = subprocess.call(qemu_img_args + list(args))
+    args = list(args)
+
+    assert args[0] != 'create', \
+            'Use iotests.create_test_image for image creation'
+
+    exitcode = subprocess.call(qemu_img_args + args)
     if exitcode < 0:
-        sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
+        sys.stderr.write('qemu-img received signal %i: %s\n' %
+                         (-exitcode, ' '.join(qemu_img_args + args)))
     return exitcode
 
 def qemu_img_pipe(*args):
     '''Run qemu-img and return its output'''
-    subp = subprocess.Popen(qemu_img_args + list(args),
+    args = list(args)
+
+    assert args[0] != 'create', \
+            'Use iotests.create_test_image for image creation'
+
+    subp = subprocess.Popen(qemu_img_args + args,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT,
                             universal_newlines=True)
     exitcode = subp.wait()
     if exitcode < 0:
-        sys.stderr.write('qemu-img received signal %i: %s\n' % (-exitcode, ' '.join(qemu_img_args + list(args))))
+        sys.stderr.write('qemu-img received signal %i: %s\n' %
+                         (-exitcode, ' '.join(qemu_img_args + args)))
     return subp.communicate()[0]
 
 def qemu_img_log(*args):