Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case to cover start virtlogd with specified configuration file #5188

Merged

Conversation

chunfuwen
Copy link
Contributor

@chunfuwen chunfuwen commented Sep 18, 2023

Add cases to cover start virtlogd with various config

 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

VIRT-xx: [virtlogd][Stop] Stop virtlogd service when guest is running

VIRT-xx: [virtlogd]Check qemu log when guest fails to start due to "qemu process exits" error

VIRT-xx: [virtlogd] Start virtlogd with default max_size and max_backups

VIRT-xx: [virtlogd]Remove the qemu log file when guest is running
VIRT-xx: [virtlogd] [start] [negative] Virtlogd.serivce start failed with invalid configuration
VIRT-xx: [virtlogd] Check opened FDs of qemu log file when guest is running and destroyed

VIRT-xx: [virtlogd] Check qemu log when guest shuts down

VIRT-xx: [virtlogd] Check qemu log when guest starts for the second time

@chunfuwen
Copy link
Contributor Author

chunfuwen commented Sep 18, 2023

cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.specific_config_file

Command 'virsh list' finished with 0 after 0.037828258s
cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.specific_timeout

cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.negative_test.invalid_virtlogd_conf.reload_virtlogd

DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 2-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.negative_test.invalid_virtlogd_conf.restart_virtlogd

DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.record_qenu_crash_log

cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.stop_virtlogd

cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.default_max_size_max_backups

Command 'virsh list' finished with 0 after 0.026679640s
cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.recreate_qemu_log

cleaning libvirtd logs...
DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.start_vm_twice_log_into_qemu_log_file

DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.vm_destroy_log_into_qemu_log_file

DATA (filename=output.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stdout.expected) => NOT FOUND (data sources: variant, test, file)
DATA (filename=stderr.expected) => NOT FOUND (data sources: variant, test, file)
PASS 1-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.opened_fd_of_qemu_log_file

@chunfuwen chunfuwen force-pushed the add_virtlogd_config_specfic_file branch 5 times, most recently from 46a5de0 to 86dc1dc Compare September 19, 2023 06:57
@chunfuwen chunfuwen force-pushed the add_virtlogd_config_specfic_file branch 4 times, most recently from d860eae to 42f909b Compare November 28, 2023 06:03
@chunfuwen
Copy link
Contributor Author

@dzhengfy
@nanli1
please help take a review

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To operate a service, we do not hardcode the command. I suggest we use
service.Factory.create_service("virtlogd").restart()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the log file name, I sugguest we get it from predefined parameter, like virtlogd_config_file_new, instead of hardcoding here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

fd.write('VIRTLOGD_ARGS="--timeout=30"')
fd.write('\n')
# restart virtlogd
process.run("systemctl restart virtlogd", ignore_status=True, shell=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To operate a service, we do not hardcode the command. I suggest we use
service.Factory.create_service("virtlogd").restart()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get service status, I suggest we use
service.Factory.create_service("virtlogd").status('Active: active')

See below definition:
def status(self, regex=r"active \(running\)"):

Copy link
Contributor Author

@chunfuwen chunfuwen Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As validated, service.status() method can not accept parameter

if ret.exit_status != 0:
test.fail("virtlogd is not in active from log:%s" % ret.stdout_text.strip())
action = params.get("action")
process.run("systemctl %s virtlogd" % action, ignore_status=True, shell=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about
service.Factory.create_service("virtlogd").action()

We'd better to add reload() in service.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look like not so urgent, so will address in another PR, but not this time

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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

@chunfuwen chunfuwen Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As validated, service.status() method can not accept parameter

"""
vm.start()
check_file_exist(guest_log_file)
# remove the qemu log file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is obviously , so no need this comment line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service.Factory.create_service("virtlogd").restart()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service.Factory.create_service("virtlogd").restart()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

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":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use elif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not updated, but I am ok with it, too.

@chunfuwen chunfuwen force-pushed the add_virtlogd_config_specfic_file branch 2 times, most recently from 3e82d6b to 74067bd Compare December 4, 2023 06:20
Comment on lines +330 to +340
try:
vm.start()
except virt_vm.VMStartError as detail:
logging.info("VM failed to start."
"Error: %s" % str(detail))
crash_information = params.get("crash_information")
if not libvirt.check_logfile(crash_information, guest_log_file):
test.fail("Check expected message log:%s failed in log file:%s"
% (crash_information, guest_log_file))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirm, When the guest start successfully ,Will we miss the check point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here Vm will fail to start, but if we don't catch exception, the whole program will be terminated immediately. In this way we can not do later check_logfile.
In terms of logging mechanism, virtlogd will output log information into specificed log file whether VM will be started successfully or not.

@chunfuwen chunfuwen force-pushed the add_virtlogd_config_specfic_file branch 2 times, most recently from 2572767 to 72f6246 Compare December 12, 2023 02:38
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

VIRT-xx: [virtlogd][Stop] Stop virtlogd service when guest is running

VIRT-xx: [virtlogd]Check qemu log when guest fails to start due to "qemu process exits" error

VIRT-xx: [virtlogd] Start virtlogd with default max_size and max_backups

VIRT-xx: [virtlogd]Remove the qemu log file when guest is running

VIRT-xx: [virtlogd] [start] [negative] Virtlogd.serivce start failed with invalid configuration

VIRT-xx: [virtlogd] Check opened FDs of qemu log file when guest is running and destroyed

VIRT-xx: [virtlogd] Check qemu log when guest shuts down

VIRT-xx: [virtlogd] Check qemu log when guest starts for the second time

VIRT-xx: [virtlogd]Check the qemu log when save&restore guest.

Signed-off-by: chunfuwen <[email protected]>
@chunfuwen chunfuwen force-pushed the add_virtlogd_config_specfic_file branch from 47738b7 to 712d5c6 Compare December 12, 2023 03:18
@chunfuwen
Copy link
Contributor Author

After comments are addressed, rerun impacted cases, result follow as:

PASS 11-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.specific_config_file
PASS 12-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.specific_timeout
PASS 13-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.record_qenu_crash_log
PASS 14-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.stop_virtlogd
PASS 15-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.default_max_size_max_backups
PASS 16-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.recreate_qemu_log
PASS 17-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.opened_fd_of_qemu_log_file
PASS 18-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.vm_destroy_log_into_qemu_log_file
PASS 19-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.positive_test.start_vm_twice_log_into_qemu_log_file
PASS 20-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.negative_test.invalid
PASS 21-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.negative_test.invalid_virtlogd_conf.reload_virtlogd
PASS 22-type_specific.io-github-autotest-libvirt.conf_file.qemu_conf.set_virtlogd.negative_test.invalid_virtlogd_conf.restart_virtlogd

@chunfuwen chunfuwen merged commit 8ece722 into autotest:master Dec 13, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants