Some ./run_test.sh flags not working with Django 1.5 (SECRET_KEY)

Bug #1178663 reported by Julie Pichon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Dashboard (Horizon)
Fix Released
High
Gabriel Hurley

Bug Description

When using Django 1.5, some of the run_tests.sh commands that rely on manage.py don't work by default anymore, e.g.

$ ./run_tests.sh --compilemessages
Checking environment.
Environment is up to date.
WARNING:root:No local_settings file found.
ImproperlyConfigured: The SECRET_KEY setting must not be empty.

$ ./run_tests.sh -m startdash mydash
Checking environment.
Environment is up to date.
WARNING:root:No local_settings file found.
Unknown command: 'startdash'
Type 'manage.py help' for usage.

It's unhappy about the lack of SECRET_KEY in openstack_dashboard/settings.py, and one should now have a openstack_dashboard/local/local_settings.py for the commands to work.

We should either make it work out of the box, or update http://docs.openstack.org/developer/horizon/ref/run_tests.html to indicate the new requirement.

Changed in horizon:
importance: Undecided → High
milestone: none → havana-1
status: New → Confirmed
Revision history for this message
Tihomir Trifonov (ttrifonov) wrote :

Having in mind that the intention behind SECRET_KEY is that it it should not be present in the settings, but explicitly requires a manual intervention, to automate testing, a different approach is needed. I see two possible solutions for solving this issue so far:

1. A check in run_tests.sh for local_settings.py, and creating temp file with a SECRET_KEY, which should be removed after test are run. But there is always a probability the tests to be interrupted and the temp file to remain in dir, which might be somehow dangerous. Also this requires write permissions for openstack_dashboard/local dir, which might not work if someone tries to execute run_tests from a pip-installed version. Is it intended to be run that way?
2. To create a new executable - manage-test.py, which will inject a SECRET_KEY if it is missing, and will be used in run_tests.sh only. This is the case when we really want 'SECRET_KEY' to be only manually added from local_settings.py example file...

IMO the automation of SECRET_KEY generation for tests should not leave any traces anywhere, thus needs to be done dynamically, FOR TESTS ONLY.

Changed in horizon:
milestone: havana-1 → havana-2
Changed in horizon:
assignee: nobody → Lin Hua Cheng (lin-hua-cheng)
Changed in horizon:
milestone: havana-2 → havana-3
Revision history for this message
Julie Pichon (jpichon) wrote :

This is also responsible for bug 1188622, breaking the auto-generated API reference docs at http://docs.openstack.org/developer/horizon/ .

Changed in horizon:
assignee: Lin Hua Cheng (lin-hua-cheng) → nobody
Changed in horizon:
assignee: nobody → Victoria Martínez de la Cruz (vkmc)
Revision history for this message
Victoria Martinez de la Cruz (vkmc) wrote :

Another approach would be to set the SECRET_KEY as an environment variable if there is no SECRET_KEY defined in settings.py. This way we make sure that we don't leave permanent traces (in case of failure) and that the system is not exposed.

The thing is, could it cause other issues? (e.g. if its used in production)

Changed in horizon:
assignee: Victoria Martínez de la Cruz (vkmc) → nobody
Revision history for this message
Victoria Martinez de la Cruz (vkmc) wrote :

I checked that the environment variable option is possible and it solves our issue.

It's not just an export in the run_test.sh but it has to be setted in the venv created to run the tests.

A simple way to do this would be to get the value of the SECRET_KEY using the os module like this SECRET_KEY=os.environ.get('SECRET_KEY') from the settings.py file, but we currently set the SECRET_KEY in the local_settings file.

Simon Luo (simon-t)
Changed in horizon:
assignee: nobody → Simon Luo (simon-t)
Changed in horizon:
assignee: Simon Luo (simon-t) → nobody
assignee: nobody → Gabriel Hurley (gabriel-hurley)
Changed in horizon:
status: Confirmed → In Progress
Revision history for this message
Gabriel Hurley (gabriel-hurley) wrote :
Revision history for this message
Ladislav Smola (lsmola) wrote :

This bug is completed right? I see that the patch was merged and there is another bug for further progress.

Julie Pichon (jpichon)
Changed in horizon:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in horizon:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in horizon:
milestone: havana-3 → 2013.2
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.