blob: 66ca05fdbc5caf7c1cd10200f52db725552cf68b [file] [log] [blame]
Jay Pipesf4dad392012-06-05 16:03:58 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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()
raiesmh082d5c6512013-09-06 15:35:05 +053061 cls.network1 = cls.create_network()
62 cls.network2 = cls.create_network()
Jay Pipesf4dad392012-06-05 16:03:58 -040063 cls.name = cls.network['name']
Miguel Lavallecc939612013-02-22 17:27:20 -060064 cls.subnet = cls.create_subnet(cls.network)
65 cls.cidr = cls.subnet['cidr']
raiesmh08e1aad982013-08-05 14:19:36 +053066 cls.port = cls.create_port(cls.network)
Unmesh Gurjar44986832012-05-08 19:57:10 +053067
Nayna Patelb03eab42013-08-08 08:58:48 +000068 def _delete_networks(self, created_networks):
69 for n in created_networks:
70 resp, body = self.client.delete_network(n['id'])
71 self.assertEqual(204, resp.status)
72 # Asserting that the networks are not found in the list after deletion
73 resp, body = self.client.list_networks()
74 networks_list = list()
75 for network in body['networks']:
76 networks_list.append(network['id'])
77 for n in created_networks:
78 self.assertNotIn(n['id'], networks_list)
79
raiesmh082d5c6512013-09-06 15:35:05 +053080 def _delete_subnets(self, created_subnets):
81 for n in created_subnets:
82 resp, body = self.client.delete_subnet(n['id'])
83 self.assertEqual(204, resp.status)
84 # Asserting that the subnets are not found in the list after deletion
85 resp, body = self.client.list_subnets()
86 subnets_list = list()
87 for subnet in body['subnets']:
88 subnets_list.append(subnet['id'])
89 for n in created_subnets:
90 self.assertNotIn(n['id'], subnets_list)
91
92 def _delete_ports(self, created_ports):
93 for n in created_ports:
94 resp, body = self.client.delete_port(n['id'])
95 self.assertEqual(204, resp.status)
96 # Asserting that the ports are not found in the list after deletion
97 resp, body = self.client.list_ports()
98 ports_list = list()
99 for port in body['ports']:
100 ports_list.append(port['id'])
101 for n in created_ports:
102 self.assertNotIn(n['id'], ports_list)
103
Attila Fazekas71834a22013-08-18 06:56:21 +0200104 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530105 def test_create_update_delete_network_subnet(self):
Miguel Lavallecc939612013-02-22 17:27:20 -0600106 # Creates a network
107 name = rand_name('network-')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530108 resp, body = self.client.create_network(name)
Miguel Lavallecc939612013-02-22 17:27:20 -0600109 self.assertEqual('201', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530110 network = body['network']
raiesmh08e1aad982013-08-05 14:19:36 +0530111 net_id = network['id']
112 # Verification of network update
113 new_name = "New_network"
114 resp, body = self.client.update_network(net_id, new_name)
115 self.assertEqual('200', resp['status'])
116 updated_net = body['network']
117 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -0600118 # Find a cidr that is not in use yet and create a subnet with it
119 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
120 mask_bits = self.network_cfg.tenant_network_mask_bits
121 for subnet_cidr in cidr.subnet(mask_bits):
122 try:
raiesmh08e1aad982013-08-05 14:19:36 +0530123 resp, body = self.client.create_subnet(net_id,
Miguel Lavallecc939612013-02-22 17:27:20 -0600124 str(subnet_cidr))
125 break
126 except exceptions.BadRequest as e:
127 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
128 if not is_overlapping_cidr:
129 raise
130 self.assertEqual('201', resp['status'])
131 subnet = body['subnet']
raiesmh08e1aad982013-08-05 14:19:36 +0530132 subnet_id = subnet['id']
133 # Verification of subnet update
134 new_subnet = "New_subnet"
135 resp, body = self.client.update_subnet(subnet_id, new_subnet)
136 self.assertEqual('200', resp['status'])
137 updated_subnet = body['subnet']
138 self.assertEqual(updated_subnet['name'], new_subnet)
raiesmh0867698322013-08-20 13:09:01 +0530139 # Delete subnet and network
raiesmh08e1aad982013-08-05 14:19:36 +0530140 resp, body = self.client.delete_subnet(subnet_id)
Miguel Lavallecc939612013-02-22 17:27:20 -0600141 self.assertEqual('204', resp['status'])
raiesmh08e1aad982013-08-05 14:19:36 +0530142 resp, body = self.client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530143 self.assertEqual('204', resp['status'])
144
Attila Fazekas71834a22013-08-18 06:56:21 +0200145 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530146 def test_show_network(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500147 # Verifies the details of a network
Miguel Lavallecc939612013-02-22 17:27:20 -0600148 resp, body = self.client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530149 self.assertEqual('200', resp['status'])
150 network = body['network']
151 self.assertEqual(self.network['id'], network['id'])
152 self.assertEqual(self.name, network['name'])
153
Attila Fazekas71834a22013-08-18 06:56:21 +0200154 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530155 def test_list_networks(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500156 # Verify the network exists in the list of all networks
Unmesh Gurjar44986832012-05-08 19:57:10 +0530157 resp, body = self.client.list_networks()
raiesmh0867698322013-08-20 13:09:01 +0530158 self.assertEqual('200', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530159 networks = body['networks']
raiesmh08e1aad982013-08-05 14:19:36 +0530160 found = None
161 for n in networks:
162 if (n['id'] == self.network['id']):
163 found = n['id']
164 msg = "Network list doesn't contain created network"
165 self.assertIsNotNone(found, msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530166
Attila Fazekas71834a22013-08-18 06:56:21 +0200167 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600168 def test_show_subnet(self):
169 # Verifies the details of a subnet
170 resp, body = self.client.show_subnet(self.subnet['id'])
171 self.assertEqual('200', resp['status'])
172 subnet = body['subnet']
173 self.assertEqual(self.subnet['id'], subnet['id'])
174 self.assertEqual(self.cidr, subnet['cidr'])
175
Attila Fazekas71834a22013-08-18 06:56:21 +0200176 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600177 def test_list_subnets(self):
178 # Verify the subnet exists in the list of all subnets
179 resp, body = self.client.list_subnets()
raiesmh0867698322013-08-20 13:09:01 +0530180 self.assertEqual('200', resp['status'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600181 subnets = body['subnets']
raiesmh08e1aad982013-08-05 14:19:36 +0530182 found = None
183 for n in subnets:
184 if (n['id'] == self.subnet['id']):
185 found = n['id']
186 msg = "Subnet list doesn't contain created subnet"
187 self.assertIsNotNone(found, msg)
188
Attila Fazekas71834a22013-08-18 06:56:21 +0200189 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530190 def test_create_update_delete_port(self):
raiesmh0867698322013-08-20 13:09:01 +0530191 # Verify that successful port creation, update & deletion
raiesmh08e1aad982013-08-05 14:19:36 +0530192 resp, body = self.client.create_port(self.network['id'])
193 self.assertEqual('201', resp['status'])
194 port = body['port']
195 # Verification of port update
196 new_port = "New_Port"
197 resp, body = self.client.update_port(port['id'], new_port)
198 self.assertEqual('200', resp['status'])
199 updated_port = body['port']
200 self.assertEqual(updated_port['name'], new_port)
201 # Verification of port delete
202 resp, body = self.client.delete_port(port['id'])
203 self.assertEqual('204', resp['status'])
204
Attila Fazekas71834a22013-08-18 06:56:21 +0200205 @attr(type='smoke')
raiesmh0867698322013-08-20 13:09:01 +0530206 def test_show_port(self):
raiesmh08e1aad982013-08-05 14:19:36 +0530207 # Verify the details of port
208 resp, body = self.client.show_port(self.port['id'])
209 self.assertEqual('200', resp['status'])
210 port = body['port']
211 self.assertEqual(self.port['id'], port['id'])
212
Attila Fazekas71834a22013-08-18 06:56:21 +0200213 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530214 def test_list_ports(self):
215 # Verify the port exists in the list of all ports
216 resp, body = self.client.list_ports()
217 self.assertEqual('200', resp['status'])
218 ports_list = body['ports']
219 found = None
220 for n in ports_list:
221 if (n['id'] == self.port['id']):
222 found = n['id']
223 self.assertIsNotNone(found, "Port list doesn't contain created port")
Anju Tiwari6656f582013-08-03 05:43:42 +0530224
Attila Fazekas71834a22013-08-18 06:56:21 +0200225 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530226 def test_show_non_existent_network(self):
227 non_exist_id = rand_name('network')
228 self.assertRaises(exceptions.NotFound, self.client.show_network,
229 non_exist_id)
230
Attila Fazekas71834a22013-08-18 06:56:21 +0200231 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530232 def test_show_non_existent_subnet(self):
233 non_exist_id = rand_name('subnet')
234 self.assertRaises(exceptions.NotFound, self.client.show_subnet,
235 non_exist_id)
Nayna Patelb03eab42013-08-08 08:58:48 +0000236
Attila Fazekas71834a22013-08-18 06:56:21 +0200237 @attr(type='smoke')
Nayna Patelb03eab42013-08-08 08:58:48 +0000238 def test_bulk_create_delete_network(self):
239 # Creates 2 networks in one request
240 network_names = [rand_name('network-'), rand_name('network-')]
241 resp, body = self.client.create_bulk_network(2, network_names)
242 created_networks = body['networks']
243 self.assertEqual('201', resp['status'])
244 self.addCleanup(self._delete_networks, created_networks)
245 # Asserting that the networks are found in the list after creation
246 resp, body = self.client.list_networks()
247 networks_list = list()
248 for network in body['networks']:
249 networks_list.append(network['id'])
250 for n in created_networks:
251 self.assertIsNotNone(n['id'])
252 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530253
raiesmh082d5c6512013-09-06 15:35:05 +0530254 @attr(type='smoke')
255 def test_bulk_create_delete_subnet(self):
256 # Creates 2 subnets in one request
257 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
258 mask_bits = self.network_cfg.tenant_network_mask_bits
259 cidrs = []
260 for subnet_cidr in cidr.subnet(mask_bits):
261 cidrs.append(subnet_cidr)
262 names = []
263 networks = [self.network1['id'], self.network2['id']]
264 for i in range(len(networks)):
265 names.append(rand_name('subnet-'))
266 subnet_list = []
267 # TODO(raies): "for IPv6, version list [4, 6] will be used.
268 # and cidr for IPv6 will be of IPv6"
269 ip_version = [4, 4]
270 for i in range(len(names)):
271 p1 = {
272 'network_id': networks[i],
273 'cidr': str(cidrs[(i)]),
274 'name': names[i],
275 'ip_version': ip_version[i]
276 }
277 subnet_list.append(p1)
278 del subnet_list[1]['name']
279 resp, body = self.client.create_bulk_subnet(subnet_list)
280 created_subnets = body['subnets']
281 self.addCleanup(self._delete_subnets, created_subnets)
282 self.assertEqual('201', resp['status'])
283 # Asserting that the subnets are found in the list after creation
284 resp, body = self.client.list_subnets()
285 subnets_list = list()
286 for subnet in body['subnets']:
287 subnets_list.append(subnet['id'])
288 for n in created_subnets:
289 self.assertIsNotNone(n['id'])
290 self.assertIn(n['id'], subnets_list)
291
292 @attr(type='smoke')
293 def test_bulk_create_delete_port(self):
294 # Creates 2 ports in one request
295 names = []
296 networks = [self.network1['id'], self.network2['id']]
297 for i in range(len(networks)):
298 names.append(rand_name('port-'))
299 port_list = []
300 state = [True, False]
301 for i in range(len(names)):
302 p1 = {
303 'network_id': networks[i],
304 'name': names[i],
305 'admin_state_up': state[i],
306 }
307 port_list.append(p1)
308 del port_list[1]['name']
309 resp, body = self.client.create_bulk_port(port_list)
310 created_ports = body['ports']
311 self.addCleanup(self._delete_ports, created_ports)
312 self.assertEqual('201', resp['status'])
313 # Asserting that the ports are found in the list after creation
314 resp, body = self.client.list_ports()
315 ports_list = list()
316 for port in body['ports']:
317 ports_list.append(port['id'])
318 for n in created_ports:
319 self.assertIsNotNone(n['id'])
320 self.assertIn(n['id'], ports_list)
321
raiesmh0867698322013-08-20 13:09:01 +0530322
323class NetworksTestXML(NetworksTestJSON):
324 _interface = 'xml'