From: Zack Cerza Date: Tue, 19 Aug 2014 20:43:01 +0000 (-0600) Subject: Optimize some list_locks() calls X-Git-Tag: 1.1.0~1228 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=40c1ee044231a21660a54d468ee1a6ad46bd99b8;p=teuthology.git Optimize some list_locks() calls Signed-off-by: Zack Cerza --- diff --git a/teuthology/lock.py b/teuthology/lock.py index d8ac78f01..a13609dab 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -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 diff --git a/teuthology/suite.py b/teuthology/suite.py index b32fc2a59..84d1f3755 100644 --- a/teuthology/suite.py +++ b/teuthology/suite.py @@ -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):