[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/34] iotests: Let _make_test_img guess $TEST_IMG_FILE
From: |
Kevin Wolf |
Subject: |
[PULL 18/34] iotests: Let _make_test_img guess $TEST_IMG_FILE |
Date: |
Fri, 11 Dec 2020 18:07:56 +0100 |
From: Max Reitz <mreitz@redhat.com>
When most iotests want to create a test image that is named differently
from the default $TEST_IMG, they do something like this:
TEST_IMG="$TEST_IMG.base" _make_test_img $options
This works fine with the "file" protocol, but not so much for anything
else: _make_test_img tries to create an image under $TEST_IMG_FILE
first, and only under $TEST_IMG if the former is not set; and on
everything but "file", $TEST_IMG_FILE is set.
There are two ways we can fix this: First, we could make all tests
adjust not only TEST_IMG, but also TEST_IMG_FILE if that is present
(e.g. with something like _set_test_img_suffix $suffix that would affect
not only TEST_IMG but also TEST_IMG_FILE, if necessary). This is a
pretty clean solution, and this is maybe what we should have done from
the start.
But it would also require changes to most existing bash tests. So the
alternative is this: Let _make_test_img see whether $TEST_IMG_FILE still
points to the original value. If so, it is possible that the caller has
adjusted $TEST_IMG but not $TEST_IMG_FILE. In such a case, we can (for
most protocols) derive the corresponding $TEST_IMG_FILE value from
$TEST_IMG value and thus work around what technically is the caller
misbehaving.
This second solution is less clean, but it is robust against people
keeping their old habit of adjusting TEST_IMG only, and requires much
less changes. So this patch implements it.
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20201027190600.192171-15-mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
tests/qemu-iotests/common.rc | 40 +++++++++++++++++++++++++++++++++---
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 494490a272..23f46da2db 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -268,6 +268,7 @@ else
TEST_IMG=$IMGPROTO:$TEST_DIR/t.$IMGFMT
fi
fi
+ORIG_TEST_IMG_FILE=$TEST_IMG_FILE
ORIG_TEST_IMG="$TEST_IMG"
if [ -z "$TEST_DIR" ]; then
@@ -330,6 +331,30 @@ _get_data_file()
| sed -e "s#\\\$TEST_IMG#$1#"
}
+# Translate a $TEST_IMG to its corresponding $TEST_IMG_FILE for
+# different protocols
+_test_img_to_test_img_file()
+{
+ case "$IMGPROTO" in
+ file)
+ echo "$1"
+ ;;
+
+ nfs)
+ echo "$1" | sed -e "s#nfs://127.0.0.1##"
+ ;;
+
+ ssh)
+ echo "$1" | \
+ sed -e "s#ssh://\\($USER@\\)\\?127.0.0.1\\(:[0-9]\\+\\)\\?##"
+ ;;
+
+ *)
+ return 1
+ ;;
+ esac
+}
+
_make_test_img()
{
# extra qemu-img options can be added by tests
@@ -343,10 +368,19 @@ _make_test_img()
local opts_param=false
local misc_params=()
- if [ -n "$TEST_IMG_FILE" ]; then
- img_name=$TEST_IMG_FILE
- else
+ if [ -z "$TEST_IMG_FILE" ]; then
img_name=$TEST_IMG
+ elif [ "$IMGOPTSSYNTAX" != "true" -a \
+ "$TEST_IMG_FILE" = "$ORIG_TEST_IMG_FILE" ]; then
+ # Handle cases of tests only updating TEST_IMG, but not TEST_IMG_FILE
+ img_name=$(_test_img_to_test_img_file "$TEST_IMG")
+ if [ "$?" != 0 ]; then
+ img_name=$TEST_IMG_FILE
+ fi
+ else
+ # $TEST_IMG_FILE is not the default value, so it definitely has been
+ # modified by the test
+ img_name=$TEST_IMG_FILE
fi
if [ -n "$IMGOPTS" ]; then
--
2.29.2
- [PULL 11/34] iotests: Do not needlessly filter _make_test_img, (continued)
- [PULL 11/34] iotests: Do not needlessly filter _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 12/34] iotests: Do not pipe _make_test_img, Kevin Wolf, 2020/12/11
- [PULL 13/34] iotests: Use convert -n in some cases, Kevin Wolf, 2020/12/11
- [PULL 14/34] iotests/046: Avoid renaming images, Kevin Wolf, 2020/12/11
- [PULL 15/34] iotests: Derive image names from $TEST_IMG, Kevin Wolf, 2020/12/11
- [PULL 16/34] iotests/091: Use _cleanup_qemu instad of "wait", Kevin Wolf, 2020/12/11
- [PULL 17/34] iotests: Restrict some Python tests to file, Kevin Wolf, 2020/12/11
- [PULL 19/34] iotests/287: Clean up subshell test image, Kevin Wolf, 2020/12/11
- [PULL 21/34] iotests: Give access to the qemu-storage-daemon, Kevin Wolf, 2020/12/11
- [PULL 24/34] iotests/308: Add test for FUSE exports, Kevin Wolf, 2020/12/11
- [PULL 18/34] iotests: Let _make_test_img guess $TEST_IMG_FILE,
Kevin Wolf <=
- [PULL 20/34] storage-daemon: Call bdrv_close_all() on exit, Kevin Wolf, 2020/12/11
- [PULL 22/34] iotests: Allow testing FUSE exports, Kevin Wolf, 2020/12/11
- [PULL 26/34] iotests/221: Discard image before qemu-img map, Kevin Wolf, 2020/12/11
- [PULL 23/34] iotests: Enable fuse for many tests, Kevin Wolf, 2020/12/11
- [PULL 27/34] can-host: Fix crash when 'canbus' property is not set, Kevin Wolf, 2020/12/11
- [PULL 25/34] file-posix: check the use_lock before setting the file lock, Kevin Wolf, 2020/12/11
- [PULL 28/34] block/file-posix: fix workaround in raw_do_pwrite_zeroes(), Kevin Wolf, 2020/12/11
- [PULL 29/34] block/io: bdrv_refresh_limits(): use ERRP_GUARD, Kevin Wolf, 2020/12/11
- [PULL 30/34] block/io: bdrv_check_byte_request(): drop bdrv_is_inserted(), Kevin Wolf, 2020/12/11
- [PULL 31/34] block: introduce BDRV_MAX_LENGTH, Kevin Wolf, 2020/12/11