From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>,
"open list:Block layer core" <qemu-block@nongnu.org>
Subject: [Qemu-devel] [PULL 16/17] iotests: add file_path helper
Date: Tue, 13 Mar 2018 12:13:44 -0500 [thread overview]
Message-ID: <20180313171345.659672-17-eblake@redhat.com> (raw)
In-Reply-To: <20180313171345.659672-1-eblake@redhat.com>
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Simple way to have auto generated filenames with auto cleanup. Like
FilePath but without using 'with' statement and without additional
indentation of the whole test.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20180312152126.286890-8-vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
[eblake: grammar tweak]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
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 c1302a2f9b1..90cd751e2af 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 is 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.14.3
next prev parent reply other threads:[~2018-03-13 17:14 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-13 17:13 [Qemu-devel] [PULL 00/17] NBD patches for 2018-03-13 (2.12 softfreeze) Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 01/17] iotests: Fix stuck NBD process on 33 Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 02/17] nbd/server: move nbd_co_send_structured_error up Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 03/17] nbd/server: fix sparse read Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 04/17] nbd/server: fix: check client->closing before sending reply Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 05/17] nbd/server: refactor nbd_trip: cmd_read and generic reply Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 06/17] nbd/server: refactor nbd_trip: split out nbd_handle_request Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 07/17] nbd/server: Honor FUA request on NBD_CMD_TRIM Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 08/17] block: let blk_add/remove_aio_context_notifier() tolerate BDS changes Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 09/17] iotests: add 208 nbd-server + blockdev-snapshot-sync test case Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 10/17] nbd/server: add nbd_opt_invalid helper Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 11/17] nbd/server: add nbd_read_opt_name helper Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 12/17] nbd: BLOCK_STATUS for standard get_block_status function: server part Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 13/17] block/nbd-client: save first fatal error in nbd_iter_error Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 14/17] nbd: BLOCK_STATUS for standard get_block_status function: client part Eric Blake
2018-03-13 17:13 ` [Qemu-devel] [PULL 15/17] iotests.py: tiny refactor: move system imports up Eric Blake
2018-03-13 17:13 ` Eric Blake [this message]
2018-03-13 17:13 ` [Qemu-devel] [PULL 17/17] iotests: new test 209 for NBD BLOCK_STATUS Eric Blake
2018-03-13 18:17 ` [Qemu-devel] [PULL 00/17] NBD patches for 2018-03-13 (2.12 softfreeze) no-reply
2018-03-13 19:30 ` Eric Blake
2018-03-13 18:19 ` no-reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180313171345.659672-17-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).