Browse Source

Parametrize scenario with variables

Ilya Shakhat 3 years ago
parent
commit
345a23a1f1

+ 4
- 4
doc/source/tools/performa-report.txt View File

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

+ 5
- 4
doc/source/tools/performa.txt View File

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

+ 3
- 3
etc/performa.conf View File

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

+ 4
- 4
performa/engine/config.py View File

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

+ 3
- 3
performa/engine/main.py View File

@@ -31,11 +31,11 @@ from performa.engine import utils
31 31
 LOG = logging.getLogger(__name__)
32 32
 
33 33
 
34
-def resolve_hosts(scenario_template, hosts):
34
+def resolve_vars(scenario_template, vars):
35 35
     jinja_env = jinja2.Environment()
36 36
 
37 37
     compiled_template = jinja_env.from_string(scenario_template)
38
-    rendered_template = compiled_template.render(hosts)
38
+    rendered_template = compiled_template.render(vars)
39 39
 
40 40
     return rendered_template
41 41
 
@@ -48,7 +48,7 @@ def main():
48 48
         alias_mapper=lambda f: config.SCENARIOS + '%s.yaml' % f)
49 49
 
50 50
     scenario_raw = utils.read_file(scenario_file_path)
51
-    scenario_raw = resolve_hosts(scenario_raw, cfg.CONF.hosts)
51
+    scenario_raw = resolve_vars(scenario_raw, cfg.CONF.vars)
52 52
     scenario = yaml.safe_load(scenario_raw)
53 53
 
54 54
     base_dir = os.path.dirname(scenario_file_path)

+ 2
- 2
performa/scenarios/mq/omsimulator.yaml View File

@@ -43,13 +43,13 @@ execution:
43 43
   -
44 44
     hosts: {{ target }}
45 45
     matrix:
46
-      host_count: [ 1, 2, 3 ]
46
+      host_count: [ 1, 2 ]
47 47
     tasks:
48 48
     - omsimulator:
49 49
         mode: call
50 50
         duration: 10
51 51
         threads: 1
52
-        url: "rabbit://stackrabbit:swordfish@localhost:5672/"
52
+        url: {{ rabbit_url }}
53 53
   -
54 54
     hosts: {{ target }}
55 55
     tasks:

Loading…
Cancel
Save