qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>, qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] iotests: Skip read-only cases in 118 when run as root
Date: Fri, 18 Oct 2019 14:59:24 +0200	[thread overview]
Message-ID: <a810971a-639e-e7dc-d5e6-6b0bb524079b@redhat.com> (raw)
In-Reply-To: <20191018115127.2671-1-kwolf@redhat.com>

Hi Kevin,

On 10/18/19 1:51 PM, Kevin Wolf wrote:
> 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 <kwolf@redhat.com>
> ---
>   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..9eff46d189 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_root

Why not have case_notrun() return 'reason' and use:

@unittest.skipIf(os.getuid() == 0, case_notrun("cannot be run as 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_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_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 3a8f378f90..9c66db613e 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -920,6 +920,16 @@ def skip_if_unsupported(required_formats=[], read_only=False):
>           return func_wrapper
>       return skip_test_decorator
>   
> +def skip_if_root(func):

skip_if_user_is_root() is slightly less confuse.

> +    '''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)
> 


  reply	other threads:[~2019-10-18 13:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 11:51 [PATCH] iotests: Skip read-only cases in 118 when run as root Kevin Wolf
2019-10-18 12:59 ` Philippe Mathieu-Daudé [this message]
2019-10-18 14:27   ` Kevin Wolf
2019-10-18 14:46     ` Philippe Mathieu-Daudé
2019-10-18 15:00     ` Max Reitz
2019-10-18 16:52       ` Kevin Wolf

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=a810971a-639e-e7dc-d5e6-6b0bb524079b@redhat.com \
    --to=philmd@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).