Skip to content

Commit 3d0195f

Browse files
committed
Merge pull request autotest#806 from yangdongsheng/libvirt_bench
libvirt: add some tests for performance of libvirt.
2 parents 916a656 + eae535e commit 3d0195f

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- libvirt_bench_domstate_switch_in_loop:
2+
virt_test_type = libvirt
3+
type = libvirt_bench_domstate_switch_in_loop
4+
start_vm = yes
5+
# Operations for domain state.
6+
LB_domstate_switch_start = no
7+
LB_domstate_switch_start_post_state = "running"
8+
LB_domstate_switch_shutdown = no
9+
LB_domstate_switch_shutdown_post_state = "running"
10+
LB_domstate_switch_destroy = no
11+
LB_domstate_switch_destroy_post_state = "shut off"
12+
LB_domstate_switch_pause = no
13+
LB_domstate_switch_pause_post_state = "paused"
14+
LB_domstate_switch_resume = no
15+
LB_domstate_switch_resume_post_state = "running"
16+
# Time(second) of a loop for the test.
17+
LB_domstate_switch_loop_time = 600
18+
variants:
19+
- shutdown_start_pause_resume:
20+
# Status chain:
21+
# running->shutdown->shut off->running->paused->running
22+
LB_domstate_switch_shutdown = yes
23+
LB_domstate_switch_start = yes
24+
LB_domstate_switch_pause = yes
25+
LB_domstate_switch_resume = yes
26+
- shutdown_start:
27+
# Status chain:
28+
# running->shutdown->shut off->running
29+
LB_domstate_switch_shutdown = yes
30+
LB_domstate_switch_start = yes
31+
- destroy_start:
32+
# Status chain:
33+
# running<-->shut off
34+
LB_domstate_switch_destroy = yes
35+
LB_domstate_switch_start = yes
36+
- pause_resume:
37+
# Status chain:
38+
# running<-->paused
39+
LB_domstate_switch_pause = yes
40+
LB_domstate_switch_resume = yes
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import time
2+
import logging
3+
4+
from autotest.client.shared import error
5+
from virttest import virsh
6+
7+
8+
def run_libvirt_bench_domstate_switch_in_loop(test, params, env):
9+
"""
10+
Test steps:
11+
12+
1) Get the params from params.
13+
2) loop:
14+
start
15+
shutdown
16+
start
17+
suspend
18+
resume
19+
destroy
20+
3) clean up.
21+
"""
22+
def for_each_vm(vms, virsh_func, state=None):
23+
"""
24+
Excecute the virsh_func with each vm in vms.
25+
26+
:Param vms: List of vm.
27+
:Param virsh_func: Function in virsh module.
28+
:Param state: State to verify the result of virsh_func.
29+
None means do not check the state.
30+
"""
31+
for vm in vms:
32+
vm_name = vm.name
33+
cmd_result = virsh_func(vm_name)
34+
if cmd_result.exit_status:
35+
raise error.TestFail(cmd_result)
36+
if state is None:
37+
continue
38+
actual_state = virsh.domstate(vm_name).stdout.strip()
39+
if not (actual_state == state):
40+
raise error.TestFail("Command %s succeed, but the state is %s,"
41+
"but not %s." %
42+
(virsh_func.__name__, actual_state, state))
43+
logging.debug("Operation %s on %s succeed.", virsh_func.__name__, vms)
44+
45+
# Get VMs.
46+
vms = env.get_all_vms()
47+
# Get operations from params.
48+
start_in_loop = ("yes" == params.get("LB_domstate_switch_start", "no"))
49+
start_post_state = params.get("LB_domstate_switch_start_post_state",
50+
"running")
51+
shutdown_in_loop = ("yes" == params.get("LB_domstate_switch_shutdown",
52+
"no"))
53+
shutdown_post_state = params.get("LB_domstate_switch_shutdown_post_state",
54+
"shutdown")
55+
destroy_in_loop = ("yes" == params.get("LB_domstate_switch_destroy", "no"))
56+
destroy_post_state = params.get("LB_domstate_switch_destroy_post_state",
57+
"shut off")
58+
suspend_in_loop = ("yes" == params.get("LB_domstate_switch_suspend", "no"))
59+
suspend_post_state = params.get("LB_domstate_switch_suspend_post_state",
60+
"paused")
61+
resume_in_loop = ("yes" == params.get("LB_domstate_switch_resume", "no"))
62+
resume_post_state = params.get("LB_domstate_switch_resume_post_state",
63+
"running")
64+
# Get the loop_time.
65+
loop_time = int(params.get("LB_domstate_switch_loop_time", "600"))
66+
current_time = int(time.time())
67+
end_time = current_time + loop_time
68+
# Init a counter for the loop.
69+
loop_counter = 0
70+
try:
71+
try:
72+
# Verify the vms is all loaded completely.
73+
for vm in vms:
74+
vm.wait_for_login()
75+
# Start the loop from current_time to end_time.
76+
while current_time < end_time:
77+
if loop_counter > (len(vms) * 1000 * loop_time):
78+
raise error.TestFail("Loop ")
79+
if shutdown_in_loop:
80+
for_each_vm(vms, virsh.shutdown, shutdown_post_state)
81+
for vm in vms:
82+
if not vm.wait_for_shutdown(count=240):
83+
raise error.TestFail("Command shutdown succeed, but "
84+
"failed to wait for shutdown.")
85+
if destroy_in_loop:
86+
for_each_vm(vms, virsh.destroy, destroy_post_state)
87+
if start_in_loop:
88+
for_each_vm(vms, virsh.start, start_post_state)
89+
for vm in vms:
90+
if not vm.wait_for_login():
91+
raise error.TestFail("Command start succeed, but "
92+
"failed to wait for login.")
93+
if suspend_in_loop:
94+
for_each_vm(vms, virsh.suspend, suspend_post_state)
95+
if resume_in_loop:
96+
for_each_vm(vms, virsh.resume, resume_post_state)
97+
logging.debug("Finish %s loop.", loop_counter)
98+
# Update the current_time and loop_counter.
99+
current_time = int(time.time())
100+
loop_counter += 1
101+
except error.TestFail, detail:
102+
raise error.TestFail("Succeed for %s loop, and got an error.\n"
103+
"Detail: %s." % (loop_counter, detail))
104+
finally:
105+
# Resume vm if vm is paused.
106+
for vm in vms:
107+
if vm.is_paused():
108+
vm.resume()
109+
vm.destroy()

0 commit comments

Comments
 (0)