Generalize common options

... to avoid implementing specific options when adding a new backend,
and simplify configuration interface as much as possible.

Change-Id: I909d9fa27c7457e1b17034b221bdb1e5e825baed
Signed-off-by: Takashi Kajinami <kajinamit@oss.nttdata.com>
This commit is contained in:
Takashi Kajinami
2026-01-28 00:25:56 +09:00
parent 54cde900bb
commit 6d34bf005f
3 changed files with 59 additions and 44 deletions

View File

@@ -147,15 +147,6 @@ FILE_OPTIONS = {
'oslo_cache.memcache_pool backends only).'
),
),
cfg.FloatOpt(
'memcache_socket_timeout',
default=1.0,
help=(
'Timeout in seconds for every call to a server. '
'(dogpile.cache.memcache and oslo_cache.memcache_pool '
'backends only).'
),
),
cfg.IntOpt(
'memcache_pool_maxsize',
default=10,
@@ -199,15 +190,6 @@ FILE_OPTIONS = {
'Layer) if the SASL_enable is true, else disable.'
),
),
cfg.StrOpt(
'memcache_username',
help='the user name for the memcached which SASL enabled',
),
cfg.StrOpt(
'memcache_password',
secret=True,
help='the password for the memcached which SASL enabled',
),
cfg.StrOpt(
'redis_server',
default='localhost:6379',
@@ -216,29 +198,33 @@ FILE_OPTIONS = {
cfg.IntOpt(
'redis_db', default=0, min=0, help='Database id in Redis server'
),
cfg.StrOpt('redis_username', help='the user name for redis'),
cfg.StrOpt(
'redis_password', secret=True, help='the password for redis'
),
cfg.ListOpt(
'redis_sentinels',
default=['localhost:26379'],
help='Redis sentinel servers in the format of "host:port"',
),
cfg.FloatOpt(
'redis_socket_timeout',
default=1.0,
help=(
'Timeout in seconds for every call to a server. '
'(dogpile.cache.redis and dogpile.cache.redis_sentinel '
'backends only).'
),
),
cfg.StrOpt(
'redis_sentinel_service_name',
default='mymaster',
help='Service name of the redis sentinel cluster.',
),
cfg.StrOpt(
'username',
help='the user name for authentication to backend.',
deprecated_opts=[
cfg.DeprecatedOpt('memcache_username', group='cache'),
cfg.DeprecatedOpt('redis_username', group='cache'),
],
),
cfg.StrOpt(
'password',
secret=True,
help='the password for authentication to backend.',
deprecated_opts=[
cfg.DeprecatedOpt('memcache_password', group='cache'),
cfg.DeprecatedOpt('redis_password', group='cache'),
],
),
cfg.BoolOpt(
'tls_enabled',
default=False,
@@ -297,6 +283,20 @@ FILE_OPTIONS = {
'``oslo_cache.memcache_pool``.'
),
),
cfg.FloatOpt(
'socket_timeout',
default=1.0,
deprecated_opts=[
cfg.DeprecatedOpt('memcache_socket_timeout', group='cache'),
cfg.DeprecatedOpt('redis_socket_timeout', group='cache'),
],
help=(
'Timeout in seconds for every call to a server. '
'Currently supported by ``dogpile.cache.memcache``, '
'``oslo_cache.memcache_pool``, ``dogpile.cache.redis`` '
'and ``dogpile.cache.redis_sentinel``.'
),
),
cfg.BoolOpt(
'enable_socket_keepalive',
default=False,

View File

@@ -170,18 +170,16 @@ def _build_cache_config(conf: cfg.ConfigOpts) -> dict[str, Any]:
_LOG.debug('Oslo Cache Config: %s', conf_dict)
if conf.cache.backend == 'dogpile.cache.redis':
if conf.cache.redis_password is None:
if conf.cache.password is None:
netloc = conf.cache.redis_server
else:
if conf.cache.redis_username:
if conf.cache.username:
netloc = (
f'{conf.cache.redis_username}:{conf.cache.redis_password}'
f'{conf.cache.username}:{conf.cache.password}'
f'@{conf.cache.redis_server}'
)
else:
netloc = (
f':{conf.cache.redis_password}@{conf.cache.redis_server}'
)
netloc = f':{conf.cache.password}@{conf.cache.redis_server}'
parts = urllib.parse.ParseResult(
scheme=('rediss' if conf.cache.tls_enabled else 'redis'),
@@ -195,13 +193,15 @@ def _build_cache_config(conf: cfg.ConfigOpts) -> dict[str, Any]:
conf_dict.setdefault(
f'{prefix}.arguments.url', urllib.parse.urlunparse(parts)
)
for arg in ('socket_timeout',):
value = getattr(conf.cache, 'redis_' + arg)
conf_dict[f'{prefix}.arguments.{arg}'] = value
conf_dict[f'{prefix}.arguments.socket_timeout'] = (
conf.cache.socket_timeout
)
elif conf.cache.backend == 'dogpile.cache.redis_sentinel':
for arg in ('username', 'password', 'socket_timeout', 'db'):
value = getattr(conf.cache, 'redis_' + arg)
conf_dict[f'{prefix}.arguments.{arg}'] = value
for arg in ('username', 'password', 'socket_timeout'):
conf_dict[f'{prefix}.arguments.{arg}'] = getattr(conf.cache, arg)
conf_dict[f'{prefix}.arguments.db'] = conf.cache.redis_db
conf_dict[f'{prefix}.arguments.service_name'] = (
conf.cache.redis_sentinel_service_name
)
@@ -238,8 +238,14 @@ def _build_cache_config(conf: cfg.ConfigOpts) -> dict[str, Any]:
)
for arg in (
'dead_retry',
'socket_timeout',
'username',
'password',
):
conf_dict[f'{prefix}.arguments.{arg}'] = getattr(conf.cache, arg)
for arg in (
'dead_retry',
'pool_maxsize',
'pool_unused_timeout',
'pool_connection_get_timeout',

View File

@@ -0,0 +1,9 @@
---
deprecations:
- |
The following ``[cache]`` options have been deprecated
- ``memcache_username`` and ``redis_username`` (Use ``username``)
- ``memcache_password`` and ``redis_password`` (Use ``password``)
- ``memcache_socket_timeout`` and ``redis_socket_timeout``
(Use ``socket_timeout``)