From f98f45447ed63d9bd3446e86a91b731ebf45945e Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 2 Feb 2014 10:04:34 -0800 Subject: [PATCH] Add a validate method to dir and memory backends In order to allow all connections to be validated post-creation add a new method onto the memory backend (a no-op) and add a new method onto the dir backend (which checks directory existence) and raise appropriate errors when validation fails. Change-Id: Ie476d0c33a970e543ffba21ee8b669ac02258923 --- taskflow/persistence/backends/impl_dir.py | 13 +++++++++++++ taskflow/persistence/backends/impl_memory.py | 3 +++ 2 files changed, 16 insertions(+) diff --git a/taskflow/persistence/backends/impl_dir.py b/taskflow/persistence/backends/impl_dir.py index 7c934435..5f627972 100644 --- a/taskflow/persistence/backends/impl_dir.py +++ b/taskflow/persistence/backends/impl_dir.py @@ -95,6 +95,19 @@ class Connection(base.Connection): # to restrict the multi-process access does not work inside a process. self._lock = backend._lock + def validate(self): + # Verify key paths exist. + paths = [ + self._backend.base_path, + self._backend.lock_path, + self._flow_path, + self._task_path, + self._book_path, + ] + for p in paths: + if not os.path.isdir(p): + raise RuntimeError("Missing required directory: %s" % (p)) + def _read_from(self, filename): # This is very similar to the oslo-incubator fileutils module, but # tweaked to not depend on a global cache, as well as tweaked to not diff --git a/taskflow/persistence/backends/impl_memory.py b/taskflow/persistence/backends/impl_memory.py index 5208e7f7..db9ba97f 100644 --- a/taskflow/persistence/backends/impl_memory.py +++ b/taskflow/persistence/backends/impl_memory.py @@ -78,6 +78,9 @@ class Connection(base.Connection): def upgrade(self): pass + def validate(self): + pass + @property def backend(self): return self._backend