Bug 862078 - Getting "ImportError: No module named django.core.management" error on slave gears
Summary: Getting "ImportError: No module named django.core.management" error on slave ...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: OKD
Classification: Red Hat
Component: Containers
Version: 2.x
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
: ---
Assignee: Ram Ranganathan
QA Contact: libra bugs
URL:
Whiteboard:
: 851007 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-10-01 19:39 UTC by Sumana Annam
Modified: 2015-05-14 23:00 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-11-06 18:49:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Sumana Annam 2012-10-01 19:39:10 UTC
Description of problem:

Created a scalable python application using quick start from https://github.com/openshift/django-example.git and instructions from comment https://openshift.redhat.com/community/comment/reply/8095/16195.

Instructions work great with the regular application but fails in scalable env. It appears that /virt/bin/activate is not activating the env properly on slave gears.

On primary gear - No error:

[rangoscale-sannam.rhcloud.com ~]\> source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate
(virtenv)[rangoscale-sannam.rhcloud.com ~]\> export PYTHON_EGG_CACHE=$OPENSHIFT_GEAR_DIR/virtenv/lib/python-2.6
(virtenv)[rangoscale-sannam.rhcloud.com ~]\> python
Python 2.6.6 (r266:84292, Aug 28 2012, 10:55:56) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.management import execute_manager
>>> 

On secondary gear - doing the same source, export, results in "no module error":

[rangoscale-sannam.rhcloud.com ~]\> ssh e57c87a536eb41fdba69d8749dba81e5.80.47
[e57c87a536-sannam.rhcloud.com ~]\> source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate
(virtenv)[e57c87a536-sannam.rhcloud.com ~]\> export PYTHON_EGG_CACHE=$OPENSHIFT_GEAR_DIR/virtenv/lib/python-2.6
(virtenv)[e57c87a536-sannam.rhcloud.com ~]\> python
Python 2.6.6 (r266:84292, Aug 28 2012, 10:55:56) 
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.management import execute_manager
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django.core.management

Git push of the application also results in the no module error because syncdb command is getting executed on the secondary gear. 

Deploy hook getting executed:

remote: + ssh e57c87a536eb41fdba69d8749dba81e5.80.47 deploy.sh
remote: Running .openshift/action_hooks/deploy
remote: Executing 'python /var/lib/stickshift/e57c87a536eb41fdba69d8749dba81e5/app-root/runtime/repo//wsgi/openshift/manage.py syncdb --noinput'
remote: Traceback (most recent call last):
remote:   File "/var/lib/stickshift/e57c87a536eb41fdba69d8749dba81e5/app-root/runtime/repo/wsgi/openshift/manage.py", line 2, in <module>
remote:     from django.core.management import execute_manager
remote: ImportError: No module named django.core.management
remote: Executing 'python /var/lib/stickshift/e57c87a536eb41fdba69d8749dba81e5/app-root/runtime/repo//wsgi/openshift/manage.py collectstatic --noinput'
remote: Traceback (most recent call last):
remote:   File "/var/lib/stickshift/e57c87a536eb41fdba69d8749dba81e5/app-root/runtime/repo/wsgi/openshift/manage.py", line 2, in <module>
remote:     from django.core.management import execute_manager
remote: ImportError: No module named django.core.management

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Follow instructions from https://openshift.redhat.com/community/comment/reply/8095/16195
2. Replace OPENSHIFT_APP_DIR with OPENSHIFT_GEAR_DIR in the instructions from the above link.
3. git push should result in no module error
4. login via ssh into primary gear and run 

source $OPENSHIFT_GEAR_DIR/virtenv/bin/activate
export PYTHON_EGG_CACHE=$OPENSHIFT_GEAR_DIR/virtenv/lib/python-2.6
python 

at the prompt enter : from django.core.management import execute_manager

5. login via ssh into secondary gear and repeat steps from 4.

Actual results:


Expected results:


Additional info:

Comment 1 Sumana Annam 2012-10-01 21:31:49 UTC
Notes from Ramr:

that might be a bug with virtenv/bin/activate (yeah might be because of the UUIDs of the gear -- different on the primary and slave gears and we just rsync it).

Comment 2 Ram Ranganathan 2012-10-02 20:41:29 UTC
Fixed with pull request: 
    https://github.com/openshift/crankcase/pull/582

waiting on merge

Comment 3 Ram Ranganathan 2012-10-02 20:44:41 UTC
*** Bug 851007 has been marked as a duplicate of this bug. ***

Comment 4 Attila Nagy 2012-10-09 12:18:40 UTC
Tested against devenv_2301 (ami-d817abb1). I still can see 'ImportError: No module named django.core.management' during deployment. 

Can you please verify steps to reproduce? The link to the forum post is outdated.

Comment 5 Ram Ranganathan 2012-10-09 20:13:32 UTC
This works fine for me on the devenv launched yesterday. 

Here's the steps I used to verify:
1. Create python app: 
      rhc app create -a applepie -t python-2.6 -s -d
2. Add django dependency
      cd applepie/
      # edit setup.py and uncomment the Django dependency line
      sed -i "s/^\s*#\(\s*install_requires.*\)/\1/" setup.py 
      git commit . -m 'django rides again' && git push 

3. Once the deployment completes (push completes), ssh into the app
      ssh  $uuid@$dns  #  ssh to haproxy gear
       haproxy-gear-sh>    source python-2.6/virtenv/bin/activate
       haproxy-gear-sh (virtenv)> python -c "import django; print django" 

4. Get ssh info for the other gears.
       haproxy-gear-sh>  cat haproxy-1.4/conf/gear-registry.db   

5. For each of the slave/serving gears -- ssh into those gears and run:
      haproxy-gear-sh> ssh  to slave gear (found in step 4)
         slave-gear-sh>  source python-2.6/virtenv/bin/activate
         slave-gear-sh (virtenv)> python -c "import django; print django"

That should run on all the gears.

You can also change the python command to be something like:
   python -c "import django.core.management; print django.core.management" 
If you want to look at the django core management bits.

Comment 6 Peter Ruan 2012-10-10 20:08:43 UTC
verified with devenv_2307
 
python -c "import django; print django"
<module 'django' from '/var/lib/openshift/7b44a04aa4714f7cb8371303076608f1/python-2.6/virtenv/lib/python2.6/site-packages/Django-1.4.1-py2.6.egg/django/__init__.pyc'>


Note You need to log in before you can comment on or make changes to this bug.