From 5bead93672679adb2774740b7e727fb8f9433d30 Mon Sep 17 00:00:00 2001 From: Abhinandan Prateek Date: Mon, 14 Dec 2015 12:10:48 +0530 Subject: [PATCH] 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 --- .../cloudstack/quota/QuotaManagerImpl.java | 4 +- .../response/QuotaResponseBuilderImpl.java | 2 +- test/integration/smoke/test_quota.py | 44 +++++++++++++++---- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/framework/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java b/framework/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java index b039e26a9b5..ac14718fd4e 100644 --- a/framework/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java +++ b/framework/quota/src/org/apache/cloudstack/quota/QuotaManagerImpl.java @@ -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); } diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java index 4a2816d2ea2..56d108a06f4 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java @@ -186,7 +186,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder { //check that there is at least one balance entry for (Iterator it = quotaBalance.iterator(); it.hasNext();) { QuotaBalanceVO entry = it.next(); - if (entry.getCreditsId() > 0) { + if (entry.getCreditsId() == 0) { have_balance_entries = true; break; } diff --git a/test/integration/smoke/test_quota.py b/test/integration/smoke/test_quota.py index d4e4323e9b3..e399d6337b5 100644 --- a/test/integration/smoke/test_quota.py +++ b/test/integration/smoke/test_quota.py @@ -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