Skip to content

Commit ccd0f22

Browse files
CLOUDSTACK-9161: fix the quota marvin test
1. Create a dummy user, as existing user may already have stale quota data 2. fix the tests to use the dummy user 3. a boundary condition was revealed and fixed for a new user where quota service has never run and created bootstrap entries Quota Marvin: If the quota plugin is not enabled skip tests Quota Service: Enable quota plugin in zone setup configuration Quota: Moving test_quota.py the test to test/integration/plugins In most automated environment this test case will not run as it requires a mangement server restart to enable the plugin. Due to this requirement moving it to plugin folder. This condition is already documented in the test case.
1 parent 94a1448 commit ccd0f22

5 files changed

Lines changed: 89 additions & 16 deletions

File tree

framework/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ public void processQuotaBalanceForAccount(final AccountVO account, final List<Qu
220220
_quotaBalanceDao.saveQuotaBalance(firstBalance);
221221
} else {
222222
QuotaBalanceVO lastRealBalanceEntry = _quotaBalanceDao.findLastBalanceEntry(account.getAccountId(), account.getDomainId(), endDate);
223-
aggrUsage = aggrUsage.add(lastRealBalanceEntry.getCreditBalance());
223+
if (lastRealBalanceEntry != null){
224+
aggrUsage = aggrUsage.add(lastRealBalanceEntry.getCreditBalance());
225+
}
224226
if (s_logger.isDebugEnabled()) {
225227
s_logger.debug("Last balance entry " + lastRealBalanceEntry + " AggrUsage=" + aggrUsage);
226228
}

framework/quota/src/org/apache/cloudstack/quota/vo/QuotaBalanceVO.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public QuotaBalanceVO(final QuotaCreditsVO credit) {
6262
this.accountId = credit.getAccountId();
6363
this.domainId = credit.getDomainId();
6464
this.creditBalance = credit.getCredit();
65-
this.updatedOn = credit.getUpdatedOn() == null ? null : new Date(credit.getUpdatedOn().getTime());
65+
this.updatedOn = credit.getUpdatedOn() == null ? null : new Date(credit.getUpdatedOn().getTime());
6666
this.creditsId = credit.getId();
6767
}
6868

@@ -72,7 +72,7 @@ public QuotaBalanceVO(final Long accountId, final Long domainId, final BigDecima
7272
this.domainId = domainId;
7373
this.creditBalance = creditBalance;
7474
this.creditsId = 0L;
75-
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
75+
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
7676
}
7777

7878
@Override
@@ -108,6 +108,10 @@ public void setCreditsId(Long creditsId) {
108108
this.creditsId = creditsId;
109109
}
110110

111+
public boolean isBalanceEntry(){
112+
return creditsId==0;
113+
}
114+
111115
public BigDecimal getCreditBalance() {
112116
return creditBalance;
113117
}
@@ -121,7 +125,7 @@ public Date getUpdatedOn() {
121125
}
122126

123127
public void setUpdatedOn(Date updatedOn) {
124-
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
128+
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
125129
}
126130

127131
@Override

plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public int compare(QuotaBalanceVO o1, QuotaBalanceVO o2) {
186186
//check that there is at least one balance entry
187187
for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) {
188188
QuotaBalanceVO entry = it.next();
189-
if (entry.getCreditsId() > 0) {
189+
if (entry.isBalanceEntry()) {
190190
have_balance_entries = true;
191191
break;
192192
}
Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,30 @@
3030
#Import System modules
3131
import time
3232

33-
#ENABLE THE QUOTA PLUGIN AND RESTART THE MANAGEMENT SERVER TO RUN QUOTA TESTS
34-
3533
class TestQuota(cloudstackTestCase):
3634

35+
@classmethod
36+
def setUpClass(cls):
37+
# Create Account
38+
testClient = super(TestQuota, cls).getClsTestClient()
39+
cls.apiclient = testClient.getApiClient()
40+
cls.services = testClient.getParsedTestDataConfig()
41+
42+
# Get Zone, Domain
43+
cls.domain = get_domain(cls.apiclient)
44+
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
45+
46+
# Create Account
47+
cls.account = Account.create(
48+
cls.apiclient,
49+
cls.services["account"],
50+
domainid=cls.domain.id
51+
)
52+
cls._cleanup = [
53+
cls.account,
54+
]
55+
return
56+
3757
def setUp(self):
3858
self.apiclient = self.testClient.getApiClient()
3959
self.hypervisor = self.testClient.getHypervisorInfo()
@@ -55,6 +75,12 @@ def tearDown(self):
5575
#Check quotaTariffList API returning 22 items
5676
@attr(tags=["smoke", "advanced"], required_hardware="false")
5777
def test_01_quota(self):
78+
if not is_config_suitable(
79+
apiclient=self.apiclient,
80+
name='quota.enable.service',
81+
value='true'):
82+
self.skipTest('quota.enable.service should be true. skipping')
83+
5884
cmd = quotaTariffList.quotaTariffListCmd()
5985
response = self.apiclient.quotaTariffList(cmd)
6086

@@ -75,6 +101,12 @@ def test_01_quota(self):
75101
#Check quota tariff on a particualr day
76102
@attr(tags=["smoke", "advanced"], required_hardware="false")
77103
def test_02_quota(self):
104+
if not is_config_suitable(
105+
apiclient=self.apiclient,
106+
name='quota.enable.service',
107+
value='true'):
108+
self.skipTest('quota.enable.service should be true. skipping')
109+
78110
cmd = quotaTariffList.quotaTariffListCmd()
79111
cmd.startdate='2015-07-06'
80112
response = self.apiclient.quotaTariffList(cmd)
@@ -89,6 +121,12 @@ def test_02_quota(self):
89121
#check quota tariff of a particular item
90122
@attr(tags=["smoke", "advanced"], required_hardware="false")
91123
def test_03_quota(self):
124+
if not is_config_suitable(
125+
apiclient=self.apiclient,
126+
name='quota.enable.service',
127+
value='true'):
128+
self.skipTest('quota.enable.service should be true. skipping')
129+
92130
cmd = quotaTariffList.quotaTariffListCmd()
93131
cmd.startdate='2015-07-06'
94132
cmd.usagetype='10'
@@ -107,6 +145,12 @@ def test_03_quota(self):
107145
#check the old tariff it should be same
108146
@attr(tags=["smoke", "advanced"], required_hardware="false")
109147
def test_04_quota(self):
148+
if not is_config_suitable(
149+
apiclient=self.apiclient,
150+
name='quota.enable.service',
151+
value='true'):
152+
self.skipTest('quota.enable.service should be true. skipping')
153+
110154
cmd = quotaTariffList.quotaTariffListCmd()
111155
cmd.startdate='2015-07-06'
112156
cmd.usagetype='10'
@@ -157,9 +201,15 @@ def test_04_quota(self):
157201
#Make credit deposit
158202
@attr(tags=["smoke", "advanced"], required_hardware="false")
159203
def test_05_quota(self):
204+
if not is_config_suitable(
205+
apiclient=self.apiclient,
206+
name='quota.enable.service',
207+
value='true'):
208+
self.skipTest('quota.enable.service should be true. skipping')
209+
160210
cmd = quotaCredits.quotaCreditsCmd()
161-
cmd.domainid = '1'
162-
cmd.account = 'admin'
211+
cmd.domainid = self.account.domainid
212+
cmd.account = self.account.name
163213
cmd.value = '10'
164214
cmd.quota_enforce = '1'
165215
cmd.min_balance = '9'
@@ -173,32 +223,45 @@ def test_05_quota(self):
173223
#Make credit deposit and check today balance
174224
@attr(tags=["smoke", "advanced"], required_hardware="false")
175225
def test_06_quota(self):
226+
if not is_config_suitable(
227+
apiclient=self.apiclient,
228+
name='quota.enable.service',
229+
value='true'):
230+
self.skipTest('quota.enable.service should be true. skipping')
231+
176232
cmd = quotaBalance.quotaBalanceCmd()
177233
today = datetime.date.today()
178-
cmd.domainid = '1'
179-
cmd.account = 'admin'
234+
cmd.domainid = self.account.domainid
235+
cmd.account = self.account.name
180236
cmd.startdate = today
181237
response = self.apiclient.quotaBalance(cmd)
182238

183239
self.debug("Quota Balance on: %s" % response.startdate)
184240
self.debug("is: %s" % response.startquota)
185241

186-
self.assertGreater( response.startquota, 9)
242+
self.assertEqual( response.startquota, 10)
187243
return
188244

189245
#make credit deposit and check start and end date balances
190246
@attr(tags=["smoke", "advanced"], required_hardware="false")
191247
def test_07_quota(self):
248+
if not is_config_suitable(
249+
apiclient=self.apiclient,
250+
name='quota.enable.service',
251+
value='true'):
252+
self.skipTest('quota.enable.service should be true. skipping')
253+
192254
cmd = quotaBalance.quotaBalanceCmd()
193255
today = datetime.date.today()
194-
cmd.domainid = '1'
195-
cmd.account = 'admin'
256+
cmd.domainid = self.account.domainid
257+
cmd.account = self.account.name
196258
cmd.startdate = today - datetime.timedelta(days=2)
197-
cmd.enddate = today
259+
cmd.enddate = today
198260
response = self.apiclient.quotaBalance(cmd)
199261

200262
self.debug("Quota Balance on: %s" % response.startdate)
201263
self.debug("is: %s" % response.startquota)
202264

203-
self.assertGreater( response.endquota, 9)
265+
self.assertEqual( response.startquota, 0)
266+
self.assertEqual( response.endquota, 10)
204267
return

tools/marvin/marvin/config/setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
"LogFolderPath": "/tmp/"
143143
},
144144
"globalConfig": [
145+
{
146+
"name": "quota.enable.service",
147+
"value": "true"
148+
},
145149
{
146150
"name": "network.gc.wait",
147151
"value": "60"

0 commit comments

Comments
 (0)