blob: f2df1ee78d270f68b5e3d8b3dd52149ee011cccc [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
Unmesh Gurjar44986832012-05-08 19:57:10 +053021from tempest.common.utils.data_utils import rand_name
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
69 name = 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):
189 non_exist_id = rand_name('network')
190 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):
195 non_exist_id = rand_name('subnet')
196 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):
201 non_exist_id = rand_name('port')
202 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
277 network_names = [rand_name('network-'), rand_name('network-')]
278 resp, body = self.client.create_bulk_network(2, network_names)
279 created_networks = body['networks']
280 self.assertEqual('201', resp['status'])
281 self.addCleanup(self._delete_networks, created_networks)
282 # Asserting that the networks are found in the list after creation
283 resp, body = self.client.list_networks()
284 networks_list = list()
285 for network in body['networks']:
286 networks_list.append(network['id'])
287 for n in created_networks:
288 self.assertIsNotNone(n['id'])
289 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530290
raiesmh082d5c6512013-09-06 15:35:05 +0530291 @attr(type='smoke')
292 def test_bulk_create_delete_subnet(self):
293 # Creates 2 subnets in one request
294 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
295 mask_bits = self.network_cfg.tenant_network_mask_bits
296 cidrs = []
297 for subnet_cidr in cidr.subnet(mask_bits):
298 cidrs.append(subnet_cidr)
299 names = []
300 networks = [self.network1['id'], self.network2['id']]
301 for i in range(len(networks)):
302 names.append(rand_name('subnet-'))
303 subnet_list = []
304 # TODO(raies): "for IPv6, version list [4, 6] will be used.
305 # and cidr for IPv6 will be of IPv6"
306 ip_version = [4, 4]
307 for i in range(len(names)):
308 p1 = {
309 'network_id': networks[i],
310 'cidr': str(cidrs[(i)]),
311 'name': names[i],
312 'ip_version': ip_version[i]
313 }
314 subnet_list.append(p1)
315 del subnet_list[1]['name']
316 resp, body = self.client.create_bulk_subnet(subnet_list)
317 created_subnets = body['subnets']
318 self.addCleanup(self._delete_subnets, created_subnets)
319 self.assertEqual('201', resp['status'])
320 # Asserting that the subnets are found in the list after creation
321 resp, body = self.client.list_subnets()
322 subnets_list = list()
323 for subnet in body['subnets']:
324 subnets_list.append(subnet['id'])
325 for n in created_subnets:
326 self.assertIsNotNone(n['id'])
327 self.assertIn(n['id'], subnets_list)
328
329 @attr(type='smoke')
330 def test_bulk_create_delete_port(self):
331 # Creates 2 ports in one request
332 names = []
333 networks = [self.network1['id'], self.network2['id']]
334 for i in range(len(networks)):
335 names.append(rand_name('port-'))
336 port_list = []
337 state = [True, False]
338 for i in range(len(names)):
339 p1 = {
340 'network_id': networks[i],
341 'name': names[i],
342 'admin_state_up': state[i],
343 }
344 port_list.append(p1)
345 del port_list[1]['name']
346 resp, body = self.client.create_bulk_port(port_list)
347 created_ports = body['ports']
348 self.addCleanup(self._delete_ports, created_ports)
349 self.assertEqual('201', resp['status'])
350 # Asserting that the ports are found in the list after creation
351 resp, body = self.client.list_ports()
352 ports_list = list()
353 for port in body['ports']:
354 ports_list.append(port['id'])
355 for n in created_ports:
356 self.assertIsNotNone(n['id'])
357 self.assertIn(n['id'], ports_list)
358
raiesmh0867698322013-08-20 13:09:01 +0530359
raiesmh086b055e22013-09-16 12:59:57 +0530360class BulkNetworkOpsXML(BulkNetworkOpsJSON):
raiesmh0867698322013-08-20 13:09:01 +0530361 _interface = 'xml'