Skip to content

Commit c986a94

Browse files
committed
add case for guest reboot or shutdown after detach nic
xxxx-95889 - [virtual network][virtual-nic-device] guest reboot after hotunplug nic xxxx-95888 - [virtual network][virtual-nic-device] guest shutdown after hotunplug nic Signed-off-by: nanli <[email protected]>
1 parent 536a3d2 commit c986a94

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- virtual_network.qemu_test.hotunplug_nic_with_operation:
2+
type = hotunplug_nic_with_operation
3+
start_vm = yes
4+
take_regular_screendumps = no
5+
create_vm_libvirt = "yes"
6+
kill_vm_libvirt = "yes"
7+
repeat_times = 1
8+
login_timeout = 360
9+
shutdown_command = "shutdown -h now"
10+
ovmf:
11+
kill_vm_libvirt_options = --nvram
12+
RHEL.7:
13+
make_change = yes
14+
variants:
15+
- with_shutdown:
16+
variants:
17+
- after_unplug:
18+
sub_type_after_unplug = shutdown
19+
shutdown_method = shell
20+
check_image = yes
21+
- with_reboot:
22+
sub_type_after_unplug = reboot
23+
reboot_method = shell
24+
variants:
25+
- nic_virtio_net:
26+
nic_model_nic1 = virtio
27+
- nic_e1000e_net:
28+
nic_model_nic1 = e1000e
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
#
3+
# Copyright Redhat
4+
#
5+
# SPDX-License-Identifier: GPL-2.0
6+
# Author: Transferred from tp-qemu nic_hotplug test case
7+
#
8+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
from virttest import virsh
10+
from virttest import utils_misc
11+
from virttest import utils_net
12+
13+
from virttest.libvirt_xml import vm_xml
14+
from virttest.utils_test import libvirt
15+
16+
from provider.virtual_network import network_base
17+
18+
virsh_opt = {"debug": True, "ignore_status": False}
19+
20+
21+
def run_sub_test(test, vm, params, plug_tag):
22+
"""
23+
Run subtest before/after hotplug/unplug device.
24+
25+
:param test: test object
26+
:param vm: VM object
27+
:param params: test parameters
28+
:param plug_tag: identify when to run subtest, ex, after_plug
29+
:return: whether vm was successfully shut-down if needed
30+
"""
31+
sub_type = params.get("sub_type_%s" % plug_tag)
32+
login_timeout = params.get_numeric("login_timeout", 360)
33+
vm.cleanup_serial_console()
34+
vm.create_serial_console()
35+
session = vm.wait_for_serial_login(timeout=login_timeout)
36+
shutdown_method = params.get("shutdown_method", "shell")
37+
shutdown_command = params.get("shutdown_command")
38+
if sub_type == "reboot":
39+
test.log.info("Running sub test '%s' %s", sub_type, plug_tag)
40+
if params.get("reboot_method"):
41+
vm.reboot(session, params["reboot_method"], 0, login_timeout, serial=True)
42+
elif sub_type == "shutdown":
43+
test.log.info("Running sub test '%s' %s", sub_type, plug_tag)
44+
if shutdown_method == "shell":
45+
session.sendline(shutdown_command)
46+
if not utils_misc.wait_for(lambda: vm.state() == "shut off", 120):
47+
test.fail("VM failed to shutdown within timeout")
48+
49+
50+
def run(test, params, env):
51+
"""
52+
Test hotplug of virtio-net NIC devices with shutdown/reboot operations.
53+
54+
Transferred from tp-qemu nic_hotplug.one_pci.nic_virtio.with_shutdown/with_reboot
55+
and adapted to tp-libvirt structure and function usage.
56+
57+
Test procedure:
58+
1) Boot a guest with interface
59+
2) Check connectivity
60+
3) Pause/resume VM and verify connectivity
61+
4) Hotunplug the interface
62+
5) Perform shutdown or reboot operation based on test variant
63+
64+
:param test: QEMU test object
65+
:param params: Dictionary with the test parameters
66+
:param env: Dictionary with test environment
67+
"""
68+
vm_name = params.get("main_vm")
69+
vm = env.get_vm(vm_name)
70+
login_timeout = params.get_numeric("login_timeout", 360)
71+
repeat_times = params.get_numeric("repeat_times", 1)
72+
ping_params = {'vm_ping_host': 'pass'}
73+
ips = {'host_ip': utils_net.get_host_ip_address(params)}
74+
75+
def run_test():
76+
"""
77+
Execute the main virtio-net hotplug with shutdown/reboot test.
78+
"""
79+
for iteration in range(repeat_times):
80+
test.log.info("TEST_STEP 1:Start test iteration %s, guest xml", iteration + 1)
81+
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
82+
test.log.debug("Prepare guest xml:%s\n", vmxml)
83+
iface = libvirt.get_vm_device(vmxml, "interface", index=-1)[0]
84+
85+
test.log.info("TEST_STEP 2: Ping host from guest")
86+
session = vm.wait_for_login(timeout=login_timeout)
87+
network_base.ping_check(ping_params, ips, session, force_ipv4=True)
88+
89+
test.log.info("TEST_STEP 3: Pause vm and resume and check connectivity again")
90+
virsh.suspend(vm_name, **virsh_opt)
91+
virsh.resume(vm_name, **virsh_opt)
92+
network_base.ping_check(ping_params, ips, session, force_ipv4=True)
93+
94+
test.log.info("TEST_STEP 4: Ping host from guest after resume")
95+
network_base.ping_check(ping_params, ips, session, force_ipv4=True)
96+
session.close()
97+
98+
test.log.info("TEST_STEP 5: Hot-unplug the interface")
99+
virsh.detach_device(vm_name, iface.xml, wait_for_event=True, **virsh_opt)
100+
run_sub_test(test, vm, params, "after_unplug")
101+
102+
run_test()

0 commit comments

Comments
 (0)