blob: 79817034d613484c3533a79c62ed39ae9fbf7cd2 [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'],
Ann Kamyshnikovab6659402014-01-09 17:50:31 +0400159 name=new_name,
160 description="new_description",
161 lb_method='LEAST_CONNECTIONS')
raiesmh080fe76852013-09-13 11:52:56 +0530162 self.assertEqual('200', resp['status'])
163 updated_pool = body['pool']
Ann Kamyshnikovab6659402014-01-09 17:50:31 +0400164 self.assertEqual(new_name, updated_pool['name'])
165 self.assertEqual('new_description', updated_pool['description'])
166 self.assertEqual('LEAST_CONNECTIONS', updated_pool['lb_method'])
raiesmh080fe76852013-09-13 11:52:56 +0530167 # Verification of pool delete
168 resp, body = self.client.delete_pool(pool['id'])
169 self.assertEqual('204', resp['status'])
170
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100171 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +0530172 def test_show_vip(self):
173 # Verifies the details of a vip
174 resp, body = self.client.show_vip(self.vip['id'])
175 self.assertEqual('200', resp['status'])
176 vip = body['vip']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400177 for key, value in vip.iteritems():
178 # 'status' should not be confirmed in api tests
179 if key != 'status':
180 self.assertEqual(self.vip[key], value)
raiesmh0802d04b02013-09-16 12:10:10 +0530181
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100182 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530183 def test_show_pool(self):
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400184 # Here we need to new pool without any dependence with vips
185 resp, body = self.client.create_pool(
186 name=data_utils.rand_name("pool-"),
187 lb_method='ROUND_ROBIN',
188 protocol='HTTP',
189 subnet_id=self.subnet['id'])
190 self.assertEqual('201', resp['status'])
raiesmh08f5153f72013-09-16 13:38:37 +0530191 pool = body['pool']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400192 self.addCleanup(self.client.delete_pool, pool['id'])
193 # Verifies the details of a pool
194 resp, body = self.client.show_pool(pool['id'])
195 self.assertEqual('200', resp['status'])
196 shown_pool = body['pool']
197 for key, value in pool.iteritems():
198 # 'status' should not be confirmed in api tests
199 if key != 'status':
200 self.assertEqual(value, shown_pool[key])
raiesmh08f5153f72013-09-16 13:38:37 +0530201
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100202 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530203 def test_list_pools(self):
204 # Verify the pool exists in the list of all pools
205 resp, body = self.client.list_pools()
206 self.assertEqual('200', resp['status'])
207 pools = body['pools']
208 self.assertIn(self.pool['id'], [p['id'] for p in pools])
209
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100210 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400211 def test_list_pools_with_filters(self):
212 attr_exceptions = ['status', 'vip_id', 'members', 'provider',
213 'status_description']
214 self._check_list_with_filter(
215 'pool', attr_exceptions, name=data_utils.rand_name("pool-"),
216 lb_method="ROUND_ROBIN", protocol="HTTPS",
217 subnet_id=self.subnet['id'],
218 description=data_utils.rand_name('description-'),
219 admin_state_up=False)
220
221 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530222 def test_list_members(self):
223 # Verify the member exists in the list of all members
224 resp, body = self.client.list_members()
225 self.assertEqual('200', resp['status'])
226 members = body['members']
227 self.assertIn(self.member['id'], [m['id'] for m in members])
228
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100229 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400230 def test_list_members_with_filters(self):
231 attr_exceptions = ['status', 'status_description']
232 self._check_list_with_filter('member', attr_exceptions,
233 address="10.0.9.47", protocol_port=80,
234 pool_id=self.pool['id'])
235
236 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530237 def test_create_update_delete_member(self):
238 # Creates a member
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400239 resp, body = self.client.create_member(address="10.0.9.47",
240 protocol_port=80,
241 pool_id=self.pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530242 self.assertEqual('201', resp['status'])
243 member = body['member']
244 # Verification of member update
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400245 resp, body = self.client.update_member(member['id'],
246 admin_state_up=False)
raiesmh08f8437ed2013-09-17 10:59:38 +0530247 self.assertEqual('200', resp['status'])
248 updated_member = body['member']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400249 self.assertFalse(updated_member['admin_state_up'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530250 # Verification of member delete
251 resp, body = self.client.delete_member(member['id'])
252 self.assertEqual('204', resp['status'])
253
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100254 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530255 def test_show_member(self):
256 # Verifies the details of a member
257 resp, body = self.client.show_member(self.member['id'])
258 self.assertEqual('200', resp['status'])
259 member = body['member']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400260 for key, value in member.iteritems():
261 # 'status' should not be confirmed in api tests
262 if key != 'status':
263 self.assertEqual(self.member[key], value)
raiesmh08f8437ed2013-09-17 10:59:38 +0530264
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100265 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530266 def test_list_health_monitors(self):
267 # Verify the health monitor exists in the list of all health monitors
268 resp, body = self.client.list_health_monitors()
269 self.assertEqual('200', resp['status'])
270 health_monitors = body['health_monitors']
271 self.assertIn(self.health_monitor['id'],
272 [h['id'] for h in health_monitors])
273
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100274 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400275 def test_list_health_monitors_with_filters(self):
276 attr_exceptions = ['status', 'status_description', 'pools']
277 self._check_list_with_filter('health_monitor', attr_exceptions,
278 delay=5, max_retries=4, type="TCP",
279 timeout=2)
280
281 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530282 def test_create_update_delete_health_monitor(self):
283 # Creates a health_monitor
Elena Ezhova43c70a22014-01-14 12:42:51 +0400284 resp, body = self.client.create_health_monitor(delay=4,
285 max_retries=3,
286 type="TCP",
287 timeout=1)
raiesmh0832580d02013-09-17 13:11:34 +0530288 self.assertEqual('201', resp['status'])
289 health_monitor = body['health_monitor']
290 # Verification of health_monitor update
Elena Ezhova43c70a22014-01-14 12:42:51 +0400291 resp, body = (self.client.update_health_monitor
292 (health_monitor['id'],
293 admin_state_up=False))
raiesmh0832580d02013-09-17 13:11:34 +0530294 self.assertEqual('200', resp['status'])
295 updated_health_monitor = body['health_monitor']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400296 self.assertFalse(updated_health_monitor['admin_state_up'])
raiesmh0832580d02013-09-17 13:11:34 +0530297 # Verification of health_monitor delete
298 resp, body = self.client.delete_health_monitor(health_monitor['id'])
299 self.assertEqual('204', resp['status'])
300
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100301 @test.attr(type='smoke')
Elena Ezhovab40848f2014-01-15 10:17:35 +0400302 def test_create_health_monitor_http_type(self):
303 hm_type = "HTTP"
304 resp, body = self.client.create_health_monitor(delay=4,
305 max_retries=3,
306 type=hm_type,
307 timeout=1)
308 self.assertEqual('201', resp['status'])
309 health_monitor = body['health_monitor']
310 self.addCleanup(self.client.delete_health_monitor,
311 health_monitor['id'])
312 self.assertEqual(hm_type, health_monitor['type'])
313
314 @test.attr(type='smoke')
315 def test_update_health_monitor_http_method(self):
316 resp, body = self.client.create_health_monitor(delay=4,
317 max_retries=3,
318 type="HTTP",
319 timeout=1)
320 self.assertEqual('201', resp['status'])
321 health_monitor = body['health_monitor']
322 self.addCleanup(self.client.delete_health_monitor,
323 health_monitor['id'])
324 resp, body = (self.client.update_health_monitor
325 (health_monitor['id'],
326 http_method="POST",
327 url_path="/home/user",
328 expected_codes="290"))
329 self.assertEqual('200', resp['status'])
330 updated_health_monitor = body['health_monitor']
331 self.assertEqual("POST", updated_health_monitor['http_method'])
332 self.assertEqual("/home/user", updated_health_monitor['url_path'])
333 self.assertEqual("290", updated_health_monitor['expected_codes'])
334
335 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530336 def test_show_health_monitor(self):
337 # Verifies the details of a health_monitor
338 resp, body = self.client.show_health_monitor(self.health_monitor['id'])
339 self.assertEqual('200', resp['status'])
340 health_monitor = body['health_monitor']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400341 for key, value in health_monitor.iteritems():
342 # 'status' should not be confirmed in api tests
343 if key != 'status':
344 self.assertEqual(self.health_monitor[key], value)
raiesmh0832580d02013-09-17 13:11:34 +0530345
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100346 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530347 def test_associate_disassociate_health_monitor_with_pool(self):
348 # Verify that a health monitor can be associated with a pool
349 resp, body = (self.client.associate_health_monitor_with_pool
350 (self.health_monitor['id'], self.pool['id']))
351 self.assertEqual('201', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400352 resp, body = self.client.show_health_monitor(
353 self.health_monitor['id'])
354 health_monitor = body['health_monitor']
355 resp, body = self.client.show_pool(self.pool['id'])
356 pool = body['pool']
357 self.assertIn(pool['id'],
358 [p['pool_id'] for p in health_monitor['pools']])
359 self.assertIn(health_monitor['id'], pool['health_monitors'])
raiesmh0832580d02013-09-17 13:11:34 +0530360 # Verify that a health monitor can be disassociated from a pool
361 resp, body = (self.client.disassociate_health_monitor_with_pool
362 (self.health_monitor['id'], self.pool['id']))
363 self.assertEqual('204', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400364 resp, body = self.client.show_pool(self.pool['id'])
365 pool = body['pool']
366 resp, body = self.client.show_health_monitor(
367 self.health_monitor['id'])
368 health_monitor = body['health_monitor']
369 self.assertNotIn(health_monitor['id'], pool['health_monitors'])
370 self.assertNotIn(pool['id'],
371 [p['pool_id'] for p in health_monitor['pools']])
raiesmh0832580d02013-09-17 13:11:34 +0530372
nayna-patel87b4ef22014-02-07 10:24:59 +0000373 @test.attr(type='smoke')
374 def test_get_lb_pool_stats(self):
375 # Verify the details of pool stats
376 resp, body = self.client.list_lb_pool_stats(self.pool['id'])
377 self.assertEqual('200', resp['status'])
378 stats = body['stats']
379 self.assertIn("bytes_in", stats)
380 self.assertIn("total_connections", stats)
381 self.assertIn("active_connections", stats)
382 self.assertIn("bytes_out", stats)
383
Ann Kamyshnikovab6659402014-01-09 17:50:31 +0400384 @test.attr(type='smoke')
385 def test_update_list_of_health_monitors_associated_with_pool(self):
386 resp, _ = (self.client.associate_health_monitor_with_pool
387 (self.health_monitor['id'], self.pool['id']))
388 self.assertEqual('201', resp['status'])
389 resp, _ = self.client.update_health_monitor(
390 self.health_monitor['id'], admin_state_up=False)
391 self.assertEqual('200', resp['status'])
392 resp, body = self.client.show_pool(self.pool['id'])
393 self.assertEqual('200', resp['status'])
394 health_monitors = body['pool']['health_monitors']
395 for health_monitor_id in health_monitors:
396 resp, body = self.client.show_health_monitor(health_monitor_id)
397 self.assertEqual('200', resp['status'])
398 self.assertFalse(body['health_monitor']['admin_state_up'])
399 resp, _ = (self.client.disassociate_health_monitor_with_pool
400 (self.health_monitor['id'], self.pool['id']))
401 self.assertEqual('204', resp['status'])
402
403 @test.attr(type='smoke')
404 def test_update_admin_state_up_of_pool(self):
405 resp, _ = self.client.update_pool(self.pool['id'],
406 admin_state_up=False)
407 self.assertEqual('200', resp['status'])
408 resp, body = self.client.show_pool(self.pool['id'])
409 self.assertEqual('200', resp['status'])
410 pool = body['pool']
411 self.assertFalse(pool['admin_state_up'])
412
413 @test.attr(type='smoke')
414 def test_show_vip_associated_with_pool(self):
415 resp, body = self.client.show_pool(self.pool['id'])
416 self.assertEqual('200', resp['status'])
417 pool = body['pool']
418 resp, body = self.client.show_vip(pool['vip_id'])
419 self.assertEqual('200', resp['status'])
420 vip = body['vip']
421 self.assertEqual(self.vip['name'], vip['name'])
422 self.assertEqual(self.vip['id'], vip['id'])
423
424 @test.attr(type='smoke')
425 def test_show_members_associated_with_pool(self):
426 resp, body = self.client.show_pool(self.pool['id'])
427 self.assertEqual('200', resp['status'])
428 members = body['pool']['members']
429 for member_id in members:
430 resp, body = self.client.show_member(member_id)
431 self.assertEqual('200', resp['status'])
432 self.assertIsNotNone(body['member']['status'])
433 self.assertEqual(member_id, body['member']['id'])
434 self.assertIsNotNone(body['member']['admin_state_up'])
435
raiesmh0802d04b02013-09-16 12:10:10 +0530436
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900437class LoadBalancerTestXML(LoadBalancerTestJSON):
raiesmh0802d04b02013-09-16 12:10:10 +0530438 _interface = 'xml'