From 10c95a23e4ff11cf1871bbb56a66b986a706878a Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Tue, 1 Sep 2015 09:59:37 +0200 Subject: [PATCH] Rename sleep to watch in a AbstractDCS This method suppose to watch for changes of leader key if current node is not leader and also it could watch for changes in a members list if current conde is the leader. --- helpers/dcs.py | 2 +- helpers/etcd.py | 4 ++-- helpers/zookeeper.py | 2 +- tests/test_etcd.py | 12 ++++++------ tests/test_zookeeper.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/helpers/dcs.py b/helpers/dcs.py index f5984fd9..63515e81 100644 --- a/helpers/dcs.py +++ b/helpers/dcs.py @@ -153,5 +153,5 @@ class AbstractDCS: """Voluntarily remove leader key from DCS This method should remove leader key if current instance is the leader""" - def sleep(self, timeout): + def watch(self, timeout): sleep(timeout) diff --git a/helpers/etcd.py b/helpers/etcd.py index ac83fce8..6bea59e7 100644 --- a/helpers/etcd.py +++ b/helpers/etcd.py @@ -224,7 +224,7 @@ class Etcd(AbstractDCS): def delete_leader(self): return self.client.delete(self.client_path('/leader'), prevValue=self._name) - def sleep(self, timeout): + def watch(self, timeout): # watch on leader key changes if it is defined and current node is not lock owner if self.cluster and self.cluster.leader and self.cluster.leader.member.name != self._name: end_time = time.time() + timeout @@ -244,4 +244,4 @@ class Etcd(AbstractDCS): timeout = end_time - time.time() - timeout > 0 and super(Etcd, self).sleep(timeout) + timeout > 0 and super(Etcd, self).watch(timeout) diff --git a/helpers/zookeeper.py b/helpers/zookeeper.py index 56e755a0..bf8b281a 100644 --- a/helpers/zookeeper.py +++ b/helpers/zookeeper.py @@ -220,7 +220,7 @@ class ZooKeeper(AbstractDCS): if isinstance(self.leader, Leader) and self.leader.member.name == self._name: self.client.delete(self.client_path('/leader')) - def sleep(self, timeout): + def watch(self, timeout): self.cluster_event.wait(timeout) if self.cluster_event.isSet(): self.fetch_cluster = True diff --git a/tests/test_etcd.py b/tests/test_etcd.py index 8de4ca46..6754a68a 100644 --- a/tests/test_etcd.py +++ b/tests/test_etcd.py @@ -253,11 +253,11 @@ class TestEtcd(unittest.TestCase): self.etcd.client.delete = etcd_delete self.assertFalse(self.etcd.delete_leader()) - def test_sleep(self): + def test_watch(self): self.etcd.client.watch = etcd_watch - self.etcd.sleep(100) + self.etcd.watch(100) self.etcd.get_cluster() - self.etcd.sleep(1) - self.etcd.sleep(5) - self.etcd.sleep(10) - self.etcd.sleep(100) + self.etcd.watch(1) + self.etcd.watch(5) + self.etcd.watch(10) + self.etcd.watch(100) diff --git a/tests/test_zookeeper.py b/tests/test_zookeeper.py index 54adea5e..01100c4e 100644 --- a/tests/test_zookeeper.py +++ b/tests/test_zookeeper.py @@ -164,5 +164,5 @@ class TestZooKeeper(unittest.TestCase): self.zk.last_leader_operation = -1 self.assertTrue(self.zk.update_leader(MockPostgresql())) - def test_sleep(self): - self.zk.sleep(0) + def test_watch(self): + self.zk.watch(0)