Remove deprecated "memcached_server" in Default section

The 'memcached_server' option in DEFAULT section which was deprecated in
Mitaka has been completely removed in Newton. This has been replaced by
options from oslo cache section.

Change-Id: I0b23fd65a04de6a35e8ce9efd1110caad63ad562
This commit is contained in:
Hieu LE 2016-05-12 18:12:00 +07:00
parent 80fa358e86
commit 505bc44615
5 changed files with 12 additions and 93 deletions

View File

@ -4,7 +4,6 @@ wrap_width = 79
namespace = nova
namespace = nova.conf
namespace = nova.api
namespace = nova.cache_utils
namespace = nova.cells
namespace = nova.compute
namespace = nova.network

View File

@ -16,87 +16,34 @@
"""Super simple fake memcache client."""
import copy
from oslo_cache import core as cache
from oslo_config import cfg
from nova.i18n import _
# NOTE(dims): There are many copies of memcache_opts with memcached_servers
# in various projects as this used to be in a copy of memory_cache.py
# Since we are making a change in just our copy, oslo-config-generator fails
# with cfg.DuplicateOptError unless we override the comparison check
class _DeprecatedListOpt(cfg.ListOpt):
def __ne__(self, another):
self_dict = copy.deepcopy(vars(self))
another_dict = copy.deepcopy(vars(another))
self_dict.pop('help')
self_dict.pop('deprecated_for_removal')
another_dict.pop('help')
another_dict.pop('deprecated_for_removal')
return self_dict != another_dict
memcache_opts = [
_DeprecatedListOpt('memcached_servers',
help='DEPRECATED: Memcached servers or None for in '
'process cache. "memcached_servers" opt is '
'deprecated in Mitaka. In Newton release '
'oslo.cache config options should be used as '
'this option will be removed. Please add a '
'[cache] group in your nova.conf file and '
'add "enable" and "memcache_servers" option in '
'this section.',
deprecated_for_removal=True),
]
CONF = cfg.CONF
CONF.register_opts(memcache_opts)
WEEK = 604800
def list_opts():
"""Entry point for oslo-config-generator."""
return [(None, copy.deepcopy(memcache_opts))]
def get_memcached_client(expiration_time=0):
"""Used ONLY when memcached is explicitly needed."""
# If the operator uses the old style [DEFAULT]/memcached_servers
# then we just respect that setting
if CONF.memcached_servers:
return CacheClient(
_get_custom_cache_region(expiration_time=expiration_time,
backend='dogpile.cache.memcached',
url=CONF.memcached_servers))
# If the operator still uses the new style [cache]/memcache_servers
# and has [cache]/enabled flag on then we let oslo_cache configure
# the region from the configuration settings
elif CONF.cache.enabled and CONF.cache.memcache_servers:
# If the operator has [cache]/enabled flag on then we let oslo_cache
# configure the region from the configuration settings
if CONF.cache.enabled and CONF.cache.memcache_servers:
return CacheClient(
_get_default_cache_region(expiration_time=expiration_time))
raise RuntimeError(_('memcached_servers not defined'))
def get_client(expiration_time=0):
"""Used to get a caching client."""
# If the operator still uses the old style [DEFAULT]/memcached_servers
# then we just respect that setting
if CONF.memcached_servers:
return CacheClient(
_get_custom_cache_region(expiration_time=expiration_time,
backend='dogpile.cache.memcached',
url=CONF.memcached_servers))
# If the operator has [cache]/enabled flag on then we let oslo_cache
# configure the region from configuration settings.
elif CONF.cache.enabled:
if CONF.cache.enabled:
return CacheClient(
_get_default_cache_region(expiration_time=expiration_time))
# If [cache]/enabled flag is off and [DEFAULT]/memcached_servers is
# absent we use the dictionary backend
# If [cache]/enabled flag is off, we use the dictionary backend
return CacheClient(
_get_custom_cache_region(expiration_time=expiration_time,
backend='oslo_cache.dict'))

View File

@ -28,8 +28,7 @@ class MemcachedServiceGroupTestCase(test.NoDBTestCase):
super(MemcachedServiceGroupTestCase, self).setUp()
self.mc_client = mock.MagicMock()
mgc_mock.return_value = self.mc_client
self.flags(memcached_servers='ignored',
servicegroup_driver='mc')
self.flags(servicegroup_driver='mc')
self.servicegroup_api = servicegroup.API()
def test_is_up(self):

View File

@ -33,16 +33,10 @@ class TestOsloCache(test.NoDBTestCase):
self.assertIsNotNone(
cache_utils.get_client(expiration_time=60))
self.flags(memcached_servers=['localhost:11211'])
self.assertIsNotNone(
cache_utils.get_client(expiration_time=60))
self.flags(memcached_servers=None)
self.flags(group='cache', enabled=True)
self.assertIsNotNone(
cache_utils.get_client(expiration_time=60))
self.flags(memcached_servers=None)
self.flags(group='cache', enabled=False)
client = cache_utils.get_client(expiration_time=60)
self.assertIsNotNone(client.region)
@ -51,9 +45,6 @@ class TestOsloCache(test.NoDBTestCase):
[mock.call('oslo_cache.dict',
arguments={'expiration_time': 60},
expiration_time=60),
mock.call('dogpile.cache.memcached',
arguments={'url': ['localhost:11211']},
expiration_time=60),
mock.call('dogpile.cache.null',
_config_argument_dict=mock.ANY,
_config_prefix='cache.oslo.arguments.',
@ -86,35 +77,13 @@ class TestOsloCache(test.NoDBTestCase):
@mock.patch('dogpile.cache.region.CacheRegion.configure')
def test_get_memcached_client(self, mock_cacheregion):
self.flags(memcached_servers=None)
self.flags(group='cache', enabled=False)
self.assertRaises(
RuntimeError,
cache_utils.get_memcached_client,
expiration_time=60)
self.flags(memcached_servers=['localhost:11211'])
self.assertIsNotNone(
cache_utils.get_memcached_client(expiration_time=60))
self.flags(memcached_servers=['localhost:11211'])
self.assertIsNotNone(
cache_utils.get_memcached_client(expiration_time=60))
self.flags(memcached_servers=None)
self.flags(group='cache', enabled=True)
self.flags(group='cache', memcache_servers=['localhost:11211'])
self.assertIsNotNone(
cache_utils.get_memcached_client(expiration_time=60))
mock_cacheregion.assert_has_calls(
[mock.call('dogpile.cache.memcached',
arguments={'url': ['localhost:11211']},
expiration_time=60),
mock.call('dogpile.cache.memcached',
arguments={'url': ['localhost:11211']},
expiration_time=60),
mock.call('dogpile.cache.null',
[mock.call('dogpile.cache.null',
_config_argument_dict=mock.ANY,
_config_prefix='cache.oslo.arguments.',
expiration_time=60, wrap=None)]

View File

@ -0,0 +1,5 @@
---
upgrade:
- The 'memcached_server' option in DEFAULT section which was deprecated in
Mitaka has been completely removed in Newton. This has been replaced by
options from oslo cache section.