Remove magic HOLDOFF number in resource_locking.py 64/91464/1
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 7 Oct 2016 15:26:24 +0000 (17:26 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 7 Oct 2016 15:29:30 +0000 (17:29 +0200)
Change-Id: I56cf4cadb695bc12b5494f4fab404ab8905af733
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tct/resource_locking.py

index 5183411..7c94e30 100755 (executable)
@@ -111,9 +111,10 @@ class UUIDlist(object):
         return ret
 
 class UUIDmanager:
-    def __init__(self, target, inc):
+    def __init__(self, target, inc, holdoff):
         self.target = target
         self.inc = inc
+        self.holdoff = holdoff
 
     def lock(self):
         # go through the list of not locked uuid files and stop on the first successfully locked
@@ -147,13 +148,13 @@ class UUIDmanager:
         return Lockfile.unlock(UUID_DIR + UUID_PREFIX + self.target) == 0
 
     def retrylock(self):
-        # try to lock a target every 60s
+        # try to lock a target every self.holdoff seconds
         # returns False if there are no available targets
         # True otherwise
         while not self.lock():
             if self.target_list_is_empty():
                 return False
-            time.sleep(60)
+            time.sleep(self.holdoff)
         return True
 
     def unlockfailed(self):
@@ -177,7 +178,11 @@ def parse_arguments():
 
     group.add_argument("-r", "--retrylock",
             action="store_true", default=False, dest="retrylock",
-            help="Try to lock a device until successful")
+            help="Try to lock a device every HOLDOFF seconds until successful")
+
+    parser.add_argument("--holdoff", type=int,
+            action="store", default=60, dest="holdoff",
+            help="Set HOLDOFF value (default: 60)")
 
     group.add_argument("-u", "--unlock",
             action="store_true", default=False, dest="unlock",
@@ -207,7 +212,7 @@ def main():
             raise ValueError('Invalid log level: %s' % args.loglevel)
         logging.basicConfig(format='%(asctime)s %(message)s',level=numeric_level)
     logging.debug("Begin")
-    uuid_man = UUIDmanager(args.target, args.inc)
+    uuid_man = UUIDmanager(args.target, args.inc, args.holdoff)
     if args.lock:
         if not uuid_man.lock():
             logging.warn("File locking unsuccessful!")