From 78465631321bff442755070f4e3c18c171840dcf Mon Sep 17 00:00:00 2001 From: Christoph Manns Date: Mon, 18 Jun 2018 16:41:03 +0200 Subject: [PATCH] Add a new parameter named cache_server_url If you want to use horizon with a different cacheing backend you may run into problems. E.g. with redis it expects a database after the port. So introducing a new parameter which allows any string as LOCATION solves this problem and maybe a couple of others. Change-Id: Ida54599049f69573d27f477c395f14ae0ec26c3c --- manifests/init.pp | 10 ++++++++++ spec/classes/horizon_init_spec.rb | 17 +++++++++++++++++ templates/local_settings.py.erb | 3 +++ 3 files changed, 30 insertions(+) diff --git a/manifests/init.pp b/manifests/init.pp index 173c0267..17d1c725 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -35,6 +35,11 @@ # (optional) A hash of parameters to enable specific cache options. # Defaults to undef # +# [*cache_server_url*] +# (optional) URL of a cache server. +# This allows arbitary strings to be set as CACHE BACKEND LOCATION. +# Defaults to undef. +# # [*cache_server_ip*] # (optional) Memcached IP address. Can be a string, or an array. # Defaults to undef. @@ -426,6 +431,7 @@ class horizon( $package_ensure = 'present', $cache_backend = 'django.core.cache.backends.locmem.LocMemCache', $cache_options = undef, + $cache_server_url = undef, $cache_server_ip = undef, $cache_server_port = '11211', $horizon_app_links = false, @@ -498,6 +504,10 @@ class horizon( include ::horizon::deps + if $cache_server_url and $cache_server_ip { + fail('Only one of cache_server_url or cache_server_ip can be set.') + } + $hypervisor_defaults = { 'can_set_mount_point' => true, 'can_set_password' => false, diff --git a/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index 4487cfe8..1eda63a8 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -242,6 +242,23 @@ describe 'horizon' do it { is_expected.to contain_exec('refresh_horizon_django_compress') } end + context 'with overridden parameters and cache_server_url' do + before do + params.merge!({ + :cache_server_url => 'redis://:password@10.0.0.1:6379/1', + }) + end + + it 'generates local_settings.py' do + verify_concat_fragment_contents(catalogue, 'local_settings.py', [ + " 'LOCATION': 'redis://:password@10.0.0.1:6379/1',", + ]) + end + + it { is_expected.to contain_exec('refresh_horizon_django_cache') } + it { is_expected.to contain_exec('refresh_horizon_django_compress') } + end + context 'installs python memcache library when cache_backend is set to memcache' do before do params.merge!({ diff --git a/templates/local_settings.py.erb b/templates/local_settings.py.erb index 783054f4..08d59da9 100644 --- a/templates/local_settings.py.erb +++ b/templates/local_settings.py.erb @@ -226,6 +226,9 @@ CACHES = { 'LOCATION': '<%= @cache_server_ip %>:<%= @cache_server_port %>', <% end %> <% end %> + <% if @cache_server_url %> + 'LOCATION': '<%= @cache_server_url %>', + <% end %> } }