From d8f49316e20cd11885f2ee5cfb9ad0ac7cf336c6 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 20 Jun 2012 23:58:29 -0700 Subject: 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 --- cloudinit/helpers.py | 17 +++++++++++++---- 1 file 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: -- cgit v1.2.3