From c39842b8495894b296d80e1149138581cab12f47 Mon Sep 17 00:00:00 2001 From: Renat Akhmerov Date: Tue, 6 Nov 2018 13:50:14 +0700 Subject: [PATCH] Fix usage of cachetools in lookup_utils * In the latest version of cachetools lib (3.0.0) the previously deprecated argument "missing" of cache classes has been removed. * Disabled test_generator failing due to the changes in the senlin client until it's fixed by https://review.openstack.org/614211 Change-Id: Iac42f592834734a6fddb743e947860b3bb7e1aba --- .../unit/actions/openstack/test_generator.py | 2 ++ mistral/workflow/lookup_utils.py | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 294e20b94..7df19580d 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -14,6 +14,7 @@ import contextlib import os from oslo_config import cfg +import testtools import mock @@ -85,6 +86,7 @@ class GeneratorTest(base.BaseTest): self.baremetal_patch.start() self.addCleanup(self.baremetal_patch.stop) + @testtools.skip("Finish https://review.openstack.org/#/c/614211") def test_generator(self): for generator_cls in generator_factory.all_generators(): action_classes = generator_cls.create_actions() diff --git a/mistral/workflow/lookup_utils.py b/mistral/workflow/lookup_utils.py index 7f78672b2..9df20f9f9 100644 --- a/mistral/workflow/lookup_utils.py +++ b/mistral/workflow/lookup_utils.py @@ -41,18 +41,17 @@ from mistral.workflow import states CONF = cfg.CONF -def _create_lru_cache_for_workflow_execution(wf_ex_id): +def _create_workflow_execution_cache(): return cachetools.LRUCache(maxsize=500) + # This is a two-level caching structure. # First level: [ -> ] # Second level (task execution cache): [ -> ] # The first level (by workflow execution id) allows to invalidate # needed cache entry when the workflow gets completed. -_TASK_EX_CACHE = cachetools.LRUCache( - maxsize=100, - missing=_create_lru_cache_for_workflow_execution -) +_TASK_EX_CACHE = cachetools.LRUCache(maxsize=100) + _ACTION_DEF_CACHE = cachetools.TTLCache( maxsize=1000, @@ -92,7 +91,14 @@ def find_task_executions_by_name(wf_ex_id, task_name): may contain task execution clones not bound to the DB session. """ with _TASK_EX_CACHE_LOCK: - t_execs = _TASK_EX_CACHE[wf_ex_id].get(task_name) + if wf_ex_id in _TASK_EX_CACHE: + wf_ex_cache = _TASK_EX_CACHE[wf_ex_id] + else: + wf_ex_cache = _create_workflow_execution_cache() + + _TASK_EX_CACHE[wf_ex_id] = wf_ex_cache + + t_execs = wf_ex_cache.get(task_name) if t_execs: return t_execs @@ -113,7 +119,7 @@ def find_task_executions_by_name(wf_ex_id, task_name): if all_finished: with _TASK_EX_CACHE_LOCK: - _TASK_EX_CACHE[wf_ex_id][task_name] = t_execs + wf_ex_cache[task_name] = t_execs return t_execs