diff --git a/contrib/heat_docker/heat_docker/tests/test_docker_container.py b/contrib/heat_docker/heat_docker/tests/test_docker_container.py index 37748ae536..3f2e1cf471 100644 --- a/contrib/heat_docker/heat_docker/tests/test_docker_container.py +++ b/contrib/heat_docker/heat_docker/tests/test_docker_container.py @@ -123,6 +123,7 @@ class DockerContainerTest(common.HeatTestCase): mock_client.logs.return_value = "Container startup failed" test_client.return_value = mock_client mock_stack = mock.Mock() + mock_stack.has_cache_data.return_value = False mock_stack.db_resource_get.return_value = None res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) docker_res = docker_container.DockerContainer("test", res_def, diff --git a/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py b/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py index cb2be90339..4ce7150215 100644 --- a/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py +++ b/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py @@ -444,6 +444,7 @@ class LoadBalancerTest(common.HeatTestCase): } stack = mock.Mock() stack.db_resource_get.return_value = None + stack.has_cache_data.return_value = False # happy path resdef = rsrc_defn.ResourceDefinition("testvip", lb.CloudLoadBalancer, @@ -652,6 +653,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_check(self): stack = mock.Mock() stack.db_resource_get.return_value = None + stack.has_cache_data.return_value = False resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition) loadbalancer = lb.CloudLoadBalancer("test", resdef, stack) loadbalancer._add_event = mock.Mock() @@ -730,6 +732,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_resolve_attr_noid(self): stack = mock.Mock() stack.db_resource_get.return_value = None + stack.has_cache_data.return_value = False resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition) lbres = lb.CloudLoadBalancer("test", resdef, stack) self.assertIsNone(lbres._resolve_attribute("PublicIp")) @@ -1551,6 +1554,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_check_delete_complete(self): mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False mock_resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition) mock_loadbalancer = lb.CloudLoadBalancer("test", mock_resdef, mock_stack) @@ -1569,6 +1573,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_redir(self): mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False props = {'httpsRedirect': True, 'protocol': 'HTTPS', 'port': 443, @@ -1595,6 +1600,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_invalid_redir_proto(self): mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False props = {'httpsRedirect': True, 'protocol': 'TCP', 'port': 1234, @@ -1611,6 +1617,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_invalid_redir_ssl(self): mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False props = {'httpsRedirect': True, 'protocol': 'HTTP', 'port': 1234, diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 216a31bb26..3c000771b4 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -192,7 +192,7 @@ class Resource(object): self.status_reason = '' self.id = None self.uuid = None - self._data = {} + self._data = None self._rsrc_metadata = None self._stored_properties_data = None self.created_time = stack.created_time @@ -208,6 +208,11 @@ class Resource(object): resource = stack.db_resource_get(name) if resource: self._load_data(resource) + else: + self.action = stack.cache_data[name]['action'] + self.status = stack.cache_data[name]['status'] + self.id = stack.cache_data[name]['id'] + self.uuid = stack.cache_data[name]['uuid'] def rpc_client(self): '''Return a client for making engine RPC calls.''' diff --git a/heat/engine/stack.py b/heat/engine/stack.py index a2c35acc32..6210e1fc87 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -570,16 +570,15 @@ class Stack(collections.Mapping): refid, or None if not found ''' for r in six.itervalues(self): - if r.FnGetRefId() == refid: - if self.has_cache_data(r.name) or r.state in ( - (r.INIT, r.COMPLETE), - (r.CREATE, r.IN_PROGRESS), - (r.CREATE, r.COMPLETE), - (r.RESUME, r.IN_PROGRESS), - (r.RESUME, r.COMPLETE), - (r.UPDATE, r.IN_PROGRESS), - (r.UPDATE, r.COMPLETE)): - return r + if r.state in ( + (r.INIT, r.COMPLETE), + (r.CREATE, r.IN_PROGRESS), + (r.CREATE, r.COMPLETE), + (r.RESUME, r.IN_PROGRESS), + (r.RESUME, r.COMPLETE), + (r.UPDATE, r.IN_PROGRESS), + (r.UPDATE, r.COMPLETE)) and r.FnGetRefId() == refid: + return r def register_access_allowed_handler(self, credential_id, handler): ''' diff --git a/heat/engine/worker.py b/heat/engine/worker.py index 0eb2fa435f..25cd5e9eee 100644 --- a/heat/engine/worker.py +++ b/heat/engine/worker.py @@ -325,7 +325,10 @@ def construct_input_data(rsrc): input_data = {'id': rsrc.id, 'name': rsrc.name, 'reference_id': rsrc.FnGetRefId(), - 'attrs': resolved_attributes} + 'attrs': resolved_attributes, + 'status': rsrc.status, + 'action': rsrc.action, + 'uuid': rsrc.uuid} return input_data diff --git a/heat/tests/engine/test_engine_worker.py b/heat/tests/engine/test_engine_worker.py index 16d3a83956..807d4caa41 100644 --- a/heat/tests/engine/test_engine_worker.py +++ b/heat/tests/engine/test_engine_worker.py @@ -531,7 +531,10 @@ class MiscMethodsTest(common.HeatTestCase): (u'nested_dict', u'dict', u'b'): 2}, 'id': mock.ANY, 'reference_id': 'A', - 'name': 'A'} + 'name': 'A', + 'uuid': mock.ANY, + 'action': mock.ANY, + 'status': mock.ANY} actual_input_data = worker.construct_input_data(self.resource) self.assertEqual(expected_input_data, actual_input_data) @@ -539,7 +542,10 @@ class MiscMethodsTest(common.HeatTestCase): expected_input_data = {'attrs': {}, 'id': mock.ANY, 'reference_id': 'A', - 'name': 'A'} + 'name': 'A', + 'uuid': mock.ANY, + 'action': mock.ANY, + 'status': mock.ANY} self.resource.FnGetAtt = mock.Mock( side_effect=exception.InvalidTemplateAttribute(resource='A', key='value')) diff --git a/heat/tests/test_os_database.py b/heat/tests/test_os_database.py index 64462f94a3..98eefe383f 100644 --- a/heat/tests/test_os_database.py +++ b/heat/tests/test_os_database.py @@ -182,6 +182,7 @@ class OSDBInstanceTest(common.HeatTestCase): def test_create_failed(self): mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) osdb_res = os_database.OSDBInstance("test", res_def, mock_stack) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 645474469c..2cbb91c93d 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -1460,7 +1460,11 @@ class ResourceTest(common.HeatTestCase): stack = parser.Stack(utils.dummy_context(), 'test', tmpl, cache_data={ 'res': {'attributes': {'Foo': 'res', - 'foo': 'res'}}}) + 'foo': 'res'}, + 'uuid': mock.ANY, + 'id': mock.ANY, + 'action': 'CREATE', + 'status': 'COMPLETE'}}) res = stack['res'] self.assertEqual({'foo': 'res', 'Foo': 'res'}, res.FnGetAtts()) diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index b8aceaf31d..01632c5a99 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -290,8 +290,12 @@ class StackTest(common.HeatTestCase): {'A': {'Type': 'StackResourceType'}, 'B': {'Type': 'GenericResourceType'}}} - cache_data = {'A': {'reference_id': 'A-id'}, - 'B': {'reference_id': 'B-id'}} + cache_data = {'A': {'reference_id': 'A-id', 'uuid': mock.ANY, + 'id': mock.ANY, 'action': 'CREATE', + 'status': 'COMPLETE'}, + 'B': {'reference_id': 'B-id', 'uuid': mock.ANY, + 'id': mock.ANY, 'action': 'CREATE', + 'status': 'COMPLETE'}} self.stack = stack.Stack(self.ctx, 'test_stack', template.Template(tpl), @@ -930,9 +934,6 @@ class StackTest(common.HeatTestCase): try: self.assertIsNone(self.stack.resource_by_refid('aaaa')) self.assertIsNone(self.stack.resource_by_refid('bbbb')) - # if there is cached data, we should ignore the state - self.stack.cache_data = {'AResource': {'reference_id': 'aaaa'}} - self.assertEqual(rsrc, self.stack.resource_by_refid('aaaa')) finally: rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE) @@ -1969,8 +1970,12 @@ class StackTest(common.HeatTestCase): }) cache_data = {'foo': {'reference_id': 'foo-id', - 'attrs': {'bar': 'baz'}}, - 'bar': {'reference_id': 'bar-id'}} + 'attrs': {'bar': 'baz'}, 'uuid': mock.ANY, + 'id': mock.ANY, 'action': 'CREATE', + 'status': 'COMPLETE'}, + 'bar': {'reference_id': 'bar-id', 'uuid': mock.ANY, + 'id': mock.ANY, 'action': 'CREATE', + 'status': 'COMPLETE'}} tmpl_stack = stack.Stack(self.ctx, 'test', tmpl) tmpl_stack.store() lightweight_stack = stack.Stack.load(self.ctx, stack_id=tmpl_stack.id, @@ -2003,8 +2008,12 @@ class StackTest(common.HeatTestCase): } }) - cache_data = {'foo': {'reference_id': 'physical-resource-id'}, - 'bar': {'reference_id': 'bar-id'}} + cache_data = {'foo': {'reference_id': 'physical-resource-id', + 'uuid': mock.ANY, 'id': mock.ANY, + 'action': 'CREATE', 'status': 'COMPLETE'}, + 'bar': {'reference_id': 'bar-id', 'uuid': mock.ANY, + 'id': mock.ANY, 'action': 'CREATE', + 'status': 'COMPLETE'}} tmpl_stack = stack.Stack(self.ctx, 'test', tmpl) tmpl_stack.store() lightweight_stack = stack.Stack.load(self.ctx, stack_id=tmpl_stack.id, diff --git a/heat/tests/test_zaqar_queue.py b/heat/tests/test_zaqar_queue.py index 36e9e69fe5..10aeb1615f 100644 --- a/heat/tests/test_zaqar_queue.py +++ b/heat/tests/test_zaqar_queue.py @@ -198,6 +198,7 @@ class ZaqarMessageQueueTest(common.HeatTestCase): mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) mock_stack = mock.Mock() mock_stack.db_resource_get.return_value = None + mock_stack.has_cache_data.return_value = False zaqar_q = mock.Mock() zaqar_q.delete.side_effect = ResourceNotFound