]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Make far less requests when simply locking
authorZack Cerza <zack.cerza@inktank.com>
Thu, 21 Aug 2014 18:51:42 +0000 (12:51 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Mon, 25 Aug 2014 17:14:38 +0000 (11:14 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/lock.py

index a13609dab05c7640c9206627a4f93797355a66ea..6a820d21b337f046fcc6db927b6a9f1a67bc624d 100644 (file)
@@ -145,7 +145,7 @@ def main(ctx):
 
     elif ctx.lock:
         for machine in machines:
-            if not lock_one(machine, user):
+            if not lock_one(machine, user, ctx.desc):
                 ret = 1
                 if not ctx.f:
                     return ret
@@ -161,7 +161,8 @@ def main(ctx):
             else:
                 machines_to_update.append(machine)
     elif ctx.num_to_lock:
-        result = lock_many(ctx, ctx.num_to_lock, ctx.machine_type, user)
+        result = lock_many(ctx, ctx.num_to_lock, ctx.machine_type, user,
+                           ctx.desc)
         if not result:
             ret = 1
         else:
@@ -195,9 +196,9 @@ def main(ctx):
         assert ctx.owner is None, 'only description and status may be updated'
         machines_to_update = machines
 
-    if ctx.desc is not None or ctx.status is not None:
-        for machine in machines_to_update:
-            update_lock(machine, ctx.desc, ctx.status)
+        if ctx.desc is not None or ctx.status is not None:
+            for machine in machines_to_update:
+                update_lock(machine, ctx.desc, ctx.status)
 
     return ret
 
@@ -208,15 +209,16 @@ def lock_many(ctx, num, machinetype, user=None, description=None):
         user = misc.get_user()
     for machinetype in machinetypes:
         uri = os.path.join(config.lock_server, 'nodes', 'lock_many', '')
+        data = dict(
+            locked_by=user,
+            count=num,
+            machine_type=machinetype,
+            description=description,
+        )
         response = requests.post(
             uri,
-            json.dumps(
-                dict(
-                    locked_by=user,
-                    count=num,
-                    machine_type=machinetype,
-                    description=description,
-                ))
+            data=json.dumps(data),
+            headers={'content-type': 'application/json'},
         )
         if response.ok:
             machines = {machine['name']: machine['ssh_pub_key']