Skip to content

Commit

Permalink
virtiofs_another_user_access: 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 May 8, 2023
1 parent 82e2de2 commit bf418e2
Show file tree
Hide file tree
Showing 2 changed files with 203 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
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
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 = 4096
mem_devs = mem1
backend_mem_mem1 = memory-backend-file
mem-path_mem1 = /dev/shm
size_mem1 = 4G
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'
x86_64:
install_winfsp_path = 'C:\Program Files (x86)'
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'
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}
143 changes: 143 additions & 0 deletions qemu/tests/virtio_fs_group_permission_access.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
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


@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
vm = 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 = "/home/" + user_one + "/" + fs_source
if not os.path.exists(shared_dir):
process.system("runuser -l " + user_one + " -c 'mkdir -p " +
shared_dir + "'")
# 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

if setup_local_nfs:
params["nfs_mount_dir"] = shared_dir
nfs_local = nfs.Nfs(params)
nfs_local.setup()

# 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)
guest_session = vm.reboot(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)
guest_session.close()
finally:
if setup_local_nfs:
if vm and vm.is_alive():
vm.destroy()
params["rm_export_dir"] = params.get("export_dir")
params["rm_mount_dir"] = params.get("nfs_mount_dir")
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)

error_context.context("Close the host session...", test.log.info)
if host_session:
host_session.close()

0 comments on commit bf418e2

Please sign in to comment.