Merge "Fix traces left in zookeeper"
This commit is contained in:
@@ -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:'}
|
||||
|
||||
Reference in New Issue
Block a user