Use Jinja as template engine for scenarios

This commit is contained in:
Ilya Shakhat 2016-03-11 18:38:03 +03:00
parent 740d44c8ad
commit b3e489cdcb
3 changed files with 21 additions and 12 deletions

View File

@ -15,6 +15,7 @@
import os import os
import jinja2
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import yaml import yaml
@ -30,11 +31,13 @@ from performa.engine import utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
def resolve_hosts(scenario, hosts): def resolve_hosts(scenario_template, hosts):
for k, v in hosts.items(): jinja_env = jinja2.Environment()
scenario = scenario.replace('$%s' % k, ','.join(v) + ',')
return scenario compiled_template = jinja_env.from_string(scenario_template)
rendered_template = compiled_template.render(hosts)
return rendered_template
def main(): def main():

View File

@ -3,9 +3,12 @@ title: Sysbench DB
description: description:
This scenario uses sysbench to execute DB test plan. This scenario uses sysbench to execute DB test plan.
parameters:
target: List of hosts were omsimulator will be executed
setup: setup:
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- name: installing sysbench - name: installing sysbench
apt: name=sysbench apt: name=sysbench
@ -15,20 +18,20 @@ setup:
name: atop, daemon name: atop, daemon
become: yes become: yes
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- atop: command=start - atop: command=start
execution: execution:
- -
hosts: $target hosts: {{ target }}
matrix: matrix:
threads: [ 10, 20, 30, 40, 50, 60 ] threads: [ 10, 20, 30, 40, 50, 60 ]
tasks: tasks:
- sysbench_oltp: - sysbench_oltp:
duration: 10 duration: 10
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- atop: - atop:
command: stop command: stop

View File

@ -3,9 +3,12 @@ title: OMSimulator
description: description:
This scenario uses oslo.messaging simulator tool to execute MQ test plan. This scenario uses oslo.messaging simulator tool to execute MQ test plan.
parameters:
target: List of hosts were omsimulator will be executed
setup: setup:
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- apt: name=git - apt: name=git
become: yes become: yes
@ -25,11 +28,11 @@ setup:
execution: execution:
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- atop: command=start - atop: command=start
- -
hosts: $target hosts: {{ target }}
matrix: matrix:
threads: [ 1, 2, 5, 10, 25, 50, 100 ] threads: [ 1, 2, 5, 10, 25, 50, 100 ]
tasks: tasks:
@ -38,7 +41,7 @@ execution:
duration: 10 duration: 10
url: "rabbit://stackrabbit:swordfish@localhost:5672/" url: "rabbit://stackrabbit:swordfish@localhost:5672/"
- -
hosts: $target hosts: {{ target }}
tasks: tasks:
- atop: - atop:
command: stop command: stop