qemu-devel
[Top][All Lists]
Advanced

[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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]