ricolin | f61390f | 2016-07-20 10:36:07 +0800 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from heat_integrationtests.functional import functional_base |
| 14 | |
| 15 | |
| 16 | class ExternalReferencesTest(functional_base.FunctionalTestsBase): |
| 17 | |
| 18 | TEMPLATE = ''' |
| 19 | heat_template_version: 2016-10-14 |
| 20 | resources: |
| 21 | test1: |
| 22 | type: OS::Heat::TestResource |
| 23 | ''' |
| 24 | TEMPLATE_WITH_EX_REF = ''' |
| 25 | heat_template_version: 2016-10-14 |
| 26 | resources: |
| 27 | test1: |
| 28 | type: OS::Heat::TestResource |
| 29 | external_id: foobar |
| 30 | outputs: |
| 31 | str: |
| 32 | value: {get_resource: test1} |
| 33 | ''' |
| 34 | |
| 35 | def test_create_with_external_ref(self): |
| 36 | stack_name = self._stack_rand_name() |
| 37 | stack_identifier = self.stack_create( |
| 38 | stack_name=stack_name, |
| 39 | template=self.TEMPLATE_WITH_EX_REF, |
| 40 | files={}, |
| 41 | disable_rollback=True, |
| 42 | parameters={}, |
| 43 | environment={} |
| 44 | ) |
| 45 | |
| 46 | stack = self.client.stacks.get(stack_identifier) |
| 47 | |
| 48 | self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 49 | expected_resources = {'test1': 'OS::Heat::TestResource'} |
| 50 | self.assertEqual(expected_resources, |
| 51 | self.list_resources(stack_identifier)) |
| 52 | stack = self.client.stacks.get(stack_identifier) |
| 53 | self.assertEqual( |
| 54 | [{'description': 'No description given', |
| 55 | 'output_key': 'str', |
| 56 | 'output_value': 'foobar'}], stack.outputs) |
| 57 | |
| 58 | def test_update_with_external_ref(self): |
| 59 | stack_name = self._stack_rand_name() |
| 60 | stack_identifier = self.stack_create( |
| 61 | stack_name=stack_name, |
| 62 | template=self.TEMPLATE, |
| 63 | files={}, |
| 64 | disable_rollback=True, |
| 65 | parameters={}, |
| 66 | environment={} |
| 67 | ) |
| 68 | stack = self.client.stacks.get(stack_identifier) |
| 69 | |
| 70 | self._wait_for_stack_status(stack_identifier, 'CREATE_COMPLETE') |
| 71 | expected_resources = {'test1': 'OS::Heat::TestResource'} |
| 72 | self.assertEqual(expected_resources, |
| 73 | self.list_resources(stack_identifier)) |
| 74 | stack = self.client.stacks.get(stack_identifier) |
| 75 | self.assertEqual([], stack.outputs) |
| 76 | |
| 77 | stack_name = stack_identifier.split('/')[0] |
| 78 | kwargs = {'stack_id': stack_identifier, 'stack_name': stack_name, |
| 79 | 'template': self.TEMPLATE_WITH_EX_REF, 'files': {}, |
| 80 | 'disable_rollback': True, 'parameters': {}, 'environment': {} |
| 81 | } |
| 82 | self.client.stacks.update(**kwargs) |
| 83 | self._wait_for_stack_status(stack_identifier, 'UPDATE_FAILED') |