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 #31694: running with closed stdin on python 3 #31695

Merged
merged 1 commit into from
Nov 8, 2017

Conversation

adelton
Copy link
Contributor

@adelton adelton commented Oct 13, 2017

SUMMARY

Fixes #31694.

When stdin is /dev/null, self._connection._new_stdin.buffer fails with AttributeError.

This amends #26495.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

./lib/ansible/plugins/action/pause.py

ANSIBLE VERSION
ansible-playbook 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.2 (default, Oct  2 2017, 16:51:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
ADDITIONAL INFORMATION

Before:

# python3 /usr/bin/ansible-playbook -i localhost, /tmp/pause.yaml < /dev/null

PLAY [localhost] ***************************************************************

TASK [pause] *******************************************************************
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: UnboundLocalError: local variable 'stdin' referenced before assignment
fatal: [localhost]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

NO MORE HOSTS LEFT *************************************************************
	to retry, use: --limit @/tmp/pause.retry

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=0    failed=1   

After:

# python3 /usr/bin/ansible-playbook -i localhost, /tmp/pause.yaml < /dev/null

PLAY [localhost] ***************************************************************

TASK [pause] *******************************************************************
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bugfix_pull_request needs_triage Needs a first human triage before being processed. plugins/action python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 13, 2017
@adelton
Copy link
Contributor Author

adelton commented Oct 13, 2017

Alternative to #31586.

@ansibot ansibot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. label Oct 13, 2017
@adelton
Copy link
Contributor Author

adelton commented Oct 13, 2017

Could this change have caused the https://app.shippable.com/github/ansible/ansible/runs/40761/24/console failure or is that merely a fluke?

@mkrizek
Copy link
Contributor

mkrizek commented Oct 13, 2017

@adelton I just re-triggered the shippable job, we'll see...

@mkrizek mkrizek removed the needs_triage Needs a first human triage before being processed. label Oct 13, 2017
@ansibot ansibot added new_contributor This PR is the first contribution by a new community member. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Oct 13, 2017
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Oct 26, 2017
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Nov 3, 2017
@adelton
Copy link
Contributor Author

adelton commented Nov 6, 2017

@mkrizek, what is the best course of action to get this PR reviewed and merged?

@mkrizek mkrizek requested a review from abadger November 6, 2017 14:53
@abadger
Copy link
Contributor

abadger commented Nov 6, 2017

Overall change looks good, but it seems a little clunky to check for closed file descriptor for stdin twice. Perhaps structure the change like this:

[...]
‎‎fd = Nonetry:
‎‎    if PY3:
‎‎        fd = self._connection._new_stdin.buffer.fileno()
‎‎    else:
‎        fd = self._connection._new_stdin.fileno()
‎‎except (ValueError, AttributeError):
‎‎    # ValueError: someone is using a closed file descriptor as stdin
‎‎    [...]

@adelton
Copy link
Contributor Author

adelton commented Nov 6, 2017

The problem is, that stdin (result of either stdin = self._connection._new_stdin.buffer or stdin = stdin = self._connection._new_stdin) is used further down the code: termios.tcflush(stdin, termios.TCIFLUSH), key_pressed = stdin.read(1), ...

So we cannot just skip the assignment to stdin and go directly with the .fileno().

@abadger
Copy link
Contributor

abadger commented Nov 6, 2017 via email

@adelton
Copy link
Contributor Author

adelton commented Nov 7, 2017

@abadger, thanks. Please consider rebased / modified patch 5707ad8.

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Nov 7, 2017
@mkrizek mkrizek merged commit e5dbf63 into ansible:devel Nov 8, 2017
mkrizek pushed a commit that referenced this pull request Nov 8, 2017
@mkrizek mkrizek added this to Done in 2.4.2 in 2.4.x Blocker List Nov 8, 2017
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 6, 2018
@adelton adelton deleted the issue-31694 branch June 22, 2018 09:44
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. plugins/action python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
No open projects
2.4.x Blocker List
Done in 2.4.2
Development

Successfully merging this pull request may close these issues.

Use of pause fails with python3 when stdin is closed
4 participants