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] 34d78c5827be5b2410003dd76e7273159024650e

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

Backport note to ussuri:
Resolved conflict caused by the keystone::cache class which was added
to puppet-keystone during Victoria cycle.

Conflicts:
	manifests/profile/base/keystone.pp

Backport note to train:
Resolved conflict caused by the following two facters.
 - Usage of absolute class names which was required in stable/train
 - The keystone_resources_managed parameter which was removed during
   Ussuri cycle

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

Closes-Bug: #1964824
Change-Id: I22f8fc7f59b4eeac10c3a274c36daeaa1861fd69
(cherry picked from commit c127941d8f5244847016f7dfc342c5e285f3901b)
(cherry picked from commit 5e8b5d570ddadf00921d9b12eb908940611731c5)
(cherry picked from commit 682f67673e2e02d6c570209ee122b6358eb44b70)
(cherry picked from commit fe51d0a3e20c67c94d0473de99236a1cecf84dab)
This commit is contained in:
Takashi Kajinami 2022-03-15 12:08:06 +09:00 committed by Harald Jensås
parent 09d7754a5f
commit 5dd3c698f3
6 changed files with 244 additions and 18 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
@ -151,14 +161,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)
#
# [*keystone_resources_managed*]
# (Optional) Enable the management of Keystone resources with Puppet.
# Can be disabled if Ansible manages these resources instead of Puppet.
@ -209,11 +217,13 @@ 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),
$keystone_resources_managed = hiera('keystone_resources_managed', true),
# 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) and $keystone_resources_managed {
$sync_db = true
@ -245,7 +255,20 @@ 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':
sync_db => $sync_db,
@ -269,7 +292,7 @@ class tripleo::profile::base::keystone (
notification_topics => union($ceilometer_notification_topics,
$barbican_notification_topics,
$extra_notification_topics),
cache_memcache_servers => $memcached_servers
cache_memcache_servers => $cache_memcache_servers
}
if 'amqp' in [$oslomsg_rpc_proto, $oslomsg_notify_proto]{
@ -304,9 +327,8 @@ 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':
openidc_cache_type => 'memcache',
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

@ -181,6 +181,62 @@ describe 'tripleo::profile::base::keystone' do
is_expected.to contain_class('keystone::cron::token_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').with(
:cache_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').with(
:cache_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').with(
:cache_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').with(
:cache_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