Parametrize scenario with variables

This commit is contained in:
Ilya Shakhat 2016-03-14 13:59:32 +03:00
parent 19e4f64fe9
commit 345a23a1f1
6 changed files with 21 additions and 20 deletions

View File

@ -1,5 +1,5 @@
usage: performa-report [-h] [--book BOOK] [--config-dir DIR]
[--config-file PATH] [--debug] [--hosts HOSTS]
[--config-file PATH] [--debug]
[--log-config-append PATH]
[--log-date-format DATE_FORMAT] [--log-dir LOG_DIR]
[--log-file PATH] [--mongo-db MONGO_DB]
@ -7,7 +7,7 @@ usage: performa-report [-h] [--book BOOK] [--config-dir DIR]
[--noverbose] [--nowatch-log-file]
[--remote-user REMOTE_USER] [--scenario SCENARIO]
[--syslog-log-facility SYSLOG_LOG_FACILITY] [--tag TAG]
[--use-syslog] [--verbose] [--version]
[--use-syslog] [--vars VARS] [--verbose] [--version]
[--watch-log-file]
optional arguments:
@ -25,8 +25,6 @@ optional arguments:
precedence. Defaults to None.
--debug, -d If set to true, the logging level will be set to DEBUG
instead of the default INFO level.
--hosts HOSTS Hosts inventory definition in YAML format, Can be
specified via env[PERFORMA_HOSTS].
--log-config-append PATH, --log_config PATH
The name of a logging configuration file. This file is
appended to any existing logging configuration files.
@ -69,6 +67,8 @@ optional arguments:
--use-syslog Use syslog for logging. Existing syslog format is
DEPRECATED and will be changed later to honor RFC5424.
This option is ignored if log_config_append is set.
--vars VARS Variables that are injected into scenario template.
Can be specified via env[PERFORMA_VARS].
--verbose, -v If set to false, the logging level will be set to
WARNING instead of the default INFO level.
--version show program's version number and exit

View File

@ -1,12 +1,13 @@
usage: performa [-h] [--book BOOK] [--config-dir DIR] [--config-file PATH]
[--debug] [--hosts HOSTS] [--log-config-append PATH]
[--debug] [--log-config-append PATH]
[--log-date-format DATE_FORMAT] [--log-dir LOG_DIR]
[--log-file PATH] [--mongo-db MONGO_DB]
[--mongo-url MONGO_URL] [--nodebug] [--nouse-syslog]
[--noverbose] [--nowatch-log-file] [--remote-user REMOTE_USER]
[--scenario SCENARIO]
[--syslog-log-facility SYSLOG_LOG_FACILITY] [--tag TAG]
[--use-syslog] [--verbose] [--version] [--watch-log-file]
[--use-syslog] [--vars VARS] [--verbose] [--version]
[--watch-log-file]
optional arguments:
-h, --help show this help message and exit
@ -23,8 +24,6 @@ optional arguments:
precedence. Defaults to None.
--debug, -d If set to true, the logging level will be set to DEBUG
instead of the default INFO level.
--hosts HOSTS Hosts inventory definition in YAML format, Can be
specified via env[PERFORMA_HOSTS].
--log-config-append PATH, --log_config PATH
The name of a logging configuration file. This file is
appended to any existing logging configuration files.
@ -67,6 +66,8 @@ optional arguments:
--use-syslog Use syslog for logging. Existing syslog format is
DEPRECATED and will be changed later to honor RFC5424.
This option is ignored if log_config_append is set.
--vars VARS Variables that are injected into scenario template.
Can be specified via env[PERFORMA_VARS].
--verbose, -v If set to false, the logging level will be set to
WARNING instead of the default INFO level.
--version show program's version number and exit

View File

@ -113,9 +113,9 @@
# (string value)
#remote_user = <None>
# Hosts inventory definition in YAML format, Can be specified via
# env[PERFORMA_HOSTS]. (string value)
#hosts = <None>
# Variables that are injected into scenario template. Can be specified via
# env[PERFORMA_VARS]. (string value)
#vars = <None>
# Generate report in ReST format and store it into the specified folder,
# defaults to env[PERFORMA_BOOK]. (string value)

View File

@ -72,12 +72,12 @@ MAIN_OPTS = [
required=True,
help='User for connecting to remote systems, '
'defaults to env[PERFORMA_REMOTE_USER].'),
cfg.Opt('hosts',
cfg.Opt('vars',
type=Yaml(),
default=utils.env('PERFORMA_HOSTS'),
default=utils.env('PERFORMA_VARS'),
required=True,
help='Hosts inventory definition in YAML format, '
'Can be specified via env[PERFORMA_HOSTS].'),
help='Variables that are injected into scenario template. '
'Can be specified via env[PERFORMA_VARS].'),
cfg.StrOpt('book',
default=utils.env('PERFORMA_BOOK'),
help='Generate report in ReST format and store it into the '

View File

@ -31,11 +31,11 @@ from performa.engine import utils
LOG = logging.getLogger(__name__)
def resolve_hosts(scenario_template, hosts):
def resolve_vars(scenario_template, vars):
jinja_env = jinja2.Environment()
compiled_template = jinja_env.from_string(scenario_template)
rendered_template = compiled_template.render(hosts)
rendered_template = compiled_template.render(vars)
return rendered_template
@ -48,7 +48,7 @@ def main():
alias_mapper=lambda f: config.SCENARIOS + '%s.yaml' % f)
scenario_raw = utils.read_file(scenario_file_path)
scenario_raw = resolve_hosts(scenario_raw, cfg.CONF.hosts)
scenario_raw = resolve_vars(scenario_raw, cfg.CONF.vars)
scenario = yaml.safe_load(scenario_raw)
base_dir = os.path.dirname(scenario_file_path)

View File

@ -43,13 +43,13 @@ execution:
-
hosts: {{ target }}
matrix:
host_count: [ 1, 2, 3 ]
host_count: [ 1, 2 ]
tasks:
- omsimulator:
mode: call
duration: 10
threads: 1
url: "rabbit://stackrabbit:swordfish@localhost:5672/"
url: {{ rabbit_url }}
-
hosts: {{ target }}
tasks: