blob: f3d14855f324c056f9d48df6b8d254b85fd480c1 [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()
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
Nayna Patelb03eab42013-08-08 08:58:48 +000066 def _delete_networks(self, created_networks):
67 for n in created_networks:
68 resp, body = self.client.delete_network(n['id'])
69 self.assertEqual(204, resp.status)
70 # Asserting that the networks are not found in the list after deletion
71 resp, body = self.client.list_networks()
72 networks_list = list()
73 for network in body['networks']:
74 networks_list.append(network['id'])
75 for n in created_networks:
76 self.assertNotIn(n['id'], networks_list)
77
Attila Fazekas71834a22013-08-18 06:56:21 +020078 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +053079 def test_create_update_delete_network_subnet(self):
Miguel Lavallecc939612013-02-22 17:27:20 -060080 # Creates a network
81 name = rand_name('network-')
Unmesh Gurjar44986832012-05-08 19:57:10 +053082 resp, body = self.client.create_network(name)
Miguel Lavallecc939612013-02-22 17:27:20 -060083 self.assertEqual('201', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053084 network = body['network']
raiesmh08e1aad982013-08-05 14:19:36 +053085 net_id = network['id']
86 # Verification of network update
87 new_name = "New_network"
88 resp, body = self.client.update_network(net_id, new_name)
89 self.assertEqual('200', resp['status'])
90 updated_net = body['network']
91 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -060092 # Find a cidr that is not in use yet and create a subnet with it
93 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
94 mask_bits = self.network_cfg.tenant_network_mask_bits
95 for subnet_cidr in cidr.subnet(mask_bits):
96 try:
raiesmh08e1aad982013-08-05 14:19:36 +053097 resp, body = self.client.create_subnet(net_id,
Miguel Lavallecc939612013-02-22 17:27:20 -060098 str(subnet_cidr))
99 break
100 except exceptions.BadRequest as e:
101 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
102 if not is_overlapping_cidr:
103 raise
104 self.assertEqual('201', resp['status'])
105 subnet = body['subnet']
raiesmh08e1aad982013-08-05 14:19:36 +0530106 subnet_id = subnet['id']
107 # Verification of subnet update
108 new_subnet = "New_subnet"
109 resp, body = self.client.update_subnet(subnet_id, new_subnet)
110 self.assertEqual('200', resp['status'])
111 updated_subnet = body['subnet']
112 self.assertEqual(updated_subnet['name'], new_subnet)
raiesmh0867698322013-08-20 13:09:01 +0530113 # Delete subnet and network
raiesmh08e1aad982013-08-05 14:19:36 +0530114 resp, body = self.client.delete_subnet(subnet_id)
Miguel Lavallecc939612013-02-22 17:27:20 -0600115 self.assertEqual('204', resp['status'])
raiesmh08e1aad982013-08-05 14:19:36 +0530116 resp, body = self.client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530117 self.assertEqual('204', resp['status'])
118
Attila Fazekas71834a22013-08-18 06:56:21 +0200119 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530120 def test_show_network(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500121 # Verifies the details of a network
Miguel Lavallecc939612013-02-22 17:27:20 -0600122 resp, body = self.client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530123 self.assertEqual('200', resp['status'])
124 network = body['network']
125 self.assertEqual(self.network['id'], network['id'])
126 self.assertEqual(self.name, network['name'])
127
Attila Fazekas71834a22013-08-18 06:56:21 +0200128 @attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530129 def test_list_networks(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500130 # Verify the network exists in the list of all networks
Unmesh Gurjar44986832012-05-08 19:57:10 +0530131 resp, body = self.client.list_networks()
raiesmh0867698322013-08-20 13:09:01 +0530132 self.assertEqual('200', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530133 networks = body['networks']
raiesmh08e1aad982013-08-05 14:19:36 +0530134 found = None
135 for n in networks:
136 if (n['id'] == self.network['id']):
137 found = n['id']
138 msg = "Network list doesn't contain created network"
139 self.assertIsNotNone(found, msg)
Unmesh Gurjar44986832012-05-08 19:57:10 +0530140
Attila Fazekas71834a22013-08-18 06:56:21 +0200141 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600142 def test_show_subnet(self):
143 # Verifies the details of a subnet
144 resp, body = self.client.show_subnet(self.subnet['id'])
145 self.assertEqual('200', resp['status'])
146 subnet = body['subnet']
147 self.assertEqual(self.subnet['id'], subnet['id'])
148 self.assertEqual(self.cidr, subnet['cidr'])
149
Attila Fazekas71834a22013-08-18 06:56:21 +0200150 @attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600151 def test_list_subnets(self):
152 # Verify the subnet exists in the list of all subnets
153 resp, body = self.client.list_subnets()
raiesmh0867698322013-08-20 13:09:01 +0530154 self.assertEqual('200', resp['status'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600155 subnets = body['subnets']
raiesmh08e1aad982013-08-05 14:19:36 +0530156 found = None
157 for n in subnets:
158 if (n['id'] == self.subnet['id']):
159 found = n['id']
160 msg = "Subnet list doesn't contain created subnet"
161 self.assertIsNotNone(found, msg)
162
Attila Fazekas71834a22013-08-18 06:56:21 +0200163 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530164 def test_create_update_delete_port(self):
raiesmh0867698322013-08-20 13:09:01 +0530165 # Verify that successful port creation, update & deletion
raiesmh08e1aad982013-08-05 14:19:36 +0530166 resp, body = self.client.create_port(self.network['id'])
167 self.assertEqual('201', resp['status'])
168 port = body['port']
169 # Verification of port update
170 new_port = "New_Port"
171 resp, body = self.client.update_port(port['id'], new_port)
172 self.assertEqual('200', resp['status'])
173 updated_port = body['port']
174 self.assertEqual(updated_port['name'], new_port)
175 # Verification of port delete
176 resp, body = self.client.delete_port(port['id'])
177 self.assertEqual('204', resp['status'])
178
Attila Fazekas71834a22013-08-18 06:56:21 +0200179 @attr(type='smoke')
raiesmh0867698322013-08-20 13:09:01 +0530180 def test_show_port(self):
raiesmh08e1aad982013-08-05 14:19:36 +0530181 # Verify the details of port
182 resp, body = self.client.show_port(self.port['id'])
183 self.assertEqual('200', resp['status'])
184 port = body['port']
185 self.assertEqual(self.port['id'], port['id'])
186
Attila Fazekas71834a22013-08-18 06:56:21 +0200187 @attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +0530188 def test_list_ports(self):
189 # Verify the port exists in the list of all ports
190 resp, body = self.client.list_ports()
191 self.assertEqual('200', resp['status'])
192 ports_list = body['ports']
193 found = None
194 for n in ports_list:
195 if (n['id'] == self.port['id']):
196 found = n['id']
197 self.assertIsNotNone(found, "Port list doesn't contain created port")
Anju Tiwari6656f582013-08-03 05:43:42 +0530198
Attila Fazekas71834a22013-08-18 06:56:21 +0200199 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530200 def test_show_non_existent_network(self):
201 non_exist_id = rand_name('network')
202 self.assertRaises(exceptions.NotFound, self.client.show_network,
203 non_exist_id)
204
Attila Fazekas71834a22013-08-18 06:56:21 +0200205 @attr(type=['negative', 'smoke'])
Anju Tiwari6656f582013-08-03 05:43:42 +0530206 def test_show_non_existent_subnet(self):
207 non_exist_id = rand_name('subnet')
208 self.assertRaises(exceptions.NotFound, self.client.show_subnet,
209 non_exist_id)
Nayna Patelb03eab42013-08-08 08:58:48 +0000210
Attila Fazekas71834a22013-08-18 06:56:21 +0200211 @attr(type='smoke')
Nayna Patelb03eab42013-08-08 08:58:48 +0000212 def test_bulk_create_delete_network(self):
213 # Creates 2 networks in one request
214 network_names = [rand_name('network-'), rand_name('network-')]
215 resp, body = self.client.create_bulk_network(2, network_names)
216 created_networks = body['networks']
217 self.assertEqual('201', resp['status'])
218 self.addCleanup(self._delete_networks, created_networks)
219 # Asserting that the networks are found in the list after creation
220 resp, body = self.client.list_networks()
221 networks_list = list()
222 for network in body['networks']:
223 networks_list.append(network['id'])
224 for n in created_networks:
225 self.assertIsNotNone(n['id'])
226 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530227
228
229class NetworksTestXML(NetworksTestJSON):
230 _interface = 'xml'