From: Zack Cerza Date: Fri, 22 Aug 2014 16:18:36 +0000 (-0600) Subject: Add unlock_many() and use it when possible X-Git-Tag: 1.1.0~1225 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4eda1d327331e4fbac9445c2ccd206135fc7ca6b;p=teuthology.git Add unlock_many() and use it when possible Signed-off-by: Zack Cerza --- diff --git a/teuthology/lock.py b/teuthology/lock.py index 6a820d21b3..1d49d54713 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -21,6 +21,8 @@ log = logging.getLogger(__name__) logging.getLogger("requests.packages.urllib3.connectionpool").setLevel( logging.WARNING) +is_vpm = lambda name: 'vpm' in name + def main(ctx): if ctx.verbose: @@ -153,6 +155,10 @@ def main(ctx): machines_to_update.append(machine) provision.create_if_vm(ctx, machine) elif ctx.unlock: + # If none of them are vpm, do them all in one shot + if not filter(is_vpm, machines): + res = unlock_many(machines, user) + return 0 if res else 1 for machine in machines: if not unlock_one(ctx, machine, user): ret = 1 @@ -266,6 +272,24 @@ def lock_one(name, user=None, description=None): return response +def unlock_many(names, user): + uri = os.path.join(config.lock_server, 'nodes', 'unlock_many', '') + data = dict( + locked_by=user, + names=names, + ) + response = requests.post( + uri, + data=json.dumps(data), + headers={'content-type': 'application/json'}, + ) + if response.ok: + log.debug("Unlocked: %s", ', '.join(names)) + else: + log.error("Failed to unlock: %s", ', '.join(names)) + return response.ok + + def unlock_one(ctx, name, user=None): if user is None: user = misc.get_user()