From 0145b4e130994fab778b38a490e7d72ffb740589 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:43 +0200 Subject: [PATCH 1/6] qemu-iotests: check: don't place files with predictable names in /tmp Placing files with predictable or even hard-coded names in /tmp is a security risk and can prevent or disturb operation on a multi-user machine. Place them inside the "scratch" directory instead, as we already do for most other test-related files. Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-2-git-send-email-silbe@linux.vnet.ibm.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/check | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check index c350f16b6a..4cba2151e4 100755 --- a/tests/qemu-iotests/check +++ b/tests/qemu-iotests/check @@ -19,7 +19,6 @@ # Control script for QA # -tmp=/tmp/$$ status=0 needwrap=true try=0 @@ -130,6 +129,8 @@ fi # exit 1 #fi +tmp="${TEST_DIR}"/$$ + _wallclock() { date "+%H %M %S" | $AWK_PROG '{ print $1*3600 + $2*60 + $3 }' @@ -146,8 +147,8 @@ _wrapup() # for hangcheck ... # remove files that were used by hangcheck # - [ -f /tmp/check.pid ] && rm -rf /tmp/check.pid - [ -f /tmp/check.sts ] && rm -rf /tmp/check.sts + [ -f "${TEST_DIR}"/check.pid ] && rm -rf "${TEST_DIR}"/check.pid + [ -f "${TEST_DIR}"/check.sts ] && rm -rf "${TEST_DIR}"/check.sts if $showme then @@ -197,8 +198,8 @@ END { if (NR > 0) { needwrap=false fi - rm -f /tmp/*.out /tmp/*.err /tmp/*.time - rm -f /tmp/check.pid /tmp/check.sts + rm -f "${TEST_DIR}"/*.out "${TEST_DIR}"/*.err "${TEST_DIR}"/*.time + rm -f "${TEST_DIR}"/check.pid "${TEST_DIR}"/check.sts rm -f $tmp.* } @@ -208,16 +209,16 @@ trap "_wrapup; exit \$status" 0 1 2 3 15 # Save pid of check in a well known place, so that hangcheck can be sure it # has the right pid (getting the pid from ps output is not reliable enough). # -rm -rf /tmp/check.pid -echo $$ >/tmp/check.pid +rm -rf "${TEST_DIR}"/check.pid +echo $$ > "${TEST_DIR}"/check.pid # for hangcheck ... # Save the status of check in a well known place, so that hangcheck can be # sure to know where check is up to (getting test number from ps output is # not reliable enough since the trace stuff has been introduced). # -rm -rf /tmp/check.sts -echo "preamble" >/tmp/check.sts +rm -rf "${TEST_DIR}"/check.sts +echo "preamble" > "${TEST_DIR}"/check.sts # don't leave old full output behind on a clean run rm -f check.full @@ -285,7 +286,7 @@ do rm -f core $seq.notrun # for hangcheck ... - echo "$seq" >/tmp/check.sts + echo "$seq" > "${TEST_DIR}"/check.sts start=`_wallclock` $timestamp && echo -n " ["`date "+%T"`"]" From 1759386b7cfdd36f11cb4228d2237468814b0989 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:44 +0200 Subject: [PATCH 2/6] qemu-iotests: fix 051 on non-PC architectures Commit 61de4c68 [block: Remove BDRV_O_CACHE_WB] updated the reference output for PCs, but neglected to do the same for the generic reference output file. Fix 051 on all non-PC architectures by applying the same change to the generic output file. Fixes: 61de4c68 ("block: Remove BDRV_O_CACHE_WB") Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-3-git-send-email-silbe@linux.vnet.ibm.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/051.out | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index c1291ff317..408d613bc1 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -145,7 +145,7 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive driver=null-co,cache=invalid_value QEMU_PROG: -drive driver=null-co,cache=invalid_value: invalid cache option -Testing: -drive file=TEST_DIR/t.qcow2,cache=writeback,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=writeback,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) iininfinfoinfo info binfo blinfo bloinfo blocinfo block drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) @@ -165,7 +165,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) qququiquit -Testing: -drive file=TEST_DIR/t.qcow2,cache=writethrough,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=writethrough,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) iininfinfoinfo info binfo blinfo bloinfo blocinfo block drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) @@ -185,7 +185,7 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) qququiquit -Testing: -drive file=TEST_DIR/t.qcow2,cache=unsafe,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +Testing: -drive file=TEST_DIR/t.qcow2,cache=unsafe,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults QEMU X.Y.Z monitor - type 'help' for more information (qemu) iininfinfoinfo info binfo blinfo bloinfo blocinfo block drive0 (NODE_NAME): TEST_DIR/t.qcow2 (qcow2) @@ -205,8 +205,8 @@ backing-file: TEST_DIR/t.qcow2.base (file, read-only) Cache mode: writeback, ignore flushes (qemu) qququiquit -Testing: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults -QEMU_PROG: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0: invalid cache option +Testing: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0 -nodefaults +QEMU_PROG: -drive file=TEST_DIR/t.qcow2,cache=invalid_value,backing.file.filename=TEST_DIR/t.qcow2.base,backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=drive0: invalid cache option === Specifying the protocol layer === From c1c71e49bcf8a0e6f5ba2a41845678d4954c8106 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:45 +0200 Subject: [PATCH 3/6] qemu-iotests: iotests.VM: remove qtest socket on error On error, VM.launch() cleaned up the monitor unix socket, but left the qtest unix socket behind. This caused the remaining sub-tests to fail with EADDRINUSE: +====================================================================== +ERROR: testQuorum (__main__.TestFifoQuorumEvents) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "148", line 63, in setUp + self.vm.launch() + File "/home6/silbe/qemu/tests/qemu-iotests/iotests.py", line 247, in launch + self._qmp.accept() + File "/home6/silbe/qemu/tests/qemu-iotests/../../scripts/qmp/qmp.py", line 141, in accept + return self.__negotiate_capabilities() + File "/home6/silbe/qemu/tests/qemu-iotests/../../scripts/qmp/qmp.py", line 57, in __negotiate_capabilities + raise QMPConnectError +QMPConnectError + +====================================================================== +ERROR: testQuorum (__main__.TestQuorumEvents) +---------------------------------------------------------------------- +Traceback (most recent call last): + File "148", line 63, in setUp + self.vm.launch() + File "/home6/silbe/qemu/tests/qemu-iotests/iotests.py", line 244, in launch + self._qtest = qtest.QEMUQtestProtocol(self._qtest_path, server=True) + File "/home6/silbe/qemu/tests/qemu-iotests/../../scripts/qtest.py", line 33, in __init__ + self._sock.bind(self._address) + File "/usr/lib64/python2.7/socket.py", line 224, in meth + return getattr(self._sock,name)(*args) +error: [Errno 98] Address already in use Fix this by cleaning up both the monitor socket and the qtest socket iff they exist. Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-4-git-send-email-silbe@linux.vnet.ibm.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 8499e1b611..fb5c4824f3 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # +import errno import os import re import subprocess @@ -247,7 +248,8 @@ class VM(object): self._qmp.accept() self._qtest.accept() except: - os.remove(self._monitor_path) + _remove_if_exists(self._monitor_path) + _remove_if_exists(self._qtest_path) raise def shutdown(self): @@ -409,6 +411,15 @@ class QMPTestCase(unittest.TestCase): event = self.wait_until_completed(drive=drive) self.assert_qmp(event, 'data/type', 'mirror') +def _remove_if_exists(path): + '''Remove file object at path if it exists''' + try: + os.remove(path) + except OSError as exception: + if exception.errno == errno.ENOENT: + return + raise + def notrun(reason): '''Skip this test suite''' # Each test in qemu-iotests has a number ("seq") From 3f647b510f1f68e549425cd9671b1aa63c93ec3c Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:46 +0200 Subject: [PATCH 4/6] qemu-iotests: 148: properly skip test if quorum support is missing qemu-iotests test case 148 already had some code for skipping the test if quorum support is missing, but it didn't work in all cases. TestQuorumEvents.setUp() gets run before the actual test class (which contains the skipping code) and tries to start qemu with a drive using the quorum driver. For some reason this works fine when using qcow2, but fails for raw. As the entire test case requires quorum, just check for availability before even starting the test suite. Introduce a verify_quorum() function in iotests.py for this purpose so future test cases can make use of it. Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-5-git-send-email-silbe@linux.vnet.ibm.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/148 | 4 +--- tests/qemu-iotests/iotests.py | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/148 b/tests/qemu-iotests/148 index d066ec3e41..e01b061fe7 100644 --- a/tests/qemu-iotests/148 +++ b/tests/qemu-iotests/148 @@ -79,9 +79,6 @@ sector = "%d" self.assert_qmp(event, 'data/sector-num', sector) def testQuorum(self): - if not 'quorum' in iotests.qemu_img_pipe('--help'): - return - # Generate an error and get an event self.vm.hmp_qemu_io("drive0", "aio_read %d %d" % (offset * sector_size, sector_size)) @@ -139,4 +136,5 @@ class TestFifoQuorumEvents(TestQuorumEvents): read_pattern = 'fifo' if __name__ == '__main__': + iotests.verify_quorum() iotests.main(supported_fmts=["raw"]) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index fb5c4824f3..bf31ec8231 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -437,6 +437,11 @@ def verify_platform(supported_oses=['linux']): if True not in [sys.platform.startswith(x) for x in supported_oses]: notrun('not suitable for this OS: %s' % sys.platform) +def verify_quorum(): + '''Skip test suite if quorum support is not available''' + if 'quorum' not in qemu_img_pipe('--help'): + notrun('quorum support missing') + def main(supported_fmts=[], supported_oses=['linux']): '''Run tests''' From 9bf8027dde31923b08a09d5cf2ddd47efe9146e8 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:47 +0200 Subject: [PATCH 5/6] qemu-iotests: 068: don't require KVM None of the other test cases explicitly enable KVM and there's no obvious reason for 068 to require it. Drop this so all test cases can be executed in environments where KVM is not available (e.g. because the user doesn't have sufficient permissions to access /dev/kvm). Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-6-git-send-email-silbe@linux.vnet.ibm.com Signed-off-by: Max Reitz --- tests/qemu-iotests/068 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068 index 58d1d80e78..7562dd77ee 100755 --- a/tests/qemu-iotests/068 +++ b/tests/qemu-iotests/068 @@ -53,7 +53,7 @@ _make_test_img $IMG_SIZE case "$QEMU_DEFAULT_MACHINE" in s390-ccw-virtio) - platform_parm="-no-shutdown -machine accel=kvm" + platform_parm="-no-shutdown" ;; *) platform_parm="" From 3ef3dcef563e231a13543264975b9ef75080f9b3 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Tue, 5 Apr 2016 11:21:49 +0200 Subject: [PATCH 6/6] qemu-iotests: iotests.py: get rid of __all__ The __all__ list contained a typo for as long as the iotests module existed. That typo prevented "from iotests import *" (which is the only case where iotests.__all__ is used at all) from ever working. The names used by iotests are highly prone to name collisions, so importing them all unconditionally is a bad idea anyway. Since __all__ is not adding any value, let's just get rid of it. Fixes: f345cfd0 ("qemu-iotests: add iotests Python module") Signed-off-by: Sascha Silbe Reviewed-by: Bo Tu Message-id: 1459848109-29756-8-git-send-email-silbe@linux.vnet.ibm.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index bf31ec8231..0c0b5334b3 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -29,10 +29,6 @@ import qmp import qtest import struct -__all__ = ['imgfmt', 'imgproto', 'test_dir' 'qemu_img', 'qemu_io', - 'VM', 'QMPTestCase', 'notrun', 'main', 'verify_image_format', - 'verify_platform', 'filter_test_dir', 'filter_win32', - 'filter_qemu_io', 'filter_chown', 'log'] # This will not work if arguments contain spaces but is necessary if we # want to support the override options that ./check supports.