Add inet6 prefix only when MemcacheCache is used

inet6 prefix is required only by python-memcached and it should NOT be
added when a different backend like PyMemcacheCache is used.

Closes-Bug: #1983182
Change-Id: Iee260f8578ed6c473c651e0665a548c68e94c954
This commit is contained in:
Takashi Kajinami 2022-07-31 00:22:22 +09:00
parent aac496aa1b
commit 94422e6dcc
2 changed files with 30 additions and 5 deletions

View File

@ -665,7 +665,11 @@ and usage of a quoted value is deprecated.')
} }
if $cache_server_ip { if $cache_server_ip {
if $cache_backend =~ /\.MemcachedCache$/ {
$cache_server_ip_real = inet6_prefix($cache_server_ip) $cache_server_ip_real = inet6_prefix($cache_server_ip)
} else {
$cache_server_ip_real = normalize_ip_for_uri($cache_server_ip)
}
} }
$hypervisor_defaults = { $hypervisor_defaults = {
@ -737,7 +741,7 @@ and usage of a quoted value is deprecated.')
validate_legacy(Enum['legacy', 'angular'], 'validate_re', $images_panel, [['^legacy$', '^angular$']]) validate_legacy(Enum['legacy', 'angular'], 'validate_re', $images_panel, [['^legacy$', '^angular$']])
validate_legacy(Stdlib::Absolutepath, 'validate_absolute_path', $root_path) validate_legacy(Stdlib::Absolutepath, 'validate_absolute_path', $root_path)
if $manage_memcache_package and $cache_backend =~ /MemcachedCache/ { if $manage_memcache_package and $cache_backend =~ /\.MemcachedCache$/ {
ensure_packages('python-memcache', { ensure_packages('python-memcache', {
name => $::horizon::params::memcache_package, name => $::horizon::params::memcache_package,
tag => ['openstack'], tag => ['openstack'],

View File

@ -93,7 +93,7 @@ describe 'horizon' do
context 'with overridden parameters' do context 'with overridden parameters' do
before do before do
params.merge!({ params.merge!({
:cache_backend => 'horizon.backends.memcached.HorizonMemcached', :cache_backend => 'django.core.cache.backends.memcached.MemcachedCache',
:cache_options => {'SOCKET_TIMEOUT' => 1,'SERVER_RETRIES' => 1,'DEAD_RETRY' => 1}, :cache_options => {'SOCKET_TIMEOUT' => 1,'SERVER_RETRIES' => 1,'DEAD_RETRY' => 1},
:cache_server_ip => '10.0.0.1', :cache_server_ip => '10.0.0.1',
:django_session_engine => 'django.contrib.sessions.backends.cache', :django_session_engine => 'django.contrib.sessions.backends.cache',
@ -160,7 +160,7 @@ describe 'horizon' do
" 'DEAD_RETRY': 1,", " 'DEAD_RETRY': 1,",
" 'SERVER_RETRIES': 1,", " 'SERVER_RETRIES': 1,",
" 'SOCKET_TIMEOUT': 1,", " 'SOCKET_TIMEOUT': 1,",
" 'BACKEND': 'horizon.backends.memcached.HorizonMemcached',", " 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',",
" 'LOCATION': '10.0.0.1:11211',", " 'LOCATION': '10.0.0.1:11211',",
'SESSION_ENGINE = "django.contrib.sessions.backends.cache"', 'SESSION_ENGINE = "django.contrib.sessions.backends.cache"',
'OPENSTACK_KEYSTONE_URL = "https://keystone.example.com:4682"', 'OPENSTACK_KEYSTONE_URL = "https://keystone.example.com:4682"',
@ -237,15 +237,17 @@ describe 'horizon' do
it { is_expected.to contain_exec('refresh_horizon_django_compress') } it { is_expected.to contain_exec('refresh_horizon_django_compress') }
end end
context 'with overridden parameters and IPv6 cache_server_ip array' do context 'with overridden parameters, IPv6 cache_server_ip array and MemcachedCache' do
before do before do
params.merge!({ params.merge!({
:cache_backend => 'django.core.cache.backends.memcached.MemcachedCache',
:cache_server_ip => ['fd12:3456:789a:1::1','fd12:3456:789a:1::2'], :cache_server_ip => ['fd12:3456:789a:1::1','fd12:3456:789a:1::2'],
}) })
end end
it 'generates local_settings.py' do it 'generates local_settings.py' do
verify_concat_fragment_contents(catalogue, 'local_settings.py', [ verify_concat_fragment_contents(catalogue, 'local_settings.py', [
" 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',",
" 'LOCATION': [ 'inet6:[fd12:3456:789a:1::1]:11211','inet6:[fd12:3456:789a:1::2]:11211', ],", " 'LOCATION': [ 'inet6:[fd12:3456:789a:1::1]:11211','inet6:[fd12:3456:789a:1::2]:11211', ],",
]) ])
end end
@ -254,6 +256,25 @@ describe 'horizon' do
it { is_expected.to contain_exec('refresh_horizon_django_compress') } it { is_expected.to contain_exec('refresh_horizon_django_compress') }
end end
context 'with overridden parameters, IPv6 cache_server_ip array and PyMemcacheCache' do
before do
params.merge!({
:cache_backend => 'django.core.cache.backends.memcached.PyMemcacheCache',
:cache_server_ip => ['fd12:3456:789a:1::1','fd12:3456:789a:1::2'],
})
end
it 'generates local_settings.py' do
verify_concat_fragment_contents(catalogue, 'local_settings.py', [
" 'BACKEND': 'django.core.cache.backends.memcached.PyMemcacheCache',",
" 'LOCATION': [ '[fd12:3456:789a:1::1]:11211','[fd12:3456:789a:1::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 'with overridden parameters and cache_server_url (string)' do context 'with overridden parameters and cache_server_url (string)' do
before do before do
params.merge!({ params.merge!({