Simplify selection of report template

Report template can be specified by full path or via alias.
List of available aliases can be found in the docs and CLI tools
help.

Change-Id: I22eb933d57a52b4eec24bba53b783e224a0a651b
This commit is contained in:
Ilya Shakhat
2015-06-16 17:21:47 +03:00
parent ebaf2c9d45
commit 366f92c98b
11 changed files with 32 additions and 22 deletions

View File

@@ -35,9 +35,9 @@ optional arguments:
Name of image flavor. The default is created by
shaker-image-builder.
--image-builder-template IMAGE_BUILDER_TEMPLATE
File name of Heat template that contains receipt of
building the image. Or one of predefined names from
the list: "ubuntu", "debian"
Heat template containing receipt of building the
image. Can be a file name or one of aliases: "debian",
"ubuntu". Defaults to "ubuntu".
--image-name IMAGE_NAME
Name of image to use. The default is created by
shaker-image-builder.

View File

@@ -37,9 +37,9 @@ optional arguments:
Name of image flavor. The default is created by
shaker-image-builder.
--image-builder-template IMAGE_BUILDER_TEMPLATE
File name of Heat template that contains receipt of
building the image. Or one of predefined names from
the list: "ubuntu", "debian"
Heat template containing receipt of building the
image. Can be a file name or one of aliases: "debian",
"ubuntu". Defaults to "ubuntu".
--image-name IMAGE_NAME
Name of image to use. The default is created by
shaker-image-builder.

View File

@@ -65,4 +65,6 @@ optional arguments:
instead of default WARNING level).
--version show program's version number and exit
--report-template REPORT_TEMPLATE
Report template file name
Template for report. Can be a file name or one of
aliases: "interactive", "json". Defaults to
"interactive".

View File

@@ -90,7 +90,9 @@ optional arguments:
How frequently the agent polls server, in seconds
--report REPORT Report file name, defaults to env[SHAKER_REPORT].
--report-template REPORT_TEMPLATE
Report template file name
Template for report. Can be a file name or one of
aliases: "interactive", "json". Defaults to
"interactive".
--scenario SCENARIO Scenario file name, defaults to env[SHAKER_SCENARIO].
--subunit SUBUNIT Subunit stream file name, defaults to
env[SHAKER_SUBUNIT].

View File

@@ -144,8 +144,9 @@
# Do not generate report for failed scenarios (boolean value)
#no_report_on_error = false
# Report template file name (string value)
#report_template = shaker/resources/report_template.html
# Template for report. Can be a file name or one of aliases: "interactive",
# "json". Defaults to "interactive". (string value)
#report_template = interactive
# Report file name, defaults to env[SHAKER_REPORT]. (string value)
#report = <None>
@@ -159,6 +160,6 @@
# Agent unique id, defaults to MAC of primary interface. (string value)
#agent_id = <None>
# File name of Heat template that contains receipt of building the image. Or
# one of predefined names from the list: "ubuntu", "debian" (string value)
# Heat template containing receipt of building the image. Can be a file name or
# one of aliases: "debian", "ubuntu". Defaults to "ubuntu". (string value)
#image_builder_template = ubuntu

View File

@@ -21,7 +21,8 @@ from oslo_config import types
from shaker.engine import utils
IMAGE_BUILDER_RESOURCES = 'shaker/resources/image_builder_templates/'
IMAGE_BUILDER_TEMPLATES = 'shaker/resources/image_builder_templates/'
REPORT_TEMPLATES = 'shaker/resources/report_templates/'
class Endpoint(types.String):
@@ -113,9 +114,11 @@ SERVER_OPTS = [
REPORT_OPTS = [
cfg.StrOpt('report-template',
default=(utils.env('SHAKER_REPORT_TEMPLATE') or
'shaker/resources/report_template.html'),
help='Report template file name'),
default=(utils.env('SHAKER_REPORT_TEMPLATE') or 'interactive'),
help=utils.make_help_options(
'Template for report. Can be a file name or one of '
'aliases: %s. Defaults to "interactive".',
REPORT_TEMPLATES)),
cfg.StrOpt('report',
default=utils.env('SHAKER_REPORT'),
help='Report file name, defaults to env[SHAKER_REPORT]. '),
@@ -145,9 +148,9 @@ IMAGE_BUILDER_OPTS = [
default=(utils.env('SHAKER_IMAGE_BUILDER_TEMPLATE') or
'ubuntu'),
help=utils.make_help_options(
'File name of Heat template that contains receipt of '
'building the image. Or one of predefined names from the '
'list: %s', IMAGE_BUILDER_RESOURCES)),
'Heat template containing receipt of building the image. '
'Can be a file name or one of aliases: %s. '
'Defaults to "ubuntu".', IMAGE_BUILDER_TEMPLATES)),
]

View File

@@ -67,7 +67,7 @@ def build_image():
template = None
template_filename = cfg.CONF.image_builder_template
try:
am = lambda f: config.IMAGE_BUILDER_RESOURCES + '%s.yaml' % f
am = lambda f: config.IMAGE_BUILDER_TEMPLATES + '%s.yaml' % f
template = utils.read_file(template_filename, alias_mapper=am)
except IOError:
LOG.error('Error reading template file: %s. '

View File

@@ -148,7 +148,8 @@ def generate_report(data, report_template, report_filename, subunit_filename):
jinja_env.filters['yaml'] = functools.partial(yaml.safe_dump, indent=2,
default_flow_style=False)
template = utils.read_file(report_template)
alias_mapper = lambda f: config.REPORT_TEMPLATES + '%s.html' % f
template = utils.read_file(report_template, alias_mapper=alias_mapper)
compiled_template = jinja_env.from_string(template)
rendered_template = compiled_template.render(dict(report=data))

View File

@@ -174,4 +174,4 @@ def flatten_dict(d, prefix='', sep='.'):
def make_help_options(message, base):
path = resolve_relative_path(base)
return message % ', '.join('"%s"' % os.path.basename(f).partition('.')[0]
for f in os.listdir(path))
for f in sorted(os.listdir(path)))

View File

@@ -0,0 +1 @@
[[[ report | json]]]