summaryrefslogtreecommitdiff
path: root/cloudinit/helpers.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-20 23:58:29 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-20 23:58:29 -0700
commitd8f49316e20cd11885f2ee5cfb9ad0ac7cf336c6 (patch)
tree6d88f00afc24c97cb5c22a138f1f913a79106da9 /cloudinit/helpers.py
parent85f9913e10e55bad037ea70a205c40ff169b7540 (diff)
downloadvyos-cloud-init-d8f49316e20cd11885f2ee5cfb9ad0ac7cf336c6.tar.gz
vyos-cloud-init-d8f49316e20cd11885f2ee5cfb9ad0ac7cf336c6.zip
1. Add a dummy lock object + a file lock object
2. Use this object when returning semaphores 3. Adjust the debug statement to show this object
Diffstat (limited to 'cloudinit/helpers.py')
-rw-r--r--cloudinit/helpers.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 4447d1ee..b6974f3c 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -40,13 +40,17 @@ class LockFailure(Exception):
pass
+class DummyLock(object):
+ pass
+
+
class DummySemaphores(object):
def __init__(self):
pass
@contextlib.contextmanager
def lock(self, _name, _freq, _clear_on_fail=False):
- yield True
+ yield DummyLock()
def has_run(self, _name, _freq):
return False
@@ -58,6 +62,11 @@ class DummySemaphores(object):
pass
+class FileLock(object):
+ def __init__(self, fn):
+ self.fn = fn
+
+
class FileSemaphores(object):
def __init__(self, sem_path):
self.sem_path = sem_path
@@ -101,7 +110,7 @@ class FileSemaphores(object):
except (IOError, OSError):
util.logexc(LOG, "Failed writing semaphore file %s", sem_file)
return None
- return sem_file
+ return FileLock(sem_file)
def has_run(self, name, freq):
if not freq or freq == PER_ALWAYS:
@@ -158,8 +167,8 @@ class Runners(object):
if not lk:
raise LockFailure("Failed to acquire lock for %s" % name)
else:
- LOG.debug("Running %s with args %s using lock %s (%s)",
- functor, args, util.obj_name(lk), lk)
+ LOG.debug("Running %s with args %s using lock (%s)",
+ functor, args, lk)
if isinstance(args, (dict)):
results = functor(**args)
else: