]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
lock: locked_since_seconds converts locked_since
authorLoic Dachary <ldachary@redhat.com>
Fri, 27 Nov 2015 20:39:43 +0000 (21:39 +0100)
committerLoic Dachary <ldachary@redhat.com>
Tue, 1 Dec 2015 11:19:23 +0000 (12:19 +0100)
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 <loic@dachary.org>
teuthology/lock.py
teuthology/test/test_lock.py [new file with mode: 0644]

index 688849c30294a0174138a69c24bb556030e800b3..7eddd2cd3fb2c84d3740add8cb1f8d6df05c2f98 100644 (file)
@@ -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 (file)
index 0000000..9dd9e44
--- /dev/null
@@ -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