Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
f457d3c3
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f457d3c3
编写于
8月 10, 2015
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #752 from clebergnu/vm_snapshot_bug
VM plugin cleanup bug
上级
e5e28c25
734ec9e7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
104 addition
and
14 deletion
+104
-14
avocado/core/plugins/vm.py
avocado/core/plugins/vm.py
+7
-12
avocado/core/remote/result.py
avocado/core/remote/result.py
+4
-2
examples/tests/vm-cleanup.py
examples/tests/vm-cleanup.py
+88
-0
examples/tests/vm-cleanup.py.data/vm-cleanup.yaml
examples/tests/vm-cleanup.py.data/vm-cleanup.yaml
+4
-0
selftests/all/unit/avocado/vm_unittest.py
selftests/all/unit/avocado/vm_unittest.py
+1
-0
未找到文件。
avocado/core/plugins/vm.py
浏览文件 @
f457d3c3
...
...
@@ -40,30 +40,25 @@ class RunVM(plugin.Plugin):
default_hypervisor_uri
=
'qemu:///system'
msg
=
'test execution on a Virtual Machine'
self
.
vm_parser
=
parser
.
runner
.
add_argument_group
(
msg
)
self
.
vm_parser
.
add_argument
(
'--vm-domain'
,
dest
=
'vm_domain'
,
self
.
vm_parser
.
add_argument
(
'--vm-domain'
,
help
=
(
'Specify Libvirt Domain Name'
))
self
.
vm_parser
.
add_argument
(
'--vm-hypervisor-uri'
,
dest
=
'vm_hypervisor_uri'
,
default
=
default_hypervisor_uri
,
help
=
(
'Specify hypervisor URI driver '
'connection. Current: %s'
%
default_hypervisor_uri
))
self
.
vm_parser
.
add_argument
(
'--vm-hostname'
,
dest
=
'vm_hostname'
,
self
.
vm_parser
.
add_argument
(
'--vm-hostname'
,
help
=
'Specify VM hostname to login'
)
self
.
vm_parser
.
add_argument
(
'--vm-username'
,
dest
=
'vm_username'
,
default
=
username
,
self
.
vm_parser
.
add_argument
(
'--vm-username'
,
default
=
username
,
help
=
'Specify the username to login on VM'
)
self
.
vm_parser
.
add_argument
(
'--vm-password'
,
dest
=
'vm_password'
,
self
.
vm_parser
.
add_argument
(
'--vm-password'
,
default
=
None
,
help
=
'Specify the password to login on VM'
)
self
.
vm_parser
.
add_argument
(
'--vm-cleanup'
,
dest
=
'vm_cleanup'
,
action
=
'store_true'
,
default
=
False
,
self
.
vm_parser
.
add_argument
(
'--vm-cleanup'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Restore VM to a previous state, '
'before running tests'
)
self
.
vm_parser
.
add_argument
(
'--vm-no-copy'
,
dest
=
'vm_no_copy'
,
action
=
'store_true'
,
self
.
vm_parser
.
add_argument
(
'--vm-no-copy'
,
action
=
'store_true'
,
help
=
"Don't copy tests and use the "
"exact uri on VM machine."
)
self
.
configured
=
True
...
...
avocado/core/remote/result.py
浏览文件 @
f457d3c3
...
...
@@ -145,5 +145,7 @@ class VMTestResult(RemoteTestResult):
def
tear_down
(
self
):
super
(
VMTestResult
,
self
).
tear_down
()
if
self
.
args
.
vm_cleanup
is
True
and
self
.
vm
.
snapshot
is
not
None
:
self
.
vm
.
restore_snapshot
()
if
self
.
args
.
vm_cleanup
is
True
:
self
.
vm
.
stop
()
if
self
.
vm
.
snapshot
is
not
None
:
self
.
vm
.
restore_snapshot
()
examples/tests/vm-cleanup.py
0 → 100644
浏览文件 @
f457d3c3
import
os
import
sys
import
shutil
import
tempfile
from
avocado
import
Test
from
avocado.utils
import
script
from
avocado.utils
import
process
CLEAN_TEST
=
"""import os
from avocado import Test
class Clean(Test):
def test(self):
path = os.path.expanduser("~/.avocado-has-not-touched-me")
self.assertFalse(os.path.exists(path))
"""
DIRTY_TEST
=
"""import os
from avocado import Test
class Dirty(Test):
def test(self):
self.touch(os.path.expanduser("~/.avocado-has-not-touched-me"))
@staticmethod
def touch(name):
with open(name, 'w'):
os.utime(name, None)
"""
class
VMCleanup
(
Test
):
"""
Tests the Avocado VM plugin `--vm-cleanup` feature
The approach chosen here is to have a first run of Avocado making sure that
a flag file does not exist. A second run of Avocado, now executed with an
additional `--vm-cleanup` parameter runs a test that creates the flag file.
Finally, the third and last execution of re-runs the same test as the first
run, checking that the flag file does *not* exist, that is, the clean up of
the VM did work.
Because this test requires a libvirt domain and the hostname/address of
that virtual machine, these parameters assume no defaults for safety and/or
security causes. Please edit the vm-cleanup.yaml file with the appropriate
parameters.
"""
def
setUp
(
self
):
vm_domain
=
self
.
params
.
get
(
"vm_domain"
,
default
=
None
)
vm_host
=
self
.
params
.
get
(
"vm_host"
,
default
=
None
)
if
vm_domain
is
None
or
vm_host
is
None
:
self
.
skip
(
'Either "vm_domain" or "vm_host" parameters have not '
'been given. Please edit the "vm-cleanup.yaml" file '
'with the appropriate parameters'
)
self
.
tmpdir
=
tempfile
.
mkdtemp
()
clean_test
=
os
.
path
.
join
(
self
.
tmpdir
,
'clean.py'
)
self
.
clean_test_path
=
script
.
make_script
(
clean_test
,
CLEAN_TEST
)
dirty_test
=
os
.
path
.
join
(
self
.
tmpdir
,
'dirty.py'
)
self
.
dirty_test_path
=
script
.
make_script
(
dirty_test
,
DIRTY_TEST
)
def
test
(
self
):
vm_domain
=
self
.
params
.
get
(
"vm_domain"
,
default
=
None
)
vm_host
=
self
.
params
.
get
(
"vm_host"
,
default
=
None
)
vm_username
=
self
.
params
.
get
(
"vm_username"
,
default
=
None
)
vm_password
=
self
.
params
.
get
(
"vm_password"
,
default
=
None
)
cmd
=
(
'avocado run --sysinfo=off --job-results-dir %s --vm-domain=%s '
'--vm-host=%s'
)
cmd
%=
(
self
.
tmpdir
,
vm_domain
,
vm_host
)
if
vm_username
:
cmd
+=
' --vm-username=%s'
%
vm_username
if
vm_password
:
cmd
+=
' --vm-password=%s'
%
vm_password
cmd_clean
=
'%s %s'
%
(
cmd
,
self
.
clean_test_path
)
cmd_dirty
=
'%s --vm-cleanup %s'
%
(
cmd
,
self
.
dirty_test_path
)
process
.
run
(
cmd_clean
)
process
.
run
(
cmd_dirty
)
process
.
run
(
cmd_clean
)
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
tmpdir
)
examples/tests/vm-cleanup.py.data/vm-cleanup.yaml
0 → 100644
浏览文件 @
f457d3c3
vm_domain
:
REPLACE_WITH_DOMAIN_NAME
vm_host
:
REPLACE_WITH_VM_DOMAIN_HOSTNAME_OR_IP_ADDRESS
vm_username
:
REPLACE_WITH_USERNAME_ON_VM
vm_password
:
BETTER_COMMENT_THIS_AND_USE_AN_SSH_KEY
selftests/all/unit/avocado/vm_unittest.py
浏览文件 @
f457d3c3
...
...
@@ -52,6 +52,7 @@ class VMTestResultTest(unittest.TestCase):
self
.
remote
=
VMTestResult
(
Stream
,
Args
)
# vm.RemoteTestResult.tear_down()
RemoteTestResult
.
should_receive
(
'tear_down'
).
once
().
ordered
()
mock_vm
.
should_receive
(
'stop'
).
once
().
ordered
()
mock_vm
.
should_receive
(
'restore_snapshot'
).
once
().
ordered
()
def
tearDown
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录