Setting up Horizon with PyCharm

Author:
Email: jonas.pfannschmidt at gmail.com
Date: 19/05/2015

Introduction

The following is a short description on how to setup OpenStack Horizon in PyCharm. Unfortunately Django, the web-framework used by Horizon, is only supported in PyCharm Professional - The community edition is not sufficient.

A prerequisite is a running OpenStack installation. Horizon needs at least Keystone to communiacte to, although other services are needed as well to do anything useful. My recommendation is to use a devstack installation in a virtual machine. The development Horizon will still run on the local machine but it will point the Keystone within the devstack VM.

Development environment - Step by step

  1. Clone the horizon repository: git clone https://github.com/openstack/horizon.git
  2. From the cloned directory, run: ./runtests.sh. This will create a virtual environment and run all tests against that environment.
  3. Create the file local_settings.py from the example provided by Horizon: cp openstack_dashboard/local/local_settings.py.example openstack_dashboard/local/local_settings.py
  4. Open the file openstack_dashboard/local/local_settings.py and search for OPENSTACK_HOST. Change this variable to point to your local devstack installation.
  5. Start PyCharm
  6. Click Create New Project
  7. Cick Django
  8. Point Location at your checked out horizon repository
  9. Click the gear-wheel icon next to Interpreter → Add Local and point to the interpreter in the virtual environment (Should be at: horizon/.venv/bin/python)
  10. Click File → Settings → Languages & Frameworks → Django and fill out the fields as in the screenshot below.
  11. Run Horizon by clicking on the Run icon or the Debug icon at the top right corner.
  12. Horizon should now be aviable under http://localhost:8001

Enable debug logging to the console

By default Horizon logs all messages with INFO level or higher to the console. For development purposes it makes sense to change this to DEBUG. This can be changed in the file openstack_dashboard/local/local_settings.py. In this file, search for LOGGING and change the console handler to DEBUG.

...
LOGGING = {
    'version': 1,
    # When set to True this will disable all logging except
    # for loggers specified in this configuration dictionary. Note that
    # if nothing is specified here and disable_existing_loggers is True,
    # django.db.backends will still log unless it is disabled explicitly.
    'disable_existing_loggers': False,
    'handlers': {
        'null': {
            'level': 'DEBUG',
            'class': 'django.utils.log.NullHandler',
        },
        'console': {
            # Set the level to "DEBUG" for verbose output logging.
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
        },
    },
...