Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
4065952a
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,发现更多精彩内容 >>
提交
4065952a
编写于
6月 04, 2015
作者:
L
Lucas Meneghel Rodrigues
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #633 from ldoktor/mux-args2tree3
avocado.multiplexer: Support for modifying multiplex tree on cmdline [v3]
上级
b6488cce
e9f5187a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
111 addition
and
48 deletion
+111
-48
avocado/core/parser.py
avocado/core/parser.py
+8
-2
avocado/core/plugins/multiplexer.py
avocado/core/plugins/multiplexer.py
+28
-19
avocado/core/plugins/runner.py
avocado/core/plugins/runner.py
+14
-1
avocado/core/tree.py
avocado/core/tree.py
+29
-3
avocado/multiplexer.py
avocado/multiplexer.py
+8
-6
selftests/all/unit/avocado/multiplexer_unittest.py
selftests/all/unit/avocado/multiplexer_unittest.py
+19
-12
selftests/all/unit/avocado/tree_unittest.py
selftests/all/unit/avocado/tree_unittest.py
+5
-5
未找到文件。
avocado/core/parser.py
浏览文件 @
4065952a
...
...
@@ -20,6 +20,7 @@ Avocado application command line parsing.
import
sys
import
argparse
from
avocado.core
import
tree
from
avocado.version
import
VERSION
PROG
=
'avocado'
...
...
@@ -33,6 +34,8 @@ class Parser(object):
"""
def
__init__
(
self
):
self
.
args
=
None
self
.
subcommands
=
None
self
.
application
=
argparse
.
ArgumentParser
(
prog
=
PROG
,
add_help
=
False
,
# see parent parsing
...
...
@@ -71,9 +74,12 @@ class Parser(object):
"""
# Inject --help if no arguments is present
default_args
=
[
'--help'
]
if
not
sys
.
argv
[
1
:]
else
None
self
.
args
,
rest
=
self
.
application
.
parse_known_args
(
args
=
default_args
)
self
.
args
,
_
=
self
.
application
.
parse_known_args
(
args
=
default_args
)
if
not
hasattr
(
self
.
args
,
'dispatch'
):
self
.
application
.
set_defaults
(
dispatch
=
self
.
application
.
print_help
)
if
tree
.
MULTIPLEX_CAPABLE
:
# Allow overriding multiplex variants by plugins args
self
.
args
.
default_multiplex_tree
=
tree
.
TreeNode
()
def
finish
(
self
):
"""
...
...
@@ -81,7 +87,7 @@ class Parser(object):
Side effect: set the final value for attribute `args`.
"""
self
.
args
=
self
.
application
.
parse_args
()
self
.
args
=
self
.
application
.
parse_args
(
namespace
=
self
.
args
)
def
take_action
(
self
):
"""
...
...
avocado/core/plugins/multiplexer.py
浏览文件 @
4065952a
...
...
@@ -12,7 +12,6 @@
# Copyright: Red Hat Inc. 2013-2014
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
import
os
import
sys
from
avocado.core.plugins
import
plugin
...
...
@@ -57,33 +56,40 @@ class Multiplexer(plugin.Plugin):
self
.
parser
.
add_argument
(
'-d'
,
'--debug'
,
action
=
'store_true'
,
default
=
False
,
help
=
"Debug multiplexed "
"files."
)
self
.
parser
.
add_argument
(
'--env'
,
default
=
[],
nargs
=
'*'
)
super
(
Multiplexer
,
self
).
configure
(
self
.
parser
)
def
activate
(
self
,
args
):
# Extend default multiplex tree of --env values
for
value
in
getattr
(
args
,
"env"
,
[]):
value
=
value
.
split
(
':'
,
2
)
if
len
(
value
)
<
2
:
raise
ValueError
(
"key:value pairs required, found only %s"
%
(
value
))
elif
len
(
value
)
==
2
:
args
.
default_multiplex_tree
.
value
[
value
[
0
]]
=
value
[
1
]
else
:
node
=
args
.
default_multiplex_tree
.
get_node
(
value
[
0
],
True
)
node
.
value
[
value
[
1
]]
=
value
[
2
]
def
run
(
self
,
args
):
view
=
output
.
View
(
app_args
=
args
)
multiplex_files
=
args
.
multiplex_files
if
args
.
tree
:
view
.
notify
(
event
=
'message'
,
msg
=
'Config file tree structure:'
)
try
:
t
=
tree
.
create_from_yaml
(
multiplex_files
)
except
IOError
,
details
:
view
.
notify
(
event
=
'error'
,
msg
=
details
.
strerror
)
sys
.
exit
(
exit_codes
.
AVOCADO_JOB_FAIL
)
t
=
tree
.
apply_filters
(
t
,
args
.
filter_only
,
args
.
filter_out
)
view
.
notify
(
event
=
'minor'
,
msg
=
t
.
get_ascii
(
attributes
=
args
.
attr
))
sys
.
exit
(
exit_codes
.
AVOCADO_ALL_OK
)
try
:
variants
=
multiplexer
.
multiplex_yamls
(
multiplex_files
,
args
.
filter_only
,
args
.
filter_out
,
args
.
debug
)
mux_tree
=
multiplexer
.
yaml2tree
(
args
.
multiplex_files
,
args
.
filter_only
,
args
.
filter_out
,
args
.
debug
)
except
IOError
,
details
:
view
.
notify
(
event
=
'error'
,
msg
=
details
.
strerror
)
sys
.
exit
(
exit_codes
.
AVOCADO_JOB_FAIL
)
mux_tree
.
merge
(
args
.
default_multiplex_tree
)
if
args
.
tree
:
view
.
notify
(
event
=
'message'
,
msg
=
'Config file tree structure:'
)
view
.
notify
(
event
=
'minor'
,
msg
=
mux_tree
.
get_ascii
(
attributes
=
args
.
attr
))
sys
.
exit
(
exit_codes
.
AVOCADO_ALL_OK
)
variants
=
multiplexer
.
MuxTree
(
mux_tree
)
view
.
notify
(
event
=
'message'
,
msg
=
'Variants generated:'
)
for
(
index
,
tpl
)
in
enumerate
(
variants
):
if
not
args
.
debug
:
...
...
@@ -91,7 +97,10 @@ class Multiplexer(plugin.Plugin):
else
:
color
=
output
.
term_support
.
LOWLIGHT
cend
=
output
.
term_support
.
ENDC
paths
=
', '
.
join
([
"%s%s@%s%s"
%
(
_
.
name
,
color
,
_
.
yaml
,
cend
)
paths
=
', '
.
join
([
"%s%s@%s%s"
%
(
_
.
name
,
color
,
getattr
(
_
,
'yaml'
,
"Unknown"
),
cend
)
for
_
in
tpl
])
view
.
notify
(
event
=
'minor'
,
msg
=
'%sVariant %s: %s'
%
((
'
\n
'
if
args
.
contents
else
''
),
index
+
1
,
paths
))
...
...
avocado/core/plugins/runner.py
浏览文件 @
4065952a
...
...
@@ -126,11 +126,24 @@ class TestRunner(plugin.Plugin):
help
=
'Filter out path(s) from multiplexing'
)
mux
.
add_argument
(
'--mux-entry'
,
nargs
=
'*'
,
default
=
None
,
help
=
"Multiplex entry point(s)"
)
mux
.
add_argument
(
'--env'
,
default
=
[],
nargs
=
'*'
)
super
(
TestRunner
,
self
).
configure
(
self
.
parser
)
# Export the test runner parser back to the main parser
parser
.
runner
=
self
.
parser
def
activate
(
self
,
args
):
# Extend default multiplex tree of --env values
for
value
in
getattr
(
args
,
"env"
,
[]):
value
=
value
.
split
(
':'
,
2
)
if
len
(
value
)
<
2
:
raise
ValueError
(
"key:value pairs required, found only %s"
%
(
value
))
elif
len
(
value
)
==
2
:
args
.
default_multiplex_tree
.
value
[
value
[
0
]]
=
value
[
1
]
else
:
node
=
args
.
default_multiplex_tree
.
get_node
(
value
[
0
],
True
)
node
.
value
[
value
[
1
]]
=
value
[
2
]
def
_validate_job_timeout
(
self
,
raw_timeout
):
units
=
{
's'
:
1
,
'm'
:
60
,
'h'
:
3600
,
'd'
:
86400
}
mult
=
1
...
...
avocado/core/tree.py
浏览文件 @
4065952a
...
...
@@ -89,7 +89,7 @@ class TreeNode(object):
self
.
_environment
=
None
self
.
environment_origin
=
{}
self
.
ctrl
=
[]
self
.
multiplex
=
Fals
e
self
.
multiplex
=
Non
e
for
child
in
children
:
self
.
add_child
(
child
)
...
...
@@ -159,7 +159,10 @@ class TreeNode(object):
remove
.
append
(
key
)
for
key
in
remove
:
self
.
value
.
pop
(
key
,
None
)
self
.
multiplex
=
other
.
multiplex
if
other
.
multiplex
is
True
:
self
.
multiplex
=
True
elif
other
.
multiplex
is
False
:
self
.
multiplex
=
False
self
.
value
.
update
(
other
.
value
)
for
child
in
other
.
children
:
self
.
add_child
(
child
)
...
...
@@ -245,6 +248,29 @@ class TreeNode(object):
child
.
set_environment_dirty
()
self
.
_environment
=
None
def
get_node
(
self
,
path
,
create
=
False
):
"""
:param path: Path of the desired node (relative to this node)
:param create: Create the node (and intermediary ones) when not present
:return: the node associated with this path
:raise ValueError: When path doesn't exist and create not set
"""
node
=
self
for
name
in
path
.
split
(
'/'
):
if
not
name
:
continue
try
:
node
=
node
.
children
[
node
.
children
.
index
(
name
)]
except
ValueError
:
if
create
:
child
=
node
.
__class__
(
name
)
node
.
add_child
(
child
)
node
=
child
else
:
raise
ValueError
(
"Path %s does not exists in this tree
\n
%s"
%
(
path
,
self
.
get_ascii
()))
return
node
def
iter_children_preorder
(
self
):
""" Iterate through children """
queue
=
collections
.
deque
()
...
...
@@ -670,7 +696,7 @@ class TreeNodeDebug(TreeNode): # only container pylint: disable=R0903
Override origin with the one from other tree. Updated/Newly set values
are going to use this location as origin.
"""
if
hasattr
(
other
,
'yaml'
):
if
hasattr
(
other
,
'yaml'
)
and
other
.
yaml
:
srcyaml
=
os
.
path
.
relpath
(
other
.
yaml
)
# when we use TreeNodeDebug, value is always ValueDict
self
.
value
.
yaml_per_key
.
update
(
other
.
value
.
yaml_per_key
)
# pylint: disable=E1101
...
...
avocado/multiplexer.py
浏览文件 @
4065952a
...
...
@@ -90,8 +90,8 @@ class MuxTree(object):
yield
ret
def
multiplex_yamls
(
input_yamls
,
filter_only
=
None
,
filter_out
=
None
,
debug
=
False
):
def
yaml2tree
(
input_yamls
,
filter_only
=
None
,
filter_out
=
None
,
debug
=
False
):
if
filter_only
is
None
:
filter_only
=
[]
if
filter_out
is
None
:
...
...
@@ -99,8 +99,7 @@ def multiplex_yamls(input_yamls, filter_only=None, filter_out=None,
input_tree
=
tree
.
create_from_yaml
(
input_yamls
,
debug
)
# TODO: Process filters and multiplex simultaneously
final_tree
=
tree
.
apply_filters
(
input_tree
,
filter_only
,
filter_out
)
result
=
MuxTree
(
final_tree
)
return
result
return
final_tree
# TODO: Create multiplexer plugin and split these functions into multiple files
...
...
@@ -396,9 +395,12 @@ class Mux(object):
filter_only
=
getattr
(
args
,
'filter_only'
,
None
)
filter_out
=
getattr
(
args
,
'filter_out'
,
None
)
if
mux_files
:
self
.
variants
=
multiplex_yamls
(
mux_files
,
filter_only
,
filter_out
)
mux_tree
=
yaml2tree
(
mux_files
,
filter_only
,
filter_out
)
else
:
# no variants
self
.
variants
=
None
mux_tree
=
tree
.
TreeNode
()
if
getattr
(
args
,
'default_multiplex_tree'
,
None
):
mux_tree
.
merge
(
args
.
default_multiplex_tree
)
self
.
variants
=
MuxTree
(
mux_tree
)
self
.
_mux_entry
=
getattr
(
args
,
'mux_entry'
,
None
)
if
self
.
_mux_entry
is
None
:
self
.
_mux_entry
=
[
'/run/*'
]
...
...
selftests/all/unit/avocado/multiplexer_unittest.py
浏览文件 @
4065952a
...
...
@@ -43,24 +43,30 @@ class TestMultiplex(unittest.TestCase):
self
.
assertEqual
(
len
(
self
.
mux_full
),
12
)
def
test_create_variants
(
self
):
from_file
=
multiplexer
.
multiplex_yamls
([
'/:'
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
])
from_file
=
multiplexer
.
yaml2tree
(
[
"/:"
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
])
from_file
=
multiplexer
.
MuxTree
(
from_file
)
self
.
assertEqual
(
self
.
mux_full
,
tuple
(
from_file
))
# Filters are tested in tree_unittests, only verify `multiplex_yamls` calls
def
test_filter_only
(
self
):
exp
=
([
'intel'
,
'scsi'
],
[
'intel'
,
'virtio'
])
act
=
tuple
(
multiplexer
.
multiplex_yamls
([
'/:'
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
],
(
'/hw/cpu/intel'
,
'/distro/fedora'
,
'/hw'
)))
act
=
multiplexer
.
yaml2tree
([
"/:"
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
],
(
'/hw/cpu/intel'
,
'/distro/fedora'
,
'/hw'
))
act
=
tuple
(
multiplexer
.
MuxTree
(
act
))
self
.
assertEqual
(
act
,
exp
)
def
test_filter_out
(
self
):
act
=
tuple
(
multiplexer
.
multiplex_yamls
([
'/:'
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
],
None
,
(
'/hw/cpu/intel'
,
'/distro/fedora'
,
'/distro'
)))
act
=
multiplexer
.
yaml2tree
([
"/:"
+
PATH_PREFIX
+
'examples/mux-selftest.yaml'
],
None
,
(
'/hw/cpu/intel'
,
'/distro/fedora'
,
'/distro'
))
act
=
tuple
(
multiplexer
.
MuxTree
(
act
))
self
.
assertEqual
(
len
(
act
),
4
)
self
.
assertEqual
(
len
(
act
[
0
]),
3
)
str_act
=
str
(
act
)
...
...
@@ -71,8 +77,9 @@ class TestMultiplex(unittest.TestCase):
class
TestAvocadoParams
(
unittest
.
TestCase
):
yamls
=
iter
(
multiplexer
.
multiplex_yamls
([
'/:'
+
PATH_PREFIX
+
'examples/mux-selftest-params.'
'yaml'
]))
yamls
=
multiplexer
.
yaml2tree
([
"/:"
+
PATH_PREFIX
+
'examples/mux-selftest-params.yaml'
])
yamls
=
iter
(
multiplexer
.
MuxTree
(
yamls
))
params1
=
multiplexer
.
AvocadoParams
(
yamls
.
next
(),
'Unittest1'
,
1
,
[
'/ch0/*'
,
'/ch1/*'
],
{})
yamls
.
next
()
# Skip 2nd
...
...
selftests/all/unit/avocado/tree_unittest.py
浏览文件 @
4065952a
...
...
@@ -171,20 +171,20 @@ class TestTree(unittest.TestCase):
self
.
assertEqual
({
'new_value'
:
'something'
},
oldroot
.
children
[
3
].
children
[
0
].
children
[
0
].
value
)
# multiplex root (always True)
self
.
assertEqual
(
tree2
.
multiplex
,
Fals
e
)
self
.
assertEqual
(
tree2
.
multiplex
,
Non
e
)
# multiplex /virt/
self
.
assertEqual
(
tree2
.
children
[
0
].
multiplex
,
Fals
e
)
self
.
assertEqual
(
tree2
.
children
[
0
].
multiplex
,
Non
e
)
# multiplex /virt/hw
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
0
].
multiplex
,
Fals
e
)
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
0
].
multiplex
,
Non
e
)
# multiplex /virt/distro
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
1
].
multiplex
,
True
)
# multiplex /virt/env
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
2
].
multiplex
,
True
)
# multiplex /virt/absolutly
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
3
].
multiplex
,
Fals
e
)
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
3
].
multiplex
,
Non
e
)
# multiplex /virt/distro/fedora
self
.
assertEqual
(
tree2
.
children
[
0
].
children
[
1
].
children
[
0
].
multiplex
,
Fals
e
)
Non
e
)
class
TestPathParent
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录