Browse Source

Merge "Run Validations with ThreadPoolExecutor" into stable/stein

tags/11.5.1
Zuul 2 months ago
parent
commit
4d0c4ab51c
4 changed files with 47 additions and 9 deletions
  1. 2
    1
      doc/requirements.txt
  2. 1
    0
      lower-constraints.txt
  3. 1
    0
      requirements.txt
  4. 43
    8
      tripleoclient/v1/tripleo_validator.py

+ 2
- 1
doc/requirements.txt View File

@@ -1,6 +1,7 @@
1 1
 # The order of packages is significant, because pip processes them in the order
2 2
 # of appearance. Changing the order has an impact on the overall integration
3 3
 # process, which may cause wedges in the gate later.
4
-sphinx!=1.6.6,!=1.6.7,>=1.6.2 # BSD
4
+sphinx>=1.6.2,!=1.6.6,!=1.6.7,<2.0.0;python_version=='2.7'  # BSD
5
+sphinx>=1.6.2,!=1.6.6,!=1.6.7;python_version>='3.4'  # BSD
5 6
 openstackdocstheme>=1.18.1 # Apache-2.0
6 7
 reno>=2.5.0 # Apache-2.0

+ 1
- 0
lower-constraints.txt View File

@@ -25,6 +25,7 @@ extras==1.0.0
25 25
 fasteners==0.7.0
26 26
 fixtures==3.0.0
27 27
 flake8==2.5.5
28
+futures==3.0.0
28 29
 futurist==1.2.0
29 30
 gitdb==0.6.4
30 31
 GitPython==1.0.1

+ 1
- 0
requirements.txt View File

@@ -18,3 +18,4 @@ osc-lib>=1.8.0 # Apache-2.0
18 18
 websocket-client>=0.44.0 # LGPLv2+
19 19
 tripleo-common>=10.6.1 # Apache-2.0
20 20
 cryptography>=2.1 # BSD/Apache-2.0
21
+futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD

+ 43
- 8
tripleoclient/v1/tripleo_validator.py View File

@@ -18,8 +18,10 @@ import json
18 18
 import logging
19 19
 import os
20 20
 import pwd
21
+import six
21 22
 import sys
22 23
 
24
+from concurrent.futures import ThreadPoolExecutor
23 25
 from osc_lib.command import command
24 26
 from osc_lib.i18n import _
25 27
 
@@ -212,6 +214,16 @@ class TripleOValidatorRun(command.Command):
212 214
             help=_("Execute the validations using Mistral")
213 215
         )
214 216
 
217
+        parser.add_argument(
218
+            '--workers', '-w',
219
+            metavar='N',
220
+            dest='workers',
221
+            default=1,
222
+            type=int,
223
+            help=_("The maximum number of threads that can "
224
+                   "be used to execute the given validations")
225
+        )
226
+
215 227
         extra_vars_group = parser.add_mutually_exclusive_group(required=False)
216 228
 
217 229
         extra_vars_group.add_argument(
@@ -302,6 +314,23 @@ class TripleOValidatorRun(command.Command):
302 314
                 out.get('validation_name'),
303 315
                 oooutils.indent(out.get('stdout'))))
304 316
 
317
+    def _run_ansible(self, logger, plan, workdir, log_path_dir, playbook,
318
+                     inventory, retries, output_callback, extra_vars,
319
+                     python_interpreter, gathering_policy):
320
+        rc, output = oooutils.run_ansible_playbook(
321
+            logger=logger,
322
+            plan=plan,
323
+            workdir=workdir,
324
+            log_path_dir=log_path_dir,
325
+            playbook=playbook,
326
+            inventory=inventory,
327
+            retries=retries,
328
+            output_callback=output_callback,
329
+            extra_vars=extra_vars,
330
+            python_interpreter=python_interpreter,
331
+            gathering_policy=gathering_policy)
332
+        return rc, output
333
+
305 334
     def _run_validator_run(self, parsed_args):
306 335
         clients = self.app.client_manager
307 336
         LOG = logging.getLogger(__name__ + ".ValidationsRunAnsible")
@@ -343,10 +372,11 @@ class TripleOValidatorRun(command.Command):
343 372
 
344 373
         failed_val = False
345 374
 
346
-        for playbook in playbooks:
347
-            try:
348
-                LOG.debug(_('Running the validations with Ansible'))
349
-                rc, output = oooutils.run_ansible_playbook(
375
+        with ThreadPoolExecutor(max_workers=parsed_args.workers) as executor:
376
+            LOG.debug(_('Running the validations with Ansible'))
377
+            tasks_exec = {
378
+                executor.submit(
379
+                    self._run_ansible,
350 380
                     logger=LOG,
351 381
                     plan=parsed_args.plan,
352 382
                     workdir=constants.ANSIBLE_VALIDATION_DIR,
@@ -357,13 +387,18 @@ class TripleOValidatorRun(command.Command):
357 387
                     output_callback='validation_output',
358 388
                     extra_vars=extra_vars_input,
359 389
                     python_interpreter=python_interpreter,
360
-                    gathering_policy='explicit')
361
-                print('[SUCCESS] - {}\n{}'.format(playbook,
362
-                                                  oooutils.indent(output)))
390
+                    gathering_policy='explicit'): playbook
391
+                for playbook in playbooks
392
+            }
393
+
394
+        for tk, pl in six.iteritems(tasks_exec):
395
+            try:
396
+                rc, output = tk.result()
397
+                print('[SUCCESS] - {}\n{}'.format(pl, oooutils.indent(output)))
363 398
             except Exception as e:
364 399
                 failed_val = True
365 400
                 LOG.error('[FAILED] - {}\n{}'.format(
366
-                    playbook, oooutils.indent(e.args[0])))
401
+                    pl, oooutils.indent(e.args[0])))
367 402
 
368 403
         LOG.debug(_('Removing static tripleo ansible inventory file'))
369 404
         oooutils.cleanup_tripleo_ansible_inventory_file(

Loading…
Cancel
Save