Added options for CLI output management
Reasons: - When using table-based design for CLI output, the full traceback of failed test could not be shown comfortably due to long text lines - User who runs CLI does not need the full traceback about passing tests in some cases Changes: - Added option "--verbose" that tells CLI to show up test report in output (by default is False) - Added option "--no-format" that allows to print output without table markup - Moved functionality of printing results from validation plugins to CLI Implements blueprint: cli-format-output Change-Id: I919e88cb640031043fdbf5a17260e24249f6508f
This commit is contained in:
parent
0b24e8521e
commit
ca2fe0c554
|
@ -58,23 +58,31 @@ class OSTF(object):
|
|||
utils.print_dict({
|
||||
'tests': "\n".join(plugin().descriptor()['tests'])})
|
||||
|
||||
@cmd.args("--no-format", dest="no_format")
|
||||
@cmd.args("--verbose", dest="verbose")
|
||||
@cmd.args("--validation-plugin-name", dest="validation_plugin_name")
|
||||
def run_suites(self, validation_plugin_name):
|
||||
for plugin in validation_plugin.VALIDATION_PLUGINS:
|
||||
_plugin = plugin(load_tests=False)
|
||||
descriptor = _plugin.descriptor()
|
||||
if descriptor['name'] == validation_plugin_name:
|
||||
plugin().run_suites_within_cli()
|
||||
reports = plugin().run_suites_within_cli()
|
||||
utils.print_formatted(reports, CONF.no_format, CONF.verbose)
|
||||
|
||||
@cmd.args("--suite", dest="suite")
|
||||
@cmd.args("--validation-plugin-name", dest="validation_plugin_name")
|
||||
@cmd.args("--no-format", dest="no_format")
|
||||
@cmd.args("--verbose", dest="verbose")
|
||||
def run_suite(self, validation_plugin_name, suite):
|
||||
for plugin in validation_plugin.VALIDATION_PLUGINS:
|
||||
_plugin = plugin(load_tests=False)
|
||||
descriptor = _plugin.descriptor()
|
||||
if descriptor['name'] == validation_plugin_name:
|
||||
plugin().run_suite_within_cli(suite)
|
||||
reports = plugin().run_suite_within_cli(suite)
|
||||
utils.print_formatted(reports, CONF.no_format, CONF.verbose)
|
||||
|
||||
@cmd.args("--no-format", dest="no_format")
|
||||
@cmd.args("--verbose", dest="verbose")
|
||||
@cmd.args("--validation-plugin-name", dest="validation_plugin_name")
|
||||
@cmd.args("--test", dest="test")
|
||||
def run_test(self, validation_plugin_name, test):
|
||||
|
@ -82,7 +90,8 @@ class OSTF(object):
|
|||
_plugin = plugin(load_tests=False)
|
||||
descriptor = _plugin.descriptor()
|
||||
if descriptor['name'] == validation_plugin_name:
|
||||
plugin().run_test(test)
|
||||
reports = plugin().run_test(test)
|
||||
utils.print_formatted(reports, CONF.no_format, CONF.verbose)
|
||||
|
||||
|
||||
CATS = {
|
||||
|
|
|
@ -26,6 +26,11 @@ common_opts = [
|
|||
cfg.StrOpt("nose_verbosity", default="-v")
|
||||
]
|
||||
|
||||
cli_opts = [
|
||||
cfg.BoolOpt('no-format', short='F', default=False, required=False),
|
||||
cfg.BoolOpt('verbose', short='V', default=False, required=False)
|
||||
]
|
||||
|
||||
sanity_group = cfg.OptGroup("sanity", "Sanity configuration group.")
|
||||
smoke_group = cfg.OptGroup("smoke", "Smoke configuration group.")
|
||||
platform_group = cfg.OptGroup("platform",
|
||||
|
@ -104,6 +109,9 @@ CONF.register_opts(rest_opts, rest_group)
|
|||
#client opts
|
||||
CONF.register_opts(rest_client_opts)
|
||||
|
||||
# CLI opts
|
||||
CONF.register_cli_opts(cli_opts)
|
||||
|
||||
|
||||
def parse_args(argv, default_config_files=None):
|
||||
cfg.CONF(args=argv[1:],
|
||||
|
|
|
@ -30,13 +30,39 @@ def _print(pt, order):
|
|||
print(encodeutils.safe_encode(pt.get_string(sortby=order)))
|
||||
|
||||
|
||||
def print_dict(d, property="Property"):
|
||||
def print_raw(d, verbose):
|
||||
|
||||
fn_filter = (lambda key: 0) if verbose else lambda key: key == 'report'
|
||||
|
||||
for row in six.iteritems(d):
|
||||
if fn_filter(row[0]):
|
||||
continue
|
||||
|
||||
print('[%s]:\t%s' % (row[0].upper(), row[1]))
|
||||
print('')
|
||||
|
||||
|
||||
def print_dict(d, verbose, property="Property"):
|
||||
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
|
||||
pt.align = 'l'
|
||||
[pt.add_row(list(r)) for r in six.iteritems(d)]
|
||||
|
||||
fn_filter = (lambda key: 0) if verbose else lambda key: key == 'report'
|
||||
|
||||
[pt.add_row(list(r)) for r in six.iteritems(d) if not fn_filter(r[0])]
|
||||
_print(pt, property)
|
||||
|
||||
|
||||
def print_formatted(reports, raw_format, verbose):
|
||||
|
||||
if raw_format:
|
||||
fn_print = print_raw
|
||||
else:
|
||||
fn_print = print_dict
|
||||
|
||||
for report in reports:
|
||||
fn_print(report.description, verbose=verbose)
|
||||
|
||||
|
||||
def print_list(objs, fields, formatters={}, order_by=None, obj_is_dict=False,
|
||||
labels={}):
|
||||
if not labels:
|
||||
|
|
|
@ -24,7 +24,6 @@ from nose import core
|
|||
from oslo_utils import importutils
|
||||
|
||||
from cloudv_ostf_adapter.common import cfg
|
||||
from cloudv_ostf_adapter.common import utils
|
||||
from cloudv_ostf_adapter.common import object_descriptors
|
||||
from cloudv_ostf_adapter.validation_plugin import base
|
||||
from cloudv_ostf_adapter.validation_plugin.fuel_health import sanity
|
||||
|
@ -141,14 +140,10 @@ class FuelHealthPlugin(base.ValidationPlugin):
|
|||
return reports
|
||||
|
||||
def run_suites_within_cli(self):
|
||||
reports = self.run_suites()
|
||||
for report in reports:
|
||||
utils.print_dict(report.description)
|
||||
return self.run_suites()
|
||||
|
||||
def run_suite_within_cli(self, suite):
|
||||
reports = self.run_suite(suite)
|
||||
for report in reports:
|
||||
utils.print_dict(report.description)
|
||||
return self.run_suite(suite)
|
||||
|
||||
def run_test(self, test):
|
||||
safe_stderr = sys.stderr
|
||||
|
@ -162,6 +157,4 @@ class FuelHealthPlugin(base.ValidationPlugin):
|
|||
return reports
|
||||
|
||||
def run_test_within_cli(self, test):
|
||||
reports = self.run_test(test)
|
||||
for report in reports:
|
||||
utils.print_dict(report.description)
|
||||
return self.run_test(test)
|
||||
|
|
Loading…
Reference in New Issue