All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: virtio-fs@redhat.com, Miklos Szeredi <mszeredi@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [PATCH v2 7/7] tests/acceptance: Add virtiofs_submounts.py
Date: Fri, 30 Oct 2020 10:14:38 +0100	[thread overview]
Message-ID: <20680712-df27-3a7d-13bc-720c37121274@redhat.com> (raw)
In-Reply-To: <20201029204601.GM5733@habkost.net>


[-- Attachment #1.1: Type: text/plain, Size: 5477 bytes --]

On 29.10.20 21:46, Eduardo Habkost wrote:
> On Thu, Oct 29, 2020 at 06:17:44PM +0100, Max Reitz wrote:
>> This test invokes several shell scripts to create a random directory
>> tree full of submounts, and then check in the VM whether every submount
>> has its own ID and the structure looks as expected.
>>
>> (Note that the test scripts must be non-executable, so Avocado will not
>> try to execute them as if they were tests on their own, too.)
>>
>> Because at this commit's date it is unlikely that the Linux kernel on
>> the image provided by boot_linux.py supports submounts in virtio-fs, the
>> test will be cancelled if no custom Linux binary is provided through the
>> vmlinuz parameter.  (The on-image kernel can be used by providing an
>> empty string via vmlinuz=.)
>>
>> So, invoking the test can be done as follows:
>> $ avocado run \
>>     tests/acceptance/virtiofs_submounts.py \
>>     -p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage
>>
>> This test requires root privileges (through passwordless sudo -n),
>> because at this point, virtiofsd requires them.  (If you have a
>> timestamp_timeout period for sudoers (e.g. the default of 5 min), you
>> can provide this by executing something like "sudo true" before invoking
>> Avocado.)
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
>> ---
>>  tests/acceptance/virtiofs_submounts.py        | 289 ++++++++++++++++++
>>  .../virtiofs_submounts.py.data/cleanup.sh     |  46 +++
>>  .../guest-cleanup.sh                          |  30 ++
>>  .../virtiofs_submounts.py.data/guest.sh       | 138 +++++++++
>>  .../virtiofs_submounts.py.data/host.sh        | 127 ++++++++
>>  5 files changed, 630 insertions(+)
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/cleanup.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/guest-cleanup.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/guest.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/host.sh
>>
>> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
>> new file mode 100644
>> index 0000000000..8b207b3e57
>> --- /dev/null
>> +++ b/tests/acceptance/virtiofs_submounts.py
>> @@ -0,0 +1,289 @@
>> +import logging
>> +import re
>> +import os
>> +import subprocess
>> +import time
>> +
>> +from avocado import skipUnless
>> +from avocado_qemu import Test, BUILD_DIR
>> +from avocado_qemu import wait_for_console_pattern
>> +from avocado.utils import ssh
>> +
>> +from qemu.accel import kvm_available
>> +
>> +from boot_linux import BootLinux
>> +
>> +
>> +def run_cmd(args):
>> +    subp = subprocess.Popen(args,
>> +                            stdout=subprocess.PIPE,
>> +                            stderr=subprocess.PIPE,
>> +                            universal_newlines=True)
>> +    stdout, stderr = subp.communicate()
>> +    ret = subp.returncode
>> +
>> +    return (stdout, stderr, ret)
>> +
>> +def has_passwordless_sudo():
>> +    """
>> +    This function is for use in a @avocado.skipUnless decorator, e.g.:
>> +
>> +        @skipUnless(*has_passwordless_sudo())
>> +        def test_something_that_needs_sudo(self):
>> +            ...
>> +    """
>> +
>> +    _, stderr, exitcode = run_cmd(('sudo', '-n', 'true'))
> 
> This seems to break if sudo is not available in the host:

Oh, makes sense.  I’ll wrap it in a try-except.  Thanks!

Max

> https://gitlab.com/ehabkost/qemu/-/jobs/820072411#L152
> 
> 0:37:08 ERROR| ERROR 32-tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up -> TestError: Traceback (most recent call last):
>   File "/usr/lib64/python3.6/imp.py", line 235, in load_module
>     return load_source(name, filename, file)
>   File "/usr/lib64/python3.6/imp.py", line 172, in load_source
>     module = _load(spec)
>   File "<frozen importlib._bootstrap>", line 684, in _load
>   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
>   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
>   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 43, in <module>
>     class VirtiofsSubmountsTest(BootLinux):
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 195, in VirtiofsSubmountsTest
>     @skipUnless(*has_passwordless_sudo())
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 36, in has_passwordless_sudo
>     _, stderr, exitcode = run_cmd(('sudo', '-n', 'true'))
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 21, in run_cmd
>     universal_newlines=True)
>   File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
>     restore_signals, start_new_session)
>   File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
>     raise child_exception_type(errno_num, err_msg, err_filename)
> FileNotFoundError: [Errno 2] No such file or directory: 'sudo': 'sudo'
> 20:37:08 INFO | 
> 
>> +    if exitcode != 0:
>> +        return (False, f'Failed to use sudo -n: {stderr.strip()}')
>> +    else:
>> +        return (True, '')
>> +
>> +
> [...]
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: Max Reitz <mreitz@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Virtio-fs] [PATCH v2 7/7] tests/acceptance: Add virtiofs_submounts.py
Date: Fri, 30 Oct 2020 10:14:38 +0100	[thread overview]
Message-ID: <20680712-df27-3a7d-13bc-720c37121274@redhat.com> (raw)
In-Reply-To: <20201029204601.GM5733@habkost.net>


[-- Attachment #1.1: Type: text/plain, Size: 5477 bytes --]

On 29.10.20 21:46, Eduardo Habkost wrote:
> On Thu, Oct 29, 2020 at 06:17:44PM +0100, Max Reitz wrote:
>> This test invokes several shell scripts to create a random directory
>> tree full of submounts, and then check in the VM whether every submount
>> has its own ID and the structure looks as expected.
>>
>> (Note that the test scripts must be non-executable, so Avocado will not
>> try to execute them as if they were tests on their own, too.)
>>
>> Because at this commit's date it is unlikely that the Linux kernel on
>> the image provided by boot_linux.py supports submounts in virtio-fs, the
>> test will be cancelled if no custom Linux binary is provided through the
>> vmlinuz parameter.  (The on-image kernel can be used by providing an
>> empty string via vmlinuz=.)
>>
>> So, invoking the test can be done as follows:
>> $ avocado run \
>>     tests/acceptance/virtiofs_submounts.py \
>>     -p vmlinuz=/path/to/linux/build/arch/x86/boot/bzImage
>>
>> This test requires root privileges (through passwordless sudo -n),
>> because at this point, virtiofsd requires them.  (If you have a
>> timestamp_timeout period for sudoers (e.g. the default of 5 min), you
>> can provide this by executing something like "sudo true" before invoking
>> Avocado.)
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
>> ---
>>  tests/acceptance/virtiofs_submounts.py        | 289 ++++++++++++++++++
>>  .../virtiofs_submounts.py.data/cleanup.sh     |  46 +++
>>  .../guest-cleanup.sh                          |  30 ++
>>  .../virtiofs_submounts.py.data/guest.sh       | 138 +++++++++
>>  .../virtiofs_submounts.py.data/host.sh        | 127 ++++++++
>>  5 files changed, 630 insertions(+)
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/cleanup.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/guest-cleanup.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/guest.sh
>>  create mode 100644 tests/acceptance/virtiofs_submounts.py.data/host.sh
>>
>> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
>> new file mode 100644
>> index 0000000000..8b207b3e57
>> --- /dev/null
>> +++ b/tests/acceptance/virtiofs_submounts.py
>> @@ -0,0 +1,289 @@
>> +import logging
>> +import re
>> +import os
>> +import subprocess
>> +import time
>> +
>> +from avocado import skipUnless
>> +from avocado_qemu import Test, BUILD_DIR
>> +from avocado_qemu import wait_for_console_pattern
>> +from avocado.utils import ssh
>> +
>> +from qemu.accel import kvm_available
>> +
>> +from boot_linux import BootLinux
>> +
>> +
>> +def run_cmd(args):
>> +    subp = subprocess.Popen(args,
>> +                            stdout=subprocess.PIPE,
>> +                            stderr=subprocess.PIPE,
>> +                            universal_newlines=True)
>> +    stdout, stderr = subp.communicate()
>> +    ret = subp.returncode
>> +
>> +    return (stdout, stderr, ret)
>> +
>> +def has_passwordless_sudo():
>> +    """
>> +    This function is for use in a @avocado.skipUnless decorator, e.g.:
>> +
>> +        @skipUnless(*has_passwordless_sudo())
>> +        def test_something_that_needs_sudo(self):
>> +            ...
>> +    """
>> +
>> +    _, stderr, exitcode = run_cmd(('sudo', '-n', 'true'))
> 
> This seems to break if sudo is not available in the host:

Oh, makes sense.  I’ll wrap it in a try-except.  Thanks!

Max

> https://gitlab.com/ehabkost/qemu/-/jobs/820072411#L152
> 
> 0:37:08 ERROR| ERROR 32-tests/acceptance/virtiofs_submounts.py:VirtiofsSubmountsTest.test_pre_virtiofsd_set_up -> TestError: Traceback (most recent call last):
>   File "/usr/lib64/python3.6/imp.py", line 235, in load_module
>     return load_source(name, filename, file)
>   File "/usr/lib64/python3.6/imp.py", line 172, in load_source
>     module = _load(spec)
>   File "<frozen importlib._bootstrap>", line 684, in _load
>   File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
>   File "<frozen importlib._bootstrap_external>", line 678, in exec_module
>   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 43, in <module>
>     class VirtiofsSubmountsTest(BootLinux):
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 195, in VirtiofsSubmountsTest
>     @skipUnless(*has_passwordless_sudo())
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 36, in has_passwordless_sudo
>     _, stderr, exitcode = run_cmd(('sudo', '-n', 'true'))
>   File "/builds/ehabkost/qemu/build/tests/acceptance/virtiofs_submounts.py", line 21, in run_cmd
>     universal_newlines=True)
>   File "/usr/lib64/python3.6/subprocess.py", line 729, in __init__
>     restore_signals, start_new_session)
>   File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
>     raise child_exception_type(errno_num, err_msg, err_filename)
> FileNotFoundError: [Errno 2] No such file or directory: 'sudo': 'sudo'
> 20:37:08 INFO | 
> 
>> +    if exitcode != 0:
>> +        return (False, f'Failed to use sudo -n: {stderr.strip()}')
>> +    else:
>> +        return (True, '')
>> +
>> +
> [...]
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-10-30  9:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 17:17 [PATCH v2 0/7] virtiofsd: Announce submounts to the guest Max Reitz
2020-10-29 17:17 ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 1/7] virtiofsd: Check FUSE_SUBMOUNTS Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 2/7] virtiofsd: Add attr_flags to fuse_entry_param Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 3/7] meson.build: Check for statx() Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 4/7] virtiofsd: Add mount ID to the lo_inode key Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 5/7] virtiofsd: Announce sub-mount points Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 6/7] tests/acceptance/boot_linux: Accept SSH pubkey Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 17:17 ` [PATCH v2 7/7] tests/acceptance: Add virtiofs_submounts.py Max Reitz
2020-10-29 17:17   ` [Virtio-fs] " Max Reitz
2020-10-29 20:46   ` Eduardo Habkost
2020-10-29 20:46     ` [Virtio-fs] " Eduardo Habkost
2020-10-30  9:14     ` Max Reitz [this message]
2020-10-30  9:14       ` Max Reitz
2020-10-30  9:12 ` [PATCH v2 0/7] virtiofsd: Announce submounts to the guest Stefan Hajnoczi
2020-10-30  9:12   ` [Virtio-fs] " Stefan Hajnoczi

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=20680712-df27-3a7d-13bc-720c37121274@redhat.com \
    --to=mreitz@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=mszeredi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=virtio-fs@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.