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
This commit is contained in:
Abhinandan Prateek 2015-12-14 12:10:48 +05:30
parent 3c7d45589a
commit 5bead93672
3 changed files with 39 additions and 11 deletions

View File

@ -220,7 +220,9 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
_quotaBalanceDao.saveQuotaBalance(firstBalance);
} else {
QuotaBalanceVO lastRealBalanceEntry = _quotaBalanceDao.findLastBalanceEntry(account.getAccountId(), account.getDomainId(), endDate);
aggrUsage = aggrUsage.add(lastRealBalanceEntry.getCreditBalance());
if (lastRealBalanceEntry != null){
aggrUsage = aggrUsage.add(lastRealBalanceEntry.getCreditBalance());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Last balance entry " + lastRealBalanceEntry + " AggrUsage=" + aggrUsage);
}

View File

@ -186,7 +186,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
//check that there is at least one balance entry
for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) {
QuotaBalanceVO entry = it.next();
if (entry.getCreditsId() > 0) {
if (entry.getCreditsId() == 0) {
have_balance_entries = true;
break;
}

View File

@ -34,6 +34,31 @@ import time
class TestQuota(cloudstackTestCase):
@classmethod
def setUpClass(cls):
# Create Account
testClient = super(TestQuota, cls).getClsTestClient()
cls.apiclient = testClient.getApiClient()
cls.services = testClient.getParsedTestDataConfig()
# Get Zone, Domain
cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
# Create Account
cls.account = Account.create(
cls.apiclient,
cls.services["account"],
domainid=cls.domain.id
)
cls._cleanup = [
cls.account,
]
cls._cleanup = [
cls.account,
]
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.hypervisor = self.testClient.getHypervisorInfo()
@ -158,8 +183,8 @@ class TestQuota(cloudstackTestCase):
@attr(tags=["smoke", "advanced"], required_hardware="false")
def test_05_quota(self):
cmd = quotaCredits.quotaCreditsCmd()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.domainid = self.account.domainid
cmd.account = self.account.name
cmd.value = '10'
cmd.quota_enforce = '1'
cmd.min_balance = '9'
@ -175,15 +200,15 @@ class TestQuota(cloudstackTestCase):
def test_06_quota(self):
cmd = quotaBalance.quotaBalanceCmd()
today = datetime.date.today()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.domainid = self.account.domainid
cmd.account = self.account.name
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)
self.assertEqual( response.startquota, 10)
return
#make credit deposit and check start and end date balances
@ -191,14 +216,15 @@ class TestQuota(cloudstackTestCase):
def test_07_quota(self):
cmd = quotaBalance.quotaBalanceCmd()
today = datetime.date.today()
cmd.domainid = '1'
cmd.account = 'admin'
cmd.domainid = self.account.domainid
cmd.account = self.account.name
cmd.startdate = today - datetime.timedelta(days=2)
cmd.enddate = today
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)
self.assertEqual( response.startquota, 0)
self.assertEqual( response.endquota, 10)
return