summaryrefslogtreecommitdiff
path: root/tct/resource_locking.py
diff options
context:
space:
mode:
authorAleksander Mistewicz <a.mistewicz@samsung.com>2016-07-12 16:56:28 +0200
committerAleksander Mistewicz <a.mistewicz@samsung.com>2016-10-07 16:53:39 +0200
commitd292f63c6586bbf2c65456713e6c71a9c1403ce9 (patch)
treea36b8041a6c6209e65c0037b33afac96ee71ebcf /tct/resource_locking.py
parenta18f8316bd1b8b1eda6743ad848a2e384e888527 (diff)
downloadmajor-d292f63c6586bbf2c65456713e6c71a9c1403ce9.tar.gz
major-d292f63c6586bbf2c65456713e6c71a9c1403ce9.tar.bz2
major-d292f63c6586bbf2c65456713e6c71a9c1403ce9.zip
Add "--retrylock" to tct/resource_locking.py
Change-Id: I9445f87d19db642c14487c8bde11b48764f1656e Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
Diffstat (limited to 'tct/resource_locking.py')
-rwxr-xr-xtct/resource_locking.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tct/resource_locking.py b/tct/resource_locking.py
index d98d650..3bda871 100755
--- a/tct/resource_locking.py
+++ b/tct/resource_locking.py
@@ -19,6 +19,7 @@
# @author Aleksander Mistewicz <a.mistewicz@samsung.com>
import os
+import time
import subprocess
import argparse
import logging
@@ -103,6 +104,11 @@ class UUIDmanager:
logging.info("Unlocking: %s", self.target)
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
+ while not self.lock():
+ time.sleep(60)
+
def parse_arguments():
parser = argparse.ArgumentParser(description="Manager of locks on UUID files")
@@ -115,6 +121,10 @@ def parse_arguments():
action="store_true", default=False, dest="lock",
help="Lock a device")
+ group.add_argument("-r", "--retrylock",
+ action="store_true", default=False, dest="retrylock",
+ help="Try to lock a device until successful")
+
group.add_argument("-u", "--unlock",
action="store_true", default=False, dest="unlock",
help="Unlock a device")
@@ -142,6 +152,8 @@ def main():
elif args.unlock:
if not uuid_man.unlock():
logging.warn("File unlocking unsuccessful!")
+ elif args.retrylock:
+ uuid_man.retrylock()
logging.debug("End")
if __name__ == '__main__':