Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctrl+c in pause module and make other improvements #40134

Merged
merged 15 commits into from
May 21, 2018

Conversation

samdoran
Copy link
Contributor

@samdoran samdoran commented May 15, 2018

SUMMARY

Fixes #35372

Ctrl + C works in all scenarios.

Use curses to control stdout to avoid displaying control characters on screen and make interactive input more user friendly.

Validate the echo parameter and ensure it is always cast as a bool.

Add integration tests using pexpect.

Supercedes #38049

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

pause.py

ANSIBLE VERSION
2.6

bcoca and others added 5 commits May 15, 2018 01:34
now ctrl+c works in most scenarios:
 - naked:
	- pause:
 - with prompt
	- pause: prompt=hi
 - time wait
	- pause: seconds=60
 - time wait with prompt
	- pause: seconds=60 prompt=hi

removed redundant seconds if

fixes ansible#35372
@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels May 15, 2018
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label May 15, 2018
@samdoran samdoran changed the title [WIP] Fix ctrl+c in pause module and make other improvements Fix ctrl+c in pause module and make other improvements May 15, 2018
@ansibot
Copy link
Contributor

ansibot commented May 15, 2018

@ansibot ansibot added test This PR relates to tests. and removed WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. labels May 15, 2018
@ansibot
Copy link
Contributor

ansibot commented May 15, 2018

The test ansible-test sanity --test pep8 [explain] failed with 10 errors:

test/integration/targets/pause/runme.py:27:1: E265 block comment should start with '# '
test/integration/targets/pause/runme.py:83:1: E266 too many leading '#' for block comment
test/integration/targets/pause/runme.py:83:1: E303 too many blank lines (3)
test/integration/targets/pause/runme.py:139:1: E266 too many leading '#' for block comment
test/integration/targets/pause/runme.py:139:1: E303 too many blank lines (3)
test/integration/targets/pause/runme.py:195:1: E266 too many leading '#' for block comment
test/integration/targets/pause/runme.py:195:1: E303 too many blank lines (3)
test/integration/targets/pause/runme.py:254:1: E266 too many leading '#' for block comment
test/integration/targets/pause/runme.py:254:1: E303 too many blank lines (3)
test/integration/targets/pause/runme.py:270:26: E226 missing whitespace around arithmetic operator

The test ansible-test sanity --test use-compat-six [explain] failed with 1 error:

test/integration/targets/pause/runme.py:8:1: use `ansible.module_utils.six` instead of `six`

click here for bot help

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label May 15, 2018

export ANSIBLE_ROLES_PATH=./roles

python runme.py -i ../../inventory "$@"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need a runme.sh just to run runme.py, since ansible-test will execute runme.py directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, to avoid having to install pexpect for every integration test run via integration.txt, it may be better to keep this for now and install pexepect via pip here rather than using integration.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for answering that! I was going to ask you about that today but you beat me to it.

@samdoran
Copy link
Contributor Author

@mattclay One thing I've noticed is that inside the container I don't have a tty to query for the appropriate VERASE. Would there be a way to add a tty to the container by running it with -it or -t?

Traceback (most recent call last):
  File "test-pause.py", line 17, in <module>
    backspace = termios.tcgetattr(sys.stdin.fileno())[6][termios.VERASE]
termios.error: (25, 'Inappropriate ioctl for device')

@ansibot
Copy link
Contributor

ansibot commented May 16, 2018

The test ansible-test sanity --test use-compat-six [explain] failed with 1 error:

test/integration/targets/pause/test-pause.py:8:1: use `ansible.module_utils.six` instead of `six`

click here for bot help

Use six from ansible.module_utils.six
Use try except when trying to determien erase sequence to account for lack of TTY in containers
@mattclay
Copy link
Member

@samdoran I'll try adding -it when running all test containers to see if it causes any issues.

@samdoran samdoran added this to To Do in 2.5.x blocker list via automation May 17, 2018
@samdoran
Copy link
Contributor Author

@mattclay I was able to work around that with a try except statement that hardcodes a backspace escape sequence and that seems to be working.

The last test problem I need to solve is that I am testing aborting the play interactively, which causes the tests to report failure (well, unstable actually). I thought I put the correct string in the task name, but that doesn't seem to fix it. This may be different than other tests in that I am actually aborting the play, but I'm not sure.

@mattclay
Copy link
Member

@samdoran Your latest changes to use EXPECTED FAILURE should fix the unstable test results.

@ansibot ansibot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label May 17, 2018
@mattclay
Copy link
Member

It's good that you have a work around, because both -it and -t cause problems for CI.

@samdoran
Copy link
Contributor Author

samdoran commented May 17, 2018

Thanks for looking into it.

@samdoran samdoran removed this from To Do in 2.5.x blocker list May 17, 2018
Accept two digit precision for pause length in test
Check for seconds when seconds is specificed, minutes when minutes is specified
@ansibot ansibot added the affects_2.6 This issue/PR affects Ansible v2.6 label May 18, 2018
@samdoran samdoran merged commit 1c20029 into ansible:devel May 21, 2018
@samdoran samdoran deleted the issue/35372-pause-ctrl-c branch May 21, 2018 14:04
samdoran added a commit to samdoran/ansible that referenced this pull request May 22, 2018
* Fix all cases with pause and ctrl+c
 - naked:
	- pause:
 - with prompt
	- pause: prompt=hi
 - time wait
	- pause: seconds=60
 - time wait with prompt
	- pause: seconds=60 prompt=hi

Fixes ansible#35372

* Use curses to control stdout
* Use curses to clear lines on interactive input
* Validate input for echo parameter and fail nicely if invalid
* Add integration tests for pause module using pexpect
* Use try except when trying to determine erase sequence to account for lack of TTY in containers in tests
* Improve output validation for regular paus test
* Accept two digit precision for pause length in test
* Check for seconds when seconds is specificed, minutes when minutes is specified
* Add test for no TTY mode

Co-authored by: Toshio Kuratomi <a.badger@gmail.com>
Co-authored by: Brian Coca <brian.coca+git@gmail.com>

(cherry picked from commit 1c20029)
samdoran added a commit that referenced this pull request May 22, 2018
Backport # 40134 - Ensure Ctrl+C interrupt for pause module works in all cases
achinthagunasekara pushed a commit to achinthagunasekara/ansible that referenced this pull request May 23, 2018
* Fix all cases with pause and ctrl+c
 - naked:
	- pause:
 - with prompt
	- pause: prompt=hi
 - time wait
	- pause: seconds=60
 - time wait with prompt
	- pause: seconds=60 prompt=hi


Fixes ansible#35372

* Use curses to control stdout
* Use curses to clear lines on interactive input
* Validate input for echo parameter and fail nicely if invalid
* Add integration tests for pause module using pexpect
* Use try except when trying to determine erase sequence to account for lack of TTY in containers in tests
* Improve output validation for regular paus test
* Accept two digit precision for pause length in test
* Check for seconds when seconds is specificed, minutes when minutes is specified
* Add test for no TTY mode

Co-authored by: Toshio Kuratomi <a.badger@gmail.com>
Co-authored by: Brian Coca <brian.coca+git@gmail.com>
jacum pushed a commit to jacum/ansible that referenced this pull request Jun 26, 2018
* Fix all cases with pause and ctrl+c
 - naked:
	- pause:
 - with prompt
	- pause: prompt=hi
 - time wait
	- pause: seconds=60
 - time wait with prompt
	- pause: seconds=60 prompt=hi


Fixes ansible#35372

* Use curses to control stdout
* Use curses to clear lines on interactive input
* Validate input for echo parameter and fail nicely if invalid
* Add integration tests for pause module using pexpect
* Use try except when trying to determine erase sequence to account for lack of TTY in containers in tests
* Improve output validation for regular paus test
* Accept two digit precision for pause length in test
* Check for seconds when seconds is specificed, minutes when minutes is specified
* Add test for no TTY mode

Co-authored by: Toshio Kuratomi <a.badger@gmail.com>
Co-authored by: Brian Coca <brian.coca+git@gmail.com>
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
* Fix all cases with pause and ctrl+c
 - naked:
	- pause:
 - with prompt
	- pause: prompt=hi
 - time wait
	- pause: seconds=60
 - time wait with prompt
	- pause: seconds=60 prompt=hi


Fixes ansible#35372

* Use curses to control stdout
* Use curses to clear lines on interactive input
* Validate input for echo parameter and fail nicely if invalid
* Add integration tests for pause module using pexpect
* Use try except when trying to determine erase sequence to account for lack of TTY in containers in tests
* Improve output validation for regular paus test
* Accept two digit precision for pause length in test
* Check for seconds when seconds is specificed, minutes when minutes is specified
* Add test for no TTY mode

Co-authored by: Toshio Kuratomi <a.badger@gmail.com>
Co-authored by: Brian Coca <brian.coca+git@gmail.com>
@ansible ansible locked and limited conversation to collaborators May 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pause module no longer allows abort
5 participants