[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 2/7] iotests: Skip read-only cases in 118 when run as root
From: |
Kevin Wolf |
Subject: |
[PULL 2/7] iotests: Skip read-only cases in 118 when run as root |
Date: |
Fri, 25 Oct 2019 15:46:06 +0200 |
Some tests in 118 use chmod to remove write permissions from the file
and assume that the image can indeed not be opened read-write
afterwards. This doesn't work when the test is run as root, because root
can still open the file as writable even when the permission bit isn't
set.
Introduce a @skip_if_root decorator and use it in 118 to skip the tests
in question when the script is run as root.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
---
tests/qemu-iotests/118 | 3 +++
tests/qemu-iotests/iotests.py | 10 ++++++++++
2 files changed, 13 insertions(+)
diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
index ea0b326ae0..e20080e9a6 100755
--- a/tests/qemu-iotests/118
+++ b/tests/qemu-iotests/118
@@ -446,6 +446,7 @@ class TestChangeReadOnly(ChangeBaseClass):
self.assert_qmp(result, 'return[0]/inserted/ro', True)
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
+ @iotests.skip_if_user_is_root
def test_rw_ro_retain(self):
os.chmod(new_img, 0o444)
self.vm.add_drive(old_img, 'media=disk', 'none')
@@ -530,6 +531,7 @@ class TestChangeReadOnly(ChangeBaseClass):
self.assert_qmp(result, 'return[0]/inserted/ro', True)
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
+ @iotests.skip_if_user_is_root
def test_make_ro_rw(self):
os.chmod(new_img, 0o444)
self.vm.add_drive(old_img, 'media=disk', 'none')
@@ -571,6 +573,7 @@ class TestChangeReadOnly(ChangeBaseClass):
self.assert_qmp(result, 'return[0]/inserted/ro', True)
self.assert_qmp(result, 'return[0]/inserted/image/filename', new_img)
+ @iotests.skip_if_user_is_root
def test_make_ro_rw_by_retain(self):
os.chmod(new_img, 0o444)
self.vm.add_drive(old_img, 'media=disk', 'none')
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 693fde155a..709def4d5d 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -931,6 +931,16 @@ def skip_if_unsupported(required_formats=[],
read_only=False):
return func_wrapper
return skip_test_decorator
+def skip_if_user_is_root(func):
+ '''Skip Test Decorator
+ Runs the test only without root permissions'''
+ def func_wrapper(*args, **kwargs):
+ if os.getuid() == 0:
+ case_notrun('{}: cannot be run as root'.format(args[0]))
+ else:
+ return func(*args, **kwargs)
+ return func_wrapper
+
def execute_unittest(output, verbosity, debug):
runner = unittest.TextTestRunner(stream=output, descriptions=True,
verbosity=verbosity)
--
2.20.1
- [PULL 0/7] Block layer patches, Kevin Wolf, 2019/10/25
- [PULL 2/7] iotests: Skip read-only cases in 118 when run as root,
Kevin Wolf <=
- [PULL 4/7] block/backup: drop dead code from backup_job_create, Kevin Wolf, 2019/10/25
- [PULL 1/7] qapi: add support for blkreplay driver, Kevin Wolf, 2019/10/25
- [PULL 5/7] doc: Describe missing generic -blockdev options, Kevin Wolf, 2019/10/25
- [PULL 3/7] blockdev: Use error_report() in hmp_commit(), Kevin Wolf, 2019/10/25
- [PULL 7/7] qcow2: Fix corruption bug in qcow2_detect_metadata_preallocation(), Kevin Wolf, 2019/10/25
- [PULL 6/7] coroutine: Add qemu_co_mutex_assert_locked(), Kevin Wolf, 2019/10/25
- Re: [PULL 0/7] Block layer patches, Peter Maydell, 2019/10/25