From: Loic Dachary Date: Fri, 27 Nov 2015 20:39:43 +0000 (+0100) Subject: lock: locked_since_seconds converts locked_since X-Git-Tag: 1.1.0~738^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4ad59b352a23db64983a7ed5c206f3d65f61bfea;p=teuthology.git lock: locked_since_seconds converts locked_since The node locked_since property is converted by locked_since_seconds into the number of seconds since the present time, which is convenient to compare with configured delays. Signed-off-by: Loic Dachary --- diff --git a/teuthology/lock.py b/teuthology/lock.py index 688849c302..7eddd2cd3f 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -1,4 +1,5 @@ import argparse +import datetime import json import logging import subprocess @@ -535,6 +536,11 @@ def unlock_one(ctx, name, user, description=None): node=name, reason=reason)) return success +def locked_since_seconds(node): + now = datetime.datetime.now() + since = datetime.datetime.strptime( + node['locked_since'], '%Y-%m-%d %H:%M:%S.%f') + return (now - since).total_seconds() def list_locks(keyed_by_name=False, **kwargs): uri = os.path.join(config.lock_server, 'nodes', '') diff --git a/teuthology/test/test_lock.py b/teuthology/test/test_lock.py new file mode 100644 index 0000000000..9dd9e442f3 --- /dev/null +++ b/teuthology/test/test_lock.py @@ -0,0 +1,8 @@ +from teuthology import lock + + +class TestLock(object): + + def test_locked_since_seconds(self): + node = { "locked_since": "2013-02-07 19:33:55.000000" } + assert lock.locked_since_seconds(node) > 3600