From a5e79bce9d983fbfb0ad50faf49c22687f1e95f4 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Fri, 16 Dec 2016 15:44:04 +0100 Subject: [PATCH] * bugfix: pass an arguments to a callback --- patroni/postgresql.py | 7 ++++++- tests/test_postgresql.py | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index e3995c74..c8366dbe 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -610,7 +610,12 @@ class Postgresql(object): self.__cb_called = True if self.callback and cb_name in self.callback: - self._callback_executor.call(self.callback[cb_name]) + cmd = self.callback[cb_name] + try: + cmd = shlex.split(self.callback[cb_name]) + [cb_name, self.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) @property def role(self): diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index 8d062cde..b044acef 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -279,6 +279,7 @@ class TestPostgresql(unittest.TestCase): @patch.object(builtins, 'open', MagicMock()) def test_write_pgpass(self): + self.p.write_pgpass({'host': 'localhost', 'port': '5432', 'user': 'foo'}) self.p.write_pgpass({'host': 'localhost', 'port': '5432', 'user': 'foo', 'password': 'bar'}) def test_checkpoint(self): @@ -423,9 +424,9 @@ class TestPostgresql(unittest.TestCase): def test_is_running(self): self.assertFalse(self.p.is_running()) - @patch('subprocess.Popen', Mock(side_effect=OSError)) + @patch('shlex.split', Mock(side_effect=OSError)) def test_call_nowait(self): - self.assertFalse(self.p.call_nowait('on_start')) + self.assertIsNone(self.p.call_nowait('on_start')) def test_non_existing_callback(self): self.assertFalse(self.p.call_nowait('foobar'))