[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 05/67] iotests.py: Add ImagePaths
From: |
Max Reitz |
Subject: |
[PATCH 05/67] iotests.py: Add ImagePaths |
Date: |
Tue, 1 Oct 2019 21:46:13 +0200 |
create_test_image() must be paired with an ImagePath so that the image
is properly cleaned up with remove_test_image() instead of just
os.remove().
Signed-off-by: Max Reitz <address@hidden>
---
tests/qemu-iotests/iotests.py | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index fce1ab04c9..5be6ca674c 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -440,8 +440,8 @@ class FilePaths(object):
Use this context manager to generate filenames and ensure that the file
gets deleted::
- with FilePaths(['test.img']) as img_path:
- qemu_img('create', img_path, '1G')
+ with FilePaths(['migration.sock']) as migration_sock_path:
+ # Set up and use UNIX socket on migration.sock
# migration_sock_path is automatically deleted
"""
def __init__(self, names):
@@ -460,6 +460,23 @@ class FilePaths(object):
pass
return False
+class ImagePaths(FilePaths):
+ """
+ Same as FilePaths, except it calls remove_test_image() to clean up
+ (which ensures that external data files are cleaned up, too).
+
+ Use this class for test images in the default format
+ (iotests.imgfmt):
+
+ with ImagePaths(['test.img']) as img_path:
+ create_test_image(img_path, '1G')
+ # The test image is automatically cleaned up
+ """
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ for path in self.paths:
+ remove_test_image(path)
+ return False
+
class FilePath(FilePaths):
"""
FilePath is a specialization of FilePaths that takes a single filename.
@@ -470,6 +487,17 @@ class FilePath(FilePaths):
def __enter__(self):
return self.paths[0]
+class ImagePath(ImagePaths):
+ """
+ ImagePath is a specialization of ImagePaths that takes a single
+ filename.
+ """
+ def __init__(self, name):
+ super(ImagePath, self).__init__([name])
+
+ def __enter__(self):
+ return self.paths[0]
+
def file_path_remover():
for path in reversed(file_path_remover.paths):
try:
--
2.21.0
- Re: [PATCH 03/67] iotests.py: Add unsupported_imgopts, (continued)
- [PATCH 06/67] iotests.py: Add image_path(), Max Reitz, 2019/10/01
- [PATCH 08/67] iotests.py: Add filter_json_filename(), Max Reitz, 2019/10/01
- [PATCH 09/67] iotests.py: Add @hide_fields to img_info_log, Max Reitz, 2019/10/01
- [PATCH 05/67] iotests.py: Add ImagePaths,
Max Reitz <=
- [PATCH 12/67] iotests/228: Filter json:{} filenames, Max Reitz, 2019/10/01
- [PATCH 13/67] iotests/242: Hide refcount bit information, Max Reitz, 2019/10/01
- [PATCH 07/67] iotests.py: Filter data_file in filter_img_info, Max Reitz, 2019/10/01
- [PATCH 11/67] iotests/224: Filter json:{} from commit command, Max Reitz, 2019/10/01
- [PATCH 14/67] iotests: Use unsupported_imgopts in Python tests, Max Reitz, 2019/10/01
- [PATCH 10/67] iotests/169: Skip persistent cases for compat=0.10, Max Reitz, 2019/10/01
- [PATCH 15/67] iotests/030: Honor $IMGOPTS, Max Reitz, 2019/10/01
- [PATCH 18/67] iotests/044: Honor $IMGOPTS, Max Reitz, 2019/10/01
- [PATCH 16/67] iotests/040: Honor $IMGOPTS, Max Reitz, 2019/10/01
- [PATCH 17/67] iotests/041: Honor $IMGOPTS, Max Reitz, 2019/10/01