diff --git a/heat/engine/resources/openstack/heat/random_string.py b/heat/engine/resources/openstack/heat/random_string.py index fcdea373d3..0114a6bba9 100644 --- a/heat/engine/resources/openstack/heat/random_string.py +++ b/heat/engine/resources/openstack/heat/random_string.py @@ -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: diff --git a/heat/engine/resources/openstack/heat/remote_stack.py b/heat/engine/resources/openstack/heat/remote_stack.py index 32a0dd6648..89581ea493 100644 --- a/heat/engine/resources/openstack/heat/remote_stack.py +++ b/heat/engine/resources/openstack/heat/remote_stack.py @@ -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 diff --git a/heat/engine/resources/openstack/heat/swiftsignal.py b/heat/engine/resources/openstack/heat/swiftsignal.py index 361cbf33ff..39001bdb91 100644 --- a/heat/engine/resources/openstack/heat/swiftsignal.py +++ b/heat/engine/resources/openstack/heat/swiftsignal.py @@ -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) diff --git a/heat/engine/resources/openstack/mistral/workflow.py b/heat/engine/resources/openstack/mistral/workflow.py index 4347eaa968..be6eddda4a 100644 --- a/heat/engine/resources/openstack/mistral/workflow.py +++ b/heat/engine/resources/openstack/mistral/workflow.py @@ -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): diff --git a/heat/engine/resources/openstack/nova/nova_keypair.py b/heat/engine/resources/openstack/nova/nova_keypair.py index b2b9c0d92e..5cb415e075 100644 --- a/heat/engine/resources/openstack/nova/nova_keypair.py +++ b/heat/engine/resources/openstack/nova/nova_keypair.py @@ -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 diff --git a/heat/tests/mistral/test_mistral_workflow.py b/heat/tests/mistral/test_mistral_workflow.py index b18b84b98d..0068b5d6f5 100644 --- a/heat/tests/mistral/test_mistral_workflow.py +++ b/heat/tests/mistral/test_mistral_workflow.py @@ -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()) diff --git a/heat/tests/nova/test_nova_keypair.py b/heat/tests/nova/test_nova_keypair.py index fe38413398..9ece0c02fa 100644 --- a/heat/tests/nova/test_nova_keypair.py +++ b/heat/tests/nova/test_nova_keypair.py @@ -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()) diff --git a/heat/tests/test_random_string.py b/heat/tests/test_random_string.py index 9e4832c179..31fca7fb52 100644 --- a/heat/tests/test_random_string.py +++ b/heat/tests/test_random_string.py @@ -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' diff --git a/heat/tests/test_remote_stack.py b/heat/tests/test_remote_stack.py index fcc1376dbf..98a8e9af0a 100644 --- a/heat/tests/test_remote_stack.py +++ b/heat/tests/test_remote_stack.py @@ -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()) diff --git a/heat/tests/test_swiftsignal.py b/heat/tests/test_swiftsignal.py index b2de5ae16a..bb8ded6292 100644 --- a/heat/tests/test_swiftsignal.py +++ b/heat/tests/test_swiftsignal.py @@ -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):