def test_quota_usage_reserve(self): utils.create_test_quota() dbapi = db_api.get_instance() r = dbapi.quota_reserve(self.context, self.resources, {'servers': 10}, {'servers': 1}, datetime.datetime(2099, 1, 1, 0, 0), CONF.quota.until_refresh, CONF.quota.max_age, project_id=self.project_id) self.assertEqual('servers', r[0].resource_name)
def test_reserve_rollback(self): utils.create_test_quota() dbapi = db_api.get_instance() rs = dbapi.quota_reserve(self.context, self.resources, {'servers': 10}, {'servers': 1}, datetime.datetime(2099, 1, 1, 0, 0), CONF.quota.until_refresh, CONF.quota.max_age, project_id=self.project_id) r = dbapi.quota_usage_get_all_by_project(self.context, self.project_id) before_in_use = r['servers']['in_use'] dbapi.reservation_rollback(self.context, rs, self.project_id) r = dbapi.quota_usage_get_all_by_project(self.context, self.project_id) after_in_use = r['servers']['in_use'] self.assertEqual(before_in_use, after_in_use)
def test_quota_update_with_invalid_parameter_value(self): quota = utils.create_test_quota() self.assertRaises(exception.InvalidParameterValue, self.dbapi.quota_update, self.context, quota.project_id, quota.resource_name, {'resource_name': 'server_test'})
def test_quota_destroy(self): quota = utils.create_test_quota() self.dbapi.quota_destroy(self.context, quota.project_id, quota.resource_name) self.assertRaises(exception.QuotaNotFound, self.dbapi.quota_get, self.context, quota.project_id, quota.resource_name)
def test_quota_update(self): quota = utils.create_test_quota() old_limit = quota.hard_limit new_limit = 100 self.assertNotEqual(old_limit, new_limit) res = self.dbapi.quota_update(self.context, quota.project_id, quota.resource_name, {'hard_limit': new_limit}) self.assertEqual(new_limit, res.hard_limit)
def test_quota_get_all(self): ids_project_1 = [] ids_project_2 = [] ids_project_all = [] resource_names = ['servers', 'servers_type', 'test_resource'] for i in range(0, 3): quota = utils.create_test_quota(project_id='project_1', resource_name=resource_names[i]) ids_project_1.append(quota['id']) for i in range(3, 5): resource_name = resource_names[i - 3] quota = utils.create_test_quota(project_id='project_2', resource_name=resource_name) ids_project_2.append(quota['id']) ids_project_all.extend(ids_project_1) ids_project_all.extend(ids_project_2) # Set project_only to False # get all quotas from all projects res = self.dbapi.quota_get_all(self.context, project_only=False) res_ids = [r.id for r in res] six.assertCountEqual(self, ids_project_all, res_ids) # Set project_only to True # get quotas from current project (project_1) self.context.tenant = 'project_1' res = self.dbapi.quota_get_all(self.context, project_only=True) res_ids = [r.id for r in res] six.assertCountEqual(self, ids_project_1, res_ids) # Set project_only to True # get quotas from current project (project_2) self.context.tenant = 'project_2' res = self.dbapi.quota_get_all(self.context, project_only=True) res_ids = [r.id for r in res] six.assertCountEqual(self, ids_project_2, res_ids)
def test_quota_get_by_project_id_and_resource_name(self): quota = utils.create_test_quota() res = self.dbapi.quota_get(self.context, quota.project_id, quota.resource_name) self.assertEqual(quota.id, res.id)
def test_quota_create(self): utils.create_test_quota()