Merge "Don't query for resource during stack creation"

This commit is contained in:
Jenkins 2014-01-18 21:37:37 +00:00 committed by Gerrit Code Review
commit f86f51255e
2 changed files with 18 additions and 2 deletions

View File

@ -180,8 +180,12 @@ class Resource(object):
self.attributes_schema, self.attributes_schema,
self._resolve_attribute) self._resolve_attribute)
resource = db_api.resource_get_by_name_and_stack(self.context, if stack.id:
name, stack.id) resource = db_api.resource_get_by_name_and_stack(self.context,
name, stack.id)
else:
resource = None
if resource: if resource:
self.resource_id = resource.nova_instance self.resource_id = resource.nova_instance
self.action = resource.action self.action = resource.action

View File

@ -15,6 +15,8 @@
import itertools import itertools
import uuid import uuid
import mock
from heat.common import exception from heat.common import exception
from heat.engine import dependencies from heat.engine import dependencies
from heat.engine import parser from heat.engine import parser
@ -58,6 +60,16 @@ class ResourceTest(HeatTestCase):
snippet = {'Type': 'GenericResourceType'} snippet = {'Type': 'GenericResourceType'}
res = resource.Resource('aresource', snippet, self.stack) res = resource.Resource('aresource', snippet, self.stack)
self.assertIsInstance(res, generic_rsrc.GenericResource) self.assertIsInstance(res, generic_rsrc.GenericResource)
self.assertEqual("INIT", res.action)
def test_resource_new_stack_not_stored(self):
snippet = {'Type': 'GenericResourceType'}
self.stack.id = None
db_method = 'resource_get_by_name_and_stack'
with mock.patch.object(db_api, db_method) as resource_get:
res = resource.Resource('aresource', snippet, self.stack)
self.assertEqual("INIT", res.action)
self.assertIs(False, resource_get.called)
def test_resource_new_err(self): def test_resource_new_err(self):
snippet = {'Type': 'NoExistResourceType'} snippet = {'Type': 'NoExistResourceType'}