Format [oslo_cache] memcache_server when IPv6 is used

When Memcached uses IPv6 network, python-memcached requires that each
server name is formatted as is described in the following example.
 inet6:[<host>]:<port>

This change ensures the format is properly applied according to
the IP protocol version and cache backend used.

Note that the parameter in keystone was not properly formatted even
when IPs are used to set the parameter. This change fixes that and
ensure the parameter is properly configured.

Also, this change fixes the timing to apply any2array. The function
should be applied before we check the first memcache server by [0],
otherwise the logic to detect IPv6 address does not work as intended.

Backport note to victoria:
Resolved conflict caused by [1]. Also the keystone manifest is modified
to make the implementation consistent with the other two manifests.

[1] 34d78c5827

Conflicts:
	manifests/profile/base/heat.pp
	manifests/profile/base/nova.pp

Closes-Bug: #1964824
Change-Id: I22f8fc7f59b4eeac10c3a274c36daeaa1861fd69
(cherry picked from commit c127941d8f)
(cherry picked from commit 5e8b5d570d)
This commit is contained in:
Takashi Kajinami 2022-03-15 12:08:06 +09:00
parent 90f8544576
commit 682f67673e
6 changed files with 244 additions and 17 deletions

View File

@ -87,6 +87,14 @@
# (Optional) Memcached port to use.
# Defaults to hiera('memcached_port', 11211)
#
# [*memcached_ipv6*]
# (Optional) Whether Memcached uses IPv6 network instead of IPv4 network.
# Defauls to hiera('memcached_ipv6', false)
#
# [*cache_backend*]
# (Optional) oslo.cache backend used for caching.
# Defaults to hiera('heat::cache::backend', false)
#
# DEPRECATED PARAMETERS
#
# [*memcached_ips*]
@ -111,10 +119,12 @@ class tripleo::profile::base::heat (
$oslomsg_notify_use_ssl = hiera('oslo_messaging_notify_use_ssl', '0'),
$memcached_hosts = hiera('memcached_node_names', []),
$memcached_port = hiera('memcached_port', 11211),
$memcached_ipv6 = hiera('memcached_ipv6', false),
$cache_backend = hiera('heat::cache::backend', false),
# DEPRECATED PARAMETERS
$memcached_ips = undef
) {
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
$memcached_hosts_real = any2array(pick($memcached_ips, $memcached_hosts))
include tripleo::profile::base::heat::authtoken
@ -152,14 +162,22 @@ class tripleo::profile::base::heat (
include heat::cors
include heat::logging
if is_ipv6_address($memcached_hosts_real[0]) {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
if $memcached_ipv6 or is_ipv6_address($memcached_hosts_real[0]) {
if $cache_backend in ['oslo_cache.memcache_pool', 'dogpile.cache.memcached'] {
# NOTE(tkajinm): The inet6 prefix is required for backends using
# python-memcached
$cache_memcache_servers = $memcached_hosts_real.map |$server| { "inet6:[${server}]:${memcached_port}" }
} else {
# NOTE(tkajinam): The other backends like pymemcache don't require
# the inet6 prefix
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
class { 'heat::cache':
memcache_servers => $memcache_servers
memcache_servers => $cache_memcache_servers
}
}

View File

@ -162,6 +162,14 @@
# (Optional) Memcached port to use.
# Defaults to hiera('memcached_port', 11211)
#
# [*memcached_ipv6*]
# (Optional) Whether Memcached uses IPv6 network instead of IPv4 network.
# Defauls to hiera('memcached_ipv6', false)
#
# [*cache_backend*]
# (Optional) oslo.cache backend used for caching.
# Defaults to hiera('keystone::cache::backend', false)
#
# DEPRECATED PARAMETERS
#
# [*memcached_ips*]
@ -202,10 +210,12 @@ class tripleo::profile::base::keystone (
$keystone_openidc_enabled = hiera('keystone_openidc_enabled', false),
$memcached_hosts = hiera('memcached_node_names', []),
$memcached_port = hiera('memcached_port', 11211),
$memcached_ipv6 = hiera('memcached_ipv6', false),
$cache_backend = hiera('keystone::cache::backend', false),
# DEPRECATED PARAMETERS
$memcached_ips = undef
) {
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
$memcached_hosts_real = any2array(pick($memcached_ips, $memcached_hosts))
if $bootstrap_node and $::hostname == downcase($bootstrap_node) {
$sync_db = true
@ -231,10 +241,23 @@ class tripleo::profile::base::keystone (
if $step >= 4 or ( $step >= 3 and $sync_db ) {
$oslomsg_rpc_use_ssl_real = sprintf('%s', bool2num(str2bool($oslomsg_rpc_use_ssl)))
$oslomsg_notify_use_ssl_real = sprintf('%s', bool2num(str2bool($oslomsg_notify_use_ssl)))
$memcached_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
if $memcached_ipv6 or is_ipv6_address($memcached_hosts_real[0]) {
if $cache_backend in ['oslo_cache.memcache_pool', 'dogpile.cache.memcached'] {
# NOTE(tkajinm): The inet6 prefix is required for backends using
# python-memcached
$cache_memcache_servers = $memcached_hosts_real.map |$server| { "inet6:[${server}]:${memcached_port}" }
} else {
# NOTE(tkajinam): The other backends like pymemcache don't require
# the inet6 prefix
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
} else {
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
class { 'keystone::cache':
memcache_servers => $memcached_servers,
memcache_servers => $cache_memcache_servers
}
class { 'keystone':
@ -290,7 +313,7 @@ class tripleo::profile::base::keystone (
}
if $keystone_openidc_enabled {
$memcached_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
class { 'keystone::federation::openidc':
memcached_servers => $memcached_servers,
}

View File

@ -82,6 +82,14 @@
# (Optional) Memcached port to use.
# Defaults to hiera('memcached_port', 11211)
#
# [*memcached_ipv6*]
# (Optional) Whether Memcached uses IPv6 network instead of IPv4 network.
# Defauls to hiera('memcached_ipv6', false)
#
# [*cache_backend*]
# (Optional) oslo.cache backend used for caching.
# Defaults to hiera('nova::cache::backend', false)
#
# DEPRECATED PARAMETERS
#
# [*memcached_ips*]
@ -105,10 +113,12 @@ class tripleo::profile::base::nova (
$step = Integer(hiera('step')),
$memcached_hosts = hiera('memcached_node_names', []),
$memcached_port = hiera('memcached_port', 11211),
$memcached_ipv6 = hiera('memcached_ipv6', false),
$cache_backend = hiera('nova::cache::backend', false),
# DEPRECATED PARAMETERS
$memcached_ips = undef
) {
$memcached_hosts_real = pick($memcached_ips, $memcached_hosts)
$memcached_hosts_real = any2array(pick($memcached_ips, $memcached_hosts))
if $bootstrap_node and $::hostname == downcase($bootstrap_node) {
$sync_db = true
@ -116,12 +126,6 @@ class tripleo::profile::base::nova (
$sync_db = false
}
if is_ipv6_address($memcached_hosts_real[0]) {
$memcache_servers = prefix(suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}"), 'inet6:')
} else {
$memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
if $step >= 4 or ($step >= 3 and $sync_db) {
$oslomsg_rpc_use_ssl_real = sprintf('%s', bool2num(str2bool($oslomsg_rpc_use_ssl)))
$oslomsg_notify_use_ssl_real = sprintf('%s', bool2num(str2bool($oslomsg_notify_use_ssl)))
@ -130,10 +134,25 @@ class tripleo::profile::base::nova (
} else {
$oslomsg_rpc_hosts_real = $oslomsg_rpc_hosts
}
if $memcached_ipv6 or is_ipv6_address($memcached_hosts_real[0]) {
if $cache_backend in ['oslo_cache.memcache_pool', 'dogpile.cache.memcached'] {
# NOTE(tkajinm): The inet6 prefix is required for backends using
# python-memcached
$cache_memcache_servers = $memcached_hosts_real.map |$server| { "inet6:[${server}]:${memcached_port}" }
} else {
# NOTE(tkajinam): The other backends like pymemcache don't require
# the inet6 prefix
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
} else {
$cache_memcache_servers = suffix(any2array(normalize_ip_for_uri($memcached_hosts_real)), ":${memcached_port}")
}
include nova::config
include nova::logging
class { 'nova::cache':
memcache_servers => $memcache_servers,
memcache_servers => $cache_memcache_servers
}
class { 'nova':
default_transport_url => os_transport_url({

View File

@ -152,6 +152,62 @@ eos
is_expected.to_not contain_class('heat::cron::purge_deleted')
end
end
context 'with step 4 and memcache ipv6' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('heat::cache').with(
:memcache_servers => ['[::1]:11211']
)
end
end
context 'with step 4, memcache ipv6 and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('heat::cache').with(
:memcache_servers => ['inet6:[::1]:11211']
)
end
end
context 'with step 4 and the ipv6 parameter' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('heat::cache').with(
:memcache_servers => ['node.example.com:11211']
)
end
end
context 'with step 4, the ipv6 parameter and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('heat::cache').with(
:memcache_servers => ['inet6:[node.example.com]:11211']
)
end
end
end
on_supported_os.each do |os, facts|

View File

@ -187,6 +187,62 @@ describe 'tripleo::profile::base::keystone' do
is_expected.to contain_class('keystone::cron::trust_flush')
end
end
context 'with step 4 and memcache ipv6' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('keystone::cache').with(
:memcache_servers => ['[::1]:11211']
)
end
end
context 'with step 4, memcache ipv6 and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('keystone::cache').with(
:memcache_servers => ['inet6:[::1]:11211']
)
end
end
context 'with step 4 and the ipv6 parameter' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('keystone::cache').with(
:memcache_servers => ['node.example.com:11211']
)
end
end
context 'with step 4, the ipv6 parameter and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('keystone::cache').with(
:memcache_servers => ['inet6:[node.example.com]:11211']
)
end
end
end
on_supported_os.each do |os, facts|

View File

@ -107,6 +107,61 @@ describe 'tripleo::profile::base::nova' do
}
end
context 'with step 4 and memcache ipv6' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('nova::cache').with(
:memcache_servers => ['[::1]:11211']
)
end
end
context 'with step 4, memcache ipv6 and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => '::1',
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('nova::cache').with(
:memcache_servers => ['inet6:[::1]:11211']
)
end
end
context 'with step 4 and the ipv6 parameter' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('nova::cache').with(
:memcache_servers => ['node.example.com:11211']
)
end
end
context 'with step 4, the ipv6 parameter and memcached backend' do
let(:params) { {
:step => 4,
:memcached_hosts => 'node.example.com',
:memcached_ipv6 => true,
:cache_backend => 'dogpile.cache.memcached',
} }
it 'should format the memcache_server parameter' do
is_expected.to contain_class('nova::cache').with(
:memcache_servers => ['inet6:[node.example.com]:11211']
)
end
end
end