blob: ae550b282cfb5f0ff05a29a36f1aa92ff67ed644 [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
34 server:
35 type: OS::Nova::Server
36 properties:
37 image: {get_param: image}
38 flavor: {get_param: flavor}
39 networks:
40 - subnet: {get_resource: subnet}
41 fixed_ip: 11.11.11.11
42outputs:
43 networks:
44 value: {get_attr: [server, networks]}
45'''
46
47
48class CreateServerTest(functional_base.FunctionalTestsBase):
49
50 def setUp(self):
51 super(CreateServerTest, self).setUp()
52
53 def get_outputs(self, stack_identifier, output_key):
54 stack = self.client.stacks.get(stack_identifier)
55 output = self._stack_output(stack, output_key)
56 return output
57
58 def test_create_server_with_subnet_fixed_ip(self):
59 parms = {'flavor': self.conf.minimal_instance_type,
60 'image': self.conf.minimal_image_ref}
61 stack_identifier = self.stack_create(
62 template=server_with_sub_fixed_ip_template,
63 stack_name='server_with_sub_ip',
64 parameters=parms)
65 networks = self.get_outputs(stack_identifier, 'networks')
66 self.assertEqual(['11.11.11.11'], networks['my_net'])
huangtianhuaaca8b2c2016-01-14 15:37:46 +080067
68 def test_create_update_server_with_subnet(self):
69 parms = {'flavor': self.conf.minimal_instance_type,
70 'image': self.conf.minimal_image_ref}
71 template = server_with_sub_fixed_ip_template.replace(
72 'fixed_ip: 11.11.11.11', 'fixed_ip: 11.11.11.22')
73 stack_identifier = self.stack_create(
74 template=template,
75 stack_name='create_server_with_sub_ip',
76 parameters=parms)
77 networks = self.get_outputs(stack_identifier, 'networks')
78 self.assertEqual(['11.11.11.22'], networks['my_net'])
79
80 # update the server only with subnet, we won't pass
81 # both port_id and net_id to attach interface, then update success
82 template_only_subnet = template.replace(
83 'fixed_ip: 11.11.11.22', '')
84 self.update_stack(stack_identifier,
85 template_only_subnet,
86 parameters=parms)
87 new_networks = self.get_outputs(stack_identifier, 'networks')
88 self.assertNotEqual(['11.11.11.22'], new_networks['my_net'])