blob: 8259feb0bce500cc287b9c90e09be08c64e62dc4 [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
Gavin Brebner516487b2013-03-14 13:43:21 +000021
22MAX_REASONABLE_ITERATIONS = 51 # more than enough. Default for port is 50.
23
24
Sean Dague6dbc6da2013-05-08 17:49:46 -040025class TestNetworkQuotaBasic(NetworkScenarioTest):
Gavin Brebner516487b2013-03-14 13:43:21 +000026 """
27 This test suite contains tests that each loop trying to grab a
28 particular resource until a quota limit is hit.
29 For sanity, there is a maximum number of iterations - if this is hit
30 the test fails. Covers network, subnet, port.
31 """
32
33 @classmethod
34 def check_preconditions(cls):
35 super(TestNetworkQuotaBasic, cls).check_preconditions()
36
37 @classmethod
38 def setUpClass(cls):
39 super(TestNetworkQuotaBasic, cls).setUpClass()
40 cls.check_preconditions()
41 cls.networks = []
42 cls.subnets = []
43 cls.ports = []
44
45 def test_create_network_until_quota_hit(self):
46 hit_limit = False
47 for n in xrange(MAX_REASONABLE_ITERATIONS):
48 try:
49 self.networks.append(
50 self._create_network(self.tenant_id,
51 namestart='network-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -040052 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +000053 if (e.status_code != 409):
54 raise
55 hit_limit = True
56 break
57 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
58
59 def test_create_subnet_until_quota_hit(self):
60 if not self.networks:
61 self.networks.append(
62 self._create_network(self.tenant_id,
63 namestart='network-quotatest-'))
64 hit_limit = False
65 for n in xrange(MAX_REASONABLE_ITERATIONS):
66 try:
67 self.subnets.append(
68 self._create_subnet(self.networks[0],
69 namestart='subnet-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -040070 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +000071 if (e.status_code != 409):
72 raise
73 hit_limit = True
74 break
75 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")
76
77 def test_create_ports_until_quota_hit(self):
78 if not self.networks:
79 self.networks.append(
80 self._create_network(self.tenant_id,
81 namestart='network-quotatest-'))
82 hit_limit = False
83 for n in xrange(MAX_REASONABLE_ITERATIONS):
84 try:
85 self.ports.append(
86 self._create_port(self.networks[0],
87 namestart='port-quotatest-'))
Mark McClainf2982e82013-07-06 17:48:03 -040088 except exc.NeutronClientException as e:
Gavin Brebner516487b2013-03-14 13:43:21 +000089 if (e.status_code != 409):
90 raise
91 hit_limit = True
92 break
93 self.assertTrue(hit_limit, "Failed: Did not hit quota limit !")