forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_quota.py
More file actions
204 lines (169 loc) · 6.85 KB
/
Copy pathtest_quota.py
File metadata and controls
204 lines (169 loc) · 6.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" Test cases for checking quota API
"""
#Import Local Modules
import marvin
from marvin.cloudstackTestCase import *
from marvin.cloudstackAPI import *
from marvin.lib.utils import *
from marvin.lib.base import *
from marvin.lib.common import *
from marvin.lib.utils import (random_gen)
from nose.plugins.attrib import attr
#Import System modules
import time
#ENABLE THE QUOTA PLUGIN AND RESTART THE MANAGEMENT SERVER TO RUN QUOTA TESTS
class TestQuota(cloudstackTestCase):
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
self.dbclient = self.testClient.getDbConnection()
self.services = self.testClient.getParsedTestDataConfig()
self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
self.pod = get_pod(self.apiclient, self.zone.id)
self.cleanup = []
return
def tearDown(self):
try:
#Clean up, terminate the created templates
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
#Check quotaTariffList API returning 22 items
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_01_quota(self):
cmd = quotaTariffList.quotaTariffListCmd()
response = self.apiclient.quotaTariffList(cmd)
self.debug("Number of quota usage types: %s" % len(response))
self.assertEqual(
len(response), 22
)
for quota in response:
self.debug("Usage Name: %s" % quota.usageName)
self.assertEqual(
hasattr(quota, 'usageName'),
True,
"Check whether usgaeName field is there"
)
return
#Check quota tariff on a particualr day
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_02_quota(self):
cmd = quotaTariffList.quotaTariffListCmd()
cmd.startdate='2015-07-06'
response = self.apiclient.quotaTariffList(cmd)
self.debug("Number of quota usage types: %s" % len(response))
self.assertEqual(
len(response), 22
)
return
#check quota tariff of a particular item
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_03_quota(self):
cmd = quotaTariffList.quotaTariffListCmd()
cmd.startdate='2015-07-06'
cmd.usagetype='10'
response = self.apiclient.quotaTariffList(cmd)
self.debug("Number of quota usage types: %s" % len(response))
self.assertEqual(
len(response), 1
)
return
#check quota tariff
#Change it
#Check on affective date the new tariff should be applicable
#check the old tariff it should be same
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_04_quota(self):
cmd = quotaTariffList.quotaTariffListCmd()
cmd.startdate='2015-07-06'
cmd.usagetype='10'
response = self.apiclient.quotaTariffList(cmd)
self.debug("Number of quota usage types: %s" % len(response))
self.assertEqual(
len(response), 1
)
quota = response[0]
self.debug("Tariff Value for 10: %s" % quota.tariffValue)
cmd = quotaTariffUpdate.quotaTariffUpdateCmd()
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
cmd.startdate=tomorrow
cmd.usagetype='10'
cmd.value='2.9'
response = self.apiclient.quotaTariffUpdate(cmd)
cmd = quotaTariffList.quotaTariffListCmd()
cmd.startdate=tomorrow
cmd.usagetype='10'
response = self.apiclient.quotaTariffList(cmd)
self.assertEqual(
len(response), 1
)
quota = response[0]
self.debug("Tariff Value for 10: %s" % quota.tariffValue)
self.assertEqual( quota.tariffValue, 2.9)
cmd = quotaTariffList.quotaTariffListCmd()
cmd.startdate='2015-07-07'
cmd.usagetype='10'
response = self.apiclient.quotaTariffList(cmd)
self.assertEqual(
len(response), 1
)
quota = response[0]
self.debug("Tariff Value for 10: %s" % quota.tariffValue)
self.assertEqual( quota.tariffValue, 0)
return
#Make credit deposit
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_05_quota(self):
cmd = quotaCredits.quotaCreditsCmd()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.value = '10'
cmd.quota_enforce = '1'
cmd.min_balance = '9'
response = self.apiclient.quotaCredits(cmd)
self.debug("Credit response update on: %s" % response.updated_on)
return
#Make credit deposit and check today balance
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_06_quota(self):
cmd = quotaBalance.quotaBalanceCmd()
today = datetime.date.today()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.startdate = today
response = self.apiclient.quotaBalance(cmd)
self.debug("Quota Balance on: %s" % response.startdate)
self.debug("is: %s" % response.startquota)
self.assertGreater( response.startquota, 9)
return
#make credit deposit and check start and end date balances
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_07_quota(self):
cmd = quotaBalance.quotaBalanceCmd()
today = datetime.date.today()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.startdate = today - datetime.timedelta(days=2)
cmd.enddate = today
response = self.apiclient.quotaBalance(cmd)
self.debug("Quota Balance on: %s" % response.startdate)
self.debug("is: %s" % response.startquota)
self.assertGreater( response.endquota, 9)
return