Skip to content

Commit

Permalink
Merge pull request #5865 from chunfuwen/automate_serial_console_witho…
Browse files Browse the repository at this point in the history
…ut_serial_device

Automate case: Connect to the guest console without serial device
  • Loading branch information
chunfuwen authored Jan 14, 2025
2 parents dc2b424 + 569a1a7 commit 3e5b13d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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)
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
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()

0 comments on commit 3e5b13d

Please sign in to comment.