Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
tp-qemu
提交
256e9436
T
tp-qemu
项目概览
openeuler
/
tp-qemu
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tp-qemu
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
256e9436
编写于
6月 06, 2018
作者:
X
Xu Han
提交者:
GitHub
6月 06, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1396 from aliang123/1583472
Replace hotplug device defination by qcontainer.images_define_ by_params()
上级
f7a3e233
88ca0ccc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
80 addition
and
166 deletion
+80
-166
qemu/tests/block_hotplug.py
qemu/tests/block_hotplug.py
+80
-157
qemu/tests/cfg/block_hotplug.cfg
qemu/tests/cfg/block_hotplug.cfg
+0
-9
未找到文件。
qemu/tests/block_hotplug.py
浏览文件 @
256e9436
import
logging
import
logging
import
re
import
re
import
random
from
virttest
import
data_dir
from
virttest
import
storage
from
virttest
import
error_context
from
virttest
import
error_context
from
virttest
import
utils_misc
from
virttest
import
utils_misc
from
virttest
import
utils_test
from
virttest
import
utils_test
from
virttest.qemu_devices
import
qdevices
from
virttest.qemu_devices
import
qdevices
from
virttest
import
qemu_qtree
@
error_context
.
context_aware
@
error_context
.
context_aware
...
@@ -25,14 +21,6 @@ def run(test, params, env):
...
@@ -25,14 +21,6 @@ def run(test, params, env):
:param params: Dictionary with the test parameters.
:param params: Dictionary with the test parameters.
:param env: Dictionary with test environment.
:param env: Dictionary with test environment.
"""
"""
def
find_image
(
image_name
):
"""
Find the path of the iamge.
"""
image_params
=
params
.
object_params
(
image_name
)
o
=
storage
.
get_image_filename
(
image_params
,
data_dir
.
get_data_dir
())
return
o
def
find_disk
(
vm
,
cmd
):
def
find_disk
(
vm
,
cmd
):
"""
"""
Find all disks in guest.
Find all disks in guest.
...
@@ -58,20 +46,25 @@ def run(test, params, env):
...
@@ -58,20 +46,25 @@ def run(test, params, env):
disk
=
list
(
set
(
disk2
).
difference
(
set
(
disk1
)))
disk
=
list
(
set
(
disk2
).
difference
(
set
(
disk1
)))
return
disk
return
disk
def
unplug_device
(
vm
,
get_disk_cmd
,
device
):
def
run_sub_test
(
params
,
plug_tag
):
"""
"""
Unplug device
Run subtest before/after hotplug/unplug device.
:param plug_tag: identify when to run subtest,
ex, before_hotplug.
:return: whether vm was successfully shut-down
if needed
"""
"""
disks_before_unplug
=
find_disk
(
vm
,
get_disk_cmd
)
sub_type
=
params
.
get
(
"sub_type_%s"
%
plug_tag
)
device
.
unplug
(
vm
.
monitor
)
if
sub_type
:
device
.
verify_unplug
(
""
,
vm
.
monitor
)
error_context
.
context
(
context_msg
%
(
sub_type
,
plug_tag
),
unplug_status
=
utils_misc
.
wait_for
(
lambda
:
len
(
get_new_disk
(
find_disk
logging
.
info
)
(
vm
,
get_disk_cmd
),
disks_before_unplug
))
!=
0
,
pause
)
utils_test
.
run_virt_sub_test
(
test
,
params
,
env
,
sub_type
)
return
unplug_status
if
sub_type
==
"shutdown"
and
vm
.
is_dead
():
return
True
return
None
img_list
=
params
.
get
(
"images"
).
split
()
img_list
=
params
.
get
(
"images"
).
split
()
img_format_type
=
params
.
get
(
"img_format_type"
,
"qcow2"
)
pci_type
=
params
.
get
(
"pci_type"
,
"virtio-blk-pci"
)
#sometimes, ppc can't get new plugged disk in 5s, so time to 10s
#sometimes, ppc can't get new plugged disk in 5s, so time to 10s
pause
=
float
(
params
.
get
(
"virtio_block_pause"
,
10.0
))
pause
=
float
(
params
.
get
(
"virtio_block_pause"
,
10.0
))
blk_num
=
int
(
params
.
get
(
"blk_num"
,
1
))
blk_num
=
int
(
params
.
get
(
"blk_num"
,
1
))
...
@@ -88,96 +81,29 @@ def run(test, params, env):
...
@@ -88,96 +81,29 @@ def run(test, params, env):
for
iteration
in
range
(
repeat_times
):
for
iteration
in
range
(
repeat_times
):
device_list
=
[]
device_list
=
[]
controller_list
=
[]
controller_device_dict
=
{}
error_context
.
context
(
"Hotplug block device (iteration %d)"
%
iteration
,
error_context
.
context
(
"Hotplug block device (iteration %d)"
%
iteration
,
logging
.
info
)
logging
.
info
)
sub_type
=
params
.
get
(
"sub_type_before_plug"
)
plug_tag
=
"before_plug"
if
sub_type
:
run_sub_test
(
params
,
plug_tag
)
error_context
.
context
(
context_msg
%
(
sub_type
,
"before hotplug"
),
logging
.
info
)
utils_test
.
run_virt_sub_test
(
test
,
params
,
env
,
sub_type
)
for
num
in
range
(
blk_num
):
for
num
in
range
(
blk_num
):
device
=
qdevices
.
QDevice
(
pci_type
)
image_name
=
img_list
[
num
+
1
]
image_params
=
params
.
object_params
(
image_name
)
if
params
.
get
(
"need_plug"
)
==
"yes"
:
if
params
.
get
(
"need_plug"
)
==
"yes"
:
disks_before_plug
=
find_disk
(
vm
,
get_disk_cmd
)
disks_before_plug
=
find_disk
(
vm
,
get_disk_cmd
)
devs
=
vm
.
devices
.
images_define_by_params
(
image_name
,
if
params
.
get
(
"need_controller"
,
"no"
)
==
"yes"
:
image_params
,
'disk'
)
controller_model
=
params
.
get
(
"controller_model"
)
for
dev
in
devs
:
controller
=
qdevices
.
QDevice
(
controller_model
,
params
=
{
"id"
:
ret
=
vm
.
devices
.
simple_hotplug
(
dev
,
vm
.
monitor
)
"hotadded_scsi%s"
%
num
})
if
ret
[
1
]
is
False
:
bus_extra_param
=
params
.
get
(
"bus_extra_params_%s"
%
img_list
[
num
+
1
])
test
.
fail
(
"Failed to hotplug device '%s'."
if
bus_extra_param
:
"Output:
\n
%s"
%
(
dev
,
ret
[
0
]))
for
item
in
bus_extra_param
.
split
():
plug_disks
=
utils_misc
.
wait_for
(
lambda
:
get_new_disk
(
disks_before_plug
,
key
,
value
=
item
.
split
(
"="
,
1
)
find_disk
(
vm
,
get_disk_cmd
)),
pause
)
qdevice_params
=
{
key
:
value
}
if
not
plug_disks
:
controller
.
params
.
update
(
qdevice_params
)
test
.
fail
(
"Failed to hotplug device to guest"
)
controller
.
hotplug
(
vm
.
monitor
)
disk
=
plug_disks
[
0
]
ver_out
=
controller
.
verify_hotplug
(
""
,
vm
.
monitor
)
if
not
ver_out
:
err
=
"%s is not in qtree after hotplug"
%
controller_model
test
.
fail
(
err
)
else
:
controller_list
.
append
(
controller
)
drive
=
qdevices
.
QRHDrive
(
"block%d"
%
num
)
drive
.
set_param
(
"file"
,
find_image
(
img_list
[
num
+
1
]))
drive
.
set_param
(
"format"
,
img_format_type
)
drive_id
=
drive
.
get_param
(
"id"
)
drive
.
hotplug
(
vm
.
monitor
)
device
.
set_param
(
"drive"
,
drive_id
)
device
.
set_param
(
"id"
,
"block%d"
%
num
)
if
params
.
get
(
"need_controller"
,
"no"
)
==
"yes"
and
bool
(
random
.
randrange
(
2
)):
device
.
set_param
(
"bus"
,
controller
.
get_param
(
"id"
)
+
'.0'
)
blk_extra_param
=
params
.
get
(
"blk_extra_params_%s"
%
img_list
[
num
+
1
])
if
blk_extra_param
:
for
item
in
blk_extra_param
.
split
():
key
,
value
=
item
.
split
(
"="
,
1
)
device
.
set_param
(
key
,
value
)
device
.
hotplug
(
vm
.
monitor
)
ver_out
=
device
.
verify_hotplug
(
""
,
vm
.
monitor
)
if
not
ver_out
:
err
=
"%s is not in qtree after hotplug"
%
pci_type
test
.
fail
(
err
)
plug_status
=
utils_misc
.
wait_for
(
lambda
:
len
(
get_new_disk
(
disks_before_plug
,
find_disk
(
vm
,
get_disk_cmd
)))
!=
0
,
pause
)
if
plug_status
:
disks_after_plug
=
find_disk
(
vm
,
get_disk_cmd
)
new_disks
=
get_new_disk
(
disks_before_plug
,
disks_after_plug
)
else
:
test
.
fail
(
"Can't get new disks"
)
if
params
.
get
(
"need_controller"
,
"no"
)
==
"yes"
:
info_qtree
=
vm
.
monitor
.
info
(
'qtree'
,
False
)
qtree
=
qemu_qtree
.
QtreeContainer
()
qtree
.
parse_info_qtree
(
info_qtree
)
for
node
in
qtree
.
get_nodes
():
if
node
.
qtree
.
get
(
"id"
)
==
device
.
get_param
(
"id"
):
try
:
controller_id
=
node
.
parent
.
qtree
.
get
(
"id"
).
split
(
"."
)[
0
]
except
AttributeError
:
test
.
fail
(
"can't get parent of:
\n
%s"
%
node
)
controller_device_dict
.
setdefault
(
controller_id
,
[]).
append
(
device
)
break
else
:
test
.
fail
(
"Can't find device '%s' in qtree"
%
device
.
get_param
(
"id"
))
else
:
if
params
.
get
(
"drive_format"
)
in
pci_type
:
get_disk_cmd
+=
" | egrep -v '^/dev/[hsv]da[0-9]*$'"
device
.
set_param
(
"id"
,
img_list
[
num
+
1
])
new_disks
=
find_disk
(
vm
,
get_disk_cmd
)
device_list
.
append
(
device
)
if
not
new_disks
:
test
.
fail
(
"Cannot find new disk after hotplug."
)
if
params
.
get
(
"need_plug"
)
==
"yes"
:
disk
=
new_disks
[
0
]
else
:
disk
=
new_disks
[
num
]
session
=
vm
.
wait_for_login
(
timeout
=
timeout
)
session
=
vm
.
wait_for_login
(
timeout
=
timeout
)
if
params
.
get
(
"os_type"
)
==
"windows"
:
if
params
.
get
(
"os_type"
)
==
"windows"
:
...
@@ -200,41 +126,38 @@ def run(test, params, env):
...
@@ -200,41 +126,38 @@ def run(test, params, env):
status
,
output
=
session
.
cmd_status_output
(
test_cmd
,
status
,
output
=
session
.
cmd_status_output
(
test_cmd
,
timeout
=
disk_op_timeout
)
timeout
=
disk_op_timeout
)
if
status
:
if
status
:
test
.
fail
(
"Check for block device failed "
test
.
fail
(
"Check for block device failed."
"after hotplug, Output: %r"
%
output
)
"Output: %s"
%
output
)
session
.
close
()
sub_type
=
params
.
get
(
"sub_type_after_plug"
)
devs
=
[
dev
for
dev
in
devs
if
not
isinstance
(
dev
,
qdevices
.
QDrive
)]
if
sub_type
:
device_list
.
extend
(
devs
)
error_context
.
context
(
context_msg
%
(
sub_type
,
"after hotplug"
),
else
:
logging
.
info
)
for
device
in
vm
.
devices
:
utils_test
.
run_virt_sub_test
(
test
,
params
,
env
,
sub_type
)
if
device
.
get_param
(
"id"
)
==
img_list
[
num
+
1
]:
if
sub_type
==
"shutdown"
and
vm
.
is_dead
():
device_list
.
append
(
device
)
plug_tag
=
"after_plug"
vm_switched_off
=
run_sub_test
(
params
,
plug_tag
)
if
vm_switched_off
:
return
return
sub_type
=
params
.
get
(
"sub_type_before_unplug"
)
plug_tag
=
"before_unplug"
if
sub_type
:
run_sub_test
(
params
,
plug_tag
)
error_context
.
context
(
context_msg
%
(
sub_type
,
"before unplug"
),
logging
.
info
)
utils_test
.
run_virt_sub_test
(
test
,
params
,
env
,
sub_type
)
error_context
.
context
(
"Unplug block device (iteration %d)"
%
iteration
,
error_context
.
context
(
"Unplug block device (iteration %d)"
%
iteration
,
logging
.
info
)
logging
.
info
)
for
controller
in
controller_list
:
disks_before_unplug
=
find_disk
(
vm
,
get_disk_cmd
)
controller_id
=
controller
.
get_param
(
"id"
)
for
device
in
reversed
(
device_list
):
for
device
in
controller_device_dict
.
get
(
controller_id
,
[]):
ret
=
vm
.
devices
.
simple_unplug
(
device
,
vm
.
monitor
)
unplug_status
=
unplug_device
(
vm
,
get_disk_cmd
,
device
)
if
ret
[
1
]
is
False
:
if
not
unplug_status
:
test
.
fail
(
"Failed to unplug device '%s'."
test
.
fail
(
"Failed to unplug disks '%s'"
%
device
.
get_param
(
"id"
))
"Ouptut:
\n
%s"
%
(
dev
,
ret
[
0
]))
device_list
.
remove
(
device
)
controller
.
unplug
(
vm
.
monitor
)
unplug_disks
=
utils_misc
.
wait_for
(
lambda
:
get_new_disk
(
find_disk
(
vm
,
get_disk_cmd
),
for
device
in
device_list
:
disks_before_unplug
),
pause
)
unplug_status
=
unplug_device
(
vm
,
get_disk_cmd
,
device
)
if
len
(
unplug_disks
)
!=
blk_num
:
if
not
unplug_status
:
test
.
fail
(
"Failed to unplug devices from guest, need to unplug: %d,"
test
.
fail
(
"Failed to unplug disks '%s'"
%
device
.
get_param
(
"id"
))
"actual unplug: %d"
%
(
blk_num
,
len
(
unplug_disks
)))
sub_type
=
params
.
get
(
"sub_type_after_unplug"
)
plug_tag
=
"after_unplug"
if
sub_type
:
run_sub_test
(
params
,
plug_tag
)
error_context
.
context
(
context_msg
%
(
sub_type
,
"after unplug"
),
logging
.
info
)
utils_test
.
run_virt_sub_test
(
test
,
params
,
env
,
sub_type
)
qemu/tests/cfg/block_hotplug.cfg
浏览文件 @
256e9436
...
@@ -121,22 +121,13 @@
...
@@ -121,22 +121,13 @@
variants:
variants:
- block_virtio:
- block_virtio:
pci_type = virtio-blk-pci
s390x:
pci_type = virtio-blk-ccw
drive_format_stg0 = virtio
drive_format_stg0 = virtio
drive_format_stg1 = virtio
drive_format_stg1 = virtio
get_disk_pattern = "^/dev/vd[a-z]*$"
get_disk_pattern = "^/dev/vd[a-z]*$"
- block_scsi:
- block_scsi:
pci_type = scsi-hd
drive_format_stg0 = scsi-hd
drive_format_stg0 = scsi-hd
drive_format_stg1 = scsi-hd
drive_format_stg1 = scsi-hd
get_disk_pattern = "^/dev/sd[a-z]*$"
get_disk_pattern = "^/dev/sd[a-z]*$"
virtio_blk:
need_controller = yes
controller_model = virtio-scsi-pci
s390x:
controller_model = virtio-scsi-ccw
variants:
variants:
- @default:
- @default:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录