huangtianhua | 28b4870 | 2016-01-13 17:24:32 +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 | server_with_sub_fixed_ip_template = ''' |
| 17 | heat_template_version: 2016-04-08 |
| 18 | description: Test template to test nova server with subnet and fixed_ip. |
| 19 | parameters: |
| 20 | flavor: |
| 21 | type: string |
| 22 | image: |
| 23 | type: string |
| 24 | resources: |
| 25 | net: |
| 26 | type: OS::Neutron::Net |
| 27 | properties: |
| 28 | name: my_net |
| 29 | subnet: |
| 30 | type: OS::Neutron::Subnet |
| 31 | properties: |
| 32 | network: {get_resource: net} |
| 33 | cidr: 11.11.11.0/24 |
huangtianhua | 8e57189 | 2016-05-09 19:01:23 +0800 | [diff] [blame] | 34 | security_group: |
| 35 | type: OS::Neutron::SecurityGroup |
| 36 | properties: |
| 37 | name: the_sg |
| 38 | description: Ping and SSH |
| 39 | rules: |
| 40 | - protocol: icmp |
| 41 | - protocol: tcp |
| 42 | port_range_min: 22 |
| 43 | port_range_max: 22 |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 44 | server: |
| 45 | type: OS::Nova::Server |
| 46 | properties: |
| 47 | image: {get_param: image} |
| 48 | flavor: {get_param: flavor} |
| 49 | networks: |
| 50 | - subnet: {get_resource: subnet} |
| 51 | fixed_ip: 11.11.11.11 |
huangtianhua | 8e57189 | 2016-05-09 19:01:23 +0800 | [diff] [blame] | 52 | security_groups: |
| 53 | - {get_resource: security_group} |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 54 | outputs: |
| 55 | networks: |
| 56 | value: {get_attr: [server, networks]} |
| 57 | ''' |
| 58 | |
Thomas Herve | 87af900 | 2016-07-28 13:55:16 +0200 | [diff] [blame^] | 59 | server_with_port_template = ''' |
| 60 | heat_template_version: 2016-04-08 |
| 61 | description: Test template to test nova server with port. |
| 62 | parameters: |
| 63 | flavor: |
| 64 | type: string |
| 65 | image: |
| 66 | type: string |
| 67 | resources: |
| 68 | net: |
| 69 | type: OS::Neutron::Net |
| 70 | properties: |
| 71 | name: my_net |
| 72 | subnet: |
| 73 | type: OS::Neutron::Subnet |
| 74 | properties: |
| 75 | network: {get_resource: net} |
| 76 | cidr: 11.11.11.0/24 |
| 77 | port: |
| 78 | type: OS::Neutron::Port |
| 79 | properties: |
| 80 | network: {get_resource: net} |
| 81 | fixed_ips: |
| 82 | - subnet: {get_resource: subnet} |
| 83 | ip_address: 11.11.11.11 |
| 84 | server: |
| 85 | type: OS::Nova::Server |
| 86 | properties: |
| 87 | image: {get_param: image} |
| 88 | flavor: {get_param: flavor} |
| 89 | networks: |
| 90 | - port: {get_resource: port} |
| 91 | ''' |
| 92 | |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 93 | |
| 94 | class CreateServerTest(functional_base.FunctionalTestsBase): |
| 95 | |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 96 | def get_outputs(self, stack_identifier, output_key): |
| 97 | stack = self.client.stacks.get(stack_identifier) |
Thomas Herve | 87af900 | 2016-07-28 13:55:16 +0200 | [diff] [blame^] | 98 | return self._stack_output(stack, output_key) |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 99 | |
huangtianhua | 8e57189 | 2016-05-09 19:01:23 +0800 | [diff] [blame] | 100 | def test_create_server_with_subnet_fixed_ip_sec_group(self): |
huangtianhua | 28b4870 | 2016-01-13 17:24:32 +0800 | [diff] [blame] | 101 | parms = {'flavor': self.conf.minimal_instance_type, |
| 102 | 'image': self.conf.minimal_image_ref} |
| 103 | stack_identifier = self.stack_create( |
| 104 | template=server_with_sub_fixed_ip_template, |
| 105 | stack_name='server_with_sub_ip', |
| 106 | parameters=parms) |
| 107 | networks = self.get_outputs(stack_identifier, 'networks') |
| 108 | self.assertEqual(['11.11.11.11'], networks['my_net']) |
huangtianhua | aca8b2c | 2016-01-14 15:37:46 +0800 | [diff] [blame] | 109 | |
huangtianhua | 8e57189 | 2016-05-09 19:01:23 +0800 | [diff] [blame] | 110 | server_resource = self.client.resources.get( |
| 111 | stack_identifier, 'server') |
| 112 | server_id = server_resource.physical_resource_id |
| 113 | server = self.compute_client.servers.get(server_id) |
| 114 | self.assertEqual([{"name": "the_sg"}], server.security_groups) |
| 115 | |
huangtianhua | aca8b2c | 2016-01-14 15:37:46 +0800 | [diff] [blame] | 116 | def test_create_update_server_with_subnet(self): |
| 117 | parms = {'flavor': self.conf.minimal_instance_type, |
| 118 | 'image': self.conf.minimal_image_ref} |
| 119 | template = server_with_sub_fixed_ip_template.replace( |
| 120 | 'fixed_ip: 11.11.11.11', 'fixed_ip: 11.11.11.22') |
| 121 | stack_identifier = self.stack_create( |
| 122 | template=template, |
| 123 | stack_name='create_server_with_sub_ip', |
| 124 | parameters=parms) |
| 125 | networks = self.get_outputs(stack_identifier, 'networks') |
| 126 | self.assertEqual(['11.11.11.22'], networks['my_net']) |
| 127 | |
| 128 | # update the server only with subnet, we won't pass |
| 129 | # both port_id and net_id to attach interface, then update success |
| 130 | template_only_subnet = template.replace( |
| 131 | 'fixed_ip: 11.11.11.22', '') |
| 132 | self.update_stack(stack_identifier, |
| 133 | template_only_subnet, |
| 134 | parameters=parms) |
| 135 | new_networks = self.get_outputs(stack_identifier, 'networks') |
| 136 | self.assertNotEqual(['11.11.11.22'], new_networks['my_net']) |
Thomas Herve | 87af900 | 2016-07-28 13:55:16 +0200 | [diff] [blame^] | 137 | |
| 138 | def test_create_server_with_port(self): |
| 139 | parms = {'flavor': self.conf.minimal_instance_type, |
| 140 | 'image': self.conf.minimal_image_ref} |
| 141 | # We just want to make sure we can create the server, no need to assert |
| 142 | # anything |
| 143 | self.stack_create( |
| 144 | template=server_with_port_template, |
| 145 | stack_name='server_with_port', |
| 146 | parameters=parms) |