mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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.
This commit is contained in:
parent
94a14485f7
commit
ccd0f22061
@ -220,7 +220,9 @@ public class QuotaManagerImpl extends ManagerBase implements QuotaManager {
|
|||||||
_quotaBalanceDao.saveQuotaBalance(firstBalance);
|
_quotaBalanceDao.saveQuotaBalance(firstBalance);
|
||||||
} else {
|
} else {
|
||||||
QuotaBalanceVO lastRealBalanceEntry = _quotaBalanceDao.findLastBalanceEntry(account.getAccountId(), account.getDomainId(), endDate);
|
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()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Last balance entry " + lastRealBalanceEntry + " AggrUsage=" + aggrUsage);
|
s_logger.debug("Last balance entry " + lastRealBalanceEntry + " AggrUsage=" + aggrUsage);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,7 +62,7 @@ public class QuotaBalanceVO implements InternalIdentity {
|
|||||||
this.accountId = credit.getAccountId();
|
this.accountId = credit.getAccountId();
|
||||||
this.domainId = credit.getDomainId();
|
this.domainId = credit.getDomainId();
|
||||||
this.creditBalance = credit.getCredit();
|
this.creditBalance = credit.getCredit();
|
||||||
this.updatedOn = credit.getUpdatedOn() == null ? null : new Date(credit.getUpdatedOn().getTime());
|
this.updatedOn = credit.getUpdatedOn() == null ? null : new Date(credit.getUpdatedOn().getTime());
|
||||||
this.creditsId = credit.getId();
|
this.creditsId = credit.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class QuotaBalanceVO implements InternalIdentity {
|
|||||||
this.domainId = domainId;
|
this.domainId = domainId;
|
||||||
this.creditBalance = creditBalance;
|
this.creditBalance = creditBalance;
|
||||||
this.creditsId = 0L;
|
this.creditsId = 0L;
|
||||||
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
|
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -108,6 +108,10 @@ public class QuotaBalanceVO implements InternalIdentity {
|
|||||||
this.creditsId = creditsId;
|
this.creditsId = creditsId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBalanceEntry(){
|
||||||
|
return creditsId==0;
|
||||||
|
}
|
||||||
|
|
||||||
public BigDecimal getCreditBalance() {
|
public BigDecimal getCreditBalance() {
|
||||||
return creditBalance;
|
return creditBalance;
|
||||||
}
|
}
|
||||||
@ -121,7 +125,7 @@ public class QuotaBalanceVO implements InternalIdentity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdatedOn(Date updatedOn) {
|
public void setUpdatedOn(Date updatedOn) {
|
||||||
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
|
this.updatedOn = updatedOn == null ? null : new Date(updatedOn.getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -186,7 +186,7 @@ public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
|
|||||||
//check that there is at least one balance entry
|
//check that there is at least one balance entry
|
||||||
for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) {
|
for (Iterator<QuotaBalanceVO> it = quotaBalance.iterator(); it.hasNext();) {
|
||||||
QuotaBalanceVO entry = it.next();
|
QuotaBalanceVO entry = it.next();
|
||||||
if (entry.getCreditsId() > 0) {
|
if (entry.isBalanceEntry()) {
|
||||||
have_balance_entries = true;
|
have_balance_entries = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,10 +30,30 @@ from nose.plugins.attrib import attr
|
|||||||
#Import System modules
|
#Import System modules
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#ENABLE THE QUOTA PLUGIN AND RESTART THE MANAGEMENT SERVER TO RUN QUOTA TESTS
|
|
||||||
|
|
||||||
class TestQuota(cloudstackTestCase):
|
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,
|
||||||
|
]
|
||||||
|
return
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.apiclient = self.testClient.getApiClient()
|
self.apiclient = self.testClient.getApiClient()
|
||||||
self.hypervisor = self.testClient.getHypervisorInfo()
|
self.hypervisor = self.testClient.getHypervisorInfo()
|
||||||
@ -55,6 +75,12 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#Check quotaTariffList API returning 22 items
|
#Check quotaTariffList API returning 22 items
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_01_quota(self):
|
def test_01_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaTariffList.quotaTariffListCmd()
|
cmd = quotaTariffList.quotaTariffListCmd()
|
||||||
response = self.apiclient.quotaTariffList(cmd)
|
response = self.apiclient.quotaTariffList(cmd)
|
||||||
|
|
||||||
@ -75,6 +101,12 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#Check quota tariff on a particualr day
|
#Check quota tariff on a particualr day
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_02_quota(self):
|
def test_02_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaTariffList.quotaTariffListCmd()
|
cmd = quotaTariffList.quotaTariffListCmd()
|
||||||
cmd.startdate='2015-07-06'
|
cmd.startdate='2015-07-06'
|
||||||
response = self.apiclient.quotaTariffList(cmd)
|
response = self.apiclient.quotaTariffList(cmd)
|
||||||
@ -89,6 +121,12 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#check quota tariff of a particular item
|
#check quota tariff of a particular item
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_03_quota(self):
|
def test_03_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaTariffList.quotaTariffListCmd()
|
cmd = quotaTariffList.quotaTariffListCmd()
|
||||||
cmd.startdate='2015-07-06'
|
cmd.startdate='2015-07-06'
|
||||||
cmd.usagetype='10'
|
cmd.usagetype='10'
|
||||||
@ -107,6 +145,12 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#check the old tariff it should be same
|
#check the old tariff it should be same
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_04_quota(self):
|
def test_04_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaTariffList.quotaTariffListCmd()
|
cmd = quotaTariffList.quotaTariffListCmd()
|
||||||
cmd.startdate='2015-07-06'
|
cmd.startdate='2015-07-06'
|
||||||
cmd.usagetype='10'
|
cmd.usagetype='10'
|
||||||
@ -157,9 +201,15 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#Make credit deposit
|
#Make credit deposit
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_05_quota(self):
|
def test_05_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaCredits.quotaCreditsCmd()
|
cmd = quotaCredits.quotaCreditsCmd()
|
||||||
cmd.domainid = '1'
|
cmd.domainid = self.account.domainid
|
||||||
cmd.account = 'admin'
|
cmd.account = self.account.name
|
||||||
cmd.value = '10'
|
cmd.value = '10'
|
||||||
cmd.quota_enforce = '1'
|
cmd.quota_enforce = '1'
|
||||||
cmd.min_balance = '9'
|
cmd.min_balance = '9'
|
||||||
@ -173,26 +223,38 @@ class TestQuota(cloudstackTestCase):
|
|||||||
#Make credit deposit and check today balance
|
#Make credit deposit and check today balance
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_06_quota(self):
|
def test_06_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaBalance.quotaBalanceCmd()
|
cmd = quotaBalance.quotaBalanceCmd()
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
cmd.domainid = '1'
|
cmd.domainid = self.account.domainid
|
||||||
cmd.account = 'admin'
|
cmd.account = self.account.name
|
||||||
cmd.startdate = today
|
cmd.startdate = today
|
||||||
response = self.apiclient.quotaBalance(cmd)
|
response = self.apiclient.quotaBalance(cmd)
|
||||||
|
|
||||||
self.debug("Quota Balance on: %s" % response.startdate)
|
self.debug("Quota Balance on: %s" % response.startdate)
|
||||||
self.debug("is: %s" % response.startquota)
|
self.debug("is: %s" % response.startquota)
|
||||||
|
|
||||||
self.assertGreater( response.startquota, 9)
|
self.assertEqual( response.startquota, 10)
|
||||||
return
|
return
|
||||||
|
|
||||||
#make credit deposit and check start and end date balances
|
#make credit deposit and check start and end date balances
|
||||||
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
@attr(tags=["smoke", "advanced"], required_hardware="false")
|
||||||
def test_07_quota(self):
|
def test_07_quota(self):
|
||||||
|
if not is_config_suitable(
|
||||||
|
apiclient=self.apiclient,
|
||||||
|
name='quota.enable.service',
|
||||||
|
value='true'):
|
||||||
|
self.skipTest('quota.enable.service should be true. skipping')
|
||||||
|
|
||||||
cmd = quotaBalance.quotaBalanceCmd()
|
cmd = quotaBalance.quotaBalanceCmd()
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
cmd.domainid = '1'
|
cmd.domainid = self.account.domainid
|
||||||
cmd.account = 'admin'
|
cmd.account = self.account.name
|
||||||
cmd.startdate = today - datetime.timedelta(days=2)
|
cmd.startdate = today - datetime.timedelta(days=2)
|
||||||
cmd.enddate = today
|
cmd.enddate = today
|
||||||
response = self.apiclient.quotaBalance(cmd)
|
response = self.apiclient.quotaBalance(cmd)
|
||||||
@ -200,5 +262,6 @@ class TestQuota(cloudstackTestCase):
|
|||||||
self.debug("Quota Balance on: %s" % response.startdate)
|
self.debug("Quota Balance on: %s" % response.startdate)
|
||||||
self.debug("is: %s" % response.startquota)
|
self.debug("is: %s" % response.startquota)
|
||||||
|
|
||||||
self.assertGreater( response.endquota, 9)
|
self.assertEqual( response.startquota, 0)
|
||||||
|
self.assertEqual( response.endquota, 10)
|
||||||
return
|
return
|
||||||
@ -142,6 +142,10 @@
|
|||||||
"LogFolderPath": "/tmp/"
|
"LogFolderPath": "/tmp/"
|
||||||
},
|
},
|
||||||
"globalConfig": [
|
"globalConfig": [
|
||||||
|
{
|
||||||
|
"name": "quota.enable.service",
|
||||||
|
"value": "true"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "network.gc.wait",
|
"name": "network.gc.wait",
|
||||||
"value": "60"
|
"value": "60"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user