Skip to content

Commit ed6d92f

Browse files
committed
LIBVIRTAT-22036: Add VM shutdown test to iommu_device_lifecycle
This change adds new test to verify virsh shutdown command is working as expected for VM with vIOMMU devices. Also added the optional possibility to start the VM again after the shutdown and parametrize the shutdown_timeout. Improving test coverage for RHEL-109504.
1 parent 983f459 commit ed6d92f

File tree

2 files changed

+108
-62
lines changed

2 files changed

+108
-62
lines changed

libvirt/tests/cfg/sriov/vIOMMU/iommu_device_lifecycle.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@
4141
- reboot_many_times:
4242
loop_time = 5
4343
- reset:
44+
- shutdown:
45+
start_after_shutdown = yes
46+
shutdown_timeout = 60

libvirt/tests/src/sriov/vIOMMU/iommu_device_lifecycle.py

Lines changed: 105 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,109 @@
1111
from provider.sriov import sriov_base
1212
from provider.viommu import viommu_base
1313
from provider.sriov import check_points as sriov_check_points
14+
from provider.vm_lifecycle import lifecycle_base
1415

1516
VIRSH_ARGS = {'debug': True, 'ignore_status': False}
1617

1718

19+
def check_network_access(test, vm, session, need_sriov, ping_dest):
20+
"""
21+
Check network access in VM
22+
"""
23+
if need_sriov:
24+
sriov_check_points.check_vm_network_accessed(session, ping_dest=ping_dest)
25+
else:
26+
s, o = utils_net.ping(ping_dest, count=5, timeout=10, session=session)
27+
if s:
28+
test.fail(f"Failed to ping {ping_dest}! status: {s}, output: {o}")
29+
30+
31+
def test_save_suspend(test, vm, params, save_path, test_scenario):
32+
"""
33+
Test save/restore or suspend/resume scenario
34+
"""
35+
pid_ping, upsince = save_base.pre_save_setup(vm, serial=True)
36+
37+
if test_scenario == "save_restore":
38+
test.log.info("TEST_STEP: Save and restore the VM.")
39+
virsh.save(vm.name, save_path, **VIRSH_ARGS)
40+
virsh.restore(save_path, **VIRSH_ARGS)
41+
elif test_scenario == "suspend_resume":
42+
test.log.info("TEST_STEP: Suspend and resume the VM.")
43+
virsh.suspend(vm.name, **VIRSH_ARGS)
44+
virsh.resume(vm.name, **VIRSH_ARGS)
45+
46+
save_base.post_save_check(vm, pid_ping, upsince, serial=True)
47+
48+
49+
def test_reboot_reset_shutdown(test, vm, params, need_sriov, ping_dest, test_scenario):
50+
"""
51+
Test reboot or reset scenario
52+
"""
53+
# Common parameters
54+
login_timeout = int(params.get('login_timeout', 240))
55+
56+
# Setup serial console
57+
vm.cleanup_serial_console()
58+
vm.create_serial_console()
59+
60+
if test_scenario == "shutdown":
61+
lifecycle_base.test_shutdown(test, vm, params)
62+
if params.get("start_after_shutdown", "no") == "yes":
63+
test.log.info("TEST_STEP: Starting VM after shutdown")
64+
vm.start()
65+
else:
66+
return
67+
elif test_scenario == "reset":
68+
lifecycle_base.test_reset(test, vm, login_timeout)
69+
else: # reboot_many_times
70+
for _ in range(int(params.get('loop_time', '5'))):
71+
lifecycle_base.test_reset(test, vm, login_timeout)
72+
73+
# Final login to check network access
74+
session = vm.wait_for_serial_login(timeout=login_timeout)
75+
check_network_access(test, vm, session, need_sriov, ping_dest)
76+
session.close()
77+
78+
79+
def setup_vm_xml(test, vm, test_obj, need_sriov=False, cleanup_ifaces=True):
80+
"""
81+
Setup VM XML with required configurations
82+
"""
83+
test.log.info("TEST_SETUP: Update VM XML.")
84+
# Setup IOMMU test environment
85+
test_obj.setup_iommu_test(iommu_dict=eval(test_obj.params.get('iommu_dict', '{}')),
86+
cleanup_ifaces=cleanup_ifaces)
87+
test_obj.prepare_controller()
88+
89+
# Configure devices
90+
for dev in ["disk", "video"]:
91+
dev_dict = eval(test_obj.params.get('%s_dict' % dev, '{}'))
92+
if dev == "disk":
93+
dev_dict = test_obj.update_disk_addr(dev_dict)
94+
libvirt_vmxml.modify_vm_device(
95+
vm_xml.VMXML.new_from_dumpxml(vm.name), dev, dev_dict)
96+
97+
# Configure network interfaces
98+
if need_sriov:
99+
sriov_test_obj = sriov_base.SRIOVTest(vm, test, test_obj.params)
100+
iface_dicts = sriov_test_obj.parse_iface_dict()
101+
test.log.debug(iface_dicts)
102+
test_obj.params["iface_dict"] = str(sriov_test_obj.parse_iface_dict())
103+
104+
iface_dict = test_obj.parse_iface_dict()
105+
if cleanup_ifaces:
106+
libvirt_vmxml.modify_vm_device(
107+
vm_xml.VMXML.new_from_dumpxml(vm.name),
108+
"interface", iface_dict)
109+
110+
18111
def run(test, params, env):
19112
"""
20113
Test lifecycle for vm with vIOMMU enabled with different devices.
21114
"""
22115
cleanup_ifaces = "yes" == params.get("cleanup_ifaces", "yes")
23116
ping_dest = params.get('ping_dest', "127.0.0.1")
24-
iommu_dict = eval(params.get('iommu_dict', '{}'))
25117
test_scenario = params.get("test_scenario")
26118
need_sriov = "yes" == params.get("need_sriov", "no")
27119

@@ -31,73 +123,24 @@ def run(test, params, env):
31123
rand_id = utils_misc.generate_random_string(3)
32124
save_path = f'/var/tmp/{vm_name}_{rand_id}.save'
33125
test_obj = viommu_base.VIOMMUTest(vm, test, params)
34-
if need_sriov:
35-
sroiv_test_obj = sriov_base.SRIOVTest(vm, test, params)
126+
36127
try:
37-
test.log.info("TEST_SETUP: Update VM XML.")
38-
test_obj.setup_iommu_test(iommu_dict=iommu_dict,
39-
cleanup_ifaces=cleanup_ifaces)
40-
test_obj.prepare_controller()
41-
for dev in ["disk", "video"]:
42-
dev_dict = eval(params.get('%s_dict' % dev, '{}'))
43-
if dev == "disk":
44-
dev_dict = test_obj.update_disk_addr(dev_dict)
45-
libvirt_vmxml.modify_vm_device(
46-
vm_xml.VMXML.new_from_dumpxml(vm.name), dev, dev_dict)
47-
if need_sriov:
48-
iface_dicts = sroiv_test_obj.parse_iface_dict()
49-
test.log.debug(iface_dicts)
50-
test_obj.params["iface_dict"] = str(sroiv_test_obj.parse_iface_dict())
51-
iface_dict = test_obj.parse_iface_dict()
52-
if cleanup_ifaces:
53-
libvirt_vmxml.modify_vm_device(
54-
vm_xml.VMXML.new_from_dumpxml(vm.name),
55-
"interface", iface_dict)
128+
# Setup VM XML configuration
129+
setup_vm_xml(test, vm, test_obj, need_sriov, cleanup_ifaces)
56130

131+
# Start the VM
57132
test.log.info("TEST_STEP: Start the VM.")
58133
vm.start()
59134
test.log.debug(vm_xml.VMXML.new_from_dumpxml(vm.name))
60-
if test_scenario in ["reboot_many_times", "reset"]:
61-
vm.cleanup_serial_console()
62-
vm.create_serial_console()
63-
if test_scenario == "reset":
64-
test.log.info("TEST_STEP: Reset the VM.")
65-
session = vm.wait_for_serial_login(
66-
timeout=int(params.get('login_timeout')))
67-
virsh.reset(vm.name, **VIRSH_ARGS)
68-
_match, _text = session.read_until_last_line_matches(
69-
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
70-
session.close()
71-
else:
72-
for _ in range(int(params.get('loop_time', '5'))):
73-
test.log.info("TEST_STEP: Reboot the VM.")
74-
session = vm.wait_for_serial_login(
75-
timeout=int(params.get('login_timeout')))
76-
session.sendline(params.get("reboot_command"))
77-
_match, _text = session.read_until_last_line_matches(
78-
[r"[Ll]ogin:\s*"], timeout=240, internal_timeout=0.5)
79-
session.close()
80-
81-
session = vm.wait_for_serial_login(
82-
timeout=int(params.get('login_timeout')))
83-
84-
if need_sriov:
85-
sriov_check_points.check_vm_network_accessed(session, ping_dest=ping_dest)
86-
else:
87-
s, o = utils_net.ping(ping_dest, count=5, timeout=10, session=session)
88-
if s:
89-
test.fail("Failed to ping %s! status: %s, output: %s." % (ping_dest, s, o))
135+
136+
# Execute the appropriate test scenario
137+
if test_scenario in ["reboot_many_times", "reset", "shutdown"]:
138+
test_reboot_reset_shutdown(test, vm, params, need_sriov, ping_dest, test_scenario)
139+
elif test_scenario in ["save_restore", "suspend_resume"]:
140+
test_save_suspend(test, vm, params, save_path, test_scenario)
90141
else:
91-
pid_ping, upsince = save_base.pre_save_setup(vm, serial=True)
92-
if test_scenario == "save_restore":
93-
test.log.info("TEST_STEP: Save and restore the VM.")
94-
virsh.save(vm.name, save_path, **VIRSH_ARGS)
95-
virsh.restore(save_path, **VIRSH_ARGS)
96-
elif test_scenario == "suspend_resume":
97-
test.log.info("TEST_STEP: Suspend and resume the VM.")
98-
virsh.suspend(vm.name, **VIRSH_ARGS)
99-
virsh.resume(vm.name, **VIRSH_ARGS)
100-
save_base.post_save_check(vm, pid_ping, upsince, serial=True)
142+
test.log.warning(f"Unknown scenario: {test_scenario}")
143+
101144
finally:
102145
test_obj.teardown_iommu_test()
103146
if os.path.exists(save_path):

0 commit comments

Comments
 (0)