Configure zk fixture cleanup early

Generally you want to put the cleanup in place before the resource is
created. This way if you have failure in setUp then you don't leak the
resources as they should be cleaned up after early failures. Move the zk
fixture's chroot cleanup to before we create the chroot. This way if
anything fails in setting that up we should get cleaned up properly.

Also explicitly close the tmp kazoo client after stopping it as kazoo
docs say not doing this can result in leaks.

Change-Id: I6d94909b5b4836aa09528e1de744c940c2a9a12f
This commit is contained in:
Clark Boylan
2017-04-07 17:39:56 -07:00
parent 3b6bb102a1
commit 7f5f1ecd4b

View File

@@ -1068,6 +1068,8 @@ class ChrootedKazooFixture(fixtures.Fixture):
rand_test_path = '%s_%s' % (random_bits, os.getpid())
self.zookeeper_chroot = "/nodepool_test/%s" % rand_test_path
self.addCleanup(self._cleanup)
# Ensure the chroot path exists and clean up any pre-existing znodes.
_tmp_client = kazoo.client.KazooClient(
hosts='%s:%s' % (self.zookeeper_host, self.zookeeper_port))
@@ -1080,8 +1082,6 @@ class ChrootedKazooFixture(fixtures.Fixture):
_tmp_client.stop()
_tmp_client.close()
self.addCleanup(self._cleanup)
def _cleanup(self):
'''Remove the chroot path.'''
# Need a non-chroot'ed client to remove the chroot path
@@ -1090,6 +1090,7 @@ class ChrootedKazooFixture(fixtures.Fixture):
_tmp_client.start()
_tmp_client.delete(self.zookeeper_chroot, recursive=True)
_tmp_client.stop()
_tmp_client.close()
class MySQLSchemaFixture(fixtures.Fixture):