From 1135c9c7824cc4c11b26eea2084f08e0bb2f75fe Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Tue, 12 Jul 2016 18:17:03 +0200 Subject: [PATCH] Check for UUID files in tct/resource_locking.py Change-Id: Ib593cf3958392807d05d6c07cecb27c93024f581 Signed-off-by: Aleksander Mistewicz --- tct/resource_locking.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tct/resource_locking.py b/tct/resource_locking.py index af25f7d..bb0b44b 100755 --- a/tct/resource_locking.py +++ b/tct/resource_locking.py @@ -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") -- 2.7.4