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

pip: combine chdir and env only when env is set #40793

Merged
merged 2 commits into from
Aug 13, 2018
Merged

Conversation

tyll
Copy link
Contributor

@tyll tyll commented May 28, 2018

SUMMARY

This fixes an AttributeError when chdir without virtualenv is specified:

File "/tmp/ansible_2UAFsZ/ansible_module_pip.py", line 387, in main
env = os.path.join(chdir, env)
File "/usr/lib64/python2.7/posixpath.py", line 75, in join
if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

pip

ANSIBLE VERSION
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/till/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15 (default, May 16 2018, 17:50:09) [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]

ADDITIONAL INFORMATION
---
cat > 'bug_pip_chdir.yml' <<EOF
- name: Show pip chdir bug
  hosts: all
  tasks:
    - pip:
        name: pip
        extra_args: --user --upgrade
        chdir: /tmp
EOF
ansible-playbook -i rhel7, bug_pip_chdir.yml 

PLAY [Run tox tests and nmctl show] *********************************************************************

TASK [Gathering Facts] **********************************************************************************
ok: [rhel7]

TASK [pip] **********************************************************************************************
fatal: [rhel7]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.122.177 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_Q3ae1r/ansible_module_pip.py\", line 562, in <module>\r\n    main()\r\n  File \"/tmp/ansible_Q3ae1r/ansible_module_pip.py\", line 387, in main\r\n    env = os.path.join(chdir, env)\r\n  File \"/usr/lib64/python2.7/posixpath.py\", line 75, in join\r\n    if b.startswith('/'):\r\nAttributeError: 'NoneType' object has no attribute 'startswith'\r\n", "msg": "MODULE FAILURE", "rc": 1}

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

Copy link
Contributor

@resmo resmo left a comment

Choose a reason for hiding this comment

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

LGTM

@ansibot
Copy link
Contributor

ansibot commented May 28, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels May 28, 2018
Copy link
Contributor

@robinro robinro left a comment

Choose a reason for hiding this comment

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

Thanks @tyll for this PR.
This issue is already known as #37912 and there is a fix for it under discussion in #40129. The fix given here is not complete.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels May 28, 2018
@tyll
Copy link
Contributor Author

tyll commented May 28, 2018

@robinro thank you for the pointers. The fix here is complete for the error that is reported here. There seem to be other issues with the pip module discussed in #40129 that can be addressed with extra changes, but the AttributeError in discussion here could be easily fixed. IMHO it would be better to fix this actual error first and then finish the discussion about other problems. The fix could have been in several releases already and it fixes this playbook:
https://github.com/tyll/nmstate/blob/integration_tests/tests/ci_tests_basic.yml#L36

Therefore it would be great to merge at least this fix and then continue the discussion about the other problems.

@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 Jun 5, 2018
@robinro
Copy link
Contributor

robinro commented Jun 11, 2018

Since #40129 is not updated
@tyll Can you add a test for your change? I'd merge the simple fix then and ignore the executable situation for now.

@tyll tyll force-pushed the pip_chdir branch 2 times, most recently from 45a8969 to 6384c9f Compare June 12, 2018 11:54
@tyll
Copy link
Contributor Author

tyll commented Jun 12, 2018

@robinro I added an integration test

@ansibot ansibot added test This PR relates to tests. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 12, 2018
@ansibot
Copy link
Contributor

ansibot commented Jun 12, 2018

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

test/integration/targets/pip/files/ansible_test_pip_chdir/__init__.py:4:1: E302 expected 2 blank lines, found 1
test/integration/targets/pip/files/setup.py:11:7: E126 continuation line over-indented for hanging indent

The test ansible-test sanity --test shebang [explain] failed with 2 errors:

test/integration/targets/pip/files/ansible_test_pip_chdir/__init__.py:1:1: unexpected non-module shebang: b'#!/usr/bin/python3 -tt'
test/integration/targets/pip/files/setup.py:1:1: unexpected non-module shebang: b'#!/usr/bin/python -tt'

click here for bot help

@ansibot ansibot added small_patch stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jun 20, 2018
@robinro
Copy link
Contributor

robinro commented Jun 21, 2018

@tyll Thanks for the test. To me it's a bit over-the-top and also the CI complains. I wouldn't use a custom package for this.
Maybe we can have a test that "only" checks for the original issue: Not failing when chdir and env are both passed. Maybe use a relative path to a trivial requirements.txt to check if the chdir has effect, but even that is imo not necessary.

@tyll
Copy link
Contributor Author

tyll commented Jun 21, 2018 via email

@ansibot
Copy link
Contributor

ansibot commented Jun 27, 2018

The test ansible-test sanity --test shebang [explain] failed with 1 error:

test/integration/targets/pip/files/setup.py:1:1: unexpected non-module shebang: b'#!/usr/bin/python'

click here for bot help

@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 Jun 27, 2018
@tyll tyll force-pushed the pip_chdir branch 3 times, most recently from da6e1cd to 06c9d04 Compare June 28, 2018 18:59
@tyll
Copy link
Contributor Author

tyll commented Jun 28, 2018

@mattclay The failure on OS X should be fixed now, Shippable seems to take some time, so we will know later.

@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Jul 7, 2018
tyll added 2 commits July 16, 2018 15:21
This fixes an AttributeError when chdir without virtualenv is specified:

 File "/tmp/ansible_2UAFsZ/ansible_module_pip.py", line 387, in main
    env = os.path.join(chdir, env)
 File "/usr/lib64/python2.7/posixpath.py", line 75, in join
    if b.startswith('/'):
AttributeError: 'NoneType' object has no attribute 'startswith'
Signed-off-by: Till Maas <opensource@till.name>
@ansibot ansibot removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Jul 16, 2018
@robinro
Copy link
Contributor

robinro commented Jul 16, 2018

shipit

@robinro
Copy link
Contributor

robinro commented Jul 16, 2018

bot_status

@ansibot
Copy link
Contributor

ansibot commented Jul 17, 2018

Components

lib/ansible/modules/packaging/language/pip.py
support: core
maintainers: lujeni mattupstate robinro

test/integration/targets/pip/files/ansible_test_pip_chdir/init.py
support: core
maintainers: lujeni mattupstate robinro

test/integration/targets/pip/files/setup.py
support: core
maintainers: lujeni mattupstate robinro

test/integration/targets/pip/tasks/pip.yml
support: core
maintainers: lujeni mattupstate robinro

Metadata

waiting_on: ansible
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
too many files or commits: False
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 1
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 0
shipit_actors (maintainers or core team members): robinro
shipit_actors_other: []
automerge: automerge shipit test failed

click here for bot help

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jul 17, 2018
@resmo
Copy link
Contributor

resmo commented Jul 17, 2018

shipit

@ansibot ansibot added shipit This PR is ready to be merged by Core and removed core_review In order to be merged, this PR must follow the core review workflow. labels Jul 17, 2018
@orenwolf
Copy link

any chance of getting this merged?

@resmo resmo merged commit bb85bbc into ansible:devel Aug 13, 2018
@tyll tyll deleted the pip_chdir branch August 21, 2018 16:26
@orenwolf orenwolf mentioned this pull request Aug 22, 2018
@GaboFDC
Copy link

GaboFDC commented Sep 17, 2018

Will this fix only be avaiable in 2.7, or is there any chance of it being back ported to 2.5 or 2.6?

@resmo
Copy link
Contributor

resmo commented Sep 17, 2018

it is in 2.7

@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 bug This issue/PR relates to a bug. module This issue/PR relates to a module. shipit This PR is ready to be merged by Core small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants