blob: cb7aa0b9855f442c379d5704ad532293578eea4c [file] [log] [blame]
Gavin Brebner516487b2013-03-14 13:43:21 +00001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 Hewlett-Packard Development Company, L.P.
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
Mark McClainf2982e82013-07-06 17:48:03 -040018from neutronclient.common import exceptions as exc
Matthew Treinishf4418592013-09-09 20:59:23 +000019
Sean Dague6dbc6da2013-05-08 17:49:46 -040020from tempest.scenario.manager import NetworkScenarioTest
Matthew Treinish2153ec02013-09-09 20:57:30 +000021from tempest.test import services
Gavin Brebner516487b2013-03-14 13:43:21 +000022
Gavin Brebner516487b2013-03-14 13:43:21 +000023
Sean Dague6dbc6da2013-05-08 17:49:46 -040024class TestNetworkQuotaBasic(NetworkScenarioTest):
Gavin Brebner516487b2013-03-14 13:43:21 +000025 """
26 This test suite contains tests that each loop trying to grab a
27 particular resource until a quota limit is hit.
28 For sanity, there is a maximum number of iterations - if this is hit
29 the test fails. Covers network, subnet, port.
30 """
31
32 @classmethod
33 def check_preconditions(cls):
34 super(TestNetworkQuotaBasic, cls).check_preconditions()
35
36 @classmethod
37 def setUpClass(cls):
38 super(TestNetworkQuotaBasic, cls).setUpClass()
39 cls.check_preconditions()
40 cls.networks = []
41 cls.subnets = []
42 cls.ports = []
43
Matthew Treinish2153ec02013-09-09 20:57:30 +000044 @services('network')
Gavin Brebner516487b2013-03-14 13:43:21 +000045 def test_create_network_until_quota_hit(self):
46 hit_limit = False
Yuiko Takada7f4b1b32013-11-20 08:06:26 +000047 networknum = self._get_tenant_own_network_num(self.tenant_id)
48 max = self._show_quota_network(self.tenant_id) - networknum
49 for n in xrange(max):
Gavin Brebner516487b2013-03-14 13:43:21 +000050 try:
51 self.networks.append(
52 self._create_network(self.tenant_id,
53 namestart='network-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -040054 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +000055 if (e.status_code != 409):
56 raise
57 hit_limit = True
58 break
Yuiko Takada7f4b1b32013-11-20 08:06:26 +000059 self.assertFalse(hit_limit, "Failed: Hit quota limit !")
60
61 try:
62 self.networks.append(
63 self._create_network(self.tenant_id,
64 namestart='network-quotatest-'))
65 except exc.NeutronClientException as e:
66 if (e.status_code != 409):
67 raise
68 hit_limit = True
Gavin Brebner516487b2013-03-14 13:43:21 +000069 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
70
Matthew Treinish2153ec02013-09-09 20:57:30 +000071 @services('network')
Gavin Brebner516487b2013-03-14 13:43:21 +000072 def test_create_subnet_until_quota_hit(self):
73 if not self.networks:
74 self.networks.append(
75 self._create_network(self.tenant_id,
76 namestart='network-quotatest-'))
77 hit_limit = False
Yuiko Takada7f4b1b32013-11-20 08:06:26 +000078 subnetnum = self._get_tenant_own_subnet_num(self.tenant_id)
79 max = self._show_quota_subnet(self.tenant_id) - subnetnum
80 for n in xrange(max):
Gavin Brebner516487b2013-03-14 13:43:21 +000081 try:
82 self.subnets.append(
83 self._create_subnet(self.networks[0],
84 namestart='subnet-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -040085 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +000086 if (e.status_code != 409):
87 raise
88 hit_limit = True
89 break
Yuiko Takada7f4b1b32013-11-20 08:06:26 +000090 self.assertFalse(hit_limit, "Failed: Hit quota limit !")
91
92 try:
93 self.subnets.append(
94 self._create_subnet(self.networks[0],
95 namestart='subnet-quotatest-'))
96 except exc.NeutronClientException as e:
97 if (e.status_code != 409):
98 raise
99 hit_limit = True
Gavin Brebner516487b2013-03-14 13:43:21 +0000100 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
101
Matthew Treinish2153ec02013-09-09 20:57:30 +0000102 @services('network')
Gavin Brebner516487b2013-03-14 13:43:21 +0000103 def test_create_ports_until_quota_hit(self):
104 if not self.networks:
105 self.networks.append(
106 self._create_network(self.tenant_id,
107 namestart='network-quotatest-'))
108 hit_limit = False
Yuiko Takada7f4b1b32013-11-20 08:06:26 +0000109 portnum = self._get_tenant_own_port_num(self.tenant_id)
110 max = self._show_quota_port(self.tenant_id) - portnum
111 for n in xrange(max):
Gavin Brebner516487b2013-03-14 13:43:21 +0000112 try:
113 self.ports.append(
114 self._create_port(self.networks[0],
115 namestart='port-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -0400116 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +0000117 if (e.status_code != 409):
118 raise
119 hit_limit = True
120 break
Yuiko Takada7f4b1b32013-11-20 08:06:26 +0000121 self.assertFalse(hit_limit, "Failed: Hit quota limit !")
122
123 try:
124 self.ports.append(
125 self._create_port(self.networks[0],
126 namestart='port-quotatest-'))
127 except exc.NeutronClientException as e:
128 if (e.status_code != 409):
129 raise
130 hit_limit = True
Gavin Brebner516487b2013-03-14 13:43:21 +0000131 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")