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

Automate case: Connect to the guest console without serial device #5865

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libvirt/tests/cfg/serial/serial_functional.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
serial_dev_type = pty
console_target_type = virtio
second_serial_console = yes
- connect_to_console_no_serial_device:
serial_dev_type = pty
error_msg = "cannot find character device"
connect_to_console_without_serial_device = "yes"
func_supported_since_libvirt_ver = (10, 3, 0)
- type_tls_server:
serial_dev_type = tls
serial_sources = mode:bind,host:${local_ip_address},service:5556,tls:yes
Expand Down
19 changes: 19 additions & 0 deletions libvirt/tests/src/serial/serial_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from virttest import libvirt_version

from avocado.utils import astring
from avocado.utils import process


# Using as lower capital is not the best way to do, but this is just a
Expand Down Expand Up @@ -746,6 +747,7 @@ def get_console_type():
target_model = params.get('target_model', '')
console_target_port = params.get('console_target_port', '0')
second_serial_console = params.get('second_serial_console', 'no') == 'yes'
connect_to_console_without_serial_device = params.get('connect_to_console_without_serial_device', 'no') == 'yes'
custom_pki_path = params.get('custom_pki_path', '/etc/pki/libvirt-chardev')
auto_recover = params.get('auto_recover', 'no')
client_pwd = params.get('client_pwd', None)
Expand Down Expand Up @@ -821,6 +823,12 @@ def get_console_type():
if console_type == 'server':
console = prepare_serial_console()

if connect_to_console_without_serial_device:
libvirt_version.is_libvirt_feature_supported(params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest we add the libvirt_version.is_libvirt_feature_supported in global but not only in if condition. So we can reuse it if we add new test scenarios later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this dependence version is specific to this case only, so keep it in specific case looks more sensible

for device_type in remove_devices:
vm_xml.remove_all_device_by_type(device_type)
vm_xml.sync()

res = virsh.start(vm_name)
libvirt.check_result(res, expected_fails, [])
if res.exit_status:
Expand All @@ -835,8 +843,19 @@ def get_console_type():
console_type != 'server'):
check_serial_console(console, username, password)

if connect_to_console_without_serial_device:
time.sleep(20)
# use raw virsh console command since we need to output message from virsh console VM
result = process.run("virsh console %s" % vm_name, shell=True, verbose=True, ignore_status=True).stderr_text
Copy link
Contributor

Choose a reason for hiding this comment

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

We'd better to use virsh.command() but not process for virsh commands if there is no virsh.console related functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it need second terminal to launch virsh console command, virsh.command will block execution

error_msg = params.get("error_msg")
if error_msg not in result:
test.fail(f"Fail to get expected error message:{error_msg} from console")

vm.destroy()

finally:
# Recover VM.
if vm.is_alive():
vm.destroy(gracefully=False)
cleanup(objs_list)
vm_xml_backup.sync()