From d07faccefc0a30d8bed85c8ade0306c6639e691b Mon Sep 17 00:00:00 2001 From: "Houqi (Nick) Zuo" Date: Wed, 10 May 2023 09:17:50 +0800 Subject: [PATCH] virtio_fs_supp_group_transfer: add a new test case Signed-off-by: Houqi (Nick) Zuo --- .../cfg/virtio_fs_supp_group_transfer.cfg | 50 ++++++++++ qemu/tests/virtio_fs_supp_group_transfer.py | 99 +++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 qemu/tests/cfg/virtio_fs_supp_group_transfer.cfg create mode 100644 qemu/tests/virtio_fs_supp_group_transfer.py diff --git a/qemu/tests/cfg/virtio_fs_supp_group_transfer.cfg b/qemu/tests/cfg/virtio_fs_supp_group_transfer.cfg new file mode 100644 index 00000000000..52ca8acc9d0 --- /dev/null +++ b/qemu/tests/cfg/virtio_fs_supp_group_transfer.cfg @@ -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} diff --git a/qemu/tests/virtio_fs_supp_group_transfer.py b/qemu/tests/virtio_fs_supp_group_transfer.py new file mode 100644 index 00000000000..25c9f9d074f --- /dev/null +++ b/qemu/tests/virtio_fs_supp_group_transfer.py @@ -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