Skip to content

Commit

Permalink
Merge pull request #5634 from cliping/VIRT-37948
Browse files Browse the repository at this point in the history
libvirtd: Add case to test qemu monitor socket
  • Loading branch information
chunfuwen authored Oct 23, 2024
2 parents d5daba3 + 616b1ff commit f2739ff
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- daemon.qemu_monitor_socket_creation_delay:
type = qemu_monitor_socket_creation_delay
start_vm = no
check_image = no
take_regular_screendumps = no
qemu_wrapper_path = "../../deps/qemu_wrapper.py"
tmp_qemu_wrapper_path = "/tmp/qemu_wrapper.py"
12 changes: 12 additions & 0 deletions libvirt/tests/deps/qemu_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python

import os
import sys
import time

TIMEOUT = 5
QEMU_PATH = "/usr/libexec/qemu-kvm"

time.sleep(TIMEOUT)
sys.argv[0] = QEMU_PATH
os.execv(QEMU_PATH, sys.argv)
43 changes: 43 additions & 0 deletions libvirt/tests/src/daemon/qemu_monitor_socket_creation_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import shutil

from avocado.utils import process

from virttest import virt_vm

from virttest.libvirt_xml import vm_xml
from virttest.utils_libvirt import libvirt_vmxml


def run(test, params, env):
"""
Write a wrapper for qemu to wait several seconds (>3) before starts.
"""
vm_name = params.get('main_vm')
vm = env.get_vm(vm_name)
emulator_dict = eval(params.get("emulator_dict"))
qemu_wrapper_path = params.get("qemu_wrapper_path")
tmp_qemu_wrapper_path = params.get("tmp_qemu_wrapper_path")
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
xml_backup = vmxml.copy()

try:
qemu_wrapper_path = os.path.join(os.path.dirname(__file__), qemu_wrapper_path)
shutil.copyfile(qemu_wrapper_path, tmp_qemu_wrapper_path)
os.chown(tmp_qemu_wrapper_path, 107, 107)
os.chmod(tmp_qemu_wrapper_path, 0o755)
process.run("chcon system_u:object_r:qemu_exec_t:s0 %s" % tmp_qemu_wrapper_path, shell=True)

emulator_dict = {"path": "%s" % tmp_qemu_wrapper_path}
libvirt_vmxml.modify_vm_device(vmxml, "emulator", emulator_dict)
vm.start()
except virt_vm.VMStartError as e:
test.fail("Fail to Start vm with qemu monitor socket creation delay: %s" % e)

finally:
if vm.is_alive():
vm.destroy(gracefully=False)
if os.path.exists(tmp_qemu_wrapper_path):
os.remove(tmp_qemu_wrapper_path)
xml_backup.sync()

0 comments on commit f2739ff

Please sign in to comment.