Add external plugin support to subunit2sql-graph

This commit adds support to the subunit2sql-graph command to load
installed plugins that add additional graph commands. The interface
for adding additional graph commands was already modular, but it
still required additional modules added in tree. Now additional
commands can be added just by adding entry-points in the
subunit2sql.graph.plugins namespace, the same pre-existing interface
for adding graph commands should be used.

Change-Id: I2bd59d9c3565ad0d07c357307e5151904bb0e288
This commit is contained in:
Matthew Treinish 2015-05-28 13:39:09 -04:00
parent 1875f963b2
commit 60735a247a
2 changed files with 23 additions and 3 deletions

View File

@ -5,3 +5,4 @@ pbr>=1.0.0
python-subunit>=0.0.18
six>=1.5.2
SQLAlchemy>=0.7.8
stevedore>=1.3.0

View File

@ -17,6 +17,7 @@ import copy
import sys
from oslo_config import cfg
import stevedore
import subunit2sql.analysis.agg_count
import subunit2sql.analysis.dailycount
@ -42,12 +43,30 @@ SHELL_OPTS = [
]
def get_plugin_list():
plugin_list = stevedore.ExtensionManager(
'subunit2sql.graph.plugin',
invoke_on_load=True,
propagate_map_exceptions=True)
return plugin_list
def add_command_parsers(subparsers):
for name in ['failures', 'run_time', 'agg_count', 'dailycount']:
graph_commands = {}
# Put commands from in-tree commands on init list
for command in ['failures', 'run_time', 'agg_count', 'dailycount']:
graph_commands[command] = getattr(subunit2sql.analysis, command)
# Load any installed out of tree commands on the init list
for plugin in get_plugin_list():
graph_commands[plugin.name] = plugin.plugin
# Init all commands from graph_commands
for name in graph_commands:
parser = subparsers.add_parser(name)
getattr(subunit2sql.analysis, name).set_cli_opts(parser)
graph_commands[name].set_cli_opts(parser)
parser.set_defaults(
func=getattr(subunit2sql.analysis, name).generate_series)
func=graph_commands[name].generate_series)
command_opt = cfg.SubCommandOpt('command', title='graph',
help='Available graphs',