From 70593c5d69e7953ad5d4a6f6d7483b4881b29d2f Mon Sep 17 00:00:00 2001 From: Thomas Herve Date: Wed, 4 Nov 2015 10:52:59 +0100 Subject: [PATCH] Add caching to neutron extensions This adds a oslo.cache option for neutron extensions, and enable cache in integration tests. Change-Id: Ibbdc210dd57c3559f87789854b6b9b9159694cf2 Closes-Bug: #1512771 --- heat/common/cache.py | 18 ++++++++++++++++++ heat/engine/clients/os/neutron.py | 16 ++++++++++++++-- heat_integrationtests/pre_test_hook.sh | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/heat/common/cache.py b/heat/common/cache.py index 7a348104e3..c8baaa7bd4 100644 --- a/heat/common/cache.py +++ b/heat/common/cache.py @@ -54,6 +54,24 @@ def register_cache_configurations(conf): conf.register_group(constraint_cache_group) conf.register_opts(constraint_cache_opts, group=constraint_cache_group) + extension_cache_group = cfg.OptGroup('service_extension_cache') + extension_cache_opts = [ + cfg.IntOpt('expiration_time', default=3600, + help=_( + 'TTL, in seconds, for any cached item in the ' + 'dogpile.cache region used for caching of service ' + 'extensions.')), + cfg.BoolOpt('caching', default=True, + help=_( + 'Toggle to enable/disable caching when Orchestration ' + 'Engine retrieves extensions from other OpenStack ' + 'services. Please note that the global toggle for ' + 'oslo.cache(enabled=True in [cache] group) must be ' + 'enabled to use this feature.')) + ] + conf.register_group(extension_cache_group) + conf.register_opts(extension_cache_opts, group=extension_cache_group) + return conf diff --git a/heat/engine/clients/os/neutron.py b/heat/engine/clients/os/neutron.py index 86ba81e562..9703feb24c 100644 --- a/heat/engine/clients/os/neutron.py +++ b/heat/engine/clients/os/neutron.py @@ -14,13 +14,21 @@ from neutronclient.common import exceptions from neutronclient.neutron import v2_0 as neutronV20 from neutronclient.v2_0 import client as nc +from oslo_cache import core +from oslo_config import cfg from oslo_utils import uuidutils +from heat.common import cache from heat.common import exception from heat.engine.clients import client_plugin from heat.engine import constraints +MEMOIZE = core.get_memoization_decorator(conf=cfg.CONF, + region=cache.get_cache_region(), + group="service_extension_cache") + + class NeutronClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions @@ -72,10 +80,14 @@ class NeutronClientPlugin(client_plugin.ClientPlugin): return neutronV20.find_resourceid_by_name_or_id( self.client(), key_type, props.get(key)) + @MEMOIZE + def _list_extensions(self): + extensions = self.client().list_extensions().get('extensions') + return set(extension.get('alias') for extension in extensions) + def has_extension(self, alias): """Check if specific extension is present.""" - extensions = self.client().list_extensions().get('extensions') - return alias in [extension.get('alias') for extension in extensions] + return alias in self._list_extensions() def _resolve(self, props, key, id_key, key_type): if props.get(key): diff --git a/heat_integrationtests/pre_test_hook.sh b/heat_integrationtests/pre_test_hook.sh index 0de1c37ae4..21663f7be6 100755 --- a/heat_integrationtests/pre_test_hook.sh +++ b/heat_integrationtests/pre_test_hook.sh @@ -34,3 +34,5 @@ echo -e 'encrypt_parameters_and_properties=True\n' >> $localconf echo -e '[heat_api]\nworkers=1\n' >> $localconf echo -e '[heat_api_cfn]\nworkers=1\n' >> $localconf echo -e '[heat_api_cloudwatch]\nworkers=1\n' >> $localconf + +echo -e '[cache]\nenabled=True\n' >> $localconf