Browse Source

Use Jinja as template engine for scenarios

Ilya Shakhat 3 years ago
parent
commit
b3e489cdcb

+ 7
- 4
performa/engine/main.py View File

@@ -15,6 +15,7 @@
15 15
 
16 16
 import os
17 17
 
18
+import jinja2
18 19
 from oslo_config import cfg
19 20
 from oslo_log import log as logging
20 21
 import yaml
@@ -30,11 +31,13 @@ from performa.engine import utils
30 31
 LOG = logging.getLogger(__name__)
31 32
 
32 33
 
33
-def resolve_hosts(scenario, hosts):
34
-    for k, v in hosts.items():
35
-        scenario = scenario.replace('$%s' % k, ','.join(v) + ',')
34
+def resolve_hosts(scenario_template, hosts):
35
+    jinja_env = jinja2.Environment()
36 36
 
37
-    return scenario
37
+    compiled_template = jinja_env.from_string(scenario_template)
38
+    rendered_template = compiled_template.render(hosts)
39
+
40
+    return rendered_template
38 41
 
39 42
 
40 43
 def main():

+ 7
- 4
performa/scenarios/db/sysbench.yaml View File

@@ -3,9 +3,12 @@ title: Sysbench DB
3 3
 description:
4 4
   This scenario uses sysbench to execute DB test plan.
5 5
 
6
+parameters:
7
+  target: List of hosts were omsimulator will be executed
8
+
6 9
 setup:
7 10
   -
8
-    hosts: $target
11
+    hosts: {{ target }}
9 12
     tasks:
10 13
     - name: installing sysbench
11 14
       apt: name=sysbench
@@ -15,20 +18,20 @@ setup:
15 18
         name: atop, daemon
16 19
       become: yes
17 20
   -
18
-    hosts: $target
21
+    hosts: {{ target }}
19 22
     tasks:
20 23
     - atop: command=start
21 24
 
22 25
 execution:
23 26
   -
24
-    hosts: $target
27
+    hosts: {{ target }}
25 28
     matrix:
26 29
       threads: [ 10, 20, 30, 40, 50, 60 ]
27 30
     tasks:
28 31
     - sysbench_oltp:
29 32
         duration: 10
30 33
   -
31
-    hosts: $target
34
+    hosts: {{ target }}
32 35
     tasks:
33 36
     - atop:
34 37
         command: stop

+ 7
- 4
performa/scenarios/mq/omsimulator.yaml View File

@@ -3,9 +3,12 @@ title: OMSimulator
3 3
 description:
4 4
   This scenario uses oslo.messaging simulator tool to execute MQ test plan.
5 5
 
6
+parameters:
7
+  target: List of hosts were omsimulator will be executed
8
+
6 9
 setup:
7 10
   -
8
-    hosts: $target
11
+    hosts: {{ target }}
9 12
     tasks:
10 13
     - apt: name=git
11 14
       become: yes
@@ -25,11 +28,11 @@ setup:
25 28
 
26 29
 execution:
27 30
   -
28
-    hosts: $target
31
+    hosts: {{ target }}
29 32
     tasks:
30 33
     - atop: command=start
31 34
   -
32
-    hosts: $target
35
+    hosts: {{ target }}
33 36
     matrix:
34 37
       threads: [ 1, 2, 5, 10, 25, 50, 100 ]
35 38
     tasks:
@@ -38,7 +41,7 @@ execution:
38 41
         duration: 10
39 42
         url: "rabbit://stackrabbit:swordfish@localhost:5672/"
40 43
   -
41
-    hosts: $target
44
+    hosts: {{ target }}
42 45
     tasks:
43 46
     - atop:
44 47
         command: stop

Loading…
Cancel
Save