blob: 792d61d24c4c4b2ef0f1c8b214a3017bd5f79d1a [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2013 OpenStack Foundation
raiesmh080fe76852013-09-13 11:52:56 +05302# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
mouad benchchaouiea2440d2013-12-22 00:38:06 +010018from tempest import test
raiesmh080fe76852013-09-13 11:52:56 +053019
20
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +090021class LoadBalancerTestJSON(base.BaseNetworkTest):
raiesmh080fe76852013-09-13 11:52:56 +053022 _interface = 'json'
23
24 """
25 Tests the following operations in the Neutron API using the REST client for
26 Neutron:
27
28 create vIP, and Pool
29 show vIP
30 list vIP
31 update vIP
32 delete vIP
33 update pool
34 delete pool
raiesmh08f5153f72013-09-16 13:38:37 +053035 show pool
36 list pool
raiesmh0832580d02013-09-17 13:11:34 +053037 health monitoring operations
raiesmh080fe76852013-09-13 11:52:56 +053038 """
39
40 @classmethod
41 def setUpClass(cls):
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +090042 super(LoadBalancerTestJSON, cls).setUpClass()
mouad benchchaouiea2440d2013-12-22 00:38:06 +010043 if not test.is_extension_enabled('lbaas', 'network'):
44 msg = "lbaas extension not enabled."
45 raise cls.skipException(msg)
raiesmh080fe76852013-09-13 11:52:56 +053046 cls.network = cls.create_network()
47 cls.name = cls.network['name']
48 cls.subnet = cls.create_subnet(cls.network)
Masayuki Igawa259c1132013-10-31 17:48:44 +090049 pool_name = data_utils.rand_name('pool-')
50 vip_name = data_utils.rand_name('vip-')
raiesmh080fe76852013-09-13 11:52:56 +053051 cls.pool = cls.create_pool(pool_name, "ROUND_ROBIN",
52 "HTTP", cls.subnet)
Elena Ezhova43c70a22014-01-14 12:42:51 +040053 cls.vip = cls.create_vip(name=vip_name,
54 protocol="HTTP",
55 protocol_port=80,
56 subnet=cls.subnet,
57 pool=cls.pool)
raiesmh08f8437ed2013-09-17 10:59:38 +053058 cls.member = cls.create_member(80, cls.pool)
Elena Ezhova43c70a22014-01-14 12:42:51 +040059 cls.health_monitor = cls.create_health_monitor(delay=4,
60 max_retries=3,
61 Type="TCP",
62 timeout=1)
raiesmh080fe76852013-09-13 11:52:56 +053063
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +040064 def _check_list_with_filter(self, obj_name, attr_exceptions, **kwargs):
65 create_obj = getattr(self.client, 'create_' + obj_name)
66 delete_obj = getattr(self.client, 'delete_' + obj_name)
67 list_objs = getattr(self.client, 'list_' + obj_name + 's')
68
69 resp, body = create_obj(**kwargs)
70 self.assertEqual('201', resp['status'])
71 obj = body[obj_name]
72 self.addCleanup(delete_obj, obj['id'])
73 for key, value in obj.iteritems():
74 # It is not relevant to filter by all arguments. That is why
75 # there is a list of attr to except
76 if key not in attr_exceptions:
77 resp, body = list_objs(**{key: value})
78 self.assertEqual('200', resp['status'])
79 objs = [v[key] for v in body[obj_name + 's']]
80 self.assertIn(value, objs)
81
mouad benchchaouiea2440d2013-12-22 00:38:06 +010082 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +053083 def test_list_vips(self):
84 # Verify the vIP exists in the list of all vIPs
85 resp, body = self.client.list_vips()
86 self.assertEqual('200', resp['status'])
87 vips = body['vips']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +040088 self.assertIn(self.vip['id'], [v['id'] for v in vips])
raiesmh080fe76852013-09-13 11:52:56 +053089
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +040090 @test.attr(type='smoke')
91 def test_list_vips_with_filter(self):
92 name = data_utils.rand_name('vip-')
93 resp, body = self.client.create_pool(
94 name=data_utils.rand_name("pool-"), lb_method="ROUND_ROBIN",
95 protocol="HTTPS", subnet_id=self.subnet['id'])
96 self.assertEqual('201', resp['status'])
97 pool = body['pool']
98 self.addCleanup(self.client.delete_pool, pool['id'])
99 attr_exceptions = ['status', 'session_persistence',
100 'status_description']
101 self._check_list_with_filter(
102 'vip', attr_exceptions, name=name, protocol="HTTPS",
103 protocol_port=81, subnet_id=self.subnet['id'], pool_id=pool['id'],
104 description=data_utils.rand_name('description-'),
105 admin_state_up=False)
106
107 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +0530108 def test_create_update_delete_pool_vip(self):
109 # Creates a vip
Masayuki Igawa259c1132013-10-31 17:48:44 +0900110 name = data_utils.rand_name('vip-')
Elena Ezhovab40848f2014-01-15 10:17:35 +0400111 address = self.subnet['allocation_pools'][0]['end']
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400112 resp, body = self.client.create_pool(
113 name=data_utils.rand_name("pool-"),
114 lb_method='ROUND_ROBIN',
115 protocol='HTTP',
116 subnet_id=self.subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530117 pool = body['pool']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400118 resp, body = self.client.create_vip(name=name,
119 protocol="HTTP",
120 protocol_port=80,
121 subnet_id=self.subnet['id'],
Elena Ezhovab40848f2014-01-15 10:17:35 +0400122 pool_id=pool['id'],
123 address=address)
raiesmh080fe76852013-09-13 11:52:56 +0530124 self.assertEqual('201', resp['status'])
125 vip = body['vip']
126 vip_id = vip['id']
Elena Ezhovab40848f2014-01-15 10:17:35 +0400127 # Confirm VIP's address correctness with a show
128 resp, body = self.client.show_vip(vip_id)
129 self.assertEqual('200', resp['status'])
130 vip = body['vip']
131 self.assertEqual(address, vip['address'])
raiesmh080fe76852013-09-13 11:52:56 +0530132 # Verification of vip update
133 new_name = "New_vip"
Elena Ezhovab40848f2014-01-15 10:17:35 +0400134 new_description = "New description"
135 persistence_type = "HTTP_COOKIE"
136 update_data = {"session_persistence": {
137 "type": persistence_type}}
138 resp, body = self.client.update_vip(vip_id,
139 name=new_name,
140 description=new_description,
141 connection_limit=10,
142 admin_state_up=False,
143 **update_data)
raiesmh080fe76852013-09-13 11:52:56 +0530144 self.assertEqual('200', resp['status'])
145 updated_vip = body['vip']
Elena Ezhovab40848f2014-01-15 10:17:35 +0400146 self.assertEqual(new_name, updated_vip['name'])
147 self.assertEqual(new_description, updated_vip['description'])
148 self.assertEqual(10, updated_vip['connection_limit'])
149 self.assertFalse(updated_vip['admin_state_up'])
150 self.assertEqual(persistence_type,
151 updated_vip['session_persistence']['type'])
raiesmh080fe76852013-09-13 11:52:56 +0530152 # Verification of vip delete
153 resp, body = self.client.delete_vip(vip['id'])
154 self.assertEqual('204', resp['status'])
izikpensod9a01a62014-02-17 20:02:32 +0200155 self.client.wait_for_resource_deletion('vip', vip['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530156 # Verification of pool update
157 new_name = "New_pool"
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400158 resp, body = self.client.update_pool(pool['id'],
159 name=new_name)
raiesmh080fe76852013-09-13 11:52:56 +0530160 self.assertEqual('200', resp['status'])
161 updated_pool = body['pool']
162 self.assertEqual(updated_pool['name'], new_name)
163 # Verification of pool delete
164 resp, body = self.client.delete_pool(pool['id'])
165 self.assertEqual('204', resp['status'])
166
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100167 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +0530168 def test_show_vip(self):
169 # Verifies the details of a vip
170 resp, body = self.client.show_vip(self.vip['id'])
171 self.assertEqual('200', resp['status'])
172 vip = body['vip']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400173 for key, value in vip.iteritems():
174 # 'status' should not be confirmed in api tests
175 if key != 'status':
176 self.assertEqual(self.vip[key], value)
raiesmh0802d04b02013-09-16 12:10:10 +0530177
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100178 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530179 def test_show_pool(self):
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400180 # Here we need to new pool without any dependence with vips
181 resp, body = self.client.create_pool(
182 name=data_utils.rand_name("pool-"),
183 lb_method='ROUND_ROBIN',
184 protocol='HTTP',
185 subnet_id=self.subnet['id'])
186 self.assertEqual('201', resp['status'])
raiesmh08f5153f72013-09-16 13:38:37 +0530187 pool = body['pool']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400188 self.addCleanup(self.client.delete_pool, pool['id'])
189 # Verifies the details of a pool
190 resp, body = self.client.show_pool(pool['id'])
191 self.assertEqual('200', resp['status'])
192 shown_pool = body['pool']
193 for key, value in pool.iteritems():
194 # 'status' should not be confirmed in api tests
195 if key != 'status':
196 self.assertEqual(value, shown_pool[key])
raiesmh08f5153f72013-09-16 13:38:37 +0530197
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100198 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530199 def test_list_pools(self):
200 # Verify the pool exists in the list of all pools
201 resp, body = self.client.list_pools()
202 self.assertEqual('200', resp['status'])
203 pools = body['pools']
204 self.assertIn(self.pool['id'], [p['id'] for p in pools])
205
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100206 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400207 def test_list_pools_with_filters(self):
208 attr_exceptions = ['status', 'vip_id', 'members', 'provider',
209 'status_description']
210 self._check_list_with_filter(
211 'pool', attr_exceptions, name=data_utils.rand_name("pool-"),
212 lb_method="ROUND_ROBIN", protocol="HTTPS",
213 subnet_id=self.subnet['id'],
214 description=data_utils.rand_name('description-'),
215 admin_state_up=False)
216
217 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530218 def test_list_members(self):
219 # Verify the member exists in the list of all members
220 resp, body = self.client.list_members()
221 self.assertEqual('200', resp['status'])
222 members = body['members']
223 self.assertIn(self.member['id'], [m['id'] for m in members])
224
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100225 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400226 def test_list_members_with_filters(self):
227 attr_exceptions = ['status', 'status_description']
228 self._check_list_with_filter('member', attr_exceptions,
229 address="10.0.9.47", protocol_port=80,
230 pool_id=self.pool['id'])
231
232 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530233 def test_create_update_delete_member(self):
234 # Creates a member
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400235 resp, body = self.client.create_member(address="10.0.9.47",
236 protocol_port=80,
237 pool_id=self.pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530238 self.assertEqual('201', resp['status'])
239 member = body['member']
240 # Verification of member update
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400241 resp, body = self.client.update_member(member['id'],
242 admin_state_up=False)
raiesmh08f8437ed2013-09-17 10:59:38 +0530243 self.assertEqual('200', resp['status'])
244 updated_member = body['member']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400245 self.assertFalse(updated_member['admin_state_up'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530246 # Verification of member delete
247 resp, body = self.client.delete_member(member['id'])
248 self.assertEqual('204', resp['status'])
249
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100250 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530251 def test_show_member(self):
252 # Verifies the details of a member
253 resp, body = self.client.show_member(self.member['id'])
254 self.assertEqual('200', resp['status'])
255 member = body['member']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400256 for key, value in member.iteritems():
257 # 'status' should not be confirmed in api tests
258 if key != 'status':
259 self.assertEqual(self.member[key], value)
raiesmh08f8437ed2013-09-17 10:59:38 +0530260
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100261 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530262 def test_list_health_monitors(self):
263 # Verify the health monitor exists in the list of all health monitors
264 resp, body = self.client.list_health_monitors()
265 self.assertEqual('200', resp['status'])
266 health_monitors = body['health_monitors']
267 self.assertIn(self.health_monitor['id'],
268 [h['id'] for h in health_monitors])
269
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100270 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400271 def test_list_health_monitors_with_filters(self):
272 attr_exceptions = ['status', 'status_description', 'pools']
273 self._check_list_with_filter('health_monitor', attr_exceptions,
274 delay=5, max_retries=4, type="TCP",
275 timeout=2)
276
277 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530278 def test_create_update_delete_health_monitor(self):
279 # Creates a health_monitor
Elena Ezhova43c70a22014-01-14 12:42:51 +0400280 resp, body = self.client.create_health_monitor(delay=4,
281 max_retries=3,
282 type="TCP",
283 timeout=1)
raiesmh0832580d02013-09-17 13:11:34 +0530284 self.assertEqual('201', resp['status'])
285 health_monitor = body['health_monitor']
286 # Verification of health_monitor update
Elena Ezhova43c70a22014-01-14 12:42:51 +0400287 resp, body = (self.client.update_health_monitor
288 (health_monitor['id'],
289 admin_state_up=False))
raiesmh0832580d02013-09-17 13:11:34 +0530290 self.assertEqual('200', resp['status'])
291 updated_health_monitor = body['health_monitor']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400292 self.assertFalse(updated_health_monitor['admin_state_up'])
raiesmh0832580d02013-09-17 13:11:34 +0530293 # Verification of health_monitor delete
294 resp, body = self.client.delete_health_monitor(health_monitor['id'])
295 self.assertEqual('204', resp['status'])
296
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100297 @test.attr(type='smoke')
Elena Ezhovab40848f2014-01-15 10:17:35 +0400298 def test_create_health_monitor_http_type(self):
299 hm_type = "HTTP"
300 resp, body = self.client.create_health_monitor(delay=4,
301 max_retries=3,
302 type=hm_type,
303 timeout=1)
304 self.assertEqual('201', resp['status'])
305 health_monitor = body['health_monitor']
306 self.addCleanup(self.client.delete_health_monitor,
307 health_monitor['id'])
308 self.assertEqual(hm_type, health_monitor['type'])
309
310 @test.attr(type='smoke')
311 def test_update_health_monitor_http_method(self):
312 resp, body = self.client.create_health_monitor(delay=4,
313 max_retries=3,
314 type="HTTP",
315 timeout=1)
316 self.assertEqual('201', resp['status'])
317 health_monitor = body['health_monitor']
318 self.addCleanup(self.client.delete_health_monitor,
319 health_monitor['id'])
320 resp, body = (self.client.update_health_monitor
321 (health_monitor['id'],
322 http_method="POST",
323 url_path="/home/user",
324 expected_codes="290"))
325 self.assertEqual('200', resp['status'])
326 updated_health_monitor = body['health_monitor']
327 self.assertEqual("POST", updated_health_monitor['http_method'])
328 self.assertEqual("/home/user", updated_health_monitor['url_path'])
329 self.assertEqual("290", updated_health_monitor['expected_codes'])
330
331 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530332 def test_show_health_monitor(self):
333 # Verifies the details of a health_monitor
334 resp, body = self.client.show_health_monitor(self.health_monitor['id'])
335 self.assertEqual('200', resp['status'])
336 health_monitor = body['health_monitor']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400337 for key, value in health_monitor.iteritems():
338 # 'status' should not be confirmed in api tests
339 if key != 'status':
340 self.assertEqual(self.health_monitor[key], value)
raiesmh0832580d02013-09-17 13:11:34 +0530341
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100342 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530343 def test_associate_disassociate_health_monitor_with_pool(self):
344 # Verify that a health monitor can be associated with a pool
345 resp, body = (self.client.associate_health_monitor_with_pool
346 (self.health_monitor['id'], self.pool['id']))
347 self.assertEqual('201', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400348 resp, body = self.client.show_health_monitor(
349 self.health_monitor['id'])
350 health_monitor = body['health_monitor']
351 resp, body = self.client.show_pool(self.pool['id'])
352 pool = body['pool']
353 self.assertIn(pool['id'],
354 [p['pool_id'] for p in health_monitor['pools']])
355 self.assertIn(health_monitor['id'], pool['health_monitors'])
raiesmh0832580d02013-09-17 13:11:34 +0530356 # Verify that a health monitor can be disassociated from a pool
357 resp, body = (self.client.disassociate_health_monitor_with_pool
358 (self.health_monitor['id'], self.pool['id']))
359 self.assertEqual('204', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400360 resp, body = self.client.show_pool(self.pool['id'])
361 pool = body['pool']
362 resp, body = self.client.show_health_monitor(
363 self.health_monitor['id'])
364 health_monitor = body['health_monitor']
365 self.assertNotIn(health_monitor['id'], pool['health_monitors'])
366 self.assertNotIn(pool['id'],
367 [p['pool_id'] for p in health_monitor['pools']])
raiesmh0832580d02013-09-17 13:11:34 +0530368
nayna-patel87b4ef22014-02-07 10:24:59 +0000369 @test.attr(type='smoke')
370 def test_get_lb_pool_stats(self):
371 # Verify the details of pool stats
372 resp, body = self.client.list_lb_pool_stats(self.pool['id'])
373 self.assertEqual('200', resp['status'])
374 stats = body['stats']
375 self.assertIn("bytes_in", stats)
376 self.assertIn("total_connections", stats)
377 self.assertIn("active_connections", stats)
378 self.assertIn("bytes_out", stats)
379
raiesmh0802d04b02013-09-16 12:10:10 +0530380
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900381class LoadBalancerTestXML(LoadBalancerTestJSON):
raiesmh0802d04b02013-09-16 12:10:10 +0530382 _interface = 'xml'