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
This commit is contained in:
Rakesh H S 2015-09-14 17:19:06 +05:30
parent 4cf262e473
commit 1956ddd2a6
10 changed files with 60 additions and 24 deletions

View File

@ -123,6 +123,7 @@ class DockerContainerTest(common.HeatTestCase):
mock_client.logs.return_value = "Container startup failed" mock_client.logs.return_value = "Container startup failed"
test_client.return_value = mock_client test_client.return_value = mock_client
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.has_cache_data.return_value = False
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
docker_res = docker_container.DockerContainer("test", res_def, docker_res = docker_container.DockerContainer("test", res_def,

View File

@ -444,6 +444,7 @@ class LoadBalancerTest(common.HeatTestCase):
} }
stack = mock.Mock() stack = mock.Mock()
stack.db_resource_get.return_value = None stack.db_resource_get.return_value = None
stack.has_cache_data.return_value = False
# happy path # happy path
resdef = rsrc_defn.ResourceDefinition("testvip", resdef = rsrc_defn.ResourceDefinition("testvip",
lb.CloudLoadBalancer, lb.CloudLoadBalancer,
@ -652,6 +653,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_check(self): def test_check(self):
stack = mock.Mock() stack = mock.Mock()
stack.db_resource_get.return_value = None stack.db_resource_get.return_value = None
stack.has_cache_data.return_value = False
resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition) resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition)
loadbalancer = lb.CloudLoadBalancer("test", resdef, stack) loadbalancer = lb.CloudLoadBalancer("test", resdef, stack)
loadbalancer._add_event = mock.Mock() loadbalancer._add_event = mock.Mock()
@ -730,6 +732,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_resolve_attr_noid(self): def test_resolve_attr_noid(self):
stack = mock.Mock() stack = mock.Mock()
stack.db_resource_get.return_value = None stack.db_resource_get.return_value = None
stack.has_cache_data.return_value = False
resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition) resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition)
lbres = lb.CloudLoadBalancer("test", resdef, stack) lbres = lb.CloudLoadBalancer("test", resdef, stack)
self.assertIsNone(lbres._resolve_attribute("PublicIp")) self.assertIsNone(lbres._resolve_attribute("PublicIp"))
@ -1551,6 +1554,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_check_delete_complete(self): def test_check_delete_complete(self):
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None 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_resdef = mock.Mock(spec=rsrc_defn.ResourceDefinition)
mock_loadbalancer = lb.CloudLoadBalancer("test", mock_resdef, mock_loadbalancer = lb.CloudLoadBalancer("test", mock_resdef,
mock_stack) mock_stack)
@ -1569,6 +1573,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_redir(self): def test_redir(self):
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
props = {'httpsRedirect': True, props = {'httpsRedirect': True,
'protocol': 'HTTPS', 'protocol': 'HTTPS',
'port': 443, 'port': 443,
@ -1595,6 +1600,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_invalid_redir_proto(self): def test_invalid_redir_proto(self):
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
props = {'httpsRedirect': True, props = {'httpsRedirect': True,
'protocol': 'TCP', 'protocol': 'TCP',
'port': 1234, 'port': 1234,
@ -1611,6 +1617,7 @@ class LoadBalancerTest(common.HeatTestCase):
def test_invalid_redir_ssl(self): def test_invalid_redir_ssl(self):
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
props = {'httpsRedirect': True, props = {'httpsRedirect': True,
'protocol': 'HTTP', 'protocol': 'HTTP',
'port': 1234, 'port': 1234,

View File

@ -192,7 +192,7 @@ class Resource(object):
self.status_reason = '' self.status_reason = ''
self.id = None self.id = None
self.uuid = None self.uuid = None
self._data = {} self._data = None
self._rsrc_metadata = None self._rsrc_metadata = None
self._stored_properties_data = None self._stored_properties_data = None
self.created_time = stack.created_time self.created_time = stack.created_time
@ -208,6 +208,11 @@ class Resource(object):
resource = stack.db_resource_get(name) resource = stack.db_resource_get(name)
if resource: if resource:
self._load_data(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): def rpc_client(self):
'''Return a client for making engine RPC calls.''' '''Return a client for making engine RPC calls.'''

View File

@ -570,16 +570,15 @@ class Stack(collections.Mapping):
refid, or None if not found refid, or None if not found
''' '''
for r in six.itervalues(self): for r in six.itervalues(self):
if r.FnGetRefId() == refid: if r.state in (
if self.has_cache_data(r.name) or r.state in ( (r.INIT, r.COMPLETE),
(r.INIT, r.COMPLETE), (r.CREATE, r.IN_PROGRESS),
(r.CREATE, r.IN_PROGRESS), (r.CREATE, r.COMPLETE),
(r.CREATE, r.COMPLETE), (r.RESUME, r.IN_PROGRESS),
(r.RESUME, r.IN_PROGRESS), (r.RESUME, r.COMPLETE),
(r.RESUME, r.COMPLETE), (r.UPDATE, r.IN_PROGRESS),
(r.UPDATE, r.IN_PROGRESS), (r.UPDATE, r.COMPLETE)) and r.FnGetRefId() == refid:
(r.UPDATE, r.COMPLETE)): return r
return r
def register_access_allowed_handler(self, credential_id, handler): def register_access_allowed_handler(self, credential_id, handler):
''' '''

View File

@ -325,7 +325,10 @@ def construct_input_data(rsrc):
input_data = {'id': rsrc.id, input_data = {'id': rsrc.id,
'name': rsrc.name, 'name': rsrc.name,
'reference_id': rsrc.FnGetRefId(), 'reference_id': rsrc.FnGetRefId(),
'attrs': resolved_attributes} 'attrs': resolved_attributes,
'status': rsrc.status,
'action': rsrc.action,
'uuid': rsrc.uuid}
return input_data return input_data

View File

@ -531,7 +531,10 @@ class MiscMethodsTest(common.HeatTestCase):
(u'nested_dict', u'dict', u'b'): 2}, (u'nested_dict', u'dict', u'b'): 2},
'id': mock.ANY, 'id': mock.ANY,
'reference_id': 'A', '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) actual_input_data = worker.construct_input_data(self.resource)
self.assertEqual(expected_input_data, actual_input_data) self.assertEqual(expected_input_data, actual_input_data)
@ -539,7 +542,10 @@ class MiscMethodsTest(common.HeatTestCase):
expected_input_data = {'attrs': {}, expected_input_data = {'attrs': {},
'id': mock.ANY, 'id': mock.ANY,
'reference_id': 'A', 'reference_id': 'A',
'name': 'A'} 'name': 'A',
'uuid': mock.ANY,
'action': mock.ANY,
'status': mock.ANY}
self.resource.FnGetAtt = mock.Mock( self.resource.FnGetAtt = mock.Mock(
side_effect=exception.InvalidTemplateAttribute(resource='A', side_effect=exception.InvalidTemplateAttribute(resource='A',
key='value')) key='value'))

View File

@ -182,6 +182,7 @@ class OSDBInstanceTest(common.HeatTestCase):
def test_create_failed(self): def test_create_failed(self):
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) res_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
osdb_res = os_database.OSDBInstance("test", res_def, mock_stack) osdb_res = os_database.OSDBInstance("test", res_def, mock_stack)

View File

@ -1460,7 +1460,11 @@ class ResourceTest(common.HeatTestCase):
stack = parser.Stack(utils.dummy_context(), 'test', tmpl, stack = parser.Stack(utils.dummy_context(), 'test', tmpl,
cache_data={ cache_data={
'res': {'attributes': {'Foo': 'res', 'res': {'attributes': {'Foo': 'res',
'foo': 'res'}}}) 'foo': 'res'},
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE'}})
res = stack['res'] res = stack['res']
self.assertEqual({'foo': 'res', 'Foo': 'res'}, res.FnGetAtts()) self.assertEqual({'foo': 'res', 'Foo': 'res'}, res.FnGetAtts())

View File

@ -290,8 +290,12 @@ class StackTest(common.HeatTestCase):
{'A': {'Type': 'StackResourceType'}, {'A': {'Type': 'StackResourceType'},
'B': {'Type': 'GenericResourceType'}}} 'B': {'Type': 'GenericResourceType'}}}
cache_data = {'A': {'reference_id': 'A-id'}, cache_data = {'A': {'reference_id': 'A-id', 'uuid': mock.ANY,
'B': {'reference_id': 'B-id'}} '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', self.stack = stack.Stack(self.ctx, 'test_stack',
template.Template(tpl), template.Template(tpl),
@ -930,9 +934,6 @@ class StackTest(common.HeatTestCase):
try: try:
self.assertIsNone(self.stack.resource_by_refid('aaaa')) self.assertIsNone(self.stack.resource_by_refid('aaaa'))
self.assertIsNone(self.stack.resource_by_refid('bbbb')) 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: finally:
rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE) rsrc.state_set(rsrc.CREATE, rsrc.COMPLETE)
@ -1969,8 +1970,12 @@ class StackTest(common.HeatTestCase):
}) })
cache_data = {'foo': {'reference_id': 'foo-id', cache_data = {'foo': {'reference_id': 'foo-id',
'attrs': {'bar': 'baz'}}, 'attrs': {'bar': 'baz'}, 'uuid': mock.ANY,
'bar': {'reference_id': 'bar-id'}} '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 = stack.Stack(self.ctx, 'test', tmpl)
tmpl_stack.store() tmpl_stack.store()
lightweight_stack = stack.Stack.load(self.ctx, stack_id=tmpl_stack.id, 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'}, cache_data = {'foo': {'reference_id': 'physical-resource-id',
'bar': {'reference_id': 'bar-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 = stack.Stack(self.ctx, 'test', tmpl)
tmpl_stack.store() tmpl_stack.store()
lightweight_stack = stack.Stack.load(self.ctx, stack_id=tmpl_stack.id, lightweight_stack = stack.Stack.load(self.ctx, stack_id=tmpl_stack.id,

View File

@ -198,6 +198,7 @@ class ZaqarMessageQueueTest(common.HeatTestCase):
mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition) mock_def = mock.Mock(spec=rsrc_defn.ResourceDefinition)
mock_stack = mock.Mock() mock_stack = mock.Mock()
mock_stack.db_resource_get.return_value = None mock_stack.db_resource_get.return_value = None
mock_stack.has_cache_data.return_value = False
zaqar_q = mock.Mock() zaqar_q = mock.Mock()
zaqar_q.delete.side_effect = ResourceNotFound zaqar_q.delete.side_effect = ResourceNotFound