Running binaries in venv uses host python libs

Bug #1526728 reported by Matt Thompson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack-Ansible
Fix Released
Medium
Jimmy McCrory
Trunk
Fix Released
Medium
Jimmy McCrory

Bug Description

I noticed something odd today:

root@jenk-heat-669-node1_horizon_container-9c60dd1b:~# source /openstack/venvs/horizon-master/bin/activate
(horizon-master)root@jenk-heat-669-node1_horizon_container-9c60dd1b:~# horizon-manage.py clearsessions
Traceback (most recent call last):
  File "/openstack/venvs/horizon-master/bin/horizon-manage.py", line 29, in <module>
    execute_from_command_line(sys.argv)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module>
    class Permission(models.Model):
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
    value.contribute_to_class(cls, name)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/openstack/venvs/horizon-master/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
(horizon-master)root@jenk-heat-669-node1_horizon_container-9c60dd1b:~#

If you run this command outside of the venv, it works fine:

(horizon-master)root@jenk-heat-669-node1_horizon_container-9c60dd1b:~# deactivate
root@jenk-heat-669-node1_horizon_container-9c60dd1b:~# /openstack/venvs/horizon-master/bin/horizon-manage.py clearsessions
root@jenk-heat-669-node1_horizon_container-9c60dd1b:~#

Is this behaviour correct? I would have thought I should be able to run horizon-manage.py inside the venv, and if that assumption is correct then it looks like we're not installing all the necessary packages in the venv. Further, and I guess more importantly, any time we run a venv command without being inside the venv we run the risk of including libraries outside of the venv. Should we be changing any cronjob etc. that does this to set the PYTHONPATH so we restrict this from happening?

Thoughts?

--Matt

Revision history for this message
Matthew Thode (prometheanfire) wrote :

can you output your `env`?

Revision history for this message
Jimmy McCrory (jimmy-mccrory) wrote :

MySQL-python will need to be included in Horizon's venv.

It's being installed on the host through the galera_client role
https://github.com/openstack/openstack-ansible-galera_client/blob/master/defaults/main.yml#L60

Changed in openstack-ansible:
assignee: nobody → Jimmy McCrory (jimmy-mccrory)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to openstack-ansible (master)

Fix proposed to branch: master
Review: https://review.openstack.org/266600

Changed in openstack-ansible:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to openstack-ansible (master)

Reviewed: https://review.openstack.org/266600
Committed: https://git.openstack.org/cgit/openstack/openstack-ansible/commit/?id=39f10efaef22ac92d1505907d0551e985068f40d
Submitter: Jenkins
Branch: master

commit 39f10efaef22ac92d1505907d0551e985068f40d
Author: Jimmy McCrory <email address hidden>
Date: Tue Jan 12 14:28:25 2016 -0800

    Include MySQL-python in Horizon's venv

    The MySQL-python package is required to use the horizon-manage.py script
    from inside Horizon's venv.

    Change-Id: I4bbcdda966fe9b6db28bc3ba777e986f8e9a4761
    Closes-Bug: #1526728

Changed in openstack-ansible:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/openstack-ansible 13.0.0

This issue was fixed in the openstack/openstack-ansible 13.0.0 release.

Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote :

This issue was fixed in the openstack/openstack-ansible 13.0.0 release.

Revision history for this message
Jesse Pretorius (jesse-pretorius) wrote :

Milestone will be re-added if/when a patch is submitted.

no longer affects: openstack-ansible/liberty
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.