summaryrefslogtreecommitdiff
path: root/taskflow
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-06-16 21:25:49 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-06-27 15:29:22 -0700
commit783eeb5f0a4bf77b513563e1017742fe8ad9f077 (patch)
treee869b9ca982086e3d774bf098caf6a20749dab77 /taskflow
parentd9e970b3388349fa54609a981f998f5a656bed34 (diff)
downloadtaskflow-783eeb5f0a4bf77b513563e1017742fe8ad9f077.tar.gz
Fix traces left in zookeeper
We currently are leaving the root node in zookeeper whenever this test is ran, we should instead be removing the full directory and any children to avoid leaving test data behind in zookeeper (aka, cleanup our dirty laundry). Fixes bug 1330807 Change-Id: I56d9dabd9926463506e1710ddf0a6c4831d5dc57
Diffstat (limited to 'taskflow')
-rw-r--r--taskflow/tests/unit/persistence/test_zk_persistence.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/taskflow/tests/unit/persistence/test_zk_persistence.py b/taskflow/tests/unit/persistence/test_zk_persistence.py
index 414db09..354c2a7 100644
--- a/taskflow/tests/unit/persistence/test_zk_persistence.py
+++ b/taskflow/tests/unit/persistence/test_zk_persistence.py
@@ -16,13 +16,17 @@
import contextlib
+from kazoo import exceptions as kazoo_exceptions
import testtools
from zake import fake_client
+from taskflow import exceptions as exc
from taskflow.openstack.common import uuidutils
from taskflow.persistence import backends
from taskflow.persistence.backends import impl_zookeeper
from taskflow import test
+from taskflow.utils import kazoo_utils
+
from taskflow.tests.unit.persistence import base
from taskflow.tests import utils as test_utils
@@ -31,15 +35,27 @@ _ZOOKEEPER_AVAILABLE = test_utils.zookeeper_available(
impl_zookeeper.MIN_ZK_VERSION)
+def clean_backend(backend, conf):
+ with contextlib.closing(backend.get_connection()) as conn:
+ try:
+ conn.clear_all()
+ except exc.NotFound:
+ pass
+ client = kazoo_utils.make_client(conf)
+ client.start()
+ try:
+ client.delete(conf['path'], recursive=True)
+ except kazoo_exceptions.NoNodeError:
+ pass
+ finally:
+ kazoo_utils.finalize_client(client)
+
+
@testtools.skipIf(not _ZOOKEEPER_AVAILABLE, 'zookeeper is not available')
class ZkPersistenceTest(test.TestCase, base.PersistenceTestMixin):
def _get_connection(self):
return self.backend.get_connection()
- def _clear_all(self):
- with contextlib.closing(self._get_connection()) as conn:
- conn.clear_all()
-
def setUp(self):
super(ZkPersistenceTest, self).setUp()
conf = test_utils.ZK_TEST_CONFIG.copy()
@@ -48,13 +64,14 @@ class ZkPersistenceTest(test.TestCase, base.PersistenceTestMixin):
conf['path'] = TEST_PATH_TPL % (uuidutils.generate_uuid())
try:
self.backend = impl_zookeeper.ZkBackend(conf)
- self.addCleanup(self.backend.close)
except Exception as e:
self.skipTest("Failed creating backend created from configuration"
" %s due to %s" % (conf, e))
- with contextlib.closing(self._get_connection()) as conn:
- conn.upgrade()
- self.addCleanup(self._clear_all)
+ else:
+ self.addCleanup(self.backend.close)
+ self.addCleanup(clean_backend, self.backend, conf)
+ with contextlib.closing(self.backend.get_connection()) as conn:
+ conn.upgrade()
def test_zk_persistence_entry_point(self):
conf = {'connection': 'zookeeper:'}