def setUp(self): self.zk = ZooKeeper( 'foo', { 'exhibitor': { 'hosts': ['localhost', 'exhibitor'], 'port': 8181 }, 'scope': 'test' })
def get_dcs(name, config): if 'etcd' in config: return Etcd(name, config['etcd']) if 'zookeeper' in config: return ZooKeeper(name, config['zookeeper']) raise Exception( 'Can not find suitable configuration of distributed configuration store' )
def get_dcs(name, config): if 'etcd' in config: from patroni.etcd import Etcd return Etcd(name, config['etcd']) if 'zookeeper' in config: from patroni.zookeeper import ZooKeeper return ZooKeeper(name, config['zookeeper']) if 'consul' in config: from patroni.consul import Consul return Consul(name, config['consul']) raise PatroniException( 'Can not find suitable configuration of distributed configuration store' )
def setUp(self): self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'})
class TestZooKeeper(unittest.TestCase): @patch('requests.get', requests_get) @patch('patroni.zookeeper.KazooClient', MockKazooClient) def setUp(self): self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'}) def test_session_listener(self): self.zk.session_listener(KazooState.SUSPENDED) def test_get_node(self): self.assertIsNone(self.zk.get_node('/no_node')) def test_get_children(self): self.assertListEqual(self.zk.get_children('/no_node'), []) 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) self.zk.exhibitor.poll = lambda: True cluster = self.zk.get_cluster() self.assertIsInstance(cluster.leader, Leader) self.zk.touch_member('foo') self.zk.delete_leader() def test_set_failover_value(self): self.zk.set_failover_value('') self.zk.set_failover_value('ok') self.zk.set_failover_value('Exception') def test_initialize(self): self.assertFalse(self.zk.initialize()) def test_cancel_initialization(self): self.zk.cancel_initialization() def test_touch_member(self): self.zk._name = 'buzz' self.zk.get_cluster() self.zk.touch_member('new') self.zk._name = 'bar' self.zk.touch_member('new') self.zk._name = 'na' self.zk._client.exists = 1 self.zk.touch_member('exists') self.zk._name = 'bar' self.zk.touch_member('retry') self.zk._fetch_cluster = True self.zk.get_cluster() self.zk.touch_member('retry') def test_take_leader(self): self.zk.take_leader() with patch.object(MockKazooClient, 'create', Mock(side_effect=Exception)): self.zk.take_leader() def test_update_leader(self): self.assertTrue(self.zk.update_leader()) def test_write_leader_optime(self): self.zk.last_leader_operation = '0' self.zk.write_leader_optime('1') self.zk._base_path = self.zk._base_path.replace('test', 'bla') self.zk.write_leader_optime('2') def test_delete_cluster(self): self.assertTrue(self.zk.delete_cluster()) def test_watch(self): self.zk.watch(0) self.zk.event.isSet = lambda: True self.zk.watch(0)
def set_up(self): requests.get = requests_get patroni.zookeeper.KazooClient = MockKazooClient self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'})
class TestZooKeeper(unittest.TestCase): def __init__(self, method_name='runTest'): self.setUp = self.set_up super(TestZooKeeper, self).__init__(method_name) def set_up(self): requests.get = requests_get patroni.zookeeper.KazooClient = MockKazooClient self.zk = ZooKeeper('foo', {'exhibitor': {'hosts': ['localhost', 'exhibitor'], 'port': 8181}, 'scope': 'test'}) def test_session_listener(self): self.zk.session_listener(KazooState.SUSPENDED) def test_get_node(self): self.assertIsNone(self.zk.get_node('/no_node')) def test_get_children(self): self.assertListEqual(self.zk.get_children('/no_node'), []) def test__inner_load_cluster(self): self.zk._base_path = self.zk._base_path.replace('test', 'bla') self.zk._inner_load_cluster() def test_get_cluster(self): self.assertRaises(ZooKeeperError, self.zk.get_cluster) self.zk.exhibitor.poll = lambda: True cluster = self.zk.get_cluster() self.assertIsInstance(cluster.leader, Leader) self.zk.touch_member('foo') self.zk.delete_leader() def test_initialize(self): self.assertFalse(self.zk.initialize()) def test_cancel_initialization(self): self.zk.cancel_initialization() def test_touch_member(self): self.zk.touch_member('new') self.zk.touch_member('exists') self.zk.touch_member('retry') def test_take_leader(self): self.zk.take_leader() def test_update_leader(self): self.zk.last_leader_operation = -1 self.assertTrue(self.zk.update_leader(MockPostgresql())) self.zk._base_path = self.zk._base_path.replace('test', 'bla') self.zk.last_leader_operation = -1 self.assertTrue(self.zk.update_leader(MockPostgresql())) def test_watch(self): self.zk.watch(0) self.zk.cluster_event.isSet = lambda: False self.zk.watch(0)