Add cache_backend and cache_options params

* It will allow to configure horizon cache
    backend and its options in local_settings.py
  * Add tests for cache_backend and cache_options
  * Change default value of cache_server_ip to undef.
    At the moment master of horizon has default value of backend
    to: django.core.cache.backends.locmem.LocMemCache [0]
    while our template generates config with default:
    django.core.cache.backends.memcached.MemcachedCache

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

Change-Id: I7484727fd2af26d47bc0f59e59b7f6f75daf1092
Related-Bug: #1441522
This commit is contained in:
vsaienko 2015-06-11 11:44:31 +03:00 committed by Sergii Golovatiuk
parent ada3d4f548
commit e202d4e4d1
3 changed files with 28 additions and 9 deletions

View File

@ -34,9 +34,17 @@
# [*package_ensure*]
# (optional) Package ensure state. Defaults to 'present'.
#
# [*cache_backend*]
# (optional) Horizon cache backend.
# Defaults: 'django.core.cache.backends.locmem.LocMemCache'
#
# [*cache_options*]
# (optional) A hash of parameters to enable specific cache options.
# Defaults to undef
#
# [*cache_server_ip*]
# (optional) Memcached IP address. Can be a string, or an array.
# Defaults to '127.0.0.1'.
# Defaults to undef.
#
# [*cache_server_port*]
# (optional) Memcached port. Defaults to '11211'.
@ -216,7 +224,9 @@ class horizon(
$secret_key,
$fqdn = undef,
$package_ensure = 'present',
$cache_server_ip = '127.0.0.1',
$cache_backend = 'django.core.cache.backends.locmem.LocMemCache',
$cache_options = undef,
$cache_server_ip = undef,
$cache_server_port = '11211',
$horizon_app_links = false,
$keystone_url = 'http://127.0.0.1:5000/v2.0',

View File

@ -83,6 +83,8 @@ describe 'horizon' do
context 'with overridden parameters' do
before do
params.merge!({
:cache_backend => 'horizon.backends.memcached.HorizonMemcached',
:cache_options => {'SOCKET_TIMEOUT' => 1,'SERVER_RETRIES' => 1,'DEAD_RETRY' => 1},
:cache_server_ip => '10.0.0.1',
:django_session_engine => 'django.contrib.sessions.backends.cache',
:keystone_default_role => 'SwiftOperator',
@ -110,6 +112,10 @@ describe 'horizon' do
'CSRF_COOKIE_SECURE = True',
'SESSION_COOKIE_SECURE = True',
"SECRET_KEY = 'elj1IWiLoWHgcyYxFVLj7cM5rGOOxWl0'",
" 'DEAD_RETRY': 1,",
" 'SERVER_RETRIES': 1,",
" 'SOCKET_TIMEOUT': 1,",
" 'BACKEND': 'horizon.backends.memcached.HorizonMemcached',",
" 'LOCATION': '10.0.0.1:11211',",
'SESSION_ENGINE = "django.contrib.sessions.backends.cache"',
'OPENSTACK_KEYSTONE_URL = "https://keystone.example.com:4682"',

View File

@ -118,18 +118,21 @@ SECRET_KEY = '<%= @secret_key %>'
CACHES = {
'default': {
<% if @cache_server_ip %>
# 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
<% if @cache_options.kind_of?(Hash) %>
'OPTIONS': {
<% @cache_options.sort.each do |opt_name,opt_val| -%>
'<%= opt_name -%>': <%= opt_val -%>,
<% end -%>},
<% end -%>
'BACKEND': '<%= @cache_backend %>',
<% if @cache_server_ip %>
<% if @cache_server_ip.kind_of?(Array) %>
<% split = ":" + @cache_server_port + "','" %>
'LOCATION': [ <% @cache_server_ip.each do |ip| -%>'<%= ip -%>:<%= @cache_server_port -%>',<% end -%> ],
<% else %>
<% else %>
'LOCATION': '<%= @cache_server_ip %>:<%= @cache_server_port %>',
<% end %>
<% else %>
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
<% end %>
<% end %>
}
}