blob: e1eb48d41bf7b50bcc611fc48f03436d886a4bb8 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipesf4dad392012-06-05 16:03:58 -04002# 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
Miguel Lavallecc939612013-02-22 17:27:20 -060016import netaddr
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -040017import testtools
Jay Pipesf4dad392012-06-05 16:03:58 -040018
Sean Dague1937d092013-05-17 16:36:38 -040019from tempest.api.network import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090020from tempest.common.utils import data_utils
Matthew Treinish03b48df2014-01-29 16:59:49 +000021from tempest import config
sukhdevc704a702014-01-15 11:50:56 -080022from tempest import exceptions
Masayuki Igawa6d495d62014-03-19 16:38:57 +090023from tempest import test
Unmesh Gurjar44986832012-05-08 19:57:10 +053024
Matthew Treinish03b48df2014-01-29 16:59:49 +000025CONF = config.CONF
26
Unmesh Gurjar44986832012-05-08 19:57:10 +053027
raiesmh0867698322013-08-20 13:09:01 +053028class NetworksTestJSON(base.BaseNetworkTest):
29 _interface = 'json'
Unmesh Gurjar44986832012-05-08 19:57:10 +053030
Miguel Lavallecc939612013-02-22 17:27:20 -060031 """
Mark McClainf2982e82013-07-06 17:48:03 -040032 Tests the following operations in the Neutron API using the REST client for
33 Neutron:
Miguel Lavallecc939612013-02-22 17:27:20 -060034
35 create a network for a tenant
36 list tenant's networks
37 show a tenant network details
38 create a subnet for a tenant
39 list tenant's subnets
40 show a tenant subnet details
raiesmh08e1aad982013-08-05 14:19:36 +053041 network update
42 subnet update
sukhdevc704a702014-01-15 11:50:56 -080043 delete a network also deletes its subnets
Miguel Lavallecc939612013-02-22 17:27:20 -060044
Henry Gessauffda37a2014-01-16 11:17:55 -050045 All subnet tests are run once with ipv4 and once with ipv6.
46
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
Henry Gessauffda37a2014-01-16 11:17:55 -050051 can be allocated for tenant ipv4 subnets
52
53 tenant_network_v6_cidr is the equivalent for ipv6 subnets
Miguel Lavallecc939612013-02-22 17:27:20 -060054
55 tenant_network_mask_bits with the mask bits to be used to partition the
Henry Gessauffda37a2014-01-16 11:17:55 -050056 block defined by tenant_network_cidr
57
58 tenant_network_v6_mask_bits is the equivalent for ipv6 subnets
Miguel Lavallecc939612013-02-22 17:27:20 -060059 """
60
Unmesh Gurjar44986832012-05-08 19:57:10 +053061 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010062 def resource_setup(cls):
63 super(NetworksTestJSON, cls).resource_setup()
Jay Pipesf4dad392012-06-05 16:03:58 -040064 cls.network = cls.create_network()
65 cls.name = cls.network['name']
Miguel Lavallecc939612013-02-22 17:27:20 -060066 cls.subnet = cls.create_subnet(cls.network)
67 cls.cidr = cls.subnet['cidr']
Unmesh Gurjar44986832012-05-08 19:57:10 +053068
Masayuki Igawa6d495d62014-03-19 16:38:57 +090069 @test.attr(type='smoke')
raiesmh08e1aad982013-08-05 14:19:36 +053070 def test_create_update_delete_network_subnet(self):
Mark Maglana5885eb32014-02-28 10:57:34 -080071 # Create a network
Masayuki Igawa259c1132013-10-31 17:48:44 +090072 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +020073 _, body = self.client.create_network(name=name)
Unmesh Gurjar44986832012-05-08 19:57:10 +053074 network = body['network']
raiesmh08e1aad982013-08-05 14:19:36 +053075 net_id = network['id']
Santosh Kumar42c94802014-08-08 04:31:42 -070076 self.assertEqual('ACTIVE', network['status'])
Mark Maglana5885eb32014-02-28 10:57:34 -080077 # Verify network update
raiesmh08e1aad982013-08-05 14:19:36 +053078 new_name = "New_network"
Rohan Kanadeeeb21642014-08-14 12:00:26 +020079 _, body = self.client.update_network(net_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +053080 updated_net = body['network']
81 self.assertEqual(updated_net['name'], new_name)
Miguel Lavallecc939612013-02-22 17:27:20 -060082 # Find a cidr that is not in use yet and create a subnet with it
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +000083 subnet = self.create_subnet(network)
raiesmh08e1aad982013-08-05 14:19:36 +053084 subnet_id = subnet['id']
Mark Maglana5885eb32014-02-28 10:57:34 -080085 # Verify subnet update
86 new_name = "New_subnet"
Rohan Kanadeeeb21642014-08-14 12:00:26 +020087 _, body = self.client.update_subnet(subnet_id, name=new_name)
raiesmh08e1aad982013-08-05 14:19:36 +053088 updated_subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -080089 self.assertEqual(updated_subnet['name'], new_name)
raiesmh0867698322013-08-20 13:09:01 +053090 # Delete subnet and network
Rohan Kanadeeeb21642014-08-14 12:00:26 +020091 _, body = self.client.delete_subnet(subnet_id)
Matthew Treinish6b8cd2a2014-03-03 20:45:56 +000092 # Remove subnet from cleanup list
93 self.subnets.pop()
Rohan Kanadeeeb21642014-08-14 12:00:26 +020094 _, body = self.client.delete_network(net_id)
Unmesh Gurjar44986832012-05-08 19:57:10 +053095
Masayuki Igawa6d495d62014-03-19 16:38:57 +090096 @test.attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +053097 def test_show_network(self):
Mark Maglana5885eb32014-02-28 10:57:34 -080098 # Verify the details of a network
Rohan Kanadeeeb21642014-08-14 12:00:26 +020099 _, body = self.client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530100 network = body['network']
Mark Maglana5885eb32014-02-28 10:57:34 -0800101 for key in ['id', 'name']:
102 self.assertEqual(network[key], self.network[key])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530103
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900104 @test.attr(type='smoke')
jun xied557d9b2014-01-09 14:00:36 +0800105 def test_show_network_fields(self):
Mark Maglana5885eb32014-02-28 10:57:34 -0800106 # Verify specific fields of a network
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500107 fields = ['id', 'name']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200108 _, body = self.client.show_network(self.network['id'],
109 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800110 network = body['network']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500111 self.assertEqual(sorted(network.keys()), sorted(fields))
112 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800113 self.assertEqual(network[field_name], self.network[field_name])
jun xied557d9b2014-01-09 14:00:36 +0800114
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900115 @test.attr(type='smoke')
Unmesh Gurjar44986832012-05-08 19:57:10 +0530116 def test_list_networks(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -0500117 # Verify the network exists in the list of all networks
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200118 _, body = self.client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800119 networks = [network['id'] for network in body['networks']
120 if network['id'] == self.network['id']]
121 self.assertNotEmpty(networks, "Created network not found in the list")
Unmesh Gurjar44986832012-05-08 19:57:10 +0530122
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900123 @test.attr(type='smoke')
jun xie0b4735d2014-01-07 15:42:58 +0800124 def test_list_networks_fields(self):
Mark Maglana5885eb32014-02-28 10:57:34 -0800125 # Verify specific fields of the networks
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500126 fields = ['id', 'name']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200127 _, body = self.client.list_networks(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800128 networks = body['networks']
Mark Maglana5885eb32014-02-28 10:57:34 -0800129 self.assertNotEmpty(networks, "Network list returned is empty")
130 for network in networks:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500131 self.assertEqual(sorted(network.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800132
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900133 @test.attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600134 def test_show_subnet(self):
Mark Maglana5885eb32014-02-28 10:57:34 -0800135 # Verify the details of a subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200136 _, body = self.client.show_subnet(self.subnet['id'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600137 subnet = body['subnet']
Mark Maglana5885eb32014-02-28 10:57:34 -0800138 self.assertNotEmpty(subnet, "Subnet returned has no fields")
139 for key in ['id', 'cidr']:
140 self.assertIn(key, subnet)
141 self.assertEqual(subnet[key], self.subnet[key])
Miguel Lavallecc939612013-02-22 17:27:20 -0600142
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900143 @test.attr(type='smoke')
jun xied557d9b2014-01-09 14:00:36 +0800144 def test_show_subnet_fields(self):
Mark Maglana5885eb32014-02-28 10:57:34 -0800145 # Verify specific fields of a subnet
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500146 fields = ['id', 'network_id']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200147 _, body = self.client.show_subnet(self.subnet['id'],
148 fields=fields)
jun xied557d9b2014-01-09 14:00:36 +0800149 subnet = body['subnet']
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500150 self.assertEqual(sorted(subnet.keys()), sorted(fields))
151 for field_name in fields:
Mark Maglana5885eb32014-02-28 10:57:34 -0800152 self.assertEqual(subnet[field_name], self.subnet[field_name])
jun xied557d9b2014-01-09 14:00:36 +0800153
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900154 @test.attr(type='smoke')
Miguel Lavallecc939612013-02-22 17:27:20 -0600155 def test_list_subnets(self):
156 # Verify the subnet exists in the list of all subnets
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200157 _, body = self.client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800158 subnets = [subnet['id'] for subnet in body['subnets']
159 if subnet['id'] == self.subnet['id']]
160 self.assertNotEmpty(subnets, "Created subnet not found in the list")
raiesmh08e1aad982013-08-05 14:19:36 +0530161
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900162 @test.attr(type='smoke')
jun xie0b4735d2014-01-07 15:42:58 +0800163 def test_list_subnets_fields(self):
Mark Maglana5885eb32014-02-28 10:57:34 -0800164 # Verify specific fields of subnets
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500165 fields = ['id', 'network_id']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200166 _, body = self.client.list_subnets(fields=fields)
jun xie0b4735d2014-01-07 15:42:58 +0800167 subnets = body['subnets']
Mark Maglana5885eb32014-02-28 10:57:34 -0800168 self.assertNotEmpty(subnets, "Subnet list returned is empty")
169 for subnet in subnets:
Zhi Kun Liu903596c2014-04-11 08:55:53 -0500170 self.assertEqual(sorted(subnet.keys()), sorted(fields))
jun xie0b4735d2014-01-07 15:42:58 +0800171
sukhdevc704a702014-01-15 11:50:56 -0800172 def _try_delete_network(self, net_id):
173 # delete network, if it exists
174 try:
175 self.client.delete_network(net_id)
176 # if network is not found, this means it was deleted in the test
177 except exceptions.NotFound:
178 pass
179
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900180 @test.attr(type='smoke')
sukhdevc704a702014-01-15 11:50:56 -0800181 def test_delete_network_with_subnet(self):
182 # Creates a network
183 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200184 _, body = self.client.create_network(name=name)
sukhdevc704a702014-01-15 11:50:56 -0800185 network = body['network']
186 net_id = network['id']
187 self.addCleanup(self._try_delete_network, net_id)
188
189 # Find a cidr that is not in use yet and create a subnet with it
190 subnet = self.create_subnet(network)
191 subnet_id = subnet['id']
192
193 # Delete network while the subnet still exists
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200194 _, body = self.client.delete_network(net_id)
sukhdevc704a702014-01-15 11:50:56 -0800195
196 # Verify that the subnet got automatically deleted.
197 self.assertRaises(exceptions.NotFound, self.client.show_subnet,
198 subnet_id)
199
200 # Since create_subnet adds the subnet to the delete list, and it is
201 # is actually deleted here - this will create and issue, hence remove
202 # it from the list.
203 self.subnets.pop()
204
Edgar Magana6a9ac342014-01-16 13:52:49 -0800205 @test.attr(type='smoke')
206 def test_create_delete_subnet_with_gw(self):
207 gateway = '10.100.0.13'
208 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200209 _, body = self.client.create_network(name=name)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800210 network = body['network']
211 net_id = network['id']
212 subnet = self.create_subnet(network, gateway)
213 # Verifies Subnet GW in IPv4
214 self.assertEqual(subnet['gateway_ip'], gateway)
215 # Delete network and subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200216 self.client.delete_network(net_id)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800217 self.subnets.pop()
218
219 @test.attr(type='smoke')
220 def test_create_delete_subnet_without_gw(self):
sridhargaddamb1e58892014-05-13 14:18:14 +0530221 net = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
222 gateway_ip = str(netaddr.IPAddress(net.first + 1))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800223 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200224 _, body = self.client.create_network(name=name)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800225 network = body['network']
226 net_id = network['id']
227 subnet = self.create_subnet(network)
228 # Verifies Subnet GW in IPv4
sridhargaddamb1e58892014-05-13 14:18:14 +0530229 self.assertEqual(subnet['gateway_ip'], gateway_ip)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800230 # Delete network and subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200231 self.client.delete_network(net_id)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800232 self.subnets.pop()
233
raiesmh086b055e22013-09-16 12:59:57 +0530234
235class NetworksTestXML(NetworksTestJSON):
236 _interface = 'xml'
237
238
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900239class BulkNetworkOpsTestJSON(base.BaseNetworkTest):
raiesmh086b055e22013-09-16 12:59:57 +0530240 _interface = 'json'
241
242 """
243 Tests the following operations in the Neutron API using the REST client for
244 Neutron:
245
246 bulk network creation
247 bulk subnet creation
Eugene Nikanorove9d255a2013-12-18 16:31:42 +0400248 bulk port creation
raiesmh086b055e22013-09-16 12:59:57 +0530249 list tenant's networks
250
251 v2.0 of the Neutron API is assumed. It is also assumed that the following
252 options are defined in the [network] section of etc/tempest.conf:
253
254 tenant_network_cidr with a block of cidr's from which smaller blocks
255 can be allocated for tenant networks
256
257 tenant_network_mask_bits with the mask bits to be used to partition the
258 block defined by tenant-network_cidr
259 """
260
raiesmh086b055e22013-09-16 12:59:57 +0530261 def _delete_networks(self, created_networks):
262 for n in created_networks:
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200263 self.client.delete_network(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530264 # Asserting that the networks are not found in the list after deletion
265 resp, body = self.client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800266 networks_list = [network['id'] for network in body['networks']]
raiesmh086b055e22013-09-16 12:59:57 +0530267 for n in created_networks:
268 self.assertNotIn(n['id'], networks_list)
269
270 def _delete_subnets(self, created_subnets):
271 for n in created_subnets:
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200272 self.client.delete_subnet(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530273 # Asserting that the subnets are not found in the list after deletion
274 resp, body = self.client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800275 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh086b055e22013-09-16 12:59:57 +0530276 for n in created_subnets:
277 self.assertNotIn(n['id'], subnets_list)
278
279 def _delete_ports(self, created_ports):
280 for n in created_ports:
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200281 self.client.delete_port(n['id'])
raiesmh086b055e22013-09-16 12:59:57 +0530282 # Asserting that the ports are not found in the list after deletion
283 resp, body = self.client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800284 ports_list = [port['id'] for port in body['ports']]
raiesmh086b055e22013-09-16 12:59:57 +0530285 for n in created_ports:
286 self.assertNotIn(n['id'], ports_list)
287
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900288 @test.attr(type='smoke')
Nayna Patelb03eab42013-08-08 08:58:48 +0000289 def test_bulk_create_delete_network(self):
290 # Creates 2 networks in one request
Masayuki Igawa259c1132013-10-31 17:48:44 +0900291 network_names = [data_utils.rand_name('network-'),
292 data_utils.rand_name('network-')]
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200293 _, body = self.client.create_bulk_network(network_names)
Nayna Patelb03eab42013-08-08 08:58:48 +0000294 created_networks = body['networks']
Nayna Patelb03eab42013-08-08 08:58:48 +0000295 self.addCleanup(self._delete_networks, created_networks)
296 # Asserting that the networks are found in the list after creation
297 resp, body = self.client.list_networks()
Mark Maglana5885eb32014-02-28 10:57:34 -0800298 networks_list = [network['id'] for network in body['networks']]
Nayna Patelb03eab42013-08-08 08:58:48 +0000299 for n in created_networks:
300 self.assertIsNotNone(n['id'])
301 self.assertIn(n['id'], networks_list)
raiesmh0867698322013-08-20 13:09:01 +0530302
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900303 @test.attr(type='smoke')
raiesmh082d5c6512013-09-06 15:35:05 +0530304 def test_bulk_create_delete_subnet(self):
Assaf Mullere4f78992014-06-19 17:32:14 +0300305 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530306 # Creates 2 subnets in one request
Matthew Treinish03b48df2014-01-29 16:59:49 +0000307 cidr = netaddr.IPNetwork(CONF.network.tenant_network_cidr)
308 mask_bits = CONF.network.tenant_network_mask_bits
Mark Maglana5885eb32014-02-28 10:57:34 -0800309 cidrs = [subnet_cidr for subnet_cidr in cidr.subnet(mask_bits)]
Mark Maglana5885eb32014-02-28 10:57:34 -0800310 names = [data_utils.rand_name('subnet-') for i in range(len(networks))]
311 subnets_list = []
raiesmh082d5c6512013-09-06 15:35:05 +0530312 # TODO(raies): "for IPv6, version list [4, 6] will be used.
313 # and cidr for IPv6 will be of IPv6"
314 ip_version = [4, 4]
315 for i in range(len(names)):
316 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300317 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530318 'cidr': str(cidrs[(i)]),
319 'name': names[i],
320 'ip_version': ip_version[i]
321 }
Mark Maglana5885eb32014-02-28 10:57:34 -0800322 subnets_list.append(p1)
323 del subnets_list[1]['name']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200324 _, body = self.client.create_bulk_subnet(subnets_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530325 created_subnets = body['subnets']
326 self.addCleanup(self._delete_subnets, created_subnets)
raiesmh082d5c6512013-09-06 15:35:05 +0530327 # Asserting that the subnets are found in the list after creation
328 resp, body = self.client.list_subnets()
Mark Maglana5885eb32014-02-28 10:57:34 -0800329 subnets_list = [subnet['id'] for subnet in body['subnets']]
raiesmh082d5c6512013-09-06 15:35:05 +0530330 for n in created_subnets:
331 self.assertIsNotNone(n['id'])
332 self.assertIn(n['id'], subnets_list)
333
Masayuki Igawa6d495d62014-03-19 16:38:57 +0900334 @test.attr(type='smoke')
raiesmh082d5c6512013-09-06 15:35:05 +0530335 def test_bulk_create_delete_port(self):
Assaf Mullere4f78992014-06-19 17:32:14 +0300336 networks = [self.create_network(), self.create_network()]
raiesmh082d5c6512013-09-06 15:35:05 +0530337 # Creates 2 ports in one request
Mark Maglana5885eb32014-02-28 10:57:34 -0800338 names = [data_utils.rand_name('port-') for i in range(len(networks))]
raiesmh082d5c6512013-09-06 15:35:05 +0530339 port_list = []
340 state = [True, False]
341 for i in range(len(names)):
342 p1 = {
Assaf Mullere4f78992014-06-19 17:32:14 +0300343 'network_id': networks[i]['id'],
raiesmh082d5c6512013-09-06 15:35:05 +0530344 'name': names[i],
345 'admin_state_up': state[i],
346 }
347 port_list.append(p1)
348 del port_list[1]['name']
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200349 _, body = self.client.create_bulk_port(port_list)
raiesmh082d5c6512013-09-06 15:35:05 +0530350 created_ports = body['ports']
351 self.addCleanup(self._delete_ports, created_ports)
raiesmh082d5c6512013-09-06 15:35:05 +0530352 # Asserting that the ports are found in the list after creation
353 resp, body = self.client.list_ports()
Mark Maglana5885eb32014-02-28 10:57:34 -0800354 ports_list = [port['id'] for port in body['ports']]
raiesmh082d5c6512013-09-06 15:35:05 +0530355 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
Ken'ichi Ohmichi91c675d2014-02-06 02:15:21 +0900360class BulkNetworkOpsTestXML(BulkNetworkOpsTestJSON):
raiesmh0867698322013-08-20 13:09:01 +0530361 _interface = 'xml'
Henry Gessauffda37a2014-01-16 11:17:55 -0500362
363
364class NetworksIpV6TestJSON(NetworksTestJSON):
365 _ip_version = 6
Henry Gessauffda37a2014-01-16 11:17:55 -0500366
armando-migliaccio5bb7aef2014-02-19 21:55:14 -0800367 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +0100368 def resource_setup(cls):
Matthew Treinishe2e33cf2014-03-03 19:28:41 +0000369 if not CONF.network_feature_enabled.ipv6:
armando-migliaccio5bb7aef2014-02-19 21:55:14 -0800370 skip_msg = "IPv6 Tests are disabled."
371 raise cls.skipException(skip_msg)
Andrea Frittolida4a2452014-09-15 13:12:08 +0100372 super(NetworksIpV6TestJSON, cls).resource_setup()
armando-migliaccio5bb7aef2014-02-19 21:55:14 -0800373
Edgar Magana6a9ac342014-01-16 13:52:49 -0800374 @test.attr(type='smoke')
375 def test_create_delete_subnet_with_gw(self):
sridhargaddamea73d532014-05-13 14:48:30 +0530376 net = netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)
377 gateway = str(netaddr.IPAddress(net.first + 2))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800378 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200379 _, body = self.client.create_network(name=name)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800380 network = body['network']
381 net_id = network['id']
382 subnet = self.create_subnet(network, gateway)
383 # Verifies Subnet GW in IPv6
384 self.assertEqual(subnet['gateway_ip'], gateway)
385 # Delete network and subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200386 self.client.delete_network(net_id)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800387 self.subnets.pop()
388
389 @test.attr(type='smoke')
390 def test_create_delete_subnet_without_gw(self):
sridhargaddamea73d532014-05-13 14:48:30 +0530391 net = netaddr.IPNetwork(CONF.network.tenant_network_v6_cidr)
392 gateway_ip = str(netaddr.IPAddress(net.first + 1))
Edgar Magana6a9ac342014-01-16 13:52:49 -0800393 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200394 _, body = self.client.create_network(name=name)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800395 network = body['network']
396 net_id = network['id']
397 subnet = self.create_subnet(network)
398 # Verifies Subnet GW in IPv6
sridhargaddamea73d532014-05-13 14:48:30 +0530399 self.assertEqual(subnet['gateway_ip'], gateway_ip)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800400 # Delete network and subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200401 _, body = self.client.delete_network(net_id)
Edgar Magana6a9ac342014-01-16 13:52:49 -0800402 self.subnets.pop()
403
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400404 @testtools.skipUnless(CONF.network_feature_enabled.ipv6_subnet_attributes,
405 "IPv6 extended attributes for subnets not "
406 "available")
407 @test.attr(type='smoke')
408 def test_create_delete_subnet_with_v6_attributes(self):
409 name = data_utils.rand_name('network-')
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200410 _, body = self.client.create_network(name=name)
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400411 network = body['network']
412 net_id = network['id']
413 subnet = self.create_subnet(network,
414 gateway='fe80::1',
415 ipv6_ra_mode='slaac',
416 ipv6_address_mode='slaac')
417 # Verifies Subnet GW in IPv6
418 self.assertEqual(subnet['gateway_ip'], 'fe80::1')
419 self.assertEqual(subnet['ipv6_ra_mode'], 'slaac')
420 self.assertEqual(subnet['ipv6_address_mode'], 'slaac')
421 # Delete network and subnet
Rohan Kanadeeeb21642014-08-14 12:00:26 +0200422 self.client.delete_network(net_id)
Sean M. Collinsdd27a4d2014-05-13 10:33:15 -0400423 self.subnets.pop()
424
Henry Gessauffda37a2014-01-16 11:17:55 -0500425
426class NetworksIpV6TestXML(NetworksIpV6TestJSON):
427 _interface = 'xml'