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:
parent
a84c1a5669
commit
1527078a8f
3 changed files with 32 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- pause - do not accept enter to continue when a timeout is set (https://github.com/ansible/ansible/issues/73948)
|
|
@ -246,19 +246,20 @@ class ActionModule(ActionBase):
|
|||
clear_line(stdout)
|
||||
raise KeyboardInterrupt
|
||||
|
||||
# read key presses and act accordingly
|
||||
if key_pressed in (b'\r', b'\n'):
|
||||
clear_line(stdout)
|
||||
break
|
||||
elif key_pressed in backspace:
|
||||
# delete a character if backspace is pressed
|
||||
result['user_input'] = result['user_input'][:-1]
|
||||
clear_line(stdout)
|
||||
if echo:
|
||||
stdout.write(result['user_input'])
|
||||
stdout.flush()
|
||||
else:
|
||||
result['user_input'] += key_pressed
|
||||
if not seconds:
|
||||
# read key presses and act accordingly
|
||||
if key_pressed in (b'\r', b'\n'):
|
||||
clear_line(stdout)
|
||||
break
|
||||
elif key_pressed in backspace:
|
||||
# delete a character if backspace is pressed
|
||||
result['user_input'] = result['user_input'][:-1]
|
||||
clear_line(stdout)
|
||||
if echo:
|
||||
stdout.write(result['user_input'])
|
||||
stdout.flush()
|
||||
else:
|
||||
result['user_input'] += key_pressed
|
||||
|
||||
except KeyboardInterrupt:
|
||||
signal.alarm(0)
|
||||
|
|
|
@ -274,3 +274,19 @@ pause_test.send('supersecretpancakes')
|
|||
pause_test.send('\r')
|
||||
pause_test.expect(pexpect.EOF)
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue