Single user mode was waiting for user input and never finish (#634)

Regression was introduced in https://github.com/zalando/patroni/pull/576
This commit is contained in:
Alexander Kukushkin
2018-03-02 22:22:43 +01:00
committed by GitHub
parent c04e7a1798
commit 3afd26101b
2 changed files with 14 additions and 6 deletions
+13 -5
View File
@@ -1790,10 +1790,20 @@ $$""".format(name, ' '.join(options)), name, password, password)
return self.single_user_mode(options=opts) == 0 or None
def cancellable_subprocess_call(self, *args, **kwargs):
communicate_input = kwargs.pop('communicate_input', None)
for s in ('stdin', 'stdout', 'stderr'):
kwargs.pop(s, None)
communicate_input = 'communicate_input' in kwargs
if communicate_input:
input_data = kwargs.pop('communicate_input', None)
if not isinstance(input_data, string_types):
input_data = ''
if input_data and input_data[-1] != '\n':
input_data += '\n'
kwargs['stdin'] = subprocess.PIPE
kwargs['stdout'] = open(os.devnull, 'w')
kwargs['stderr'] = subprocess.STDOUT
try:
with self._cancellable_lock:
if self._is_cancelled:
@@ -1803,10 +1813,8 @@ $$""".format(name, ' '.join(options)), name, password, password)
self._cancellable = subprocess.Popen(*args, **kwargs)
if communicate_input:
kwargs['stdin'] = subprocess.PIPE
if communicate_input[-1] != '\n':
communicate_input += '\n'
self._cancellable.communicate(communicate_input + '\n')
if input_data:
self._cancellable.communicate(input_data)
self._cancellable.stdin.close()
return self._cancellable.wait()
+1 -1
View File
@@ -946,7 +946,7 @@ class TestPostgresql(unittest.TestCase):
def test_cancellable_subprocess_call(self):
self.p.cancel()
self.assertRaises(PostgresException, self.p.cancellable_subprocess_call)
self.assertRaises(PostgresException, self.p.cancellable_subprocess_call, communicate_input=None)
@patch('patroni.postgresql.polling_loop', Mock(return_value=[0, 0]))
def test_cancel(self):