def test_get_detailed_tenant_quotas_multiple_resource(self): project_1 = 'prj_test_1' resource_1 = 'res_test_1' resource_2 = 'res_test_2' resources = {resource_1: TestTrackedResource(resource_1, test_quota.MehModel), resource_2: TestCountableResource(resource_2, _count_resource)} self.plugin.update_quota_limit(self.context, project_1, resource_1, 6) self.plugin.update_quota_limit(self.context, project_1, resource_2, 9) quota_driver = driver.DbQuotaDriver() quota_driver.make_reservation(self.context, project_1, resources, {resource_1: 1, resource_2: 7}, self.plugin) quota_api.set_quota_usage(self.context, resource_1, project_1, 2) quota_api.set_quota_usage(self.context, resource_2, project_1, 3) detailed_quota = self.plugin.get_detailed_tenant_quotas(self.context, resources, project_1) self.assertEqual(6, detailed_quota[resource_1]['limit']) self.assertEqual(1, detailed_quota[resource_1]['reserved']) self.assertEqual(2, detailed_quota[resource_1]['used']) self.assertEqual(9, detailed_quota[resource_2]['limit']) self.assertEqual(7, detailed_quota[resource_2]['reserved']) self.assertEqual(3, detailed_quota[resource_2]['used'])
def test_get_detailed_project_quotas_multiple_resource(self): resources = self._create_resources() self.plugin.update_quota_limit(self.context, self.project_1, self.resource_1, 6) self.plugin.update_quota_limit(self.context, self.project_1, self.resource_2, 9) self.quota_driver.make_reservation(self.context, self.project_1, resources, { self.resource_1: 1, self.resource_2: 7 }, self.plugin) quota_api.set_quota_usage(self.context, self.resource_1, self.project_1, 2) quota_api.set_quota_usage(self.context, self.resource_2, self.project_1, 3) detailed_quota = self.plugin.get_detailed_project_quotas( self.context, resources, self.project_1) self.assertEqual(6, detailed_quota[self.resource_1]['limit']) self.assertEqual(1, detailed_quota[self.resource_1]['reserved']) self.assertEqual(2, detailed_quota[self.resource_1]['used']) self.assertEqual(9, detailed_quota[self.resource_2]['limit']) self.assertEqual(7, detailed_quota[self.resource_2]['reserved']) self.assertEqual(3, detailed_quota[self.resource_2]['used'])
def test_get_detailed_tenant_quotas_multiple_resource(self): project_1 = 'prj_test_1' resource_1 = 'res_test_1' resource_2 = 'res_test_2' resources = { resource_1: TestTrackedResource(resource_1, test_quota.MehModel), resource_2: TestCountableResource(resource_2, _count_resource) } self.plugin.update_quota_limit(self.context, project_1, resource_1, 6) self.plugin.update_quota_limit(self.context, project_1, resource_2, 9) quota_driver = driver.DbQuotaDriver() quota_driver.make_reservation(self.context, project_1, resources, { resource_1: 1, resource_2: 7 }, self.plugin) quota_api.set_quota_usage(self.context, resource_1, project_1, 2) quota_api.set_quota_usage(self.context, resource_2, project_1, 3) detailed_quota = self.plugin.get_detailed_tenant_quotas( self.context, resources, project_1) self.assertEqual(6, detailed_quota[resource_1]['limit']) self.assertEqual(1, detailed_quota[resource_1]['reserved']) self.assertEqual(2, detailed_quota[resource_1]['used']) self.assertEqual(9, detailed_quota[resource_2]['limit']) self.assertEqual(7, detailed_quota[resource_2]['reserved']) self.assertEqual(3, detailed_quota[resource_2]['used'])
def _test_count(self): res = self._create_resource() quota_api.set_quota_usage(self.context, res.name, self.project_id, in_use=0) self._add_data() return res
def test_count_first_call_with_dirty_false(self): quota_api.set_quota_usage( self.context, self.resource, self.tenant_id, in_use=1) res = self._create_resource() self._add_data() # explicitly set dirty flag to False quota_api.set_all_quota_usage_dirty( self.context, self.resource, dirty=False) # Expect correct count to be returned anyway since the first call to # count() always resyncs with the db self.assertEqual(2, res.count(self.context, None, self.tenant_id))
def test_get_detailed_project_quotas_resource(self): res = {RESOURCE: TestTrackedResource(RESOURCE, test_quota.MehModel)} self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 6) self.quota_driver.make_reservation(self.context, PROJECT, res, {RESOURCE: 1}, self.plugin) quota_api.set_quota_usage(self.context, RESOURCE, PROJECT, 2) detailed_quota = self.plugin.get_detailed_project_quotas( self.context, res, PROJECT) self.assertEqual(6, detailed_quota[RESOURCE]['limit']) self.assertEqual(2, detailed_quota[RESOURCE]['used']) self.assertEqual(1, detailed_quota[RESOURCE]['reserved'])
def _handle_expired_reservations(self, context, tenant_id, resource, expired_amount): LOG.debug( ("Adjusting usage for resource %(resource)s: " "removing %(expired)d reserved items"), {"resource": resource, "expired": expired_amount}, ) # TODO(salv-orlando): It should be possible to do this # operation for all resources with a single query. # Update reservation usage quota_api.set_quota_usage(context, resource, tenant_id, reserved=-expired_amount, delta=True) # Delete expired reservations (we don't want them to accrue # in the database) quota_api.remove_expired_reservations(context, tenant_id=tenant_id)
def test_get_detailed_tenant_quotas_resource(self): res = {RESOURCE: TestTrackedResource(RESOURCE, test_quota.MehModel)} self.plugin.update_quota_limit(self.context, PROJECT, RESOURCE, 6) quota_driver = driver.DbQuotaDriver() quota_driver.make_reservation(self.context, PROJECT, res, {RESOURCE: 1}, self.plugin) quota_api.set_quota_usage(self.context, RESOURCE, PROJECT, 2) detailed_quota = self.plugin.get_detailed_tenant_quotas(self.context, res, PROJECT) self.assertEqual(6, detailed_quota[RESOURCE]['limit']) self.assertEqual(2, detailed_quota[RESOURCE]['used']) self.assertEqual(1, detailed_quota[RESOURCE]['reserved'])
def test_update_quota_usage(self): self._create_quota_usage('goals', 26) # Higuain scores a double usage_info_1 = quota_api.set_quota_usage( self.context, 'goals', self.tenant_id, in_use=28) self._verify_quota_usage(usage_info_1, expected_used=28) usage_info_2 = quota_api.set_quota_usage( self.context, 'goals', self.tenant_id, in_use=24) self._verify_quota_usage(usage_info_2, expected_used=24)
def test_update_quota_usage_with_deltas(self): self._create_quota_usage('goals', 26, 10) # Higuain scores a double usage_info_1 = quota_api.set_quota_usage( self.context, 'goals', self.tenant_id, in_use=2, delta=True) self._verify_quota_usage(usage_info_1, expected_used=28, expected_reserved=10) usage_info_2 = quota_api.set_quota_usage( self.context, 'goals', self.tenant_id, reserved=-2, delta=True) self._verify_quota_usage(usage_info_2, expected_used=28, expected_reserved=8)
def _create_quota_usage(self, resource, used, reserved, tenant_id=None): tenant_id = tenant_id or self.tenant_id return quota_api.set_quota_usage(self.context, resource, tenant_id, in_use=used, reserved=reserved)
def test_update_quota_usage_with_deltas(self): self._create_quota_usage('goals', 26) # Higuain scores a double usage_info_1 = quota_api.set_quota_usage(self.context, 'goals', self.project_id, in_use=2, delta=True) self._verify_quota_usage(usage_info_1, expected_used=28)
def _handle_expired_reservations(self, context, tenant_id, resource, expired_amount): LOG.debug(("Adjusting usage for resource %(resource)s: " "removing %(expired)d reserved items"), {'resource': resource, 'expired': expired_amount}) # TODO(salv-orlando): It should be possible to do this # operation for all resources with a single query. # Update reservation usage quota_api.set_quota_usage( context, resource, tenant_id, reserved=-expired_amount, delta=True) # Delete expired reservations (we don't want them to accrue # in the database) quota_api.remove_expired_reservations( context, tenant_id=tenant_id)
def _set_quota_usage(self, context, tenant_id, in_use): return quota_api.set_quota_usage( context, self.name, tenant_id, in_use=in_use)
def _set_quota_usage(self, context, tenant_id, in_use, reserved): return quota_api.set_quota_usage(context, self.name, tenant_id, in_use=in_use, reserved=reserved)
def _create_quota_usage(self, resource, used, reserved, tenant_id=None): tenant_id = tenant_id or self.tenant_id return quota_api.set_quota_usage( self.context, resource, tenant_id, in_use=used, reserved=reserved)
def _test_init(self, resource_name): quota_db_api.set_quota_usage(self.ctx, resource_name, self._tenant_id)
def _create_quota_usage(self, resource, used, tenant_id=None): tenant_id = tenant_id or self.tenant_id return quota_api.set_quota_usage(context.get_admin_context(), resource, tenant_id, in_use=used)
def _test_init(self, resource_name): quota_db_api.set_quota_usage( self.ctx, resource_name, self._tenant_id)
def _set_quota_usage(self, context, project_id, in_use): return quota_api.set_quota_usage( context, self.name, project_id, in_use=in_use)
def _create_quota_usage(self, resource, used, project_id=None): project_id = project_id or self.project_id return quota_api.set_quota_usage(context.get_admin_context(), resource, project_id, in_use=used)
def _test_count(self): res = self._create_resource() quota_api.set_quota_usage( self.context, res.name, self.tenant_id, in_use=0) self._add_data() return res