mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Prevent splitbrain from duplicate names in configuration (#2724)
When starting check if node with the same is registered in DCS and try to query it's REST API. If REST API is accessible exit with the error. Close #1804
This commit is contained in:
@@ -83,3 +83,7 @@ Feature: basic replication
|
||||
Then postgres0 role is the secondary after 20 seconds
|
||||
When I add the table buz to postgres1
|
||||
Then table buz is present on postgres0 after 20 seconds
|
||||
|
||||
Scenario: check graceful rejection when two nodes have the same name
|
||||
Given I start duplicate postgres0 on port 8011
|
||||
Then there is a "Can't start; there is already a node named 'postgres0' running" CRITICAL in the dup-postgres0 patroni log
|
||||
|
||||
@@ -52,10 +52,9 @@ class AbstractController(abc.ABC):
|
||||
self._log = open(os.path.join(self._output_dir, self._name + '.log'), 'a')
|
||||
self._handle = self._start()
|
||||
|
||||
assert self._has_started(), "Process {0} is not running after being started".format(self._name)
|
||||
|
||||
max_wait_limit *= self._context.timeout_multiplier
|
||||
for _ in range(max_wait_limit):
|
||||
assert self._has_started(), "Process {0} is not running after being started".format(self._name)
|
||||
if self._is_accessible():
|
||||
break
|
||||
time.sleep(1)
|
||||
@@ -344,6 +343,13 @@ class PatroniController(AbstractController):
|
||||
'--datadir=' + os.path.join(self._work_directory, dest),
|
||||
'--dbname=' + self.backup_source])
|
||||
|
||||
def read_patroni_log(self, level):
|
||||
try:
|
||||
with open(str(os.path.join(self._output_dir or '', self._name + ".log"))) as f:
|
||||
return [line for line in f.readlines() if line[24:24 + len(level)] == level]
|
||||
except IOError:
|
||||
return []
|
||||
|
||||
|
||||
class ProcessHang(object):
|
||||
|
||||
@@ -827,7 +833,7 @@ class PatroniPoolController(object):
|
||||
|
||||
def __getattr__(self, func):
|
||||
if func not in ['stop', 'query', 'write_label', 'read_label', 'check_role_has_changed_to',
|
||||
'add_tag_to_config', 'get_watchdog', 'patroni_hang', 'backup']:
|
||||
'add_tag_to_config', 'get_watchdog', 'patroni_hang', 'backup', 'read_patroni_log']:
|
||||
raise AttributeError("PatroniPoolController instance has no attribute '{0}'".format(func))
|
||||
|
||||
def wrapper(name, *args, **kwargs):
|
||||
|
||||
@@ -9,6 +9,22 @@ def start_patroni(context, name):
|
||||
return context.pctl.start(name)
|
||||
|
||||
|
||||
@step('I start duplicate {name:w} on port {port:d}')
|
||||
def start_duplicate_patroni(context, name, port):
|
||||
config = {
|
||||
"name": name,
|
||||
"restapi": {
|
||||
"listen": "127.0.0.1:{0}".format(port)
|
||||
}
|
||||
}
|
||||
try:
|
||||
context.pctl.start('dup-' + name, custom_config=config)
|
||||
assert False, "Process was expected to fail"
|
||||
except AssertionError as e:
|
||||
assert 'is not running after being started' in str(e),\
|
||||
"No error was raised by duplicate start of {0} ".format(name)
|
||||
|
||||
|
||||
@step('I shut down {name:w}')
|
||||
def stop_patroni(context, name):
|
||||
return context.pctl.stop(name, timeout=60)
|
||||
@@ -90,3 +106,10 @@ def replication_works(context, primary, replica, time_limit):
|
||||
When I add the table test_{0} to {1}
|
||||
Then table test_{0} is present on {2} after {3} seconds
|
||||
""".format(int(time()), primary, replica, time_limit))
|
||||
|
||||
|
||||
@then('there is a "{message}" {level:w} in the {node} patroni log')
|
||||
def check_patroni_log(context, message, level, node):
|
||||
messsages_of_level = context.pctl.read_patroni_log(node, level)
|
||||
assert any(message in line for line in messsages_of_level),\
|
||||
"There was no {0} {1} in the {2} patroni log".format(message, level, node)
|
||||
|
||||
Reference in New Issue
Block a user