From a91f30b8266dad8a5cae1d6298203fe5417594af Mon Sep 17 00:00:00 2001 From: liu-sheng Date: Tue, 14 Jul 2015 12:46:35 +0800 Subject: [PATCH] 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 --- ceilometer/coordination.py | 9 +++------ ceilometer/tests/unit/test_coordination.py | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ceilometer/coordination.py b/ceilometer/coordination.py index dc383db3..e4b98aa3 100644 --- a/ceilometer/coordination.py +++ b/ceilometer/coordination.py @@ -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: diff --git a/ceilometer/tests/unit/test_coordination.py b/ceilometer/tests/unit/test_coordination.py index 06158d63..5171d67f 100644 --- a/ceilometer/tests/unit/test_coordination.py +++ b/ceilometer/tests/unit/test_coordination.py @@ -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)