Browse Source

iotests: add script_initialize

Like script_main, but doesn't require a single point of entry.
Replace all existing initialization sections with this drop-in replacement.

This brings debug support to all existing script-style iotests.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200331000014.11581-12-jsnow@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
[mreitz: Give 274 the same treatment]
Signed-off-by: Max Reitz <mreitz@redhat.com>
pull/93/head
John Snow 6 years ago
committed by Max Reitz
parent
commit
7d8140595f
  1. 3
      tests/qemu-iotests/149
  2. 4
      tests/qemu-iotests/194
  3. 4
      tests/qemu-iotests/202
  4. 4
      tests/qemu-iotests/203
  5. 2
      tests/qemu-iotests/206
  6. 6
      tests/qemu-iotests/207
  7. 2
      tests/qemu-iotests/208
  8. 2
      tests/qemu-iotests/209
  9. 6
      tests/qemu-iotests/210
  10. 6
      tests/qemu-iotests/211
  11. 6
      tests/qemu-iotests/212
  12. 6
      tests/qemu-iotests/213
  13. 4
      tests/qemu-iotests/216
  14. 2
      tests/qemu-iotests/218
  15. 2
      tests/qemu-iotests/219
  16. 7
      tests/qemu-iotests/222
  17. 4
      tests/qemu-iotests/224
  18. 6
      tests/qemu-iotests/228
  19. 4
      tests/qemu-iotests/234
  20. 4
      tests/qemu-iotests/235
  21. 2
      tests/qemu-iotests/236
  22. 2
      tests/qemu-iotests/237
  23. 2
      tests/qemu-iotests/238
  24. 2
      tests/qemu-iotests/242
  25. 2
      tests/qemu-iotests/246
  26. 2
      tests/qemu-iotests/248
  27. 2
      tests/qemu-iotests/254
  28. 2
      tests/qemu-iotests/255
  29. 2
      tests/qemu-iotests/256
  30. 7
      tests/qemu-iotests/258
  31. 4
      tests/qemu-iotests/260
  32. 4
      tests/qemu-iotests/262
  33. 4
      tests/qemu-iotests/264
  34. 4
      tests/qemu-iotests/274
  35. 2
      tests/qemu-iotests/277
  36. 8
      tests/qemu-iotests/280
  37. 4
      tests/qemu-iotests/283
  38. 76
      tests/qemu-iotests/iotests.py

3
tests/qemu-iotests/149

@ -382,8 +382,7 @@ def test_once(config, qemu_img=False):
# Obviously we only work with the luks image format
iotests.verify_image_format(supported_fmts=['luks'])
iotests.verify_platform()
iotests.script_initialize(supported_fmts=['luks'])
# We need sudo in order to run cryptsetup to create
# dm-crypt devices. This is safe to use on any

4
tests/qemu-iotests/194

@ -21,8 +21,8 @@
import iotests
iotests.verify_image_format(supported_fmts=['qcow2', 'qed', 'raw'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'],
supported_platforms=['linux'])
with iotests.FilePath('source.img') as source_img_path, \
iotests.FilePath('dest.img') as dest_img_path, \

4
tests/qemu-iotests/202

@ -24,8 +24,8 @@
import iotests
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2'],
supported_platforms=['linux'])
with iotests.FilePath('disk0.img') as disk0_img_path, \
iotests.FilePath('disk1.img') as disk1_img_path, \

4
tests/qemu-iotests/203

@ -24,8 +24,8 @@
import iotests
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2'],
supported_platforms=['linux'])
with iotests.FilePath('disk0.img') as disk0_img_path, \
iotests.FilePath('disk1.img') as disk1_img_path, \

2
tests/qemu-iotests/206

@ -23,7 +23,7 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
with iotests.FilePath('t.qcow2') as disk_path, \
iotests.FilePath('t.qcow2.base') as backing_path, \

6
tests/qemu-iotests/207

@ -24,8 +24,10 @@ import iotests
import subprocess
import re
iotests.verify_image_format(supported_fmts=['raw'])
iotests.verify_protocol(supported=['ssh'])
iotests.script_initialize(
supported_fmts=['raw'],
supported_protocols=['ssh'],
)
def filter_hash(qmsg):
def _filter(key, value):

2
tests/qemu-iotests/208

@ -22,7 +22,7 @@
import iotests
iotests.verify_image_format(supported_fmts=['generic'])
iotests.script_initialize(supported_fmts=['generic'])
with iotests.FilePath('disk.img') as disk_img_path, \
iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \

2
tests/qemu-iotests/209

@ -22,7 +22,7 @@ import iotests
from iotests import qemu_img_create, qemu_io, qemu_img_verbose, qemu_nbd, \
file_path
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
disk = file_path('disk')
nbd_sock = file_path('nbd-sock', base_dir=iotests.sock_dir)

6
tests/qemu-iotests/210

@ -23,8 +23,10 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['luks'])
iotests.verify_protocol(supported=['file'])
iotests.script_initialize(
supported_fmts=['luks'],
supported_protocols=['file'],
)
with iotests.FilePath('t.luks') as disk_path, \
iotests.VM() as vm:

6
tests/qemu-iotests/211

@ -23,8 +23,10 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['vdi'])
iotests.verify_protocol(supported=['file'])
iotests.script_initialize(
supported_fmts=['vdi'],
supported_protocols=['file'],
)
def blockdev_create(vm, options):
error = vm.blockdev_create(options)

6
tests/qemu-iotests/212

@ -23,8 +23,10 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['parallels'])
iotests.verify_protocol(supported=['file'])
iotests.script_initialize(
supported_fmts=['parallels'],
supported_protocols=['file'],
)
with iotests.FilePath('t.parallels') as disk_path, \
iotests.VM() as vm:

6
tests/qemu-iotests/213

@ -23,8 +23,10 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['vhdx'])
iotests.verify_protocol(supported=['file'])
iotests.script_initialize(
supported_fmts=['vhdx'],
supported_protocols=['file'],
)
with iotests.FilePath('t.vhdx') as disk_path, \
iotests.VM() as vm:

4
tests/qemu-iotests/216

@ -23,8 +23,8 @@ import iotests
from iotests import log, qemu_img, qemu_io_silent
# Need backing file support
iotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'],
supported_platforms=['linux'])
log('')
log('=== Copy-on-read across nodes ===')

2
tests/qemu-iotests/218

@ -29,7 +29,7 @@
import iotests
from iotests import log, qemu_img, qemu_io_silent
iotests.verify_image_format(supported_fmts=['qcow2', 'raw'])
iotests.script_initialize(supported_fmts=['qcow2', 'raw'])
# Launches the VM, adds two null-co nodes (source and target), and

2
tests/qemu-iotests/219

@ -21,7 +21,7 @@
import iotests
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
img_size = 4 * 1024 * 1024

7
tests/qemu-iotests/222

@ -24,9 +24,10 @@
import iotests
from iotests import log, qemu_img, qemu_io, qemu_io_silent
iotests.verify_platform(['linux'])
iotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk',
'vhdx', 'raw'])
iotests.script_initialize(
supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk', 'vhdx', 'raw'],
supported_platforms=['linux'],
)
patterns = [("0x5d", "0", "64k"),
("0xd5", "1M", "64k"),

4
tests/qemu-iotests/224

@ -26,8 +26,8 @@ from iotests import log, qemu_img, qemu_io_silent, filter_qmp_testfiles, \
import json
# Need backing file support (for arbitrary backing formats)
iotests.verify_image_format(supported_fmts=['qcow2', 'qcow', 'qed'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed'],
supported_platforms=['linux'])
# There are two variations of this test:

6
tests/qemu-iotests/228

@ -25,8 +25,10 @@ from iotests import log, qemu_img, filter_testfiles, filter_imgfmt, \
filter_qmp_testfiles, filter_qmp_imgfmt
# Need backing file and change-backing-file support
iotests.verify_image_format(supported_fmts=['qcow2', 'qed'])
iotests.verify_platform(['linux'])
iotests.script_initialize(
supported_fmts=['qcow2', 'qed'],
supported_platforms=['linux'],
)
def log_node_info(node):

4
tests/qemu-iotests/234

@ -23,8 +23,8 @@
import iotests
import os
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2'],
supported_platforms=['linux'])
with iotests.FilePath('img') as img_path, \
iotests.FilePath('backing') as backing_path, \

4
tests/qemu-iotests/235

@ -27,6 +27,8 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
from qemu.machine import QEMUMachine
iotests.script_initialize(supported_fmts=['qcow2'])
# Note:
# This test was added to check that mirror dead-lock was fixed (see previous
# commit before this test addition).
@ -40,8 +42,6 @@ from qemu.machine import QEMUMachine
size = 1 * 1024 * 1024 * 1024
iotests.verify_image_format(supported_fmts=['qcow2'])
disk = file_path('disk')
# prepare source image

2
tests/qemu-iotests/236

@ -22,7 +22,7 @@
import iotests
from iotests import log
iotests.verify_image_format(supported_fmts=['generic'])
iotests.script_initialize(supported_fmts=['generic'])
size = 64 * 1024 * 1024
granularity = 64 * 1024

2
tests/qemu-iotests/237

@ -24,7 +24,7 @@ import math
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['vmdk'])
iotests.script_initialize(supported_fmts=['vmdk'])
with iotests.FilePath('t.vmdk') as disk_path, \
iotests.FilePath('t.vmdk.1') as extent1_path, \

2
tests/qemu-iotests/238

@ -23,6 +23,8 @@ import os
import iotests
from iotests import log
iotests.script_initialize()
virtio_scsi_device = iotests.get_virtio_scsi_device()
vm = iotests.VM()

2
tests/qemu-iotests/242

@ -24,7 +24,7 @@ import struct
from iotests import qemu_img_create, qemu_io, qemu_img_pipe, \
file_path, img_info_log, log, filter_qemu_io
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
disk = file_path('disk')
chunk = 256 * 1024

2
tests/qemu-iotests/246

@ -22,7 +22,7 @@
import iotests
from iotests import log
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
size = 64 * 1024 * 1024 * 1024
gran_small = 32 * 1024
gran_large = 128 * 1024

2
tests/qemu-iotests/248

@ -21,7 +21,7 @@
import iotests
from iotests import qemu_img_create, qemu_io, file_path, filter_qmp_testfiles
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
source, target = file_path('source', 'target')
size = 5 * 1024 * 1024

2
tests/qemu-iotests/254

@ -21,7 +21,7 @@
import iotests
from iotests import qemu_img_create, file_path, log
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
disk, top = file_path('disk', 'top')
size = 1024 * 1024

2
tests/qemu-iotests/255

@ -23,7 +23,7 @@
import iotests
from iotests import imgfmt
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
iotests.log('Finishing a commit job with background reads')
iotests.log('============================================')

2
tests/qemu-iotests/256

@ -23,7 +23,7 @@ import os
import iotests
from iotests import log
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(supported_fmts=['qcow2'])
size = 64 * 1024 * 1024
with iotests.FilePath('img0') as img0_path, \

7
tests/qemu-iotests/258

@ -24,9 +24,10 @@ from iotests import log, qemu_img, qemu_io_silent, \
filter_qmp_testfiles, filter_qmp_imgfmt
# Need backing file and change-backing-file support
iotests.verify_image_format(supported_fmts=['qcow2', 'qed'])
iotests.verify_platform(['linux'])
iotests.script_initialize(
supported_fmts=['qcow2', 'qed'],
supported_platforms=['linux'],
)
# Returns a node for blockdev-add
def node(node_name, path, backing=None, fmt=None, throttle=None):

4
tests/qemu-iotests/260

@ -21,7 +21,9 @@
import iotests
from iotests import qemu_img_create, file_path, log, filter_qmp_event
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(
supported_fmts=['qcow2']
)
base, top = file_path('base', 'top')
size = 64 * 1024 * 3

4
tests/qemu-iotests/262

@ -23,8 +23,8 @@
import iotests
import os
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2'],
supported_platforms=['linux'])
with iotests.FilePath('img') as img_path, \
iotests.FilePath('mig_fifo') as fifo, \

4
tests/qemu-iotests/264

@ -24,7 +24,9 @@ import iotests
from iotests import qemu_img_create, qemu_io_silent_check, file_path, \
qemu_nbd_popen, log
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(
supported_fmts=['qcow2'],
)
disk_a, disk_b, nbd_sock = file_path('disk_a', 'disk_b', 'nbd-sock')
nbd_uri = 'nbd+unix:///?socket=' + nbd_sock

4
tests/qemu-iotests/274

@ -21,8 +21,8 @@
import iotests
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_platform(['linux'])
iotests.script_initialize(supported_fmts=['qcow2'],
supported_platforms=['linux'])
size_short = 1 * 1024 * 1024
size_long = 2 * 1024 * 1024

2
tests/qemu-iotests/277

@ -23,6 +23,8 @@ import subprocess
import iotests
from iotests import file_path, log
iotests.script_initialize()
nbd_sock, conf_file = file_path('nbd-sock', 'nbd-fault-injector.conf')

8
tests/qemu-iotests/280

@ -22,9 +22,11 @@
import iotests
import os
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.verify_protocol(supported=['file'])
iotests.verify_platform(['linux'])
iotests.script_initialize(
supported_fmts=['qcow2'],
supported_protocols=['file'],
supported_platforms=['linux'],
)
with iotests.FilePath('base') as base_path , \
iotests.FilePath('top') as top_path, \

4
tests/qemu-iotests/283

@ -21,7 +21,9 @@
import iotests
# The test is unrelated to formats, restrict it to qcow2 to avoid extra runs
iotests.verify_image_format(supported_fmts=['qcow2'])
iotests.script_initialize(
supported_fmts=['qcow2'],
)
size = 1024 * 1024

76
tests/qemu-iotests/iotests.py

@ -28,7 +28,8 @@ import signal
import struct
import subprocess
import sys
from typing import (Any, Callable, Dict, Iterable, List, Optional, TypeVar)
from typing import (Any, Callable, Dict, Iterable,
List, Optional, Sequence, TypeVar)
import unittest
# pylint: disable=import-error, wrong-import-position
@ -1029,12 +1030,11 @@ def verify_protocol(supported=(), unsupported=()):
if not_sup or (imgproto in unsupported):
notrun('not suitable for this protocol: %s' % imgproto)
def verify_platform(supported=None, unsupported=None):
if unsupported is not None:
if any((sys.platform.startswith(x) for x in unsupported)):
notrun('not suitable for this OS: %s' % sys.platform)
def verify_platform(supported=(), unsupported=()):
if any((sys.platform.startswith(x) for x in unsupported)):
notrun('not suitable for this OS: %s' % sys.platform)
if supported is not None:
if supported:
if not any((sys.platform.startswith(x) for x in supported)):
notrun('not suitable for this OS: %s' % sys.platform)
@ -1116,7 +1116,18 @@ def skip_if_user_is_root(func):
return func(*args, **kwargs)
return func_wrapper
def execute_unittest(output, verbosity, debug):
def execute_unittest(debug=False):
"""Executes unittests within the calling module."""
verbosity = 2 if debug else 1
if debug:
output = sys.stdout
else:
# We need to filter out the time taken from the output so that
# qemu-iotest can reliably diff the results against master output.
output = io.StringIO()
runner = unittest.TextTestRunner(stream=output, descriptions=True,
verbosity=verbosity)
try:
@ -1124,6 +1135,8 @@ def execute_unittest(output, verbosity, debug):
# exception
unittest.main(testRunner=runner)
finally:
# We need to filter out the time taken from the output so that
# qemu-iotest can reliably diff the results against master output.
if not debug:
out = output.getvalue()
out = re.sub(r'Ran (\d+) tests? in [\d.]+s', r'Ran \1 tests', out)
@ -1135,13 +1148,19 @@ def execute_unittest(output, verbosity, debug):
sys.stderr.write(out)
def execute_test(test_function=None,
supported_fmts=(),
supported_platforms=None,
supported_cache_modes=(), supported_aio_modes=(),
unsupported_fmts=(), supported_protocols=(),
unsupported_protocols=()):
"""Run either unittest or script-style tests."""
def execute_setup_common(supported_fmts: Sequence[str] = (),
supported_platforms: Sequence[str] = (),
supported_cache_modes: Sequence[str] = (),
supported_aio_modes: Sequence[str] = (),
unsupported_fmts: Sequence[str] = (),
supported_protocols: Sequence[str] = (),
unsupported_protocols: Sequence[str] = ()) -> bool:
"""
Perform necessary setup for either script-style or unittest-style tests.
:return: Bool; Whether or not debug mode has been requested via the CLI.
"""
# Note: Python 3.6 and pylint do not like 'Collection' so use 'Sequence'.
# We are using TEST_DIR and QEMU_DEFAULT_MACHINE as proxies to
# indicate that we're not being run via "check". There may be
@ -1151,34 +1170,39 @@ def execute_test(test_function=None,
sys.stderr.write('Please run this test via the "check" script\n')
sys.exit(os.EX_USAGE)
debug = '-d' in sys.argv
verbosity = 1
verify_image_format(supported_fmts, unsupported_fmts)
verify_protocol(supported_protocols, unsupported_protocols)
verify_platform(supported=supported_platforms)
verify_cache_mode(supported_cache_modes)
verify_aio_mode(supported_aio_modes)
debug = '-d' in sys.argv
if debug:
output = sys.stdout
verbosity = 2
sys.argv.remove('-d')
else:
# We need to filter out the time taken from the output so that
# qemu-iotest can reliably diff the results against master output.
output = io.StringIO()
logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
return debug
def execute_test(*args, test_function=None, **kwargs):
"""Run either unittest or script-style tests."""
debug = execute_setup_common(*args, **kwargs)
if not test_function:
execute_unittest(output, verbosity, debug)
execute_unittest(debug)
else:
test_function()
# This is called from script-style iotests without a single point of entry
def script_initialize(*args, **kwargs):
"""Initialize script-style tests without running any tests."""
execute_setup_common(*args, **kwargs)
# This is called from script-style iotests with a single point of entry
def script_main(test_function, *args, **kwargs):
"""Run script-style tests outside of the unittest framework"""
execute_test(test_function, *args, **kwargs)
execute_test(*args, test_function=test_function, **kwargs)
# This is called from unittest style iotests
def main(*args, **kwargs):
"""Run tests using the unittest framework"""
execute_test(None, *args, **kwargs)
execute_test(*args, **kwargs)

Loading…
Cancel
Save