Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 1 | # 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 Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 18 | import netaddr |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 19 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 20 | from tempest.api.network import base |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import rand_name |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 22 | from tempest import exceptions |
| 23 | from tempest.test import attr |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 24 | |
| 25 | |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 26 | class NetworksTest(base.BaseNetworkTest): |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 27 | |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 28 | """ |
| 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 Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 49 | @classmethod |
| 50 | def setUpClass(cls): |
Jay Pipes | f4dad39 | 2012-06-05 16:03:58 -0400 | [diff] [blame] | 51 | super(NetworksTest, cls).setUpClass() |
| 52 | cls.network = cls.create_network() |
| 53 | cls.name = cls.network['name'] |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 54 | cls.subnet = cls.create_subnet(cls.network) |
| 55 | cls.cidr = cls.subnet['cidr'] |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 56 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 57 | @attr(type=['positive', 'gate']) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 58 | def test_create_delete_network_subnet(self): |
| 59 | # Creates a network |
| 60 | name = rand_name('network-') |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 61 | resp, body = self.client.create_network(name) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 62 | self.assertEqual('201', resp['status']) |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 63 | network = body['network'] |
| 64 | self.assertTrue(network['id'] is not None) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 65 | # 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 Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 83 | resp, body = self.client.delete_network(network['id']) |
| 84 | self.assertEqual('204', resp['status']) |
| 85 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 86 | @attr(type=['positive', 'gate']) |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 87 | def test_show_network(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 88 | # Verifies the details of a network |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 89 | resp, body = self.client.show_network(self.network['id']) |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 90 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 95 | @attr(type=['positive', 'gate']) |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 96 | def test_list_networks(self): |
Sean Dague | 46c4a2b | 2013-01-03 17:54:17 -0500 | [diff] [blame] | 97 | # Verify the network exists in the list of all networks |
Unmesh Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 98 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 103 | @attr(type=['positive', 'gate']) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 104 | 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 Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame] | 112 | @attr(type=['positive', 'gate']) |
Miguel Lavalle | cc93961 | 2013-02-22 17:27:20 -0600 | [diff] [blame] | 113 | 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 Gurjar | 4498683 | 2012-05-08 19:57:10 +0530 | [diff] [blame] | 118 | self.assertTrue(found) |