Allow use of database for Horizon sessions

Database-backed sessions are scalable (using an appropriate database
strategy), persistent, and can be made high-concurrency and
highly-available [0]

Default is off.

[0] http://docs.openstack.org/developer/horizon/topics/deployment.html#database

Co-Authored-By: Vladislav Belogrudov <vladislav.belogrudov@oracle.com>
Closes-Bug: 1618781

Change-Id: Ib68a21397dc020d20e07dcc51d3d0fdc1de102ff
This commit is contained in:
Paul Bourke 2016-09-08 12:49:02 +01:00
parent b10e29281a
commit d3f65a812f
11 changed files with 113 additions and 1 deletions

View File

@ -320,13 +320,18 @@ glance_backend_ceph: "{{ enable_ceph }}"
cinder_backend_ceph: "{{ enable_ceph }}" cinder_backend_ceph: "{{ enable_ceph }}"
####################### #######################
# Nova options # Nova options
####################### #######################
nova_backend_ceph: "{{ enable_ceph }}" nova_backend_ceph: "{{ enable_ceph }}"
nova_backend: "{{ 'rbd' if nova_backend_ceph | bool else 'default' }}" nova_backend: "{{ 'rbd' if nova_backend_ceph | bool else 'default' }}"
#######################
# Horizon options
#######################
horizon_backend_database: "no"
################### ###################
# Ceph options # Ceph options
################### ###################

View File

@ -1,6 +1,13 @@
--- ---
project_name: "horizon" project_name: "horizon"
####################
# Database
####################
horizon_database_name: "horizon"
horizon_database_user: "horizon"
horizon_database_address: "{{ kolla_internal_fqdn }}:{{ database_port }}"
#################### ####################
# Docker # Docker
#################### ####################

View File

@ -0,0 +1,41 @@
---
- name: Creating Horizon database
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m mysql_db
-a "login_host='{{ database_address }}'
login_port='{{ database_port }}'
login_user='{{ database_user }}'
login_password='{{ database_password }}'
name='{{ horizon_database_name }}'"
register: database
changed_when: "{{ database.stdout.find('localhost | SUCCESS => ') != -1 and
(database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
failed_when: database.stdout.split()[2] != 'SUCCESS'
run_once: True
delegate_to: "{{ groups['horizon'][0] }}"
- name: Reading json from variable
set_fact:
database_created: "{{ (database.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
- name: Creating Horizon database user and setting permissions
command: docker exec -t kolla_toolbox /usr/bin/ansible localhost
-m mysql_user
-a "login_host='{{ database_address }}'
login_port='{{ database_port }}'
login_user='{{ database_user }}'
login_password='{{ database_password }}'
name='{{ horizon_database_name }}'
password='{{ horizon_database_password }}'
host='%'
priv='{{ horizon_database_name }}.*:ALL'
append_privs='yes'"
register: database_user_create
changed_when: "{{ database_user_create.stdout.find('localhost | SUCCESS => ') != -1 and
(database_user_create.stdout.split('localhost | SUCCESS => ')[1]|from_json).changed }}"
failed_when: database_user_create.stdout.split()[2] != 'SUCCESS'
run_once: True
delegate_to: "{{ groups['horizon'][0] }}"
- include: bootstrap_service.yml
when: database_created

View File

@ -0,0 +1,19 @@
---
- name: Running Horizon bootstrap container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
detach: False
environment:
KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ horizon_image_full }}"
labels:
BOOTSTRAP:
name: "bootstrap_horizon"
restart_policy: "never"
volumes:
- "{{ node_config_directory }}/horizon/:{{ container_config_directory }}/:ro"
- "kolla_logs:/var/log/kolla/"
run_once: True
delegate_to: "{{ groups['horizon'][0] }}"

View File

@ -3,4 +3,7 @@
- include: register.yml - include: register.yml
- include: bootstrap.yml
when: horizon_backend_database | bool
- include: start.yml - include: start.yml

View File

@ -29,6 +29,20 @@ WEBROOT = '/'
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['*'] ALLOWED_HOSTS = ['*']
{% if horizon_backend_database | bool %}
SESSION_ENGINE = 'django.contrib.sessions.backends.db'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '{{ horizon_database_name }}',
'USER': '{{ horizon_database_user }}',
'PASSWORD': '{{ horizon_database_password }}',
'HOST': '{{ database_address }}',
'PORT': '{{ database_port }}'
}
}
{% endif %}
# Set SSL proxy settings: # Set SSL proxy settings:
# Pass this header from the proxy after terminating the SSL, # Pass this header from the proxy after terminating the SSL,
# and don't forget to strip it from the client's request. # and don't forget to strip it from the client's request.

View File

@ -1,5 +1,16 @@
#!/bin/bash #!/bin/bash
# Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
# of the KOLLA_BOOTSTRAP variable being set, including empty.
if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
MANAGE_PY="/usr/bin/python /usr/bin/manage.py"
if [[ -f "/var/lib/kolla/venv/bin/python" ]]; then
MANAGE_PY="/var/lib/kolla/venv/bin/python /var/lib/kolla/venv/bin/manage.py"
fi
$MANAGE_PY syncdb --noinput
exit 0
fi
# NOTE(pbourke): httpd will not clean up after itself in some cases which # NOTE(pbourke): httpd will not clean up after itself in some cases which
# results in the container not being able to restart. (bug #1489676, 1557036) # results in the container not being able to restart. (bug #1489676, 1557036)
if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then if [[ "${KOLLA_BASE_DISTRO}" =~ debian|ubuntu ]]; then

View File

@ -197,6 +197,7 @@ ENV DEBIAN_FRONTEND noninteractive
'libxslt-devel', 'libxslt-devel',
'libyaml-devel', 'libyaml-devel',
'MariaDB-devel', 'MariaDB-devel',
'MySQL-python',
'openldap-devel', 'openldap-devel',
'openssl-devel', 'openssl-devel',
'postgresql', 'postgresql',

View File

@ -192,6 +192,12 @@ kolla_internal_vip_address: "10.10.10.254"
#nova_backend_ceph: "{{ enable_ceph }}" #nova_backend_ceph: "{{ enable_ceph }}"
#######################
# Horizon options
#######################
#horizon_backend_database: "no"
####################################### #######################################
# Manila - Shared File Systems Options # Manila - Shared File Systems Options
####################################### #######################################

View File

@ -82,6 +82,7 @@ congress_keystone_password:
rally_database_password: rally_database_password:
horizon_secret_key: horizon_secret_key:
horizon_database_password:
telemetry_secret_key: telemetry_secret_key:

View File

@ -0,0 +1,4 @@
---
features:
- Allow the use of a database backend for Horizon
sessions.