Skip to content

Commit

Permalink
virtio_fs_supp_group_transfer: add a new test case
Browse files Browse the repository at this point in the history
Signed-off-by: Houqi (Nick) Zuo <[email protected]>
  • Loading branch information
nickzhq committed Jun 20, 2023
1 parent 54b92d9 commit d07facc
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
50 changes: 50 additions & 0 deletions qemu/tests/cfg/virtio_fs_supp_group_transfer.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
- virtio_fs_supp_group_transfer:
type = virtio_fs_supp_group_transfer
only Linux
no Host_RHEL.m8, Host_RHEL.m7, Host_RHEL.m6
virt_test_type = qemu
required_qemu = [4.2.0,)
s390, s390x:
required_qemu = [5.2.0,)
vm_mem_share = yes
pre_command_noncritical = yes
pre_command = "echo 3 > /proc/sys/vm/drop_caches"
setup_hugepages = yes
kvm_module_parameters = 'hpage=1'
expected_hugepage_size = 1024
clone_master = yes
master_images_clone = image1
remove_image_image1 = yes
kill_vm = yes
start_vm = no
filesystems = fs
fs_driver = virtio-fs
force_create_fs_source = yes
remove_fs_source = yes
fs_target = 'myfs'
fs_driver_props = {"queue-size": 1024}
mem_devs = mem1
backend_mem_mem1 = memory-backend-file
mem-path_mem1 = /dev/shm
size_mem1 = ${mem}M
use_mem_mem1 = no
share_mem = yes
!s390, s390x:
guest_numa_nodes = shm0
numa_memdev_shm0 = mem-mem1
numa_nodeid_shm0 = 0
io_timeout = 600
fs_dest = '/mnt/${fs_target}'
new_guest_user = "user00001"
add_user_cmd = "useradd %s"
del_user_cmd = "userdel -r -f %s"
fs_enable_debug_mode = yes
fs_source_dir = virtio_fs_test/
variants:
- default:
- with_nfs_source:
setup_local_nfs = yes
nfs_mount_options = rw
export_options = 'rw,insecure,no_root_squash,async'
export_dir = /nfs/${fs_target}
nfs_mount_src = /nfs/${fs_target}
99 changes: 99 additions & 0 deletions qemu/tests/virtio_fs_supp_group_transfer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import os.path

from virttest import nfs, env_process
from virttest import error_context, utils_disk, utils_misc

from provider import virtio_fs_utils


@error_context.context_aware
def run(test, params, env):
"""
Grant write access at users allowed by group permission
on shared dir( linux only )
1) Run the virtiofsd daemon on the host and Set log level to "debug".
2) Boot a guest on the host.
3) Log into guest with root, then mount the file system.
4) In the guest, add a new user(u1)
and set the user to the wheel group (as supplementary group)
and set the dir's group to 'wheel'
5) In guest, using root to create a test directory at the shared dir.
6) Run the basic io test with the u1 user
7) After test, clear the environment.
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
add_user_cmd = params.get("add_user_cmd")
del_user_cmd = params.get("del_user_cmd")
username = params.get("new_guest_user")
fs_dest = params.get("fs_dest")
fs_target = params.get("fs_target")
fs_source_dir = params.get("fs_source_dir")
# nfs config
setup_local_nfs = params.get("setup_local_nfs")

testdir = "testdir"
guest_root_session = None
vm = None
nfs_local = None

try:
shared_dir = params.get("fs_source_dir")

if setup_local_nfs:
# delete the slash at the end
params["nfs_mount_dir"] = shared_dir[:-1]
nfs_local = nfs.Nfs(params)
nfs_local.setup()

params["start_vm"] = "yes"
env_process.preprocess_vm(test, params, env, params["main_vm"])
vm = env.get_vm(params.get("main_vm"))
vm.verify_alive()
guest_root_session = vm.wait_for_login()

error_context.context("Create a destination directory %s "
"inside guest." % fs_dest, test.log.info)
if not utils_misc.make_dirs(fs_dest, session=guest_root_session):
test.fail("Creating directory was failed!")
error_context.context("Mount virtiofs target %s to %s inside"
" guest." % (fs_target, fs_dest),
test.log.info)
if not utils_disk.mount(fs_target, fs_dest, 'virtiofs',
session=guest_root_session):
test.fail('Mount virtiofs target failed.')

guest_root_session.cmd(add_user_cmd % username)
guest_root_session.cmd("usermod -G wheel %s" % username)

guest_root_session.cmd("cd %s && mkdir -m 770 %s" % (fs_dest, testdir))
guest_root_session.cmd("cd %s && chgrp wheel %s" % (fs_dest, testdir))
params["fs_dest"] = os.path.join(fs_dest, testdir)
params["fs_source_dir"] = os.path.join(shared_dir, testdir)

guest_user_session = vm.wait_for_login()
guest_user_session.cmd("su %s" % username)
virtio_fs_utils.basic_io_test(test, params, guest_user_session)
finally:
if guest_root_session:
output = guest_root_session.cmd_output(del_user_cmd % username)
if "is currently used by process" in output:
error_context.context("Kill process before delete user...",
test.log.info)
pid = output.split(" ")[-1]
guest_root_session.cmd_output("kill -9 %s" % pid)
guest_root_session.cmd("rm -rf /home/%s" % username)

guest_root_session.cmd("rm -rf %s" % params["fs_dest"])

if setup_local_nfs:
if vm and vm.is_alive():
vm.destroy()
params["rm_mount_dir"] = params.get("nfs_mount_dir")
nfs_local.cleanup()

params["fs_dest"] = fs_dest
params["fs_source_dir"] = fs_source_dir

0 comments on commit d07facc

Please sign in to comment.