From 8b268d75cea23667ae5bf666cfa35c7ee606bea7 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 31 Jul 2022 00:08:36 +0900 Subject: [PATCH] Accept array for cache_server_url ... so that we can specify multiple backend servers. Change-Id: Iea01d1c5202890110c33341cedee4b5bc1ba324c --- spec/classes/horizon_init_spec.rb | 19 ++++++++++++++++++- templates/local_settings.py.erb | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spec/classes/horizon_init_spec.rb b/spec/classes/horizon_init_spec.rb index c2622725..b46ebd73 100644 --- a/spec/classes/horizon_init_spec.rb +++ b/spec/classes/horizon_init_spec.rb @@ -254,7 +254,7 @@ describe 'horizon' do it { is_expected.to contain_exec('refresh_horizon_django_compress') } end - context 'with overridden parameters and cache_server_url' do + context 'with overridden parameters and cache_server_url (string)' do before do params.merge!({ :cache_server_url => 'redis://:password@10.0.0.1:6379/1', @@ -271,6 +271,23 @@ describe 'horizon' do it { is_expected.to contain_exec('refresh_horizon_django_compress') } end + context 'with overridden parameters and cache_server_url (array)' do + before do + params.merge!({ + :cache_server_url => ['192.0.2.1:11211', '192.0.2.2:11211'], + }) + end + + it 'generates local_settings.py' do + verify_concat_fragment_contents(catalogue, 'local_settings.py', [ + " 'LOCATION': ['192.0.2.1:11211','192.0.2.2:11211'],", + ]) + 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 6daaa501..92076a32 100644 --- a/templates/local_settings.py.erb +++ b/templates/local_settings.py.erb @@ -243,7 +243,11 @@ CACHES = { <%- end -%> <%- end -%> <%- if @cache_server_url -%> + <%- if @cache_server_url.kind_of?(Array) -%> + 'LOCATION': ['<%= @cache_server_url.join("','") %>'], + <%- else -%> 'LOCATION': '<%= @cache_server_url %>', + <%- end -%> <%- end -%> } }