Bug 1006183

Summary: Python application is installed in the wrong cwd
Product: OpenShift Online Reporter: Kun Xi <kunxi>
Component: ContainersAssignee: Rob Millner <rmillner>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: high Docs Contact:
Priority: medium    
Version: 2.xCC: bmeng, chunchen, mfisher, mpatel
Target Milestone: ---Keywords: SupportQuestion
Target Release: ---   
Hardware: All   
OS: All   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-19 16:50:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kun Xi 2013-09-10 07:36:05 UTC
When python application is deployed, the runner *DOES NOT* change the directory to the app_root/repo to invoke 

python setup.py install

I believe the runner cd to $OPENSHIFT_PYTHON_DIR/virtenv, and reference the setup.py from there. This breaks the python package deployment.

 
This bug repros in python-2.6 and python-2.7 cartridge, not tested in python-3.3 cartridge as I do not have python-3.3 installed in the my dev box.

How reproducible:


Steps to Reproduce:
1. create a python project as: rhc app create py26 -t python-2.6
2. clone the source: rhc git-clone py26
3. cd py26; mkdir foo; touch foo/__init__.py
4. modify the setup.py as:

from setuptools import setup, find_packages

setup(
    name='foo',
    version='0.1.1',
    packages=find_packages(),
 )

5. in wsgi/application, add one line after the virtualenv is initialized:
import foo

6. git commit; git push; refresh the browser 500 error.


Actual results:

rhc tail py26, shows the ImportError, fail to import foo.

Expected results:
The foo package should be imported appropriately, here is my proof of concept:
see above for step 1 - 4:
5. create a virtualenv: mkvirtualenv bar
6. note we are in the py26 directory: python setup.py develop
7. cd /; python -c 'import foo; print foo'
<module 'foo' from 'foo/__init__.pyc'>

8. create another virtualenv: mkvirtualenv egg
9. cd /tmp; python path/to/py26/setup.py develop
10. python -c 'import foo'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named foo


Additional info:
The deploy log also shows that the cwd is incorrect, see 
remote: warning: manifest_maker: standard file 'setup.py' not found

$ git push
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 656 bytes, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Stopping PYTHON cart
remote: Waiting for stop to finish
remote: running develop
remote: running egg_info
remote: creating foo.egg-info
remote: writing requirements to foo.egg-info/requires.txt
remote: writing foo.egg-info/PKG-INFO
remote: writing top-level names to foo.egg-info/top_level.txt
remote: writing dependency_links to foo.egg-info/dependency_links.txt
remote: writing requirements to foo.egg-info/requires.txt
remote: writing foo.egg-info/PKG-INFO
remote: writing top-level names to foo.egg-info/top_level.txt
remote: writing dependency_links to foo.egg-info/dependency_links.txt
remote: writing manifest file 'foo.egg-info/SOURCES.txt'
remote: warning: manifest_maker: standard file 'setup.py' not found
remote: reading manifest file 'foo.egg-info/SOURCES.txt'
remote: writing manifest file 'foo.egg-info/SOURCES.txt'
remote: running build_ext
remote: Creating /var/lib/openshift/522ebd4e5973cab5da0000a1/python/virtenv/lib/python2.6/site-packages/foo.egg-link (link to .)
remote: Adding foo 0.1.1 to easy-install.pth file

Comment 1 Rob Millner 2013-09-10 22:30:33 UTC
Tested scaled and non-scaled applications, this is believed to be a safe change to make.

Pull request:
https://github.com/openshift/origin-server/pull/3609

Comment 2 openshift-github-bot 2013-09-11 01:21:49 UTC
Commit pushed to master at https://github.com/openshift/origin-server

https://github.com/openshift/origin-server/commit/53ee5b134ad81c39491cfec8c7bbac2bd24883aa
Bug 1006183 - Do builds from the REPO dir instead.

Comment 3 chunchen 2013-09-11 06:27:03 UTC
It's fixed, verified with scaled and non-scaled app on devenv_3771, please refer to the following results:

1. create a python
2. clone the source: rhc git-clone py
3. cd py26; mkdir foo; touch foo/__init__.py
4. modify the setup.py as:

from setuptools import setup, find_packages

setup(
    name='foo',
    version='0.1.1',
    packages=find_packages(),
 )

5. in wsgi/application, add one line after the virtualenv is initialized:
import foo

6. git commit; git push
# git add .; git commit -amp; git push
[master 04f1844] p
 2 files changed, 9 insertions(+), 15 deletions(-)
 create mode 100644 foo/__init__.py
 rewrite setup.py (99%)
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 570 bytes, done.
Total 6 (delta 2), reused 0 (delta 0)
remote: HAProxy instance is stopped
remote:   - Created/Updated virtenv and activated it.
remote:  - Found setup.py. Processing it ...
remote: running develop
remote: running egg_info
remote: creating foo.egg-info
remote: writing foo.egg-info/PKG-INFO
remote: writing dependency_links to foo.egg-info/dependency_links.txt
remote: writing top-level names to foo.egg-info/top_level.txt
remote: writing manifest file 'foo.egg-info/SOURCES.txt'
remote: reading manifest file 'foo.egg-info/SOURCES.txt'
remote: writing manifest file 'foo.egg-info/SOURCES.txt'
remote: running build_ext
remote: Creating /var/lib/openshift/52300affc6aa501c1600004c/python/virtenv/venv/lib/python3.3/site-packages/foo.egg-link (link to .)
remote: Adding foo 0.1.1 to easy-install.pth file
remote: 
remote: Installed /var/lib/openshift/52300affc6aa501c1600004c/app-root/runtime/repo
remote: Processing dependencies for foo==0.1.1
remote: Finished processing dependencies for foo==0.1.1
remote:  - Done processing setup.py
remote: Starting application cpy33s
remote: HAProxy instance is started
To ssh://52300affc6aa501c1600004c.rhcloud.com/~/git/cpy33s.git/
   2cb8fdf..04f1844  master -> master