Set fetch_cluster flag to False when _inner_load_cluster called

Set the same flag to True if the cluster does not yet exists in
ZooKeeper
This commit is contained in:
Alexander Kukushkin
2015-10-07 16:48:39 +02:00
parent d48f8384ed
commit 8a844285ff
2 changed files with 6 additions and 1 deletions
+3
View File
@@ -132,8 +132,11 @@ class ZooKeeper(AbstractDCS):
return members
def _inner_load_cluster(self):
self.fetch_cluster = False
self.event.clear()
nodes = set(self.get_children(self.client_path(''), self.cluster_watcher))
if not nodes:
self.fetch_cluster = True
# get initialize flag
initialize = self._INITIALIZE in nodes
+3 -1
View File
@@ -46,7 +46,7 @@ class MockKazooClient(Mock):
def get_children(self, path, watch=None, include_data=False):
if not isinstance(path, six.string_types):
raise TypeError("Invalid type for 'path' (string expected)")
if path == '/no_node':
if path.startswith('/no_node'):
raise NoNodeError
elif path in ['/service/bla/', '/service/test/']:
return ['initialize', 'leader', 'members', 'optime', 'failover']
@@ -121,6 +121,8 @@ class TestZooKeeper(unittest.TestCase):
def test__inner_load_cluster(self):
self.zk._base_path = self.zk._base_path.replace('test', 'bla')
self.zk._inner_load_cluster()
self.zk._base_path = self.zk._base_path = '/no_node'
self.zk._inner_load_cluster()
def test_get_cluster(self):
self.assertRaises(ZooKeeperError, self.zk.get_cluster)