Skip to content

Commit

Permalink
Add cases to cover start virtlogd with various config
Browse files Browse the repository at this point in the history
VIRT-xx: virtlogd can be started with specified config by configuring VIRTLOGD_ARGS="--config /etc/libvirt/virtlogd-new.conf"
in  /etc/sysconfig/virtlogd

VIRT-xx: [virtlogd][-t | --timeout] Start virtlogd with --timeout <SECONDS> and without active guests

VIRT-xx: [virtlogd] [Reload] [negative] Virtlogd.service reload failed with invalid configuration

Signed-off-by: chunfuwen <[email protected]>
  • Loading branch information
chunfuwen committed Sep 19, 2023
1 parent 39aa600 commit 86dc1dc
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 0 deletions.
16 changes: 16 additions & 0 deletions libvirt/tests/cfg/daemon/conf_file/qemu_conf/set_virtlogd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,24 @@
- disabled_virtlogd:
expected_result = virtlogd_disabled
start_vm = no
- specific_config_file:
expected_result = virtlogd_specific_config_file_enable
virtlogd_config_file = "/etc/sysconfig/virtlogd"
virtlogd_config_bak_file = "/etc/sysconfig/virtlogd.bak"
virtlogd_config_file_new = "/etc/libvirt/virtlogd-new.conf"
start_vm = no
- specific_timeout:
expected_result = virtlogd_specific_timeout
virtlogd_config_file = "/etc/sysconfig/virtlogd"
virtlogd_config_bak_file = "/etc/sysconfig/virtlogd.bak"
virtlogd_config_file_new = "/etc/libvirt/virtlogd-new.conf"
start_vm = no
- negative_test:
variants:
- invalid:
expected_result = unbootable
stdio_handler = 'invalid'
- invalid_virtlogd_conf:
start_vm = no
expected_result = 'invalid_virtlogd_conf'
max_clients = 'invalid'
113 changes: 113 additions & 0 deletions libvirt/tests/src/daemon/conf_file/qemu_conf/set_virtlogd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from virttest import utils_package
from virttest import virt_vm
from virttest.staging import service
from virttest.utils_test import libvirt
from virttest.libvirt_xml.vm_xml import VMXML
from virttest.libvirt_xml.devices.console import Console
from virttest.libvirt_xml.devices.graphics import Graphics
Expand Down Expand Up @@ -222,6 +223,91 @@ def configure_spice(vm_name):
vm_spice_xml.add_device(graphic)
vm_spice_xml.sync()

def enable_virtlogd_specific_config_file():
"""
Configure virtlogd using specific config file.
"""
with open(virtlogd_config_file, "w") as fd:
fd.write('VIRTLOGD_ARGS="--config /etc/libvirt/virtlogd-new.conf"')
fd.write('\n')

with open(virtlogd_config_file_new, "w") as fd:
fd.write('log_level = 2')
fd.write('\n')
fd.write('log_outputs="1:file:/var/log/libvirt/virtlogd-new.log"')
fd.write('\n')
# Modify the selinux context
cmd = "chcon system_u:object_r:virtlogd_etc_t:s0 %s" % virtlogd_config_file_new
process.run(cmd, ignore_status=True, shell=True)
# restart virtlogd
process.run("systemctl restart virtlogd", ignore_status=True, shell=True)
check_service_status("virtlogd", service_start=False)

def check_virtlogd_started_with_config():
"""
Check if virtlogd is started with --config argument
"""
cmd = "ps -fC 'virtlogd'"
cmd_result = process.run(cmd, shell=True).stdout_text.strip()
matched_message = "--config %s" % virtlogd_config_file_new
if matched_message not in cmd_result:
test.fail("Check virtlogd is started with config :%s failed in output:%s"
% (matched_message, cmd_result))
new_virtlogd_log_file = "/var/log/libvirt/virtlogd-new.log"
if not os.path.exists(new_virtlogd_log_file):
test.fail("Failed to create new virtlogd log:%s" % new_virtlogd_log_file)
str_to_grep = "virObject"
if not libvirt.check_logfile(str_to_grep, new_virtlogd_log_file):
test.fail("Check message log:%s failed in log file:%s"
% (str_to_grep, new_virtlogd_log_file))

def enable_virtlogd_timeout():
"""
Configure virtlogd using timeout parameter.
"""
with open(virtlogd_config_file, "w") as fd:
fd.write('VIRTLOGD_ARGS="--timeout=30"')
fd.write('\n')
# restart virtlogd
process.run("systemctl restart virtlogd", ignore_status=True, shell=True)
check_service_status("virtlogd", service_start=False)

def check_virtlogd_started_with_timeout():
"""
Check if virtlogd is started with timeout=30
"""
cmd = "ps -fC 'virtlogd'"
cmd_result = process.run(cmd, shell=True).stdout_text.strip()
matched_message = "--timeout=30"
if matched_message not in cmd_result:
test.fail("Check virtlogd is started with config :%s failed in output:%s"
% (matched_message, cmd_result))
# nothing to do in 40 seconds to make virtlogd timeout
time.sleep(40)
cmd = "ps aux|grep virtlogd"
if process.run(cmd, shell=True).exit_status == 0:
test.fail("Find unexpected virtlogd")

def check_virtlogd_failed_invalid_config():
"""
Check if virtlogd is failed status
"""
virtlogd_config.max_clients = params.get("max_clients")
cmd = ("systemctl status virtlogd | grep 'Active: active'")
ret = process.run(cmd, ignore_status=True, shell=True, verbose=True)
if ret.exit_status != 0:
test.fail("virtlogd is not in active from log:%s" % ret.stdout_text.strip())
process.run("systemctl reload virtlogd", ignore_status=True, shell=True)
cmd = ("systemctl status virtlogd | grep 'Active: failed'")
result = process.run(cmd, ignore_status=True, shell=True, verbose=True)
if result.exit_status != 0:
test.fail("virtlogd is not in failed state from output: %s" % result.stdout_text.strip())

vm_name = params.get("main_vm", "avocado-vt-vm1")
expected_result = params.get("expected_result", "virtlogd_disabled")
stdio_handler = params.get("stdio_handler", "not_set")
Expand All @@ -245,6 +331,7 @@ def configure_spice(vm_name):

config = utils_config.LibvirtQemuConfig()
libvirtd = utils_libvirtd.Libvirtd()
virtlogd_config = utils_config.VirtLogdConfig()
try:
if stdio_handler != 'not_set':
config['stdio_handler'] = "'%s'" % stdio_handler
Expand Down Expand Up @@ -297,6 +384,21 @@ def configure_spice(vm_name):
ret = process.run(cmd, ignore_status=True, shell=True)
if not ret.exit_status:
test.fail("virtlogd still exist.")
if expected_result in ['virtlogd_specific_config_file_enable', 'specific_timeout']:
virtlogd_config_file = params.get("virtlogd_config_file")
virtlogd_config_bak_file = params.get("virtlogd_config_bak_file")
if os.path.exists(virtlogd_config_file):
# backup config file
os.rename(virtlogd_config_file, virtlogd_config_bak_file)
virtlogd_config_file_new = params.get("virtlogd_config_file_new")
if expected_result == 'virtlogd_specific_config_file_enable':
enable_virtlogd_specific_config_file()
check_virtlogd_started_with_config()
if expected_result == 'specific_timeout':
enable_virtlogd_timeout()
check_virtlogd_started_with_timeout()
if expected_result == "invalid_virtlogd_conf":
check_virtlogd_failed_invalid_config()
else:
# Stop all VMs if VMs are already started.
for tmp_vm in env.get_all_vms():
Expand Down Expand Up @@ -425,3 +527,14 @@ def configure_spice(vm_name):
config.restore()
libvirtd.restart()
vm_xml_backup.sync()
if expected_result in ['virtlogd_specific_config_file_enable', 'specific_timeout']:
if os.path.exists(virtlogd_config_file):
os.remove(virtlogd_config_file)
if os.path.exists(virtlogd_config_file_new):
os.remove(virtlogd_config_file_new)
if virtlogd_config_bak_file:
os.rename(virtlogd_config_bak_file, virtlogd_config_file)
process.run("systemctl restart virtlogd", ignore_status=True, shell=True)
if expected_result == "invalid_virtlogd_conf":
virtlogd_config.restore()
process.run("systemctl restart virtlogd", ignore_status=True, shell=True)

0 comments on commit 86dc1dc

Please sign in to comment.