pause - do not continue with '\r' when timeout is set (#74030)

Original function of pause was, to only allow user input
(finished with enter) when no timeout was set. This restores
the behaviour.
This commit is contained in:
Alexander Sowitzki 2021-03-29 21:39:42 +02:00 committed by GitHub
parent a84c1a5669
commit 1527078a8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 13 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- pause - do not accept enter to continue when a timeout is set (https://github.com/ansible/ansible/issues/73948)

View file

@ -246,19 +246,20 @@ class ActionModule(ActionBase):
clear_line(stdout) clear_line(stdout)
raise KeyboardInterrupt raise KeyboardInterrupt
# read key presses and act accordingly if not seconds:
if key_pressed in (b'\r', b'\n'): # read key presses and act accordingly
clear_line(stdout) if key_pressed in (b'\r', b'\n'):
break clear_line(stdout)
elif key_pressed in backspace: break
# delete a character if backspace is pressed elif key_pressed in backspace:
result['user_input'] = result['user_input'][:-1] # delete a character if backspace is pressed
clear_line(stdout) result['user_input'] = result['user_input'][:-1]
if echo: clear_line(stdout)
stdout.write(result['user_input']) if echo:
stdout.flush() stdout.write(result['user_input'])
else: stdout.flush()
result['user_input'] += key_pressed else:
result['user_input'] += key_pressed
except KeyboardInterrupt: except KeyboardInterrupt:
signal.alarm(0) signal.alarm(0)

View file

@ -274,3 +274,19 @@ pause_test.send('supersecretpancakes')
pause_test.send('\r') pause_test.send('\r')
pause_test.expect(pexpect.EOF) pause_test.expect(pexpect.EOF)
pause_test.close() pause_test.close()
# Test that enter presses may not continue the play when a timeout is set.
pause_test = pexpect.spawn(
'ansible-playbook',
args=["pause-3.yml"] + args,
timeout=10,
env=os.environ
)
pause_test.logfile = log_buffer
pause_test.expect(r"\(ctrl\+C then 'C' = continue early, ctrl\+C then 'A' = abort\)")
pause_test.send('\r')
pause_test.expect(pexpect.EOF)
pause_test.close()