From 40c1ee044231a21660a54d468ee1a6ad46bd99b8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Tue, 19 Aug 2014 14:43:01 -0600 Subject: [PATCH] Optimize some list_locks() calls Signed-off-by: Zack Cerza --- teuthology/lock.py | 6 +++++- teuthology/suite.py | 13 ++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/teuthology/lock.py b/teuthology/lock.py index d8ac78f013..a13609dab0 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 b32fc2a59b..84d1f37555 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): -- 2.39.5