Check for UUID files in tct/resource_locking.py 65/79765/7
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 12 Jul 2016 16:17:03 +0000 (18:17 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Fri, 7 Oct 2016 15:13:09 +0000 (17:13 +0200)
Change-Id: Ib593cf3958392807d05d6c07cecb27c93024f581
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tct/resource_locking.py

index af25f7d..bb0b44b 100755 (executable)
@@ -129,6 +129,15 @@ class UUIDmanager:
         logging.info("Failed to lock")
         return False
 
+    def target_list_is_empty(self):
+        # return True if there are no files available for target (including locked)
+        # False otherwise
+        target_list = UUIDlist.target(self.target)
+        if len(target_list) == 0:
+            logging.error("Target list for \"%s\" is empty", self.target)
+            return True
+        return False
+
     def unlock(self):
         # remove lock on specified target
         # returns True if operation was successful (no lock is present)
@@ -137,9 +146,14 @@ class UUIDmanager:
         return Lockfile.unlock(UUID_DIR + UUID_PREFIX + self.target) == 0
 
     def retrylock(self):
-        # try to lock a target every 60s. finish if operation is successful
+        # try to lock a target every 60s
+        # 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)
+        return True
 
     def unlockfailed(self):
         # unlock target as usual and increase its counter by 10
@@ -196,7 +210,8 @@ def main():
         if not uuid_man.unlock():
             logging.warn("File unlocking unsuccessful!")
     elif args.retrylock:
-        uuid_man.retrylock()
+        if not uuid_man.retrylock():
+            logging.warn("Retrylock unsuccessful!")
     elif args.unlockfailed:
         uuid_man.unlockfailed()
     logging.debug("End")