Merge "Don't translate when loading resource from db"

This commit is contained in:
Jenkins 2016-03-04 02:53:49 +00:00 committed by Gerrit Code Review
commit 7d61fce04e
2 changed files with 30 additions and 1 deletions

View File

@ -228,6 +228,8 @@ class Resource(object):
resource = stack.db_resource_get(name)
if resource:
self._load_data(resource)
else:
self.translate_properties(self.properties)
else:
self.action = stack.cache_data[name]['action']
self.status = stack.cache_data[name]['status']
@ -331,7 +333,6 @@ class Resource(object):
def reparse(self):
self.properties = self.t.properties(self.properties_schema,
self.context)
self.translate_properties(self.properties)
def __eq__(self, other):
"""Allow == comparison of two resources."""
@ -781,6 +782,7 @@ class Resource(object):
# the parser.Stack is stored (which is after the resources
# are __init__'d, but before they are create()'d)
self.reparse()
self.translate_properties(self.properties)
self._update_stored_properties()
def pause():
@ -1098,6 +1100,7 @@ class Resource(object):
self.t = after
self.reparse()
self.translate_properties(self.properties)
self._update_stored_properties()
except exception.ResourceActionRestricted as ae:

View File

@ -163,6 +163,32 @@ class ResourceTest(common.HeatTestCase):
self.assertEqual('Resource name may not contain "/"',
six.text_type(ex))
@mock.patch.object(parser.Stack, 'db_resource_get')
@mock.patch.object(resource.Resource, '_load_data')
@mock.patch.object(resource.Resource, 'translate_properties')
def test_stack_resources(self, mock_translate, mock_load,
mock_db_get):
tpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources':
{'A': {'Type': 'ResourceWithPropsType',
'Properties': {'Foo': 'abc'}}}}
stack = parser.Stack(utils.dummy_context(),
'test_stack',
template.Template(tpl))
stack.store()
mock_db_get.return_value = None
self.assertEqual(1, len(stack.resources))
self.assertEqual(1, mock_translate.call_count)
self.assertEqual(0, mock_load.call_count)
# set stack._resources = None to reload the resources
stack._resources = None
mock_db_get.return_value = mock.Mock()
self.assertEqual(1, len(stack.resources))
self.assertEqual(1, mock_translate.call_count)
self.assertEqual(1, mock_load.call_count)
def test_resource_new_stack_not_stored(self):
snippet = rsrc_defn.ResourceDefinition('aresource',
'GenericResourceType')