From 505bc44615d922c0e9054c3ca48721b26b924caa Mon Sep 17 00:00:00 2001 From: Hieu LE Date: Thu, 12 May 2016 18:12:00 +0700 Subject: [PATCH] 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 --- etc/nova/nova-config-generator.conf | 1 - nova/cache_utils.py | 63 ++----------------- .../unit/servicegroup/test_mc_servicegroup.py | 3 +- nova/tests/unit/test_cache.py | 33 +--------- ...ached-default-option-e0e50d54cef17ac4.yaml | 5 ++ 5 files changed, 12 insertions(+), 93 deletions(-) create mode 100644 releasenotes/notes/remove-memcached-default-option-e0e50d54cef17ac4.yaml diff --git a/etc/nova/nova-config-generator.conf b/etc/nova/nova-config-generator.conf index e51e18ba6d34..931d8b456d4e 100644 --- a/etc/nova/nova-config-generator.conf +++ b/etc/nova/nova-config-generator.conf @@ -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 diff --git a/nova/cache_utils.py b/nova/cache_utils.py index 864e7b6d415f..a4eb02f41d6b 100644 --- a/nova/cache_utils.py +++ b/nova/cache_utils.py @@ -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')) diff --git a/nova/tests/unit/servicegroup/test_mc_servicegroup.py b/nova/tests/unit/servicegroup/test_mc_servicegroup.py index 5ca51af592aa..fd91c949965b 100644 --- a/nova/tests/unit/servicegroup/test_mc_servicegroup.py +++ b/nova/tests/unit/servicegroup/test_mc_servicegroup.py @@ -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): diff --git a/nova/tests/unit/test_cache.py b/nova/tests/unit/test_cache.py index 599112162104..4461b6433a12 100644 --- a/nova/tests/unit/test_cache.py +++ b/nova/tests/unit/test_cache.py @@ -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)] diff --git a/releasenotes/notes/remove-memcached-default-option-e0e50d54cef17ac4.yaml b/releasenotes/notes/remove-memcached-default-option-e0e50d54cef17ac4.yaml new file mode 100644 index 000000000000..9f233b5e28f2 --- /dev/null +++ b/releasenotes/notes/remove-memcached-default-option-e0e50d54cef17ac4.yaml @@ -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.