blob: c1bdde6042659ab41dd5d67440dc4497904270d6 [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
13from oslo_log import log as logging
14
15from heat_integrationtests.functional import functional_base
16
17LOG = logging.getLogger(__name__)
18
19
20class LoadBalancerv2Test(functional_base.FunctionalTestsBase):
21
22 create_template = '''
23heat_template_version: 2016-04-08
Anant Patile452f7a2016-06-07 15:18:35 +053024parameters:
25 subnet:
26 type: string
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050027resources:
28 loadbalancer:
29 type: OS::Neutron::LBaaS::LoadBalancer
30 properties:
31 description: aLoadBalancer
Anant Patile452f7a2016-06-07 15:18:35 +053032 vip_subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050033 listener:
34 type: OS::Neutron::LBaaS::Listener
35 properties:
36 description: aListener
37 loadbalancer: { get_resource: loadbalancer }
38 protocol: HTTP
39 protocol_port: 80
40 connection_limit: 5555
41 pool:
42 type: OS::Neutron::LBaaS::Pool
43 properties:
44 description: aPool
45 lb_algorithm: ROUND_ROBIN
46 protocol: HTTP
47 listener: { get_resource: listener }
48 poolmember:
49 type: OS::Neutron::LBaaS::PoolMember
50 properties:
51 address: 1.1.1.1
52 pool: { get_resource: pool }
53 protocol_port: 1111
Anant Patile452f7a2016-06-07 15:18:35 +053054 subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050055 weight: 255
56 # pm2
57 healthmonitor:
58 type: OS::Neutron::LBaaS::HealthMonitor
59 properties:
60 delay: 3
61 type: HTTP
62 timeout: 3
63 max_retries: 3
64 pool: { get_resource: pool }
65outputs:
66 loadbalancer:
67 value: { get_attr: [ loadbalancer, show ] }
68 pool:
69 value: { get_attr: [ pool, show ] }
70 poolmember:
71 value: { get_attr: [ poolmember, show ] }
72 listener:
73 value: { get_attr: [ listener, show ] }
74 healthmonitor:
75 value: { get_attr: [ healthmonitor, show ] }
76'''
77
78 add_member = '''
79 poolmember2:
80 type: OS::Neutron::LBaaS::PoolMember
81 properties:
82 address: 2.2.2.2
83 pool: { get_resource: pool }
84 protocol_port: 2222
Anant Patile452f7a2016-06-07 15:18:35 +053085 subnet: { get_param: subnet }
Mark Vanderwiel74690ce2016-03-14 16:49:03 -050086 weight: 222
87'''
88
89 def setUp(self):
90 super(LoadBalancerv2Test, self).setUp()
91 if not self.is_network_extension_supported('lbaasv2'):
92 self.skipTest('LBaasv2 extension not available, skipping')
93
94 def test_create_update_loadbalancer(self):
Anant Patile452f7a2016-06-07 15:18:35 +053095 parameters = {
96 'subnet': self.conf.fixed_subnet_name,
97 }
98 stack_identifier = self.stack_create(template=self.create_template,
99 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500100 stack = self.client.stacks.get(stack_identifier)
101 output = self._stack_output(stack, 'loadbalancer')
102 self.assertEqual('ONLINE', output['operating_status'])
103
104 template = self.create_template.replace('ROUND_ROBIN', 'SOURCE_IP')
105 template = template.replace('3', '6')
106 template = template.replace('255', '256')
107 template = template.replace('5555', '7777')
108 template = template.replace('aLoadBalancer', 'updatedLoadBalancer')
109 template = template.replace('aPool', 'updatedPool')
110 template = template.replace('aListener', 'updatedListener')
Anant Patile452f7a2016-06-07 15:18:35 +0530111 self.update_stack(stack_identifier, template=template,
112 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500113 stack = self.client.stacks.get(stack_identifier)
114
115 output = self._stack_output(stack, 'loadbalancer')
116 self.assertEqual('ONLINE', output['operating_status'])
117 self.assertEqual('updatedLoadBalancer', output['description'])
118 output = self._stack_output(stack, 'pool')
119 self.assertEqual('SOURCE_IP', output['lb_algorithm'])
120 self.assertEqual('updatedPool', output['description'])
121 output = self._stack_output(stack, 'poolmember')
122 self.assertEqual(256, output['weight'])
123 output = self._stack_output(stack, 'healthmonitor')
124 self.assertEqual(6, output['delay'])
125 self.assertEqual(6, output['timeout'])
126 self.assertEqual(6, output['max_retries'])
127 output = self._stack_output(stack, 'listener')
128 self.assertEqual(7777, output['connection_limit'])
129 self.assertEqual('updatedListener', output['description'])
130
131 def test_add_delete_poolmember(self):
Anant Patile452f7a2016-06-07 15:18:35 +0530132 parameters = {
133 'subnet': self.conf.fixed_subnet_name,
134 }
135 stack_identifier = self.stack_create(template=self.create_template,
136 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500137 stack = self.client.stacks.get(stack_identifier)
138 output = self._stack_output(stack, 'loadbalancer')
139 self.assertEqual('ONLINE', output['operating_status'])
140 output = self._stack_output(stack, 'pool')
141 self.assertEqual(1, len(output['members']))
142 # add pool member
143 template = self.create_template.replace('# pm2', self.add_member)
Anant Patile452f7a2016-06-07 15:18:35 +0530144 self.update_stack(stack_identifier, template=template,
145 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500146 stack = self.client.stacks.get(stack_identifier)
147 output = self._stack_output(stack, 'loadbalancer')
148 self.assertEqual('ONLINE', output['operating_status'])
149 output = self._stack_output(stack, 'pool')
150 self.assertEqual(2, len(output['members']))
151 # delete pool member
Anant Patile452f7a2016-06-07 15:18:35 +0530152 self.update_stack(stack_identifier, template=self.create_template,
153 parameters=parameters)
Mark Vanderwiel74690ce2016-03-14 16:49:03 -0500154 stack = self.client.stacks.get(stack_identifier)
155 output = self._stack_output(stack, 'loadbalancer')
156 self.assertEqual('ONLINE', output['operating_status'])
157 output = self._stack_output(stack, 'pool')
158 self.assertEqual(1, len(output['members']))