Skip to content

Commit

Permalink
Merge pull request #3698 from nickzhq/diff_user_start_virtiofs_2172397
Browse files Browse the repository at this point in the history
virtio_fs_group_permission_access: add a new test case
  • Loading branch information
YongxueHong authored Jul 5, 2023
2 parents dc4dda8 + 94b78f7 commit 7d045fa
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 0 deletions.
60 changes: 60 additions & 0 deletions qemu/tests/cfg/virtio_fs_group_permission_access.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
- virtio_fs_group_permission_access:
type = virtio_fs_group_permission_access
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
kill_vm = yes
start_vm = no
filesystems = fs
fs_driver = virtio-fs
fs_source_dir = virtio_fs_test/
force_create_fs_source = no
fs_source_user_config = 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
# install winfsp tool
i386, i686:
install_winfsp_path = 'C:\Program Files'
devcon_dirname = 'x86'
x86_64:
install_winfsp_path = 'C:\Program Files (x86)'
devcon_dirname = 'amd64'
virtio_win_media_type = iso
cdroms += " virtio"
io_timeout = 600
fs_dest = '/mnt/${fs_target}'
driver_name = viofs
cmd_run_virtiofsd = '/usr/libexec/virtiofsd --socket-path %s'
new_user = "user001 user002"
add_user_cmd = "useradd %s"
del_user_cmd = "userdel -r -f %s"
Windows:
cmd_dd = 'dd if=/dev/random of=%s bs=1M count=100'
devcon_path = "WIN_UTILS:\devcon\${devcon_dirname}\devcon.exe"
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}
149 changes: 149 additions & 0 deletions qemu/tests/virtio_fs_group_permission_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import os

import aexpect

from virttest import nfs
from avocado.utils import process
from virttest import env_process
from virttest import error_context, utils_test, utils_disk, utils_misc

from provider import virtio_fs_utils, win_driver_utils


@error_context.context_aware
def run(test, params, env):
"""
Start virtiofsd with the user who has permission to access the directory
of another user, then test whether the shared directory works well or not.
1) Create two users( e.g. u1 and u2) on host.
2) Change permission of u1 home directory, give all write permission.
3) Change user u2's supplementary group to u1.
4) Start virtiofsd under user u2
with the option "--shared-dir /home/u1/virtio_fs_test".
5) Boot a guest on the host.
6) If guest is windows, start the viofs service and reboot.
7) If the guest is linux, mount the file system.
8) Run the basic io test and folder accessing test.
9) 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.objects("new_user")
windows = params.get("os_type", "windows") == "windows"
driver_name = params.get("driver_name")
fs_dest = params.get("fs_dest")
fs_target = params.get("fs_target")
cmd_run_virtiofsd = params.get("cmd_run_virtiofsd")

# nfs config
setup_local_nfs = params.get('setup_local_nfs')

fs_source = params.get('fs_source_dir')
host_session = None
guest_session = None
vm = None
nfs_local = None

try:
for _username in username:
cmd = add_user_cmd % _username
process.run(cmd)
user_one, user_two = username[0], username[-1]
# create the folder before daemon running
shared_dir = os.path.join("/home/" + user_one, fs_source)
if not os.path.exists(shared_dir):
process.system("runuser -l " + user_one + " -c 'mkdir -p " +
shared_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()

# change permission of u1 home directory
output = process.system_output("chmod -R 777 /home/%s" % user_one)
error_context.context(output, test.log.info)
# change user u2's supplementary group to u1
output = process.system_output("usermod -G %s %s" % (user_one,
user_two))
error_context.context(output, test.log.info)

# set fs daemon config
sock_path = os.path.join("/home/" + user_two,
'-'.join(('avocado-vt-vm1', 'viofs',
'virtiofsd.sock')))
# create the file
with open(sock_path, "w") as fd:
pass
params['fs_source_user_sock_path'] = sock_path

# run daemon
cmd_run_virtiofsd = cmd_run_virtiofsd % sock_path
cmd_run_virtiofsd += " --shared-dir %s" % shared_dir
error_context.context('Running daemon command %s' % cmd_run_virtiofsd,
test.log.info)

host_session = aexpect.ShellSession("runuser -l " + user_two +
" -c '" + cmd_run_virtiofsd + "'",
auto_close=False,
output_func=utils_misc.log_line,
output_params=('virtiofs_fs-virtiofs.log',),
prompt=r"^\[.*\][\#\$]\s*$")
params["fs_source_base_dir"] = "/home/" + user_one

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_session = vm.wait_for_login()

if windows:
guest_session = utils_test.qemu.windrv_check_running_verifier(guest_session,
vm,
test,
driver_name)
virtio_fs_utils.run_viofs_service(test, params, guest_session)
else:
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_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_session):
test.fail('Mount virtiofs target failed.')
virtio_fs_utils.basic_io_test(test, params, guest_session)
finally:
if guest_session:
if windows:
virtio_fs_utils.delete_viofs_serivce(test, params, guest_session)
# for windows guest, disable/uninstall driver to get memory leak
# based on driver verifier is enabled
win_driver_utils.memory_leak_check(vm, test, params)
else:
utils_disk.umount(fs_target, fs_dest, 'virtiofs',
session=guest_session)
utils_misc.safe_rmdir(fs_dest, session=guest_session)

if vm and vm.is_alive():
vm.destroy()
if setup_local_nfs and nfs_local:
nfs_local.cleanup()

error_context.context("Delete the user(s) on host...", test.log.info)
for _username in username[::-1]:
output = process.run(del_user_cmd % _username)
if "is currently used by process" in output.stdout_text:
error_context.context("Kill process before delete user...",
test.log.info)
pid = output.split(" ")[-1]
process.run("kill -9 %s" % pid)
process.run("rm -rf /home/%s" % _username)

0 comments on commit 7d045fa

Please sign in to comment.