mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
* new node can join the cluster dynamically and become a part of consensus * it is also possible to join only Patroni cluster (without adding the node to the raft), just comment or remove `raft.self_addr` for that * when the node joins the cluster it is using values from `raft.partner_addrs` only for initial discovery. * It is possible to run Patroni and Postgres on two nodes plus one node with `patroni_raft_controller` (without Patroni and Postgres). In such setup one can temporarily lose one node without affecting the primary.
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import logging
|
|
import os
|
|
import unittest
|
|
|
|
from mock import Mock, patch
|
|
from pysyncobj import SyncObj
|
|
from patroni.config import Config
|
|
from patroni.raft_controller import RaftController, main as _main
|
|
|
|
from . import SleepException
|
|
|
|
|
|
class TestPatroniRaftController(unittest.TestCase):
|
|
|
|
SELF_ADDR = '127.0.0.1:5360'
|
|
|
|
def remove_files(self):
|
|
for f in ('journal', 'dump'):
|
|
f = self.SELF_ADDR + '.' + f
|
|
if os.path.exists(f):
|
|
os.unlink(f)
|
|
|
|
@patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
|
|
def setUp(self):
|
|
self._handlers = logging.getLogger().handlers[:]
|
|
self.remove_files()
|
|
os.environ['PATRONI_RAFT_SELF_ADDR'] = self.SELF_ADDR
|
|
config = Config('postgres0.yml', validator=None)
|
|
self.rc = RaftController(config)
|
|
|
|
def tearDown(self):
|
|
logging.getLogger().handlers[:] = self._handlers
|
|
self.remove_files()
|
|
|
|
def test_reload_config(self):
|
|
self.rc.reload_config()
|
|
|
|
@patch('logging.Logger.error', Mock(side_effect=SleepException))
|
|
@patch.object(SyncObj, 'doTick', Mock(side_effect=Exception))
|
|
def test_run(self):
|
|
self.assertRaises(SleepException, self.rc.run)
|
|
self.rc.shutdown()
|
|
|
|
@patch('sys.argv', ['patroni'])
|
|
def test_patroni_raft_controller_main(self):
|
|
self.assertRaises(SystemExit, _main)
|