[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-6.0 v3 14/20] iotests: Let _make_test_img guess $TEST_IMG_FIL
From: |
Max Reitz |
Subject: |
[PATCH for-6.0 v3 14/20] iotests: Let _make_test_img guess $TEST_IMG_FILE |
Date: |
Tue, 27 Oct 2020 20:05:54 +0100 |
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>
---
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.26.2
- [PATCH for-6.0 v3 04/20] fuse: Allow growable exports, (continued)
- [PATCH for-6.0 v3 04/20] fuse: Allow growable exports, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 05/20] fuse: (Partially) implement fallocate(), Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 06/20] fuse: Implement hole detection through lseek, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 07/20] iotests: Do not needlessly filter _make_test_img, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 08/20] iotests: Do not pipe _make_test_img, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 09/20] iotests: Use convert -n in some cases, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 10/20] iotests/046: Avoid renaming images, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 12/20] iotests/091: Use _cleanup_qemu instad of "wait", Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 11/20] iotests: Derive image names from $TEST_IMG, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 13/20] iotests: Restrict some Python tests to file, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 14/20] iotests: Let _make_test_img guess $TEST_IMG_FILE,
Max Reitz <=
- [PATCH for-6.0 v3 15/20] iotests/287: Clean up subshell test image, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 16/20] storage-daemon: Call bdrv_close_all() on exit, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 17/20] iotests: Give access to the qemu-storage-daemon, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 18/20] iotests: Allow testing FUSE exports, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 20/20] iotests/308: Add test for FUSE exports, Max Reitz, 2020/10/27
- [PATCH for-6.0 v3 19/20] iotests: Enable fuse for many tests, Max Reitz, 2020/10/27