blob: 695dbf811a0d5983a425328d9efbb6c9e9be8769 [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-')
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400111 resp, body = self.client.create_pool(
112 name=data_utils.rand_name("pool-"),
113 lb_method='ROUND_ROBIN',
114 protocol='HTTP',
115 subnet_id=self.subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530116 pool = body['pool']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400117 resp, body = self.client.create_vip(name=name,
118 protocol="HTTP",
119 protocol_port=80,
120 subnet_id=self.subnet['id'],
121 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530122 self.assertEqual('201', resp['status'])
123 vip = body['vip']
124 vip_id = vip['id']
125 # Verification of vip update
126 new_name = "New_vip"
Elena Ezhova43c70a22014-01-14 12:42:51 +0400127 resp, body = self.client.update_vip(vip_id, name=new_name)
raiesmh080fe76852013-09-13 11:52:56 +0530128 self.assertEqual('200', resp['status'])
129 updated_vip = body['vip']
130 self.assertEqual(updated_vip['name'], new_name)
131 # Verification of vip delete
132 resp, body = self.client.delete_vip(vip['id'])
133 self.assertEqual('204', resp['status'])
izikpensod9a01a62014-02-17 20:02:32 +0200134 self.client.wait_for_resource_deletion('vip', vip['id'])
raiesmh080fe76852013-09-13 11:52:56 +0530135 # Verification of pool update
136 new_name = "New_pool"
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400137 resp, body = self.client.update_pool(pool['id'],
138 name=new_name)
raiesmh080fe76852013-09-13 11:52:56 +0530139 self.assertEqual('200', resp['status'])
140 updated_pool = body['pool']
141 self.assertEqual(updated_pool['name'], new_name)
142 # Verification of pool delete
143 resp, body = self.client.delete_pool(pool['id'])
144 self.assertEqual('204', resp['status'])
145
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100146 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +0530147 def test_show_vip(self):
148 # Verifies the details of a vip
149 resp, body = self.client.show_vip(self.vip['id'])
150 self.assertEqual('200', resp['status'])
151 vip = body['vip']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400152 for key, value in vip.iteritems():
153 # 'status' should not be confirmed in api tests
154 if key != 'status':
155 self.assertEqual(self.vip[key], value)
raiesmh0802d04b02013-09-16 12:10:10 +0530156
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100157 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530158 def test_show_pool(self):
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400159 # Here we need to new pool without any dependence with vips
160 resp, body = self.client.create_pool(
161 name=data_utils.rand_name("pool-"),
162 lb_method='ROUND_ROBIN',
163 protocol='HTTP',
164 subnet_id=self.subnet['id'])
165 self.assertEqual('201', resp['status'])
raiesmh08f5153f72013-09-16 13:38:37 +0530166 pool = body['pool']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400167 self.addCleanup(self.client.delete_pool, pool['id'])
168 # Verifies the details of a pool
169 resp, body = self.client.show_pool(pool['id'])
170 self.assertEqual('200', resp['status'])
171 shown_pool = body['pool']
172 for key, value in pool.iteritems():
173 # 'status' should not be confirmed in api tests
174 if key != 'status':
175 self.assertEqual(value, shown_pool[key])
raiesmh08f5153f72013-09-16 13:38:37 +0530176
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100177 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530178 def test_list_pools(self):
179 # Verify the pool exists in the list of all pools
180 resp, body = self.client.list_pools()
181 self.assertEqual('200', resp['status'])
182 pools = body['pools']
183 self.assertIn(self.pool['id'], [p['id'] for p in pools])
184
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100185 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400186 def test_list_pools_with_filters(self):
187 attr_exceptions = ['status', 'vip_id', 'members', 'provider',
188 'status_description']
189 self._check_list_with_filter(
190 'pool', attr_exceptions, name=data_utils.rand_name("pool-"),
191 lb_method="ROUND_ROBIN", protocol="HTTPS",
192 subnet_id=self.subnet['id'],
193 description=data_utils.rand_name('description-'),
194 admin_state_up=False)
195
196 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530197 def test_list_members(self):
198 # Verify the member exists in the list of all members
199 resp, body = self.client.list_members()
200 self.assertEqual('200', resp['status'])
201 members = body['members']
202 self.assertIn(self.member['id'], [m['id'] for m in members])
203
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100204 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400205 def test_list_members_with_filters(self):
206 attr_exceptions = ['status', 'status_description']
207 self._check_list_with_filter('member', attr_exceptions,
208 address="10.0.9.47", protocol_port=80,
209 pool_id=self.pool['id'])
210
211 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530212 def test_create_update_delete_member(self):
213 # Creates a member
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400214 resp, body = self.client.create_member(address="10.0.9.47",
215 protocol_port=80,
216 pool_id=self.pool['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530217 self.assertEqual('201', resp['status'])
218 member = body['member']
219 # Verification of member update
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400220 resp, body = self.client.update_member(member['id'],
221 admin_state_up=False)
raiesmh08f8437ed2013-09-17 10:59:38 +0530222 self.assertEqual('200', resp['status'])
223 updated_member = body['member']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400224 self.assertFalse(updated_member['admin_state_up'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530225 # Verification of member delete
226 resp, body = self.client.delete_member(member['id'])
227 self.assertEqual('204', resp['status'])
228
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100229 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530230 def test_show_member(self):
231 # Verifies the details of a member
232 resp, body = self.client.show_member(self.member['id'])
233 self.assertEqual('200', resp['status'])
234 member = body['member']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400235 for key, value in member.iteritems():
236 # 'status' should not be confirmed in api tests
237 if key != 'status':
238 self.assertEqual(self.member[key], value)
raiesmh08f8437ed2013-09-17 10:59:38 +0530239
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100240 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530241 def test_list_health_monitors(self):
242 # Verify the health monitor exists in the list of all health monitors
243 resp, body = self.client.list_health_monitors()
244 self.assertEqual('200', resp['status'])
245 health_monitors = body['health_monitors']
246 self.assertIn(self.health_monitor['id'],
247 [h['id'] for h in health_monitors])
248
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100249 @test.attr(type='smoke')
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400250 def test_list_health_monitors_with_filters(self):
251 attr_exceptions = ['status', 'status_description', 'pools']
252 self._check_list_with_filter('health_monitor', attr_exceptions,
253 delay=5, max_retries=4, type="TCP",
254 timeout=2)
255
256 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530257 def test_create_update_delete_health_monitor(self):
258 # Creates a health_monitor
Elena Ezhova43c70a22014-01-14 12:42:51 +0400259 resp, body = self.client.create_health_monitor(delay=4,
260 max_retries=3,
261 type="TCP",
262 timeout=1)
raiesmh0832580d02013-09-17 13:11:34 +0530263 self.assertEqual('201', resp['status'])
264 health_monitor = body['health_monitor']
265 # Verification of health_monitor update
Elena Ezhova43c70a22014-01-14 12:42:51 +0400266 resp, body = (self.client.update_health_monitor
267 (health_monitor['id'],
268 admin_state_up=False))
raiesmh0832580d02013-09-17 13:11:34 +0530269 self.assertEqual('200', resp['status'])
270 updated_health_monitor = body['health_monitor']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400271 self.assertFalse(updated_health_monitor['admin_state_up'])
raiesmh0832580d02013-09-17 13:11:34 +0530272 # Verification of health_monitor delete
273 resp, body = self.client.delete_health_monitor(health_monitor['id'])
274 self.assertEqual('204', resp['status'])
275
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100276 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530277 def test_show_health_monitor(self):
278 # Verifies the details of a health_monitor
279 resp, body = self.client.show_health_monitor(self.health_monitor['id'])
280 self.assertEqual('200', resp['status'])
281 health_monitor = body['health_monitor']
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400282 for key, value in health_monitor.iteritems():
283 # 'status' should not be confirmed in api tests
284 if key != 'status':
285 self.assertEqual(self.health_monitor[key], value)
raiesmh0832580d02013-09-17 13:11:34 +0530286
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100287 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530288 def test_associate_disassociate_health_monitor_with_pool(self):
289 # Verify that a health monitor can be associated with a pool
290 resp, body = (self.client.associate_health_monitor_with_pool
291 (self.health_monitor['id'], self.pool['id']))
292 self.assertEqual('201', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400293 resp, body = self.client.show_health_monitor(
294 self.health_monitor['id'])
295 health_monitor = body['health_monitor']
296 resp, body = self.client.show_pool(self.pool['id'])
297 pool = body['pool']
298 self.assertIn(pool['id'],
299 [p['pool_id'] for p in health_monitor['pools']])
300 self.assertIn(health_monitor['id'], pool['health_monitors'])
raiesmh0832580d02013-09-17 13:11:34 +0530301 # Verify that a health monitor can be disassociated from a pool
302 resp, body = (self.client.disassociate_health_monitor_with_pool
303 (self.health_monitor['id'], self.pool['id']))
304 self.assertEqual('204', resp['status'])
Ann Kamyshnikova2bc1c432013-12-10 17:31:50 +0400305 resp, body = self.client.show_pool(self.pool['id'])
306 pool = body['pool']
307 resp, body = self.client.show_health_monitor(
308 self.health_monitor['id'])
309 health_monitor = body['health_monitor']
310 self.assertNotIn(health_monitor['id'], pool['health_monitors'])
311 self.assertNotIn(pool['id'],
312 [p['pool_id'] for p in health_monitor['pools']])
raiesmh0832580d02013-09-17 13:11:34 +0530313
nayna-patel87b4ef22014-02-07 10:24:59 +0000314 @test.attr(type='smoke')
315 def test_get_lb_pool_stats(self):
316 # Verify the details of pool stats
317 resp, body = self.client.list_lb_pool_stats(self.pool['id'])
318 self.assertEqual('200', resp['status'])
319 stats = body['stats']
320 self.assertIn("bytes_in", stats)
321 self.assertIn("total_connections", stats)
322 self.assertIn("active_connections", stats)
323 self.assertIn("bytes_out", stats)
324
raiesmh0802d04b02013-09-16 12:10:10 +0530325
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900326class LoadBalancerTestXML(LoadBalancerTestJSON):
raiesmh0802d04b02013-09-16 12:10:10 +0530327 _interface = 'xml'