blob: e7f56ef0ac0280aaf3b566cdab0844bf17e218db [file] [log] [blame]
Mark Vanderwiel74690ce2016-03-14 16:49:03 -05001# 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
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050013
14from heat_integrationtests.functional import functional_base
15
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050016
17class LoadBalancerv2Test(functional_base.FunctionalTestsBase):
18
19 create_template = '''
20heat_template_version: 2016-04-08
Anant Patile452f7a2016-06-07 15:18:35 +053021parameters:
22 subnet:
23 type: string
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050024resources:
25 loadbalancer:
26 type: OS::Neutron::LBaaS::LoadBalancer
27 properties:
28 description: aLoadBalancer
Anant Patile452f7a2016-06-07 15:18:35 +053029 vip_subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050030 listener:
31 type: OS::Neutron::LBaaS::Listener
32 properties:
33 description: aListener
34 loadbalancer: { get_resource: loadbalancer }
35 protocol: HTTP
36 protocol_port: 80
37 connection_limit: 5555
38 pool:
39 type: OS::Neutron::LBaaS::Pool
40 properties:
41 description: aPool
42 lb_algorithm: ROUND_ROBIN
43 protocol: HTTP
44 listener: { get_resource: listener }
45 poolmember:
46 type: OS::Neutron::LBaaS::PoolMember
47 properties:
48 address: 1.1.1.1
49 pool: { get_resource: pool }
50 protocol_port: 1111
Anant Patile452f7a2016-06-07 15:18:35 +053051 subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050052 weight: 255
53 # pm2
54 healthmonitor:
55 type: OS::Neutron::LBaaS::HealthMonitor
56 properties:
57 delay: 3
58 type: HTTP
59 timeout: 3
60 max_retries: 3
61 pool: { get_resource: pool }
62outputs:
63 loadbalancer:
64 value: { get_attr: [ loadbalancer, show ] }
65 pool:
66 value: { get_attr: [ pool, show ] }
67 poolmember:
68 value: { get_attr: [ poolmember, show ] }
69 listener:
70 value: { get_attr: [ listener, show ] }
71 healthmonitor:
72 value: { get_attr: [ healthmonitor, show ] }
73'''
74
75 add_member = '''
76 poolmember2:
77 type: OS::Neutron::LBaaS::PoolMember
78 properties:
79 address: 2.2.2.2
80 pool: { get_resource: pool }
81 protocol_port: 2222
Anant Patile452f7a2016-06-07 15:18:35 +053082 subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050083 weight: 222
84'''
85
86 def setUp(self):
87 super(LoadBalancerv2Test, self).setUp()
88 if not self.is_network_extension_supported('lbaasv2'):
89 self.skipTest('LBaasv2 extension not available, skipping')
90
91 def test_create_update_loadbalancer(self):
Anant Patile452f7a2016-06-07 15:18:35 +053092 parameters = {
93 'subnet': self.conf.fixed_subnet_name,
94 }
95 stack_identifier = self.stack_create(template=self.create_template,
96 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050097 stack = self.client.stacks.get(stack_identifier)
98 output = self._stack_output(stack, 'loadbalancer')
99 self.assertEqual('ONLINE', output['operating_status'])
100
101 template = self.create_template.replace('ROUND_ROBIN', 'SOURCE_IP')
102 template = template.replace('3', '6')
103 template = template.replace('255', '256')
104 template = template.replace('5555', '7777')
105 template = template.replace('aLoadBalancer', 'updatedLoadBalancer')
106 template = template.replace('aPool', 'updatedPool')
107 template = template.replace('aListener', 'updatedListener')
Anant Patile452f7a2016-06-07 15:18:35 +0530108 self.update_stack(stack_identifier, template=template,
109 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500110 stack = self.client.stacks.get(stack_identifier)
111
112 output = self._stack_output(stack, 'loadbalancer')
113 self.assertEqual('ONLINE', output['operating_status'])
114 self.assertEqual('updatedLoadBalancer', output['description'])
115 output = self._stack_output(stack, 'pool')
116 self.assertEqual('SOURCE_IP', output['lb_algorithm'])
117 self.assertEqual('updatedPool', output['description'])
118 output = self._stack_output(stack, 'poolmember')
119 self.assertEqual(256, output['weight'])
120 output = self._stack_output(stack, 'healthmonitor')
121 self.assertEqual(6, output['delay'])
122 self.assertEqual(6, output['timeout'])
123 self.assertEqual(6, output['max_retries'])
124 output = self._stack_output(stack, 'listener')
125 self.assertEqual(7777, output['connection_limit'])
126 self.assertEqual('updatedListener', output['description'])
127
128 def test_add_delete_poolmember(self):
Anant Patile452f7a2016-06-07 15:18:35 +0530129 parameters = {
130 'subnet': self.conf.fixed_subnet_name,
131 }
132 stack_identifier = self.stack_create(template=self.create_template,
133 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500134 stack = self.client.stacks.get(stack_identifier)
135 output = self._stack_output(stack, 'loadbalancer')
136 self.assertEqual('ONLINE', output['operating_status'])
137 output = self._stack_output(stack, 'pool')
138 self.assertEqual(1, len(output['members']))
139 # add pool member
140 template = self.create_template.replace('# pm2', self.add_member)
Anant Patile452f7a2016-06-07 15:18:35 +0530141 self.update_stack(stack_identifier, template=template,
142 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500143 stack = self.client.stacks.get(stack_identifier)
144 output = self._stack_output(stack, 'loadbalancer')
145 self.assertEqual('ONLINE', output['operating_status'])
146 output = self._stack_output(stack, 'pool')
147 self.assertEqual(2, len(output['members']))
148 # delete pool member
Anant Patile452f7a2016-06-07 15:18:35 +0530149 self.update_stack(stack_identifier, template=self.create_template,
150 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500151 stack = self.client.stacks.get(stack_identifier)
152 output = self._stack_output(stack, 'loadbalancer')
153 self.assertEqual('ONLINE', output['operating_status'])
154 output = self._stack_output(stack, 'pool')
155 self.assertEqual(1, len(output['members']))