Allow bmemcached to be optional for memcache_pool

This allows oslo_cache.memcache_pool to be used without the
python-binary-memcached package being installed, as it is
only required if sasl_enabled is set to True.

Closes-Bug: #1991250
Change-Id: I7e6cc83864be68e946d86b1f4b44847b95ea8b05
This commit is contained in:
Corey Bryant 2022-09-29 11:51:52 -04:00 committed by Felipe Reyes
parent 9c2d9786bd
commit edd10f7a9c
2 changed files with 16 additions and 1 deletions

View File

@ -19,7 +19,13 @@ import functools
from dogpile.cache.backends import memcached as memcached_backend
from oslo_cache import _bmemcache_pool
try:
from oslo_cache import _bmemcache_pool
except ImportError as e:
if str(e) == "No module named 'bmemcached'":
_bmemcache_pool = None
else:
raise
from oslo_cache import _memcache_pool
@ -57,6 +63,8 @@ class PooledMemcachedBackend(memcached_backend.MemcachedBackend):
def __init__(self, arguments):
super(PooledMemcachedBackend, self).__init__(arguments)
if arguments.get('sasl_enabled', False):
if not _bmemcache_pool:
raise ImportError("python-binary-memcached package is missing")
self.client_pool = _bmemcache_pool.BMemcacheClientPool(
self.url,
arguments,

View File

@ -0,0 +1,7 @@
---
fixes:
- |
[`bug 1991250 <https://bugs.launchpad.net/oslo.cache/+bug/1991250>`_]
The python-binary-memcached package is only required if sasl_enabled=True.
When sasl_enabled=False (default), the memcache_pool backend can be used
without the python-binary-memcached package installed.