Remove obsolete cache_data from Stack

This is no longer required as the convergence 'lightweight stack' used for
checking individual resources has now merged with the other code paths: in
every case intrinsic functions are resolved using the data about resources
stored in StackDefinition and accessed via ResourceProxy.

Change-Id: I41cf21c8e1babe819b4b6c668749ed5915ae3b54
changes/82/468582/24
Zane Bitter 5 years ago
parent 764b8fb251
commit c40e1ce3fd
  1. 59
      heat/engine/resource.py
  2. 1
      heat/engine/resources/openstack/heat/wait_condition.py
  3. 2
      heat/engine/resources/openstack/neutron/port.py
  4. 2
      heat/engine/resources/openstack/nova/server_network_mixin.py
  5. 23
      heat/engine/stack.py
  6. 2
      heat/tests/openstack/neutron/test_neutron.py
  7. 4
      heat/tests/openstack/trove/test_instance.py
  8. 14
      heat/tests/openstack/zaqar/test_queue.py

@ -254,16 +254,17 @@ class Resource(status.ResourceStatus):
self._calling_engine_id = None
self._atomic_key = None
if stack.cache_data is None:
if not self.stack.in_convergence_check:
resource = stack.db_resource_get(name)
if resource:
self._load_data(resource)
elif stack.has_cache_data(name):
cached_data = stack.cache_data[name]
self.action = cached_data.action
self.status = cached_data.status
self.id = cached_data.primary_key
self.uuid = cached_data.uuid
else:
proxy = self.stack.defn[self.name]
node_data = proxy._resource_data
if node_data is not None:
self.action, self.status = proxy.state
self.id = node_data.primary_key
self.uuid = node_data.uuid
def rpc_client(self):
"""Return a client for making engine RPC calls."""
@ -1025,7 +1026,7 @@ class Resource(status.ResourceStatus):
yield attr, None
else:
try:
yield attr, self._get_attribute_caching(*path)
yield attr, self.FnGetAtt(*path)
except exception.InvalidTemplateAttribute as ita:
LOG.info('%s', ita)
@ -1040,7 +1041,7 @@ class Resource(status.ResourceStatus):
pass
return node_data.NodeData(self.id, self.name, self.uuid,
self.get_reference_id(),
self.FnGetRefId(),
dict(get_attrs(dep_attrs)),
self.action, self.status)
@ -2237,8 +2238,6 @@ class Resource(status.ResourceStatus):
:results: the id or name of the resource.
"""
if self.stack.has_cache_data(self.name):
return self.stack.cache_data_reference_id(self.name)
return self.get_reference_id()
def physical_resource_name_or_FnGetRefId(self):
@ -2262,7 +2261,13 @@ class Resource(status.ResourceStatus):
return attributes.select_from_attribute(attribute, path)
def _get_attribute_caching(self, key, *path):
def FnGetAtt(self, key, *path):
"""For the intrinsic function Fn::GetAtt.
:param key: the attribute key.
:param path: a list of path components to select from the attribute.
:returns: the attribute value.
"""
cache_custom = ((self.attributes.get_cache_mode(key) !=
attributes.Schema.CACHE_NONE) and
(type(self).get_attribute != Resource.get_attribute))
@ -2280,36 +2285,6 @@ class Resource(status.ResourceStatus):
self.attributes.set_cached_attr(full_key, attr_val)
return attr_val
def FnGetAtt(self, key, *path):
"""For the intrinsic function Fn::GetAtt.
:param key: the attribute key.
:param path: a list of path components to select from the attribute.
:returns: the attribute value.
"""
if self.stack.has_cache_data(self.name):
# Load from cache for lightweight resources.
complex_key = key
if path:
complex_key = tuple([key] + list(path))
attribute = self.stack.cache_data_resource_attribute(
self.name, complex_key)
return attribute
return self._get_attribute_caching(key, *path)
def FnGetAtts(self):
"""For the intrinsic function get_attr which returns all attributes.
:returns: dict of all resource's attributes exclude "show" attribute.
"""
if self.stack.has_cache_data(self.name):
attrs = self.stack.cache_data_resource_all_attributes(self.name)
else:
attrs = dict((k, v) for k, v in six.iteritems(self.attributes))
attrs = dict((k, v) for k, v in six.iteritems(attrs)
if k != self.SHOW)
return attrs
def _signal_check_action(self):
if self.action in self.no_signal_actions:
self._add_event(self.action, self.status,

@ -95,6 +95,7 @@ class HeatWaitCondition(resource.Resource):
if handle is not None and isinstance(
handle, wc_base.BaseWaitConditionHandle):
return
LOG.debug("Got %r instead of wait condition handle", handle)
hn = handle.name if handle else self.properties[self.HANDLE]
msg = _('%s is not a valid wait condition handle.') % hn
raise ValueError(msg)

@ -563,7 +563,7 @@ class Port(neutron.NeutronResource):
existing_port, rsrc_owning_stack, stack = resource.Resource.load(
prev_port.context, prev_port.replaced_by,
prev_port.stack.current_traversal, True,
prev_port.stack.cache_data
prev_port.stack.defn._resource_data
)
existing_port_id = existing_port.resource_id
else:

@ -539,7 +539,7 @@ class ServerNetworkMixin(object):
rsrc, rsrc_owning_stack, stack = resource.Resource.load(
prev_server.context, prev_server.replaced_by,
prev_server.stack.current_traversal, True,
prev_server.stack.cache_data
prev_server.stack.defn._resource_data
)
existing_server = rsrc
else:

@ -178,7 +178,6 @@ class Stack(collections.Mapping):
self.tags = tags
self.prev_raw_template_id = prev_raw_template_id
self.current_deps = current_deps
self.cache_data = cache_data
self._worker_client = None
self._convg_deps = None
self.thread_group_mgr = None
@ -195,6 +194,8 @@ class Stack(collections.Mapping):
# especially during template_validate
self.service_check_defer = service_check_defer
self.in_convergence_check = cache_data is not None
if use_stored_context:
self.context = self.stored_context()
@ -321,7 +322,7 @@ class Stack(collections.Mapping):
def _find_filtered_resources(self, filters=None):
if filters:
assert self.cache_data is None, \
assert not self.in_convergence_check, \
"Resources should not be loaded from the DB"
resources = resource_objects.Resource.get_all_by_stack(
self.context, self.id, filters)
@ -366,7 +367,7 @@ class Stack(collections.Mapping):
def _db_resources_get(self):
if self._db_resources is None:
assert self.cache_data is None, \
assert not self.in_convergence_check, \
"Resources should not be loaded from the DB"
_db_resources = resource_objects.Resource.get_all_by_stack(
self.context, self.id)
@ -787,7 +788,7 @@ class Stack(collections.Mapping):
matches = proxy.FnGetRefId() == refid
if matches:
if self.cache_data is not None and r.id is not None:
if self.in_convergence_check and r.id is not None:
# We don't have resources loaded from the database at this
# point, so load the data for just this one from the DB.
db_res = resource_objects.Resource.get_obj(self.context,
@ -1266,7 +1267,6 @@ class Stack(collections.Mapping):
clear_resource_data=True)
self.reset_dependencies()
self._resources = None
self.cache_data = None
if action is not self.CREATE:
self.updated_time = oslo_timeutils.utcnow()
@ -2047,19 +2047,6 @@ class Stack(collections.Mapping):
'tags': self.tags,
}
def has_cache_data(self, resource_name):
return (self.cache_data is not None and
resource_name in self.cache_data)
def cache_data_reference_id(self, resource_name):
return self.cache_data[resource_name].reference_id()
def cache_data_resource_attribute(self, resource_name, attribute_key):
return self.cache_data[resource_name].attribute(attribute_key)
def cache_data_resource_all_attributes(self, resource_name):
return self.cache_data[resource_name].attributes()
def mark_complete(self):
"""Mark the update as complete.

@ -11,7 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from neutronclient.common import exceptions as qe
import six
@ -91,7 +90,6 @@ class NeutronTest(common.HeatTestCase):
self.dummy_stack.store()
tmpl = rsrc_defn.ResourceDefinition('test_res', 'Foo')
self.dummy_stack.has_cache_data = mock.Mock(return_value=False)
return SomeNeutronResource('aresource', tmpl, self.dummy_stack)
def test_resolve_attribute(self):

@ -588,9 +588,7 @@ class InstanceUpdateTests(common.HeatTestCase):
def setUp(self):
super(InstanceUpdateTests, self).setUp()
self._stack = mock.Mock()
self._stack.has_cache_data.return_value = False
self._stack.db_resource_get.return_value = None
self._stack = utils.parse_stack(template_format.parse(db_template))
testprops = {
"name": "testinstance",
"flavor": "foo",

@ -166,15 +166,15 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
return mockclient()
mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
mock_def.resource_type = 'OS::Zaqar::Queue'
props = mock.Mock()
props.props = {}
mock_def.properties.return_value = props
mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
stack = utils.parse_stack(template_format.parse(wp_template))
self.patchobject(stack, 'db_resource_get', return_value=None)
mockplugin = ZaqarClientPlugin(self.ctx)
mock_stack.clients = mock.Mock()
mock_stack.clients.client_plugin.return_value = mockplugin
clients = self.patchobject(stack, 'clients')
clients.client_plugin.return_value = mockplugin
mockplugin.is_not_found = mock.Mock()
mockplugin.is_not_found.return_value = True
@ -183,10 +183,10 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
zaqar_q.delete.side_effect = ResourceNotFound()
mockclient.return_value.queue.return_value = zaqar_q
zplugin = queue.ZaqarQueue("test_delete_not_found", mock_def,
mock_stack)
stack)
zplugin.resource_id = "test_delete_not_found"
zplugin.handle_delete()
mock_stack.clients.client_plugin.assert_called_once_with('zaqar')
clients.client_plugin.assert_called_once_with('zaqar')
mockplugin.is_not_found.assert_called_once_with(
zaqar_q.delete.side_effect)
mockclient.return_value.queue.assert_called_once_with(

Loading…
Cancel
Save