Peter Razumovsky | dc12a41 | 2017-01-13 18:03:09 +0400 | [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 | template_subnet_old_network = """ |
| 16 | heat_template_version: 2016-10-14 |
| 17 | parameters: |
| 18 | net_cidr: |
| 19 | type: string |
| 20 | resources: |
| 21 | net: |
| 22 | type: OS::Neutron::Net |
| 23 | subnet: |
| 24 | type: OS::Neutron::Subnet |
| 25 | properties: |
| 26 | cidr: { get_param: net_cidr } |
| 27 | network_id: { get_resource: net } |
| 28 | """ |
| 29 | |
| 30 | template_with_get_attr = """ |
| 31 | heat_template_version: 2016-10-14 |
| 32 | description: Test template to create/update subnet with translation |
| 33 | parameters: |
| 34 | net_cidr: |
| 35 | type: string |
| 36 | resources: |
| 37 | net: |
| 38 | type: OS::Neutron::Net |
| 39 | net_value: |
| 40 | type: OS::Heat::Value |
| 41 | properties: |
| 42 | value: { get_resource: net } |
| 43 | subnet: |
| 44 | type: OS::Neutron::Subnet |
| 45 | properties: |
| 46 | network: { get_attr: [net_value, value] } |
| 47 | cidr: { get_param: net_cidr } |
| 48 | """ |
| 49 | |
| 50 | template_value_from_nested_stack_main = """ |
| 51 | heat_template_version: 2016-10-14 |
| 52 | parameters: |
| 53 | flavor: |
| 54 | type: string |
| 55 | image: |
| 56 | type: string |
| 57 | public_net: |
| 58 | type: string |
| 59 | resources: |
| 60 | network_settings: |
| 61 | type: network.yaml |
| 62 | properties: |
| 63 | public_net: { get_param: public_net } |
| 64 | server: |
| 65 | type: OS::Nova::Server |
| 66 | properties: |
| 67 | flavor: { get_param: flavor } |
| 68 | image: { get_param: image } |
| 69 | networks: { get_attr: [network_settings, networks] } |
| 70 | """ |
| 71 | |
| 72 | template_value_from_nested_stack_network = """ |
| 73 | heat_template_version: 2016-10-14 |
| 74 | parameters: |
| 75 | public_net: |
| 76 | type: string |
| 77 | outputs: |
| 78 | networks: |
| 79 | value: |
| 80 | - uuid: { get_param: public_net } |
| 81 | """ |
| 82 | |
| 83 | |
| 84 | class TestTranslation(functional_base.FunctionalTestsBase): |
| 85 | |
| 86 | def test_create_update_subnet_old_network(self): |
| 87 | # Just create and update where network is translated properly. |
| 88 | env = {'parameters': {'net_cidr': '11.11.11.0/24'}} |
| 89 | stack_identifier = self.stack_create( |
| 90 | template=template_subnet_old_network, |
| 91 | environment=env) |
| 92 | env = {'parameters': {'net_cidr': '11.11.12.0/24'}} |
| 93 | self.update_stack(stack_identifier, |
| 94 | template=template_subnet_old_network, |
| 95 | environment=env) |
| 96 | |
| 97 | def test_create_update_translation_with_get_attr(self): |
| 98 | # Check create and update successful for translation function value. |
| 99 | env = {'parameters': {'net_cidr': '11.11.11.0/24'}} |
| 100 | stack_identifier = self.stack_create( |
| 101 | template=template_with_get_attr, |
| 102 | environment=env) |
| 103 | env = {'parameters': {'net_cidr': '11.11.12.0/24'}} |
| 104 | self.update_stack(stack_identifier, |
| 105 | template=template_with_get_attr, |
| 106 | environment=env) |
| 107 | |
| 108 | def test_value_from_nested_stack(self): |
| 109 | env = {'parameters': { |
| 110 | 'flavor': self.conf.minimal_instance_type, |
| 111 | 'image': self.conf.minimal_image_ref, |
| 112 | 'public_net': self.conf.fixed_network_name |
| 113 | }} |
| 114 | self.stack_create( |
| 115 | template=template_value_from_nested_stack_main, |
| 116 | environment=env, |
| 117 | files={'network.yaml': template_value_from_nested_stack_network}) |