Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
eb639434
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,发现更多精彩内容 >>
提交
eb639434
编写于
9月 30, 2016
作者:
A
Amador Pahim
提交者:
GitHub
9月 30, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1495 from clebergnu/plugins_disable
Plugins: add mechanism to disable installed plugins
上级
fa0eeb90
f3da6d27
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
92 addition
and
6 deletion
+92
-6
avocado/core/dispatcher.py
avocado/core/dispatcher.py
+15
-2
avocado/plugins/plugins.py
avocado/plugins/plugins.py
+4
-4
docs/source/Plugins.rst
docs/source/Plugins.rst
+48
-0
etc/avocado/avocado.conf
etc/avocado/avocado.conf
+3
-0
selftests/functional/test_basic.py
selftests/functional/test_basic.py
+22
-0
未找到文件。
avocado/core/dispatcher.py
浏览文件 @
eb639434
...
...
@@ -16,10 +16,12 @@
import
sys
from
stevedore
import
ExtensionManager
from
stevedore
import
E
nabledE
xtensionManager
from
.settings
import
settings
class
Dispatcher
(
ExtensionManager
):
class
Dispatcher
(
EnabledExtensionManager
):
"""
Base dispatcher for various extension types
...
...
@@ -28,10 +30,21 @@ class Dispatcher(ExtensionManager):
def
__init__
(
self
,
namespace
):
self
.
load_failures
=
[]
super
(
Dispatcher
,
self
).
__init__
(
namespace
=
namespace
,
check_func
=
self
.
enabled
,
invoke_on_load
=
True
,
on_load_failure_callback
=
self
.
store_load_failure
,
propagate_map_exceptions
=
True
)
def
enabled
(
self
,
extension
):
namespace_prefix
=
'avocado.plugins.'
if
self
.
namespace
.
startswith
(
namespace_prefix
):
namespace
=
self
.
namespace
[
len
(
namespace_prefix
):]
else
:
namespace
=
self
.
namespace
disabled
=
settings
.
get_value
(
'plugins'
,
'disable'
,
key_type
=
list
)
fqn
=
"%s.%s"
%
(
namespace
,
extension
.
entry_point
.
name
)
return
fqn
not
in
disabled
@
staticmethod
def
store_load_failure
(
manager
,
entrypoint
,
exception
):
manager
.
load_failures
.
append
((
entrypoint
,
exception
))
...
...
avocado/plugins/plugins.py
浏览文件 @
eb639434
...
...
@@ -42,13 +42,13 @@ class Plugins(CLICmd):
log
=
logging
.
getLogger
(
"avocado.app"
)
plugin_types
=
[
(
dispatcher
.
CLICmdDispatcher
(),
'Plugins that add new commands (
avocado.plugins.
cli.cmd):'
),
'Plugins that add new commands (cli.cmd):'
),
(
dispatcher
.
CLIDispatcher
(),
'Plugins that add new options to commands (
avocado.plugins.
cli):'
),
'Plugins that add new options to commands (cli):'
),
(
dispatcher
.
JobPrePostDispatcher
(),
'Plugins that run before/after the execution of jobs (
avocado.plugins.
job.prepost):'
),
'Plugins that run before/after the execution of jobs (job.prepost):'
),
(
dispatcher
.
ResultDispatcher
(),
'Plugins that generate job result in different formats (
avocado.plugins.
result):'
)
'Plugins that generate job result in different formats (result):'
)
]
for
plugins_active
,
msg
in
plugin_types
:
log
.
info
(
msg
)
...
...
docs/source/Plugins.rst
浏览文件 @
eb639434
...
...
@@ -81,6 +81,54 @@ to add to your setuptools based `setup.py` file something like::
Then, by running either ``$ python setup.py install`` or ``$ python setup.py
develop`` your plugin should be visible to Avocado.
Fully qualified named for a plugin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The plugin registry mentioned earlier, (`setuptools`_ and its `entry
points`_) is global to a given Python installation. Avocado uses the
namespace prefix ``avocado.plugins.`` to avoid name clashes with other
software. Now, inside Avocado itself, there's no need keep using the
``avocado.plugins.`` prefix.
Take for instance, the Job Pre/Post plugins are defined on
``setup.py``::
'avocado.plugins.job.prepost': [
'jobscripts = avocado.plugins.jobscripts:JobScripts'
]
The setuptools entry point namespace is composed of the mentioned
prefix ``avocado.plugins.``, which is is then followed by the Avocado
plugin type, in this case, ``job.prepost``.
Inside avocado itself, the fully qualified name for a plugin is the
plugin type, such as ``job.prepost`` concatenated to the name used in
the entry point definition itself, in this case, ``jobscripts``.
To summarize, still using the same example, the fully qualified
Avocado plugin name is going to be ``job.prepost.jobscripts``.
Disabling a plugin
~~~~~~~~~~~~~~~~~~
Even though a plugin can be installed and registered under
`setuptools`_ `entry points`_, it can be explicitly disabled in
Avocado.
The mechanism available to do so is to add entries to the ``disable``
key under the ``plugins`` section of the Avocado configuration file.
Example::
[plugins]
disable = ['cli.hello', 'job.prepost.jobscripts']
The exact effect on Avocado when a plugin is disabled depends on the
plugin type. For instance, by disabling plugins of type ``cli.cmd``,
the command implemented by the plugin should no longer be available on
the Avocado command line application. Now, by disabling a
``job.prepost`` plugin, those won't be executed before/after the
execution of the jobs.
Wrap Up
~~~~~~~
...
...
etc/avocado/avocado.conf
浏览文件 @
eb639434
...
...
@@ -69,6 +69,9 @@ username =
password
=
[
plugins
]
# Disable listed plugins completely. Use the fully qualified plugin
# name, as described in the Avocado documentation "Plugins" section.
disable
= []
# Suppress notification about broken plugins in the app standard error.
# Add the name of each broken plugin you want to suppress the notification
# in the list. The names can be easily seen from the stderr messages. Example:
...
...
selftests/functional/test_basic.py
浏览文件 @
eb639434
...
...
@@ -877,6 +877,28 @@ class PluginsTest(AbsPluginsTest, unittest.TestCase):
(
expected_rc
,
result
))
self
.
assertNotIn
(
'Disabled'
,
output
)
def
test_disable_plugin
(
self
):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado plugins'
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_ALL_OK
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
"Avocado did not return rc %d:
\n
%s"
%
(
expected_rc
,
result
))
self
.
assertIn
(
"Collect system information"
,
result
.
stdout
)
config_content
=
"[plugins]
\n
disable=['cli.cmd.sysinfo',]"
config
=
script
.
TemporaryScript
(
"disable_sysinfo_cmd.conf"
,
config_content
)
with
config
:
cmd_line
=
'./scripts/avocado --config %s plugins'
%
config
result
=
process
.
run
(
cmd_line
,
ignore_status
=
True
)
expected_rc
=
exit_codes
.
AVOCADO_ALL_OK
self
.
assertEqual
(
result
.
exit_status
,
expected_rc
,
"Avocado did not return rc %d:
\n
%s"
%
(
expected_rc
,
result
))
self
.
assertNotIn
(
"Collect system information"
,
result
.
stdout
)
def
test_Namespace_object_has_no_attribute
(
self
):
os
.
chdir
(
basedir
)
cmd_line
=
'./scripts/avocado plugins'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录