Browse code

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.

Alexander Sowitzki authored on 2021/03/30 04:39:42
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - 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):
246 246
                         clear_line(stdout)
247 247
                         raise KeyboardInterrupt
248 248
 
249
-                    # read key presses and act accordingly
250
-                    if key_pressed in (b'\r', b'\n'):
251
-                        clear_line(stdout)
252
-                        break
253
-                    elif key_pressed in backspace:
254
-                        # delete a character if backspace is pressed
255
-                        result['user_input'] = result['user_input'][:-1]
256
-                        clear_line(stdout)
257
-                        if echo:
258
-                            stdout.write(result['user_input'])
259
-                        stdout.flush()
260
-                    else:
261
-                        result['user_input'] += key_pressed
249
+                    if not seconds:
250
+                        # read key presses and act accordingly
251
+                        if key_pressed in (b'\r', b'\n'):
252
+                            clear_line(stdout)
253
+                            break
254
+                        elif key_pressed in backspace:
255
+                            # delete a character if backspace is pressed
256
+                            result['user_input'] = result['user_input'][:-1]
257
+                            clear_line(stdout)
258
+                            if echo:
259
+                                stdout.write(result['user_input'])
260
+                            stdout.flush()
261
+                        else:
262
+                            result['user_input'] += key_pressed
262 263
 
263 264
                 except KeyboardInterrupt:
264 265
                     signal.alarm(0)
... ...
@@ -274,3 +274,19 @@ pause_test.send('supersecretpancakes')
274 274
 pause_test.send('\r')
275 275
 pause_test.expect(pexpect.EOF)
276 276
 pause_test.close()
277
+
278
+
279
+# Test that enter presses may not continue the play when a timeout is set.
280
+
281
+pause_test = pexpect.spawn(
282
+    'ansible-playbook',
283
+    args=["pause-3.yml"] + args,
284
+    timeout=10,
285
+    env=os.environ
286
+)
287
+
288
+pause_test.logfile = log_buffer
289
+pause_test.expect(r"\(ctrl\+C then 'C' = continue early, ctrl\+C then 'A' = abort\)")
290
+pause_test.send('\r')
291
+pause_test.expect(pexpect.EOF)
292
+pause_test.close()