blob: 14c8500898cf8fdd2f0aaced48fc6f3cd6ca647e [file] [log] [blame]
Jay Pipesf4dad392012-06-05 16:03:58 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipesf4dad392012-06-05 16:03:58 -04004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
Miguel Lavallecc939612013-02-22 17:27:20 -060018import netaddr
Jay Pipesf4dad392012-06-05 16:03:58 -040019
Sean Dague1937d092013-05-17 16:36:38 -040020from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090021from tempest.common.utils import data_utils
Miguel Lavallecc939612013-02-22 17:27:20 -060022from tempest import exceptions
23from tempest.test import attr
Unmesh Gurjar44986832012-05-08 19:57:10 +053024
25
raiesmh0867698322013-08-20 13:09:01 +053026class NetworksTestJSON(base.BaseNetworkTest):
27 _interface = 'json'
Unmesh Gurjar44986832012-05-08 19:57:10 +053028
Miguel Lavallecc939612013-02-22 17:27:20 -060029 """
Mark McClainf2982e82013-07-06 17:48:03 -040030 Tests the following operations in the Neutron API using the REST client for
31 Neutron:
Miguel Lavallecc939612013-02-22 17:27:20 -060032
33 create a network for a tenant
34 list tenant's networks
35 show a tenant network details
36 create a subnet for a tenant
37 list tenant's subnets
38 show a tenant subnet details
raiesmh08e1aad982013-08-05 14:19:36 +053039 port create
40 port delete
41 port list
42 port show
43 port update
44 network update
45 subnet update
Miguel Lavallecc939612013-02-22 17:27:20 -060046
Mark McClainf2982e82013-07-06 17:48:03 -040047 v2.0 of the Neutron API is assumed. It is also assumed that the following
Miguel Lavallecc939612013-02-22 17:27:20 -060048 options are defined in the [network] section of etc/tempest.conf:
49
50 tenant_network_cidr with a block of cidr's from which smaller blocks
51 can be allocated for tenant networks
52
53 tenant_network_mask_bits with the mask bits to be used to partition the
54 block defined by tenant-network_cidr
55 """
56
Unmesh Gurjar44986832012-05-08 19:57:10 +053057 @classmethod
58 def setUpClass(cls):
raiesmh0867698322013-08-20 13:09:01 +053059 super(NetworksTestJSON, cls).setUpClass()
Jay Pipesf4dad392012-06-05 16:03:58 -040060 cls.network = cls.create_network()
61 cls.name = cls.network['name']
Miguel Lavallecc939612013-02-22 17:27:20 -060062 cls.subnet = cls.create_subnet(cls.network)
63 cls.cidr = cls.subnet['cidr']
raiesmh08e1aad982013-08-05 14:19:36 +053064 cls.port = cls.create_port(cls.network)
Unmesh Gurjar44986832012-05-08 19:57:10 +053065
Attila Fazekas71834a22013-08-18 06:56:21 +020066 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +053067 def test_create_update_delete_network_subnet(self):
Miguel Lavallecc939612013-02-22 17:27:20 -060068 # Creates a network
Masayuki Igawa259c1132013-10-31 17:48:44 +090069 name = data_utils.rand_name('network-')
Unmesh Gurjar44986832012-05-08 19:57:10 +053070 resp, body = self.client.create_network(name)
Miguel Lavallecc939612013-02-22 17:27:20 -060071 self.assertEqual('201', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053072 network = body['network']
raiesmh08e1aad982013-08-05 14:19:36 +053073 net_id = network['id']
74 # Verification of network update
75 new_name = "New_network"
76 resp, body = self.client.update_network(net_id, new_name)
77 self.assertEqual('200', resp['status'])
78 updated_net = body['network']
79 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -060080 # Find a cidr that is not in use yet and create a subnet with it
81 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
82 mask_bits = self.network_cfg.tenant_network_mask_bits
83 for subnet_cidr in cidr.subnet(mask_bits):
84 try:
raiesmh08e1aad982013-08-05 14:19:36 +053085 resp, body = self.client.create_subnet(net_id,
Miguel Lavallecc939612013-02-22 17:27:20 -060086 str(subnet_cidr))
87 break
88 except exceptions.BadRequest as e:
89 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
90 if not is_overlapping_cidr:
91 raise
92 self.assertEqual('201', resp['status'])
93 subnet = body['subnet']
raiesmh08e1aad982013-08-05 14:19:36 +053094 subnet_id = subnet['id']
95 # Verification of subnet update
96 new_subnet = "New_subnet"
97 resp, body = self.client.update_subnet(subnet_id, new_subnet)
98 self.assertEqual('200', resp['status'])
99 updated_subnet = body['subnet']
100 self.assertEqual(updated_subnet['name'], new_subnet)
raiesmh0867698322013-08-20 13:09:01 +0530101 # Delete subnet and network
raiesmh08e1aad982013-08-05 14:19:36 +0530102 resp, body = self.client.delete_subnet(subnet_id)
Miguel Lavallecc939612013-02-22 17:27:20 -0600103 self.assertEqual('204', resp['status'])
raiesmh08e1aad982013-08-05 14:19:36 +0530104 resp, body = self.client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530105 self.assertEqual('204', resp['status'])
106
Attila Fazekas71834a22013-08-18 06:56:21 +0200107 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530108 def test_show_network(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500109 # Verifies the details of a network
Miguel Lavallecc939612013-02-22 17:27:20 -0600110 resp, body = self.client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530111 self.assertEqual('200', resp['status'])
112 network = body['network']
113 self.assertEqual(self.network['id'], network['id'])
114 self.assertEqual(self.name, network['name'])
115
Attila Fazekas71834a22013-08-18 06:56:21 +0200116 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530117 def test_list_networks(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500118 # Verify the network exists in the list of all networks
Unmesh Gurjar44986832012-05-08 19:57:10 +0530119 resp, body = self.client.list_networks()
raiesmh0867698322013-08-20 13:09:01 +0530120 self.assertEqual('200', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530121 networks = body['networks']
raiesmh08e1aad982013-08-05 14:19:36 +0530122 found = None
123 for n in networks:
124 if (n['id'] == self.network['id']):
125 found = n['id']
126 msg = "Network list doesn't contain created network"
127 self.assertIsNotNone(found, msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530128
Attila Fazekas71834a22013-08-18 06:56:21 +0200129 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600130 def test_show_subnet(self):
131 # Verifies the details of a subnet
132 resp, body = self.client.show_subnet(self.subnet['id'])
133 self.assertEqual('200', resp['status'])
134 subnet = body['subnet']
135 self.assertEqual(self.subnet['id'], subnet['id'])
136 self.assertEqual(self.cidr, subnet['cidr'])
137
Attila Fazekas71834a22013-08-18 06:56:21 +0200138 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600139 def test_list_subnets(self):
140 # Verify the subnet exists in the list of all subnets
141 resp, body = self.client.list_subnets()
raiesmh0867698322013-08-20 13:09:01 +0530142 self.assertEqual('200', resp['status'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600143 subnets = body['subnets']
raiesmh08e1aad982013-08-05 14:19:36 +0530144 found = None
145 for n in subnets:
146 if (n['id'] == self.subnet['id']):
147 found = n['id']
148 msg = "Subnet list doesn't contain created subnet"
149 self.assertIsNotNone(found, msg)
150
Attila Fazekas71834a22013-08-18 06:56:21 +0200151 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530152 def test_create_update_delete_port(self):
raiesmh0867698322013-08-20 13:09:01 +0530153 # Verify that successful port creation, update & deletion
raiesmh08e1aad982013-08-05 14:19:36 +0530154 resp, body = self.client.create_port(self.network['id'])
155 self.assertEqual('201', resp['status'])
156 port = body['port']
157 # Verification of port update
158 new_port = "New_Port"
159 resp, body = self.client.update_port(port['id'], new_port)
160 self.assertEqual('200', resp['status'])
161 updated_port = body['port']
162 self.assertEqual(updated_port['name'], new_port)
163 # Verification of port delete
164 resp, body = self.client.delete_port(port['id'])
165 self.assertEqual('204', resp['status'])
166
Attila Fazekas71834a22013-08-18 06:56:21 +0200167 @attr(type='smoke')
raiesmh0867698322013-08-20 13:09:01 +0530168 def test_show_port(self):
raiesmh08e1aad982013-08-05 14:19:36 +0530169 # Verify the details of port
170 resp, body = self.client.show_port(self.port['id'])
171 self.assertEqual('200', resp['status'])
172 port = body['port']
173 self.assertEqual(self.port['id'], port['id'])
174
Attila Fazekas71834a22013-08-18 06:56:21 +0200175 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530176 def test_list_ports(self):
177 # Verify the port exists in the list of all ports
178 resp, body = self.client.list_ports()
179 self.assertEqual('200', resp['status'])
180 ports_list = body['ports']
181 found = None
182 for n in ports_list:
183 if (n['id'] == self.port['id']):
184 found = n['id']
185 self.assertIsNotNone(found, "Port list doesn't contain created port")
Anju Tiwari6656f582013-08-03 05:43:42 +0530186
Attila Fazekas71834a22013-08-18 06:56:21 +0200187 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530188 def test_show_non_existent_network(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900189 non_exist_id = data_utils.rand_name('network')
Anju Tiwari6656f582013-08-03 05:43:42 +0530190 self.assertRaises(exceptions.NotFound, self.client.show_network,
191 non_exist_id)
192
Attila Fazekas71834a22013-08-18 06:56:21 +0200193 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530194 def test_show_non_existent_subnet(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900195 non_exist_id = data_utils.rand_name('subnet')
Anju Tiwari6656f582013-08-03 05:43:42 +0530196 self.assertRaises(exceptions.NotFound, self.client.show_subnet,
197 non_exist_id)
Nayna Patelb03eab42013-08-08 08:58:48 +0000198
raiesmh08b35bb6d2013-09-13 11:39:11 +0530199 @attr(type=['negative', 'smoke'])
200 def test_show_non_existent_port(self):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900201 non_exist_id = data_utils.rand_name('port')
raiesmh08b35bb6d2013-09-13 11:39:11 +0530202 self.assertRaises(exceptions.NotFound, self.client.show_port,
203 non_exist_id)
204
raiesmh086b055e22013-09-16 12:59:57 +0530205
206class NetworksTestXML(NetworksTestJSON):
207 _interface = 'xml'
208
209
210class BulkNetworkOpsJSON(base.BaseNetworkTest):
211 _interface = 'json'
212
213 """
214 Tests the following operations in the Neutron API using the REST client for
215 Neutron:
216
217 bulk network creation
218 bulk subnet creation
219 bulk subnet creation
220 list tenant's networks
221
222 v2.0 of the Neutron API is assumed. It is also assumed that the following
223 options are defined in the [network] section of etc/tempest.conf:
224
225 tenant_network_cidr with a block of cidr's from which smaller blocks
226 can be allocated for tenant networks
227
228 tenant_network_mask_bits with the mask bits to be used to partition the
229 block defined by tenant-network_cidr
230 """
231
232 @classmethod
233 def setUpClass(cls):
234 super(BulkNetworkOpsJSON, cls).setUpClass()
235 cls.network1 = cls.create_network()
236 cls.network2 = cls.create_network()
237
238 def _delete_networks(self, created_networks):
239 for n in created_networks:
240 resp, body = self.client.delete_network(n['id'])
241 self.assertEqual(204, resp.status)
242 # Asserting that the networks are not found in the list after deletion
243 resp, body = self.client.list_networks()
244 networks_list = list()
245 for network in body['networks']:
246 networks_list.append(network['id'])
247 for n in created_networks:
248 self.assertNotIn(n['id'], networks_list)
249
250 def _delete_subnets(self, created_subnets):
251 for n in created_subnets:
252 resp, body = self.client.delete_subnet(n['id'])
253 self.assertEqual(204, resp.status)
254 # Asserting that the subnets are not found in the list after deletion
255 resp, body = self.client.list_subnets()
256 subnets_list = list()
257 for subnet in body['subnets']:
258 subnets_list.append(subnet['id'])
259 for n in created_subnets:
260 self.assertNotIn(n['id'], subnets_list)
261
262 def _delete_ports(self, created_ports):
263 for n in created_ports:
264 resp, body = self.client.delete_port(n['id'])
265 self.assertEqual(204, resp.status)
266 # Asserting that the ports are not found in the list after deletion
267 resp, body = self.client.list_ports()
268 ports_list = list()
269 for port in body['ports']:
270 ports_list.append(port['id'])
271 for n in created_ports:
272 self.assertNotIn(n['id'], ports_list)
273
Attila Fazekas71834a22013-08-18 06:56:21 +0200274 @attr(type='smoke')
Nayna Patelb03eab42013-08-08 08:58:48 +0000275 def test_bulk_create_delete_network(self):
276 # Creates 2 networks in one request
Masayuki Igawa259c1132013-10-31 17:48:44 +0900277 network_names = [data_utils.rand_name('network-'),
278 data_utils.rand_name('network-')]
Nayna Patelb03eab42013-08-08 08:58:48 +0000279 resp, body = self.client.create_bulk_network(2, network_names)
280 created_networks = body['networks']
281 self.assertEqual('201', resp['status'])
282 self.addCleanup(self._delete_networks, created_networks)
283 # Asserting that the networks are found in the list after creation
284 resp, body = self.client.list_networks()
285 networks_list = list()
286 for network in body['networks']:
287 networks_list.append(network['id'])
288 for n in created_networks:
289 self.assertIsNotNone(n['id'])
290 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530291
raiesmh082d5c6512013-09-06 15:35:05 +0530292 @attr(type='smoke')
293 def test_bulk_create_delete_subnet(self):
294 # Creates 2 subnets in one request
295 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
296 mask_bits = self.network_cfg.tenant_network_mask_bits
297 cidrs = []
298 for subnet_cidr in cidr.subnet(mask_bits):
299 cidrs.append(subnet_cidr)
300 names = []
301 networks = [self.network1['id'], self.network2['id']]
302 for i in range(len(networks)):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900303 names.append(data_utils.rand_name('subnet-'))
raiesmh082d5c6512013-09-06 15:35:05 +0530304 subnet_list = []
305 # TODO(raies): "for IPv6, version list [4, 6] will be used.
306 # and cidr for IPv6 will be of IPv6"
307 ip_version = [4, 4]
308 for i in range(len(names)):
309 p1 = {
310 'network_id': networks[i],
311 'cidr': str(cidrs[(i)]),
312 'name': names[i],
313 'ip_version': ip_version[i]
314 }
315 subnet_list.append(p1)
316 del subnet_list[1]['name']
317 resp, body = self.client.create_bulk_subnet(subnet_list)
318 created_subnets = body['subnets']
319 self.addCleanup(self._delete_subnets, created_subnets)
320 self.assertEqual('201', resp['status'])
321 # Asserting that the subnets are found in the list after creation
322 resp, body = self.client.list_subnets()
323 subnets_list = list()
324 for subnet in body['subnets']:
325 subnets_list.append(subnet['id'])
326 for n in created_subnets:
327 self.assertIsNotNone(n['id'])
328 self.assertIn(n['id'], subnets_list)
329
330 @attr(type='smoke')
331 def test_bulk_create_delete_port(self):
332 # Creates 2 ports in one request
333 names = []
334 networks = [self.network1['id'], self.network2['id']]
335 for i in range(len(networks)):
Masayuki Igawa259c1132013-10-31 17:48:44 +0900336 names.append(data_utils.rand_name('port-'))
raiesmh082d5c6512013-09-06 15:35:05 +0530337 port_list = []
338 state = [True, False]
339 for i in range(len(names)):
340 p1 = {
341 'network_id': networks[i],
342 'name': names[i],
343 'admin_state_up': state[i],
344 }
345 port_list.append(p1)
346 del port_list[1]['name']
347 resp, body = self.client.create_bulk_port(port_list)
348 created_ports = body['ports']
349 self.addCleanup(self._delete_ports, created_ports)
350 self.assertEqual('201', resp['status'])
351 # Asserting that the ports are found in the list after creation
352 resp, body = self.client.list_ports()
353 ports_list = list()
354 for port in body['ports']:
355 ports_list.append(port['id'])
356 for n in created_ports:
357 self.assertIsNotNone(n['id'])
358 self.assertIn(n['id'], ports_list)
359
raiesmh0867698322013-08-20 13:09:01 +0530360
raiesmh086b055e22013-09-16 12:59:57 +0530361class BulkNetworkOpsXML(BulkNetworkOpsJSON):
raiesmh0867698322013-08-20 13:09:01 +0530362 _interface = 'xml'