diff --git a/features/basic_replication.feature b/features/basic_replication.feature index 6acffe5c..4b8b2686 100644 --- a/features/basic_replication.feature +++ b/features/basic_replication.feature @@ -65,6 +65,7 @@ Feature: basic replication Then I receive a response returncode 0 And postgres2 role is the primary after 24 seconds And Response on GET http://127.0.0.1:8010/history contains recovery after 10 seconds + And there is a postgres2_cb.log with "on_role_change master batman" in postgres2 data directory When I issue a PATCH request to http://127.0.0.1:8010/config with {"synchronous_mode": null, "master_start_timeout": 0} Then I receive a response code 200 When I add the table bar to postgres2 diff --git a/features/environment.py b/features/environment.py index 5b05887d..76eb8316 100644 --- a/features/environment.py +++ b/features/environment.py @@ -201,6 +201,8 @@ class PatroniController(AbstractController): config['name'] = name config['postgresql']['data_dir'] = self._data_dir.replace('\\', '/') config['postgresql']['basebackup'] = [{'checkpoint': 'fast'}] + config['postgresql']['callbacks'] = { + 'on_role_change': '{0} features/callback2.py {1}'.format(self._context.pctl.PYTHON, name)} config['postgresql']['use_unix_socket'] = os.name != 'nt' # windows doesn't yet support unix-domain sockets config['postgresql']['use_unix_socket_repl'] = os.name != 'nt' config['postgresql']['pgpass'] = os.path.join(tempfile.gettempdir(), 'pgpass_' + name).replace('\\', '/') diff --git a/features/steps/cascading_replication.py b/features/steps/cascading_replication.py index 944d98ca..9783fbae 100644 --- a/features/steps/cascading_replication.py +++ b/features/steps/cascading_replication.py @@ -11,11 +11,8 @@ def start_patroni_with_a_name_value_tag(context, name, tag_name, tag_value): @then('There is a {label} with "{content}" in {name:w} data directory') def check_label(context, label, content, name): - label = context.pctl.read_label(name, label) - if label is None: - label = "" - label = label.replace('\n', '\\n') - assert content in label, "\"{0}\" doesn't contain {1}".format(label, content) + value = (context.pctl.read_label(name, label) or '').replace('\n', '\\n') + assert content in value, "\"{0}\" in {1} doesn't contain {2}".format(value, label, content) @step('I create label with "{content:w}" in {name:w} data directory') diff --git a/patroni/postgresql/__init__.py b/patroni/postgresql/__init__.py index 2356110c..bed125c4 100644 --- a/patroni/postgresql/__init__.py +++ b/patroni/postgresql/__init__.py @@ -505,11 +505,12 @@ class Postgresql(object): if self.callback and cb_name in self.callback: cmd = self.callback[cb_name] + role = 'master' if self.role == 'promoted' else self.role try: - cmd = shlex.split(self.callback[cb_name]) + [cb_name, self.role, self.scope] + cmd = shlex.split(self.callback[cb_name]) + [cb_name, role, self.scope] self._callback_executor.call(cmd) except Exception: - logger.exception('callback %s %s %s %s failed', cmd, cb_name, self.role, self.scope) + logger.exception('callback %s %s %s %s failed', cmd, cb_name, role, self.scope) @property def role(self):