Convergence: Fix to use cache_data for FnGetRefId (2)

Partial-Bug: #1492116
Change-Id: I4ea0507ceddae7ea9930c36dbc68edc8a0e64aa8
This commit is contained in:
Rakesh H S 2015-09-29 14:25:14 +05:30
parent 62fe22dc2e
commit 6908e824cd
10 changed files with 96 additions and 8 deletions

View File

@ -299,7 +299,7 @@ class RandomString(resource.Resource):
if name == self.VALUE:
return self.data().get(self.VALUE)
def FnGetRefId(self):
def get_reference_id(self):
if self.resource_id is not None:
return self.data().get('value')
else:

View File

@ -300,7 +300,7 @@ class RemoteStack(resource.Resource):
return dict((output['output_key'], output['output_value'])
for output in outputs)
def FnGetRefId(self):
def get_reference_id(self):
return self.resource_id

View File

@ -132,7 +132,7 @@ class SwiftSignalHandle(resource.Resource):
self.data_delete(self.ENDPOINT)
def FnGetRefId(self):
def get_reference_id(self):
return self.data().get(self.ENDPOINT)

View File

@ -319,7 +319,7 @@ class Workflow(signal_responder.SignalResponder,
)
}
def FnGetRefId(self):
def get_reference_id(self):
return self._workflow_name()
def _validate_signal_data(self, data):

View File

@ -129,7 +129,7 @@ class KeyPair(resource.Resource):
self.PUBLIC_KEY_ATTR: self.public_key}
return six.text_type(attr_fn[key])
def FnGetRefId(self):
def get_reference_id(self):
return self.resource_id

View File

@ -636,3 +636,26 @@ class TestMistralWorkflow(common.HeatTestCase):
self.assertEqual(False, task['keep-result'])
return [FakeWorkflow('create_vm')]
def test_mistal_workflow_refid(self):
tmpl = template_format.parse(workflow_template)
stack = utils.parse_stack(tmpl, stack_name='test')
rsrc = stack['workflow']
rsrc.uuid = '4c885bde-957e-4758-907b-c188a487e908'
rsrc.id = 'mockid'
rsrc.action = 'CREATE'
self.assertEqual('test-workflow-owevpzgiqw66', rsrc.FnGetRefId())
def test_mistal_workflow_refid_convergence_cache_data(self):
tmpl = template_format.parse(workflow_template)
cache_data = {'workflow': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'convg_xyz'
}}
stack = utils.parse_stack(tmpl, stack_name='test',
cache_data=cache_data)
rsrc = stack['workflow']
self.assertEqual('convg_xyz', rsrc.FnGetRefId())

View File

@ -185,3 +185,21 @@ class NovaKeyPairTest(common.HeatTestCase):
self.assertEqual((tp_test.CREATE, tp_test.COMPLETE), tp_test.state)
self.assertEqual(tp_test.resource_id, created_key.name)
self.m.VerifyAll()
def test_nova_keypair_refid(self):
stack = utils.parse_stack(self.kp_template)
rsrc = stack['kp']
rsrc.resource_id = 'xyz'
self.assertEqual('xyz', rsrc.FnGetRefId())
def test_nova_keypair_refid_convergence_cache_data(self):
cache_data = {'kp': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'convg_xyz'
}}
stack = utils.parse_stack(self.kp_template, cache_data=cache_data)
rsrc = stack['kp']
self.assertEqual('convg_xyz', rsrc.FnGetRefId())

View File

@ -13,6 +13,7 @@
import re
import mock
import six
from testtools import matchers
@ -154,6 +155,19 @@ Resources:
secret6.resource_id = None
self.assertEqual('secret6', secret6.FnGetRefId())
def test_random_string_refid_convergence_cache_data(self):
t = template_format.parse(self.template_random_string)
cache_data = {'secret1': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'xyz'
}}
stack = utils.parse_stack(t, cache_data=cache_data)
rsrc = stack['secret1']
self.assertEqual('xyz', rsrc.FnGetRefId())
def test_invalid_length(self):
template_random_string = '''
HeatTemplateFormatVersion: '2012-12-12'

View File

@ -140,7 +140,8 @@ class RemoteStackTest(tests_common.HeatTestCase):
self.old_clients = None
def unset_clients_property():
type(self.this_context).clients = self.old_clients
if self.this_context is not None:
type(self.this_context).clients = self.old_clients
self.addCleanup(unset_clients_property)
@ -659,3 +660,23 @@ class RemoteStackTest(tests_common.HeatTestCase):
self.heat.stacks.get = mock.MagicMock(side_effect=stacks)
scheduler.TaskRunner(rsrc.update, update_snippet)()
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
def test_remote_stack_refid(self):
t = template_format.parse(parent_stack_template)
stack = utils.parse_stack(t)
rsrc = stack['remote_stack']
rsrc.resource_id = 'xyz'
self.assertEqual('xyz', rsrc.FnGetRefId())
def test_remote_stack_refid_convergence_cache_data(self):
t = template_format.parse(parent_stack_template)
cache_data = {'remote_stack': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'convg_xyz'
}}
stack = utils.parse_stack(t, cache_data=cache_data)
rsrc = stack['remote_stack']
self.assertEqual('convg_xyz', rsrc.FnGetRefId())

View File

@ -81,12 +81,12 @@ obj_header = {
}
def create_stack(template, stack_id=None):
def create_stack(template, stack_id=None, cache_data=None):
tmpl = template_format.parse(template)
template = templatem.Template(tmpl)
ctx = utils.dummy_context(tenant_id='test_tenant')
st = stack.Stack(ctx, 'test_st', template,
disable_rollback=True)
disable_rollback=True, cache_data=cache_data)
# Stub out the stack ID so we have a known value
if stack_id is None:
@ -282,6 +282,18 @@ class SwiftSignalHandleTest(common.HeatTestCase):
scheduler.TaskRunner(handle.update, update_snippet)()
self.assertEqual(old_url, rsrc.FnGetRefId())
def test_swift_handle_refid_convergence_cache_data(self):
cache_data = {'test_wait_condition_handle': {
'uuid': mock.ANY,
'id': mock.ANY,
'action': 'CREATE',
'status': 'COMPLETE',
'reference_id': 'convg_xyz'
}}
st = create_stack(swiftsignalhandle_template, cache_data=cache_data)
rsrc = st['test_wait_condition_handle']
self.assertEqual('convg_xyz', rsrc.FnGetRefId())
class SwiftSignalTest(common.HeatTestCase):
def setUp(self):