]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Reimage machines in parallel
authorZack Cerza <zack@redhat.com>
Tue, 7 Nov 2017 23:05:21 +0000 (16:05 -0700)
committerZack Cerza <zack@redhat.com>
Thu, 30 Nov 2017 19:15:42 +0000 (12:15 -0700)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/lock/cli.py
teuthology/lock/ops.py

index a3c3002a2219bc24b83aeaf2fae05b972e3101a0..4848e502ee5b23a65b97e802e46587477d56c567 100644 (file)
@@ -7,6 +7,7 @@ import re
 import yaml
 
 import teuthology
+import teuthology.parallel
 import teuthology.provision
 from teuthology import misc
 from teuthology.config import set_config_attr
@@ -144,24 +145,40 @@ def main(ctx):
         return 0
 
     elif ctx.lock:
-        if not util.vps_version_or_type_valid(ctx.machine_type, ctx.os_type,
-                                         ctx.os_version):
+        if not util.vps_version_or_type_valid(
+                ctx.machine_type, ctx.os_type, ctx.os_version):
             log.error('Invalid os-type or version detected -- lock failed')
             return 1
+        reimage_types = teuthology.provision.fog.get_types()
+        reimage_machines = list()
+        updatekeys_machines = list()
         for machine in machines:
-            if not ops.lock_one(machine, user, ctx.desc):
+            resp = ops.lock_one(machine, user, ctx.desc)
+            if resp.ok:
+                machine_status = resp.json()
+                machine_type = machine_status['machine_type']
+            if not resp.ok:
                 ret = 1
                 if not ctx.f:
                     return ret
-            elif not query.is_vm(machine):
-                teuthology.provision.reimage(ctx, machine)
-                keys.do_update_keys([machine])
+            elif not query.is_vm(machine, machine_status):
+                if machine_type in reimage_types:
+                    # Reimage in parallel just below here
+                    reimage_machines.append(machine)
+                # Update keys last
+                updatekeys_machines = list()
             else:
                 machines_to_update.append(machine)
                 teuthology.provision.create_if_vm(
                     ctx,
                     misc.canonicalize_hostname(machine),
                 )
+        with teuthology.parallel.parallel() as p:
+            for machine in reimage_machines:
+                p.spawn(teuthology.provision.reimage, ctx, machine)
+        for machine in updatekeys_machines:
+            keys.do_update_keys([machine])
+
     elif ctx.unlock:
         if ctx.owner is None and user is None:
             user = misc.get_user()
index 309ae044c9da3c41c47625754b6dd7c4c753651e..71581ef4d97b8e87e8cbf3b9fc5d76a245373fd7 100644 (file)
@@ -4,6 +4,7 @@ import os
 
 import requests
 
+import teuthology.parallel
 import teuthology.provision
 from teuthology import misc
 from teuthology.config import config
@@ -109,9 +110,10 @@ def lock_many(ctx, num, machine_type, user=None, description=None,
                 return ok_machs
             elif machine_type in reimage_types:
                 reimaged = dict()
-                for machine in machines:
-                    teuthology.provision.reimage(ctx, machine)
-                    reimaged[machine] = machines[machine]
+                with teuthology.parallel.parallel() as p:
+                    for machine in machines:
+                        p.spawn(teuthology.provision.reimage, ctx, machine)
+                        reimaged[machine] = machines[machine]
                 reimaged = keys.do_update_keys(reimaged.keys())[1]
                 return reimaged
             return machines