Use start status of coodinator in tooz
CoordinationDriver of tooz has maintained the status about coordinator started or not. we don't need to re-define a _started in ceilometer. Depends-on: I1a177cf3efd63593667751c6b53bcc536fb0670f Change-Id: I8487275b419e355548ef9df6e7c8515f569f83bd
This commit is contained in:
parent
0d39daa881
commit
a91f30b826
@ -63,7 +63,6 @@ class PartitionCoordinator(object):
|
||||
self._coordinator = None
|
||||
self._groups = set()
|
||||
self._my_id = my_id or str(uuid.uuid4())
|
||||
self._started = False
|
||||
|
||||
def start(self):
|
||||
backend_url = cfg.CONF.coordination.backend_url
|
||||
@ -72,10 +71,8 @@ class PartitionCoordinator(object):
|
||||
self._coordinator = tooz.coordination.get_coordinator(
|
||||
backend_url, self._my_id)
|
||||
self._coordinator.start()
|
||||
self._started = True
|
||||
LOG.info(_LI('Coordination backend started successfully.'))
|
||||
except tooz.coordination.ToozError:
|
||||
self._started = False
|
||||
LOG.exception(_LE('Error connecting to coordination backend.'))
|
||||
|
||||
def stop(self):
|
||||
@ -91,14 +88,13 @@ class PartitionCoordinator(object):
|
||||
LOG.exception(_LE('Error connecting to coordination backend.'))
|
||||
finally:
|
||||
self._coordinator = None
|
||||
self._started = False
|
||||
|
||||
def is_active(self):
|
||||
return self._coordinator is not None
|
||||
|
||||
def heartbeat(self):
|
||||
if self._coordinator:
|
||||
if not self._started:
|
||||
if not self._coordinator.is_started:
|
||||
# re-connect
|
||||
self.start()
|
||||
try:
|
||||
@ -117,7 +113,8 @@ class PartitionCoordinator(object):
|
||||
self._coordinator.run_watchers()
|
||||
|
||||
def join_group(self, group_id):
|
||||
if not self._coordinator or not self._started or not group_id:
|
||||
if (not self._coordinator or not self._coordinator.is_started
|
||||
or not group_id):
|
||||
return
|
||||
while True:
|
||||
try:
|
||||
|
@ -28,9 +28,10 @@ class MockToozCoordinator(object):
|
||||
def __init__(self, member_id, shared_storage):
|
||||
self._member_id = member_id
|
||||
self._groups = shared_storage
|
||||
self.is_started = False
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
self.is_started = True
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
@ -230,7 +231,7 @@ class TestPartitioning(base.BaseTestCase):
|
||||
|
||||
def test_group_id_none(self):
|
||||
coord = self._get_new_started_coordinator({}, 'a')
|
||||
self.assertTrue(coord._started)
|
||||
self.assertTrue(coord._coordinator.is_started)
|
||||
|
||||
with mock.patch.object(coord._coordinator, 'join_group') as mocked:
|
||||
coord.join_group(None)
|
||||
@ -241,9 +242,8 @@ class TestPartitioning(base.BaseTestCase):
|
||||
|
||||
def test_stop(self):
|
||||
coord = self._get_new_started_coordinator({}, 'a')
|
||||
self.assertTrue(coord._started)
|
||||
self.assertTrue(coord._coordinator.is_started)
|
||||
coord.join_group("123")
|
||||
coord.stop()
|
||||
self.assertIsEmpty(coord._groups)
|
||||
self.assertFalse(coord._started)
|
||||
self.assertIsNone(coord._coordinator)
|
||||
|
Loading…
Reference in New Issue
Block a user