Convergence: Store resource status in cache data

Fix failing convergence gate functional tests
- store resource uuid, action, status in cache data. Most of the code
requires the resource to have proper status and uuid to work.
- initialize rsrc._data to None so that the resource data is fetched from
db first time.

Change-Id: I7309c7da8fe1ce3e1c7e3d3027dea2e400111015
Co-Authored-By: Anant Patil <anant.patil@hp.com>
Partial-Bug: #1492116
Closes-Bug: #1495094
changes/66/222866/2
Rakesh H S 7 years ago
parent 4cf262e473
commit 1956ddd2a6
  1. 1
      contrib/heat_docker/heat_docker/tests/test_docker_container.py
  2. 7
      contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py
  3. 7
      heat/engine/resource.py
  4. 19
      heat/engine/stack.py
  5. 5
      heat/engine/worker.py
  6. 10
      heat/tests/engine/test_engine_worker.py
  7. 1
      heat/tests/test_os_database.py
  8. 6
      heat/tests/test_resource.py
  9. 27
      heat/tests/test_stack.py
  10. 1
      heat/tests/test_zaqar_queue.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,

@ -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,

@ -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.'''

@ -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):
'''

@ -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

@ -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'))

@ -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)

@ -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())

@ -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,

@ -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

Loading…
Cancel
Save