def limit_check(self, context, tenant_id, **values): quotas = self.get_quotas(context, tenant_id) for resource, value in values.items(): if resource in quotas: if value >= quotas[resource]: raise exceptions.OverQuota() else: raise exceptions.QuotaResourceUnknown()
def limit_check(self, context, tenant_id, **values): quotas = self.get_quotas(context, tenant_id) for resource, value in values.items(): if resource in quotas: # Setting the resource quota to a negative value will make # the resource unlimited if quotas[resource] >= 0 and value >= quotas[resource]: raise exceptions.OverQuota() else: raise exceptions.QuotaResourceUnknown("%s is not a valid quota" " resource", resource)
def test_exceed_size_quota(self, _): context = mock.Mock() export = dict(location=None, id=4) size = 9999999999 self.tm.quota.limit_check.side_effect = exceptions.OverQuota() out = self.tm._determine_export_method(context, export, size) self.tm.quota.limit_check.side_effect = None self.assertDictEqual( { 'status': 'ERROR', 'id': 4, 'location': None, 'message': 'Zone is too large to export' }, out )
def _determine_export_method(self, context, export, size): synchronous = CONF['service:zone_manager'].export_synchronous # NOTE(timsim): # The logic here with swift will work like this: # cfg.CONF.export_swift_enabled: # An export will land in their swift container, even if it's # small, but the link that comes back will be the synchronous # link (unless export_syncronous is False, in which case it # will behave like the next option) # cfg.CONF.export_swift_preffered: # The link that the user gets back will always be the swift # container, and status of the export resource will depend # on the Swift process. # If the export is too large for synchronous, or synchronous is not # enabled and swift is not enabled, it will fall through to ERROR # swift = False if synchronous: try: self.quota.limit_check(context, context.tenant, api_export_size=size) except exceptions.OverQuota(): LOG.debug('Zone Export too large to perform synchronously') export['status'] = 'ERROR' export['message'] = 'Zone is too large to export' return export export['location'] = \ "designate://v2/zones/tasks/exports/%(eid)s/export" % \ {'eid': export['id']} export['status'] = 'COMPLETE' else: LOG.debug('No method found to export zone') export['status'] = 'ERROR' export['message'] = 'No suitable method for export' return export