blob: f258f83176193509cd9cb77af3cce3dac17e99e7 [file] [log] [blame]
huangtianhua28b48702016-01-13 17:24:32 +08001# 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
13from heat_integrationtests.functional import functional_base
14
15
16server_with_sub_fixed_ip_template = '''
17heat_template_version: 2016-04-08
18description: Test template to test nova server with subnet and fixed_ip.
19parameters:
20 flavor:
21 type: string
22 image:
23 type: string
24resources:
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
huangtianhua8e571892016-05-09 19:01:23 +080034 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
huangtianhua28b48702016-01-13 17:24:32 +080044 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
huangtianhua8e571892016-05-09 19:01:23 +080052 security_groups:
53 - {get_resource: security_group}
huangtianhua28b48702016-01-13 17:24:32 +080054outputs:
55 networks:
56 value: {get_attr: [server, networks]}
57'''
58
59
60class CreateServerTest(functional_base.FunctionalTestsBase):
61
62 def setUp(self):
63 super(CreateServerTest, self).setUp()
64
65 def get_outputs(self, stack_identifier, output_key):
66 stack = self.client.stacks.get(stack_identifier)
67 output = self._stack_output(stack, output_key)
68 return output
69
huangtianhua8e571892016-05-09 19:01:23 +080070 def test_create_server_with_subnet_fixed_ip_sec_group(self):
huangtianhua28b48702016-01-13 17:24:32 +080071 parms = {'flavor': self.conf.minimal_instance_type,
72 'image': self.conf.minimal_image_ref}
73 stack_identifier = self.stack_create(
74 template=server_with_sub_fixed_ip_template,
75 stack_name='server_with_sub_ip',
76 parameters=parms)
77 networks = self.get_outputs(stack_identifier, 'networks')
78 self.assertEqual(['11.11.11.11'], networks['my_net'])
huangtianhuaaca8b2c2016-01-14 15:37:46 +080079
huangtianhua8e571892016-05-09 19:01:23 +080080 server_resource = self.client.resources.get(
81 stack_identifier, 'server')
82 server_id = server_resource.physical_resource_id
83 server = self.compute_client.servers.get(server_id)
84 self.assertEqual([{"name": "the_sg"}], server.security_groups)
85
huangtianhuaaca8b2c2016-01-14 15:37:46 +080086 def test_create_update_server_with_subnet(self):
87 parms = {'flavor': self.conf.minimal_instance_type,
88 'image': self.conf.minimal_image_ref}
89 template = server_with_sub_fixed_ip_template.replace(
90 'fixed_ip: 11.11.11.11', 'fixed_ip: 11.11.11.22')
91 stack_identifier = self.stack_create(
92 template=template,
93 stack_name='create_server_with_sub_ip',
94 parameters=parms)
95 networks = self.get_outputs(stack_identifier, 'networks')
96 self.assertEqual(['11.11.11.22'], networks['my_net'])
97
98 # update the server only with subnet, we won't pass
99 # both port_id and net_id to attach interface, then update success
100 template_only_subnet = template.replace(
101 'fixed_ip: 11.11.11.22', '')
102 self.update_stack(stack_identifier,
103 template_only_subnet,
104 parameters=parms)
105 new_networks = self.get_outputs(stack_identifier, 'networks')
106 self.assertNotEqual(['11.11.11.22'], new_networks['my_net'])