blob: 78c09e0b9cb22d83684571f9075a4f18f0c1e5e4 [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
Jay Pipesf4dad392012-06-05 16:03:58 -040026class NetworksTest(base.BaseNetworkTest):
Unmesh Gurjar44986832012-05-08 19:57:10 +053027
Miguel Lavallecc939612013-02-22 17:27:20 -060028 """
29 Tests the following operations in the Quantum API using the REST client for
30 Quantum:
31
32 create a network for a tenant
33 list tenant's networks
34 show a tenant network details
35 create a subnet for a tenant
36 list tenant's subnets
37 show a tenant subnet details
38
39 v2.0 of the Quantum API is assumed. It is also assumed that the following
40 options are defined in the [network] section of etc/tempest.conf:
41
42 tenant_network_cidr with a block of cidr's from which smaller blocks
43 can be allocated for tenant networks
44
45 tenant_network_mask_bits with the mask bits to be used to partition the
46 block defined by tenant-network_cidr
47 """
48
Unmesh Gurjar44986832012-05-08 19:57:10 +053049 @classmethod
50 def setUpClass(cls):
Jay Pipesf4dad392012-06-05 16:03:58 -040051 super(NetworksTest, cls).setUpClass()
52 cls.network = cls.create_network()
53 cls.name = cls.network['name']
Miguel Lavallecc939612013-02-22 17:27:20 -060054 cls.subnet = cls.create_subnet(cls.network)
55 cls.cidr = cls.subnet['cidr']
Unmesh Gurjar44986832012-05-08 19:57:10 +053056
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040057 @attr(type=['positive', 'gate'])
Miguel Lavallecc939612013-02-22 17:27:20 -060058 def test_create_delete_network_subnet(self):
59 # Creates a network
60 name = rand_name('network-')
Unmesh Gurjar44986832012-05-08 19:57:10 +053061 resp, body = self.client.create_network(name)
Miguel Lavallecc939612013-02-22 17:27:20 -060062 self.assertEqual('201', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053063 network = body['network']
64 self.assertTrue(network['id'] is not None)
Miguel Lavallecc939612013-02-22 17:27:20 -060065 # Find a cidr that is not in use yet and create a subnet with it
66 cidr = netaddr.IPNetwork(self.network_cfg.tenant_network_cidr)
67 mask_bits = self.network_cfg.tenant_network_mask_bits
68 for subnet_cidr in cidr.subnet(mask_bits):
69 try:
70 resp, body = self.client.create_subnet(network['id'],
71 str(subnet_cidr))
72 break
73 except exceptions.BadRequest as e:
74 is_overlapping_cidr = 'overlaps with another subnet' in str(e)
75 if not is_overlapping_cidr:
76 raise
77 self.assertEqual('201', resp['status'])
78 subnet = body['subnet']
79 self.assertTrue(subnet['id'] is not None)
80 #Deletes subnet and network
81 resp, body = self.client.delete_subnet(subnet['id'])
82 self.assertEqual('204', resp['status'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053083 resp, body = self.client.delete_network(network['id'])
84 self.assertEqual('204', resp['status'])
85
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040086 @attr(type=['positive', 'gate'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053087 def test_show_network(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050088 # Verifies the details of a network
Miguel Lavallecc939612013-02-22 17:27:20 -060089 resp, body = self.client.show_network(self.network['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053090 self.assertEqual('200', resp['status'])
91 network = body['network']
92 self.assertEqual(self.network['id'], network['id'])
93 self.assertEqual(self.name, network['name'])
94
Giampaolo Lauriae9c77022013-05-22 01:23:58 -040095 @attr(type=['positive', 'gate'])
Unmesh Gurjar44986832012-05-08 19:57:10 +053096 def test_list_networks(self):
Sean Dague46c4a2b2013-01-03 17:54:17 -050097 # Verify the network exists in the list of all networks
Unmesh Gurjar44986832012-05-08 19:57:10 +053098 resp, body = self.client.list_networks()
99 networks = body['networks']
100 found = any(n for n in networks if n['id'] == self.network['id'])
101 self.assertTrue(found)
102
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400103 @attr(type=['positive', 'gate'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600104 def test_show_subnet(self):
105 # Verifies the details of a subnet
106 resp, body = self.client.show_subnet(self.subnet['id'])
107 self.assertEqual('200', resp['status'])
108 subnet = body['subnet']
109 self.assertEqual(self.subnet['id'], subnet['id'])
110 self.assertEqual(self.cidr, subnet['cidr'])
111
Giampaolo Lauriae9c77022013-05-22 01:23:58 -0400112 @attr(type=['positive', 'gate'])
Miguel Lavallecc939612013-02-22 17:27:20 -0600113 def test_list_subnets(self):
114 # Verify the subnet exists in the list of all subnets
115 resp, body = self.client.list_subnets()
116 subnets = body['subnets']
117 found = any(n for n in subnets if n['id'] == self.subnet['id'])
Unmesh Gurjar44986832012-05-08 19:57:10 +0530118 self.assertTrue(found)