Add modular subunit2sql-graph entry point

This commit replaces the previous entry point in run_time.py for the
subunit2sql-graph command and creates a new module for it in graph.py.
This will enable the expansion of the types of graph commands
supported in future patches, by using an oslo.config subparsers it
will make expanding the subunit2sql-graph command a bit simpler.

Change-Id: I0de9aedae5447690b5433842799758d406b9b6ec
This commit is contained in:
Matthew Treinish 2015-04-21 18:36:11 -04:00
parent 2ad66e54d0
commit 7585906bda
No known key found for this signature in database
GPG Key ID: FD12A0F214C9E177
3 changed files with 80 additions and 43 deletions

View File

@ -28,7 +28,7 @@ console_scripts =
subunit2sql = subunit2sql.shell:main
sql2subunit = subunit2sql.write_subunit:main
subunit2sql-db-manage = subunit2sql.migrations.cli:main
subunit2sql-graph = subunit2sql.analysis.run_time:main
subunit2sql-graph = subunit2sql.analysis.graph:main
oslo.config.opts =
subunit2sql.shell = subunit2sql.shell:list_opts
subunit2sql.write_subunit = subunit2sql.write_subunit:list_opts

73
subunit2sql/analysis/graph.py Executable file
View File

@ -0,0 +1,73 @@
#!/bin/env python2
# Copyright 2015 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import sys
from oslo_config import cfg
import subunit2sql.analysis.run_time
from subunit2sql import shell
CONF = cfg.CONF
SHELL_OPTS = [
cfg.StrOpt('title', short='t', help='Optional title to use for the graph '
'output. If one is not specified, the '
'full test_id will be used'),
cfg.StrOpt('output', short='o', required=True,
help='Output path to write image file to. The file extension '
'will determine the file format.'),
cfg.StrOpt('start-date', short='d',
help='Start date for the graph only data from after this date '
'will be used. Uses ISO 8601 format: 1914-06-28'),
cfg.StrOpt('stop-date', short='s',
help='Stop date for the graph only data from before this date '
'will be used. Uses ISO 8601 format: 1914-06-28'),
]
def add_command_parsers(subparsers):
for name in ['run_time']:
parser = subparsers.add_parser(name)
getattr(subunit2sql.analysis, name).set_cli_opts(parser)
parser.set_defaults(
func=getattr(subunit2sql.analysis, name).generate_series)
command_opt = cfg.SubCommandOpt('command', title='graph',
help='Available graphs',
handler=add_command_parsers)
def cli_opts():
for opt in SHELL_OPTS:
CONF.register_cli_opt(opt)
CONF.register_cli_opt(command_opt)
def list_opts():
opt_list = copy.deepcopy(SHELL_OPTS)
return [('DEFAULT', opt_list)]
def main():
cli_opts()
shell.parse_args(sys.argv)
CONF.command.func()
print('Graph saved at: %s' % CONF.output)
if __name__ == "__main__":
sys.exit(main())

48
subunit2sql/analysis/run_time.py Executable file → Normal file
View File

@ -1,4 +1,3 @@
#!/bin/env python2
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -13,47 +12,22 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import sys
from oslo.config import cfg
import pandas as pd
from subunit2sql.analysis import utils
from subunit2sql.db import api
from subunit2sql import shell
CONF = cfg.CONF
SHELL_OPTS = [
cfg.StrOpt('test_id', positional=True, required=True,
help='Test id to extract time series for'),
cfg.StrOpt('title', short='t', help='Optional title to use for the graph '
'output. If one is not specified, the '
'full test_id will be used'),
cfg.StrOpt('output', short='o', required=True,
help='Output path to write image file to. The file extension '
'will determine the file format.'),
cfg.StrOpt('start-date', short='d',
help='Start date for the graph only data from after this date '
'will be used. Uses ISO8601 format: 1914-06-28'),
cfg.StrOpt('stop-date', short='s',
help='Stop date for the graph only data from before this date '
'will be used. Uses ISO8601 format: 1914-06-28'),
]
def set_cli_opts(parser):
parser.add_argument('test_id', nargs='?',
help='Test id to extract time series for')
def cli_opts():
for opt in SHELL_OPTS:
CONF.register_cli_opt(opt)
def list_opts():
opt_list = copy.deepcopy(SHELL_OPTS)
return [('DEFAULT', opt_list)]
def generate_series(test_id):
def generate_series():
test_id = CONF.command.test_id
session = api.get_session()
run_times = api.get_test_run_time_series(test_id, session)
if not CONF.title:
@ -70,13 +44,3 @@ def generate_series(test_id):
plot.set_ylabel('Time (sec.)')
fig.savefig(CONF.output)
return ts
def main():
cli_opts()
shell.parse_args(sys.argv)
generate_series(CONF.test_id)
print('Graph saved at: %s' % CONF.output)
if __name__ == "__main__":
sys.exit(main())