]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Optimize some list_locks() calls
authorZack Cerza <zack.cerza@inktank.com>
Tue, 19 Aug 2014 20:43:01 +0000 (14:43 -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
teuthology/suite.py

index d8ac78f01334b127efd0fb303dd07cf17c1a564d..a13609dab05c7640c9206627a4f93797355a66ea 100644 (file)
@@ -399,7 +399,11 @@ def push_new_keys(keys_dict, reference):
 
 def do_summary(ctx):
     lockd = collections.defaultdict(lambda: [0, 0, 'unknown'])
-    for l in list_locks(machine_type=ctx.machine_type):
+    if ctx.machine_type:
+        locks = list_locks(machine_type=ctx.machine_type)
+    else:
+        locks = list_locks()
+    for l in locks:
         who = l['locked_by'] if l['locked'] == 1 \
             else '(free)', l['machine_type']
         lockd[who][0] += 1
index b32fc2a59b0dc21028f86a98116411108dc1ccdf..84d1f375554f9d73788a0917aec7ab321aa62298 100644 (file)
@@ -611,16 +611,15 @@ def build_matrix(path):
 def get_arch(machine_type):
     """
     Based on a given machine_type, return its architecture by querying the lock
-    server. Sound expensive? It is!
+    server.
 
     :returns: A string or None
     """
-    locks = lock.list_locks()
-    for machine in locks:
-        if machine['type'] == machine_type:
-            arch = machine['arch']
-            return arch
-    return None
+    result = lock.list_locks(machine_type=machine_type, count=1)
+    if not result:
+        log.warn("No machines found with machine_type %s!", machine_type)
+    else:
+        return result[0]['arch']
 
 
 class Placeholder(object):