[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 8/9] iotests: add file_path helper
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[Qemu-block] [PATCH 8/9] iotests: add file_path helper |
Date: |
Thu, 15 Feb 2018 16:51:46 +0300 |
Simple way to have auto generated filenames with auto clenup. Like
FilePath but without using 'with' statement and without additional
indentation of the whole test.
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
tests/qemu-iotests/iotests.py | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index c1302a2f9b..f2d05ca3fd 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -27,6 +27,7 @@ import struct
import json
import signal
import logging
+import atexit
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'scripts'))
import qtest
@@ -250,6 +251,37 @@ class FilePath(object):
return False
+def file_path_remover():
+ for path in reversed(file_path_remover.paths):
+ try:
+ os.remove(path)
+ except OSError:
+ pass
+
+
+def file_path(*names):
+ ''' Another way to get auto-generated filename that cleans itself up.
+
+ Use it as simple as:
+
+ img_a, img_b = file_path('a.img', 'b.img')
+ sock = file_path('socket')
+ '''
+
+ if not hasattr(file_path_remover, 'paths'):
+ file_path_remover.paths = []
+ atexit.register(file_path_remover)
+
+ paths = []
+ for name in names:
+ filename = '{0}-{1}'.format(os.getpid(), name)
+ path = os.path.join(test_dir, filename)
+ file_path_remover.paths.append(path)
+ paths.append(path)
+
+ return paths[0] if len(paths) == 1 else paths
+
+
class VM(qtest.QEMUQtestMachine):
'''A QEMU VM'''
--
2.11.1
- Re: [Qemu-block] [PATCH 3/9] nbd: BLOCK_STATUS for standard get_block_status function: server part, (continued)
[Qemu-block] [PATCH 5/9] nbd/client: fix error messages in nbd_handle_reply_err, Vladimir Sementsov-Ogievskiy, 2018/02/15
[Qemu-block] [PATCH 7/9] iotests.py: tiny refactor: move system imports up, Vladimir Sementsov-Ogievskiy, 2018/02/15
[Qemu-block] [PATCH 9/9] iotests: new test 206 for NBD BLOCK_STATUS, Vladimir Sementsov-Ogievskiy, 2018/02/15
[Qemu-block] [PATCH 8/9] iotests: add file_path helper,
Vladimir Sementsov-Ogievskiy <=
[Qemu-block] [PATCH 6/9] nbd: BLOCK_STATUS for standard get_block_status function: client part, Vladimir Sementsov-Ogievskiy, 2018/02/15
Re: [Qemu-block] [Qemu-devel] [PATCH 0/9] nbd block status base:allocation, no-reply, 2018/02/22
Re: [Qemu-block] [Qemu-devel] [PATCH 0/9] nbd block status base:allocation, no-reply, 2018/02/23
Re: [Qemu-block] [Qemu-devel] [PATCH 0/9] nbd block status base:allocation, no-reply, 2018/02/24
Message not available
Message not available