Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
tp-qemu
提交
e0d91732
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,发现更多精彩内容 >>
未验证
提交
e0d91732
编写于
8月 24, 2018
作者:
X
Xu Han
提交者:
GitHub
8月 24, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1259 from lolyu/dev0
eject_media: use eject_cdrom and change_media
上级
262a0dfc
b1f05d40
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
56 deletion
+54
-56
qemu/tests/eject_media.py
qemu/tests/eject_media.py
+54
-56
未找到文件。
qemu/tests/eject_media.py
浏览文件 @
e0d91732
...
...
@@ -2,7 +2,7 @@ import logging
import
time
from
virttest
import
error_context
from
virttest
import
utils_misc
from
qemu.lib.cdrom
import
QMPEventCheckCDEject
,
QMPEventCheckCDChange
@
error_context
.
context_aware
...
...
@@ -23,18 +23,15 @@ def run(test, params, env):
:param env: Dictionary with test environment
"""
qemu_binary
=
utils_misc
.
get_qemu_binary
(
params
)
if
not
utils_misc
.
qemu_has_option
(
"qmp"
,
qemu_binary
):
logging
.
warn
(
"qemu does not support qmp. Human monitor will be used."
)
qmp_used
=
False
vm
=
env
.
get_vm
(
params
[
"main_vm"
])
vm
.
verify_alive
()
session
=
vm
.
wait_for_login
(
timeout
=
int
(
params
.
get
(
"login_timeout"
,
360
)))
logging
.
info
(
"Wait until device is ready"
)
time
.
sleep
(
10
)
if
vm
.
monitor
.
protocol
==
"qmp"
:
qmp_used
=
True
def
check_block
(
block
):
return
True
if
block
in
str
(
vm
.
monitor
.
info
(
"block"
))
else
False
orig_img_name
=
params
.
get
(
"cdrom_cd1"
)
p_dict
=
{
"file"
:
orig_img_name
}
...
...
@@ -42,72 +39,73 @@ def run(test, params, env):
if
device_name
is
None
:
msg
=
"Fail to get device using image %s"
%
orig_img_name
test
.
fail
(
msg
)
error_context
.
context
(
"Eject original device."
)
eject_cmd
=
"eject device=%s"
%
device_name
vm
.
monitor
.
send_args_cmd
(
eject_cmd
)
logging
.
info
(
"Wait until device is ejected"
)
time
.
sleep
(
10
)
blocks_info
=
vm
.
monitor
.
info
(
"block"
)
if
orig_img_name
in
str
(
blocks_info
):
eject_check
=
QMPEventCheckCDEject
(
vm
,
device_name
)
change_check
=
QMPEventCheckCDChange
(
vm
,
device_name
)
# eject first time
error_context
.
context
(
"Eject original device."
,
logging
.
info
)
with
eject_check
:
vm
.
eject_cdrom
(
device_name
)
if
check_block
(
orig_img_name
):
test
.
fail
(
"Fail to eject cdrom %s. "
%
orig_img_name
)
error_context
.
context
(
"Eject original device for second time"
)
vm
.
monitor
.
send_args_cmd
(
eject_cmd
)
# eject second time
error_context
.
context
(
"Eject original device for second time"
,
logging
.
info
)
with
eject_check
:
vm
.
eject_cdrom
(
device_name
)
# change media
new_img_name
=
params
.
get
(
"new_img_name"
)
error_context
.
context
(
"Insert new image to device."
)
change_cmd
=
"change device=%s,target=%s"
%
(
device_name
,
new_img_name
)
vm
.
monitor
.
send_args_cmd
(
change_cmd
)
logging
.
info
(
"Wait until device changed"
)
time
.
sleep
(
10
)
blocks_info
=
vm
.
monitor
.
info
(
"block"
)
if
new_img_name
not
in
str
(
blocks_info
):
test
.
fail
(
"Fail to chang cdrom to %s."
%
new_img_name
)
if
qmp_used
:
eject_cmd
=
"eject device=%s, force=True"
%
device_name
else
:
eject_cmd
=
"eject device=%s"
%
device_name
error_context
.
context
(
"Eject device after add new image by change command"
)
vm
.
monitor
.
send_args_cmd
(
eject_cmd
)
logging
.
info
(
"Wait until new image is ejected"
)
time
.
sleep
(
10
)
error_context
.
context
(
"Insert new image to device."
,
logging
.
info
)
with
change_check
:
vm
.
change_media
(
device_name
,
new_img_name
)
if
not
check_block
(
new_img_name
):
test
.
fail
(
"Fail to change cdrom to %s."
%
new_img_name
)
blocks_info
=
vm
.
monitor
.
info
(
"block"
)
if
new_img_name
in
str
(
blocks_info
):
# eject after change
error_context
.
context
(
"Eject device after add new image by change command"
,
logging
.
info
)
with
eject_check
:
vm
.
eject_cdrom
(
device_name
)
if
check_block
(
new_img_name
):
test
.
fail
(
"Fail to eject cdrom %s."
%
orig_img_name
)
error_context
.
context
(
"Insert %s to device %s"
%
(
orig_img_name
,
device_name
))
change_cmd
=
"change device=%s,target=%s"
%
(
device_name
,
orig_img_name
)
vm
.
monitor
.
send_args_cmd
(
change_cmd
)
logging
.
info
(
"Wait until device changed"
)
time
.
sleep
(
10
)
blocks_info
=
vm
.
monitor
.
info
(
"block"
)
if
orig_img_name
not
in
str
(
blocks_info
):
# change back to orig_img_name
error_context
.
context
(
"Insert %s to device %s"
%
(
orig_img_name
,
device_name
),
logging
.
info
)
with
change_check
:
vm
.
change_media
(
device_name
,
orig_img_name
)
if
not
check_block
(
orig_img_name
):
test
.
fail
(
"Fail to change cdrom to %s."
%
orig_img_name
)
error_context
.
context
(
"Try to eject non-removable device"
)
# change again
error_context
.
context
(
"Insert %s to device %s"
%
(
new_img_name
,
device_name
),
logging
.
info
)
with
change_check
:
vm
.
change_media
(
device_name
,
new_img_name
)
if
not
check_block
(
new_img_name
):
test
.
fail
(
"Fail to change cdrom to %s."
%
new_img_name
)
# eject non-removable
error_context
.
context
(
"Try to eject non-removable device"
,
logging
.
info
)
p_dict
=
{
"removable"
:
False
}
device_name
=
vm
.
get_block
(
p_dict
)
if
device_name
is
None
:
test
.
fail
(
"Could not find non-removable device"
)
if
params
.
get
(
"force_eject"
,
"no"
)
==
"yes"
:
if
not
qmp_used
:
eject_cmd
=
"eject -f %s "
%
device_name
else
:
eject_cmd
=
"eject device=%s, force=True"
%
device_name
else
:
eject_cmd
=
"eject device=%s,"
%
device_name
test
.
error
(
"Could not find non-removable device"
)
try
:
vm
.
monitor
.
send_args_cmd
(
eject_cmd
)
if
params
.
get
(
"force_eject"
,
"no"
)
==
"yes"
:
vm
.
eject_cdrom
(
device_name
,
force
=
True
)
else
:
vm
.
eject_cdrom
(
device_name
)
except
Exception
as
e
:
if
"is not removable"
not
in
str
(
e
):
test
.
fail
(
e
)
logging
.
debug
(
"Catch exception message: %s"
%
e
)
logging
.
info
(
"Wait until device is ejected"
)
time
.
sleep
(
10
)
blocks_info
=
vm
.
monitor
.
info
(
"block"
)
if
device_name
not
in
str
(
blocks_info
):
if
not
check_block
(
device_name
):
test
.
fail
(
"Could remove non-removable device!"
)
session
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录