blob: 03e095d247eba3123bf0fdbccc204215e5114e9d [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
mouad benchchaouiea2440d2013-12-22 00:38:06 +010064 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +053065 def test_list_vips(self):
66 # Verify the vIP exists in the list of all vIPs
67 resp, body = self.client.list_vips()
68 self.assertEqual('200', resp['status'])
69 vips = body['vips']
70 found = None
71 for n in vips:
72 if (n['id'] == self.vip['id']):
73 found = n['id']
74 msg = "vIPs list doesn't contain created vip"
75 self.assertIsNotNone(found, msg)
76
77 def test_create_update_delete_pool_vip(self):
78 # Creates a vip
Masayuki Igawa259c1132013-10-31 17:48:44 +090079 name = data_utils.rand_name('vip-')
Eugene Nikanorov431e04a2013-12-17 15:44:27 +040080 resp, body = self.client.create_pool(
81 name=data_utils.rand_name("pool-"),
82 lb_method='ROUND_ROBIN',
83 protocol='HTTP',
84 subnet_id=self.subnet['id'])
raiesmh080fe76852013-09-13 11:52:56 +053085 pool = body['pool']
Elena Ezhova43c70a22014-01-14 12:42:51 +040086 resp, body = self.client.create_vip(name=name,
87 protocol="HTTP",
88 protocol_port=80,
89 subnet_id=self.subnet['id'],
90 pool_id=pool['id'])
raiesmh080fe76852013-09-13 11:52:56 +053091 self.assertEqual('201', resp['status'])
92 vip = body['vip']
93 vip_id = vip['id']
94 # Verification of vip update
95 new_name = "New_vip"
Elena Ezhova43c70a22014-01-14 12:42:51 +040096 resp, body = self.client.update_vip(vip_id, name=new_name)
raiesmh080fe76852013-09-13 11:52:56 +053097 self.assertEqual('200', resp['status'])
98 updated_vip = body['vip']
99 self.assertEqual(updated_vip['name'], new_name)
100 # Verification of vip delete
101 resp, body = self.client.delete_vip(vip['id'])
102 self.assertEqual('204', resp['status'])
103 # Verification of pool update
104 new_name = "New_pool"
Eugene Nikanorov431e04a2013-12-17 15:44:27 +0400105 resp, body = self.client.update_pool(pool['id'],
106 name=new_name)
raiesmh080fe76852013-09-13 11:52:56 +0530107 self.assertEqual('200', resp['status'])
108 updated_pool = body['pool']
109 self.assertEqual(updated_pool['name'], new_name)
110 # Verification of pool delete
111 resp, body = self.client.delete_pool(pool['id'])
112 self.assertEqual('204', resp['status'])
113
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100114 @test.attr(type='smoke')
raiesmh080fe76852013-09-13 11:52:56 +0530115 def test_show_vip(self):
116 # Verifies the details of a vip
117 resp, body = self.client.show_vip(self.vip['id'])
118 self.assertEqual('200', resp['status'])
119 vip = body['vip']
120 self.assertEqual(self.vip['id'], vip['id'])
121 self.assertEqual(self.vip['name'], vip['name'])
raiesmh0802d04b02013-09-16 12:10:10 +0530122
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100123 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530124 def test_show_pool(self):
125 # Verifies the details of a pool
126 resp, body = self.client.show_pool(self.pool['id'])
127 self.assertEqual('200', resp['status'])
128 pool = body['pool']
129 self.assertEqual(self.pool['id'], pool['id'])
130 self.assertEqual(self.pool['name'], pool['name'])
131
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100132 @test.attr(type='smoke')
raiesmh08f5153f72013-09-16 13:38:37 +0530133 def test_list_pools(self):
134 # Verify the pool exists in the list of all pools
135 resp, body = self.client.list_pools()
136 self.assertEqual('200', resp['status'])
137 pools = body['pools']
138 self.assertIn(self.pool['id'], [p['id'] for p in pools])
139
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100140 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530141 def test_list_members(self):
142 # Verify the member exists in the list of all members
143 resp, body = self.client.list_members()
144 self.assertEqual('200', resp['status'])
145 members = body['members']
146 self.assertIn(self.member['id'], [m['id'] for m in members])
147
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100148 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530149 def test_create_update_delete_member(self):
150 # Creates a member
Stephen Granabbe5632013-11-19 19:16:14 +0000151 resp, body = self.client.create_member("10.0.9.47", 80,
raiesmh08f8437ed2013-09-17 10:59:38 +0530152 self.pool['id'])
153 self.assertEqual('201', resp['status'])
154 member = body['member']
155 # Verification of member update
Elena Ezhova43c70a22014-01-14 12:42:51 +0400156 resp, body = self.client.update_member(False, member['id'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530157 self.assertEqual('200', resp['status'])
158 updated_member = body['member']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400159 self.assertFalse(updated_member['admin_state_up'])
raiesmh08f8437ed2013-09-17 10:59:38 +0530160 # Verification of member delete
161 resp, body = self.client.delete_member(member['id'])
162 self.assertEqual('204', resp['status'])
163
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100164 @test.attr(type='smoke')
raiesmh08f8437ed2013-09-17 10:59:38 +0530165 def test_show_member(self):
166 # Verifies the details of a member
167 resp, body = self.client.show_member(self.member['id'])
168 self.assertEqual('200', resp['status'])
169 member = body['member']
170 self.assertEqual(self.member['id'], member['id'])
171 self.assertEqual(self.member['admin_state_up'],
172 member['admin_state_up'])
173
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100174 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530175 def test_list_health_monitors(self):
176 # Verify the health monitor exists in the list of all health monitors
177 resp, body = self.client.list_health_monitors()
178 self.assertEqual('200', resp['status'])
179 health_monitors = body['health_monitors']
180 self.assertIn(self.health_monitor['id'],
181 [h['id'] for h in health_monitors])
182
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100183 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530184 def test_create_update_delete_health_monitor(self):
185 # Creates a health_monitor
Elena Ezhova43c70a22014-01-14 12:42:51 +0400186 resp, body = self.client.create_health_monitor(delay=4,
187 max_retries=3,
188 type="TCP",
189 timeout=1)
raiesmh0832580d02013-09-17 13:11:34 +0530190 self.assertEqual('201', resp['status'])
191 health_monitor = body['health_monitor']
192 # Verification of health_monitor update
Elena Ezhova43c70a22014-01-14 12:42:51 +0400193 resp, body = (self.client.update_health_monitor
194 (health_monitor['id'],
195 admin_state_up=False))
raiesmh0832580d02013-09-17 13:11:34 +0530196 self.assertEqual('200', resp['status'])
197 updated_health_monitor = body['health_monitor']
Elena Ezhova43c70a22014-01-14 12:42:51 +0400198 self.assertFalse(updated_health_monitor['admin_state_up'])
raiesmh0832580d02013-09-17 13:11:34 +0530199 # Verification of health_monitor delete
200 resp, body = self.client.delete_health_monitor(health_monitor['id'])
201 self.assertEqual('204', resp['status'])
202
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100203 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530204 def test_show_health_monitor(self):
205 # Verifies the details of a health_monitor
206 resp, body = self.client.show_health_monitor(self.health_monitor['id'])
207 self.assertEqual('200', resp['status'])
208 health_monitor = body['health_monitor']
209 self.assertEqual(self.health_monitor['id'], health_monitor['id'])
210 self.assertEqual(self.health_monitor['admin_state_up'],
211 health_monitor['admin_state_up'])
212
mouad benchchaouiea2440d2013-12-22 00:38:06 +0100213 @test.attr(type='smoke')
raiesmh0832580d02013-09-17 13:11:34 +0530214 def test_associate_disassociate_health_monitor_with_pool(self):
215 # Verify that a health monitor can be associated with a pool
216 resp, body = (self.client.associate_health_monitor_with_pool
217 (self.health_monitor['id'], self.pool['id']))
218 self.assertEqual('201', resp['status'])
219 # Verify that a health monitor can be disassociated from a pool
220 resp, body = (self.client.disassociate_health_monitor_with_pool
221 (self.health_monitor['id'], self.pool['id']))
222 self.assertEqual('204', resp['status'])
223
nayna-patel87b4ef22014-02-07 10:24:59 +0000224 @test.attr(type='smoke')
225 def test_get_lb_pool_stats(self):
226 # Verify the details of pool stats
227 resp, body = self.client.list_lb_pool_stats(self.pool['id'])
228 self.assertEqual('200', resp['status'])
229 stats = body['stats']
230 self.assertIn("bytes_in", stats)
231 self.assertIn("total_connections", stats)
232 self.assertIn("active_connections", stats)
233 self.assertIn("bytes_out", stats)
234
raiesmh0802d04b02013-09-16 12:10:10 +0530235
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900236class LoadBalancerTestXML(LoadBalancerTestJSON):
raiesmh0802d04b02013-09-16 12:10:10 +0530237 _interface = 'xml'