Refactor of QuotaError
moved QuotaError from quota.py to exception.py Change-Id: Ic03301492a2df323074d73e8481e0e3aee89f74c
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
from webob import exc
|
||||
|
||||
from nova import db
|
||||
from nova import quota
|
||||
from nova import exception
|
||||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
|
||||
@@ -53,7 +53,7 @@ class FlavorExtraSpecsController(object):
|
||||
db.instance_type_extra_specs_update_or_create(context,
|
||||
flavor_id,
|
||||
specs)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
return body
|
||||
|
||||
@@ -70,7 +70,7 @@ class FlavorExtraSpecsController(object):
|
||||
db.instance_type_extra_specs_update_or_create(context,
|
||||
flavor_id,
|
||||
body)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
|
||||
return body
|
||||
|
||||
@@ -21,7 +21,6 @@ from webob import exc
|
||||
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import quota
|
||||
from nova.volume import volume_types
|
||||
from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
@@ -55,7 +54,7 @@ class VolumeTypesController(object):
|
||||
try:
|
||||
volume_types.create(context, name, specs)
|
||||
vol_type = volume_types.get_volume_type_by_name(context, name)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
@@ -118,7 +117,7 @@ class VolumeTypeExtraSpecsController(object):
|
||||
db.volume_type_extra_specs_update_or_create(context,
|
||||
vol_type_id,
|
||||
specs)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
return body
|
||||
|
||||
@@ -135,7 +134,7 @@ class VolumeTypeExtraSpecsController(object):
|
||||
db.volume_type_extra_specs_update_or_create(context,
|
||||
vol_type_id,
|
||||
body)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
|
||||
return body
|
||||
|
||||
@@ -21,7 +21,6 @@ from nova import compute
|
||||
from nova.api.openstack import common
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import exception
|
||||
from nova import quota
|
||||
|
||||
|
||||
class Controller(object):
|
||||
@@ -120,7 +119,7 @@ class Controller(object):
|
||||
msg = _("Malformed request body")
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
|
||||
def show(self, req, server_id, id):
|
||||
|
||||
@@ -40,7 +40,6 @@ from nova import exception
|
||||
from nova import flags
|
||||
from nova import image
|
||||
from nova import log as logging
|
||||
from nova import quota
|
||||
from nova.rpc import common as rpc_common
|
||||
from nova.scheduler import api as scheduler_api
|
||||
from nova import utils
|
||||
@@ -412,7 +411,7 @@ class Controller(object):
|
||||
availability_zone=availability_zone,
|
||||
config_drive=config_drive,
|
||||
block_device_mapping=block_device_mapping)
|
||||
except quota.QuotaError as error:
|
||||
except exception.QuotaError as error:
|
||||
self._handle_quota_error(error)
|
||||
except exception.InstanceTypeMemoryTooSmall as error:
|
||||
raise exc.HTTPBadRequest(explanation=unicode(error))
|
||||
|
||||
+7
-6
@@ -139,15 +139,16 @@ class API(base.Base):
|
||||
return
|
||||
limit = quota.allowed_injected_files(context, len(injected_files))
|
||||
if len(injected_files) > limit:
|
||||
raise quota.QuotaError(code="OnsetFileLimitExceeded")
|
||||
raise exception.QuotaError(code="OnsetFileLimitExceeded")
|
||||
path_limit = quota.allowed_injected_file_path_bytes(context)
|
||||
for path, content in injected_files:
|
||||
if len(path) > path_limit:
|
||||
raise quota.QuotaError(code="OnsetFilePathLimitExceeded")
|
||||
raise exception.QuotaError(code="OnsetFilePathLimitExceeded")
|
||||
content_limit = quota.allowed_injected_file_content_bytes(
|
||||
context, len(content))
|
||||
if len(content) > content_limit:
|
||||
raise quota.QuotaError(code="OnsetFileContentLimitExceeded")
|
||||
raise exception.QuotaError(
|
||||
code="OnsetFileContentLimitExceeded")
|
||||
|
||||
def _check_metadata_properties_quota(self, context, metadata=None):
|
||||
"""Enforce quota limits on metadata properties."""
|
||||
@@ -160,7 +161,7 @@ class API(base.Base):
|
||||
msg = _("Quota exceeded for %(pid)s, tried to set "
|
||||
"%(num_metadata)s metadata properties") % locals()
|
||||
LOG.warn(msg)
|
||||
raise quota.QuotaError(msg, "MetadataLimitExceeded")
|
||||
raise exception.QuotaError(msg, "MetadataLimitExceeded")
|
||||
|
||||
# Because metadata is stored in the DB, we hard-code the size limits
|
||||
# In future, we may support more variable length strings, so we act
|
||||
@@ -171,7 +172,7 @@ class API(base.Base):
|
||||
msg = _("Quota exceeded for %(pid)s, metadata property "
|
||||
"key or value too long") % locals()
|
||||
LOG.warn(msg)
|
||||
raise quota.QuotaError(msg, "MetadataLimitExceeded")
|
||||
raise exception.QuotaError(msg, "MetadataLimitExceeded")
|
||||
|
||||
def _check_requested_networks(self, context, requested_networks):
|
||||
""" Check if the networks requested belongs to the project
|
||||
@@ -227,7 +228,7 @@ class API(base.Base):
|
||||
else:
|
||||
message = _("Instance quota exceeded. You can only run %s "
|
||||
"more instances of this type.") % num_instances
|
||||
raise quota.QuotaError(message, "InstanceLimitExceeded")
|
||||
raise exception.QuotaError(message, "InstanceLimitExceeded")
|
||||
|
||||
self._check_metadata_properties_quota(context, metadata)
|
||||
self._check_injected_file_quota(context, injected_files)
|
||||
|
||||
@@ -871,3 +871,8 @@ class NoValidHost(NovaException):
|
||||
|
||||
class WillNotSchedule(NovaException):
|
||||
message = _("Host %(host)s is not up or doesn't exist.")
|
||||
|
||||
|
||||
class QuotaError(ApiError):
|
||||
"""Quota Exceeded."""
|
||||
pass
|
||||
|
||||
@@ -293,7 +293,7 @@ class FloatingIP(object):
|
||||
LOG.warn(_('Quota exceeded for %s, tried to allocate '
|
||||
'address'),
|
||||
context.project_id)
|
||||
raise quota.QuotaError(_('Address quota exceeded. You cannot '
|
||||
raise exception.QuotaError(_('Address quota exceeded. You cannot '
|
||||
'allocate any more addresses'))
|
||||
# TODO(vish): add floating ips through manage command
|
||||
return self.db.floating_ip_allocate_address(context,
|
||||
|
||||
@@ -162,8 +162,3 @@ def allowed_injected_file_content_bytes(context, requested_bytes):
|
||||
def allowed_injected_file_path_bytes(context):
|
||||
"""Return the number of bytes allowed in an injected file path."""
|
||||
return FLAGS.quota_max_injected_file_path_bytes
|
||||
|
||||
|
||||
class QuotaError(exception.ApiError):
|
||||
"""Quota Exceeded."""
|
||||
pass
|
||||
|
||||
@@ -20,7 +20,6 @@ from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import log as logging
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
from nova.network import manager as network_manager
|
||||
@@ -463,7 +462,7 @@ class VlanNetworkTestCase(test.TestCase):
|
||||
|
||||
# this time should raise
|
||||
self.stubs.Set(self.network.db, 'floating_ip_count_by_project', fake2)
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
self.network.allocate_floating_ip,
|
||||
ctxt,
|
||||
ctxt.project_id)
|
||||
|
||||
@@ -21,6 +21,7 @@ from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import quota
|
||||
from nova import exception
|
||||
from nova import rpc
|
||||
from nova import test
|
||||
from nova import volume
|
||||
@@ -219,7 +220,7 @@ class QuotaTestCase(test.TestCase):
|
||||
instance_ids.append(instance_id)
|
||||
inst_type = instance_types.get_instance_type_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
self.assertRaises(quota.QuotaError, compute.API().create,
|
||||
self.assertRaises(exception.QuotaError, compute.API().create,
|
||||
self.context,
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
@@ -234,7 +235,7 @@ class QuotaTestCase(test.TestCase):
|
||||
instance_ids.append(instance_id)
|
||||
inst_type = instance_types.get_instance_type_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
self.assertRaises(quota.QuotaError, compute.API().create,
|
||||
self.assertRaises(exception.QuotaError, compute.API().create,
|
||||
self.context,
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
@@ -248,7 +249,7 @@ class QuotaTestCase(test.TestCase):
|
||||
for i in range(FLAGS.quota_volumes):
|
||||
volume_id = self._create_volume()
|
||||
volume_ids.append(volume_id)
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
volume.API().create,
|
||||
self.context,
|
||||
size=10,
|
||||
@@ -262,7 +263,7 @@ class QuotaTestCase(test.TestCase):
|
||||
volume_ids = []
|
||||
volume_id = self._create_volume(size=20)
|
||||
volume_ids.append(volume_id)
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
volume.API().create,
|
||||
self.context,
|
||||
size=10,
|
||||
@@ -277,7 +278,7 @@ class QuotaTestCase(test.TestCase):
|
||||
db.floating_ip_create(context.get_admin_context(),
|
||||
{'address': address,
|
||||
'project_id': self.project_id})
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
self.network.allocate_floating_ip,
|
||||
self.context,
|
||||
self.project_id)
|
||||
@@ -289,7 +290,7 @@ class QuotaTestCase(test.TestCase):
|
||||
metadata['key%s' % i] = 'value%s' % i
|
||||
inst_type = instance_types.get_instance_type_by_name('m1.small')
|
||||
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
|
||||
self.assertRaises(quota.QuotaError, compute.API().create,
|
||||
self.assertRaises(exception.QuotaError, compute.API().create,
|
||||
self.context,
|
||||
min_count=1,
|
||||
max_count=1,
|
||||
@@ -367,7 +368,7 @@ class QuotaTestCase(test.TestCase):
|
||||
files = []
|
||||
for i in xrange(FLAGS.quota_max_injected_files + 1):
|
||||
files.append(('/my/path%d' % i, 'my\ncontent%d\n' % i))
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
self._create_with_injected_files, files)
|
||||
|
||||
def test_max_injected_file_content_bytes(self):
|
||||
@@ -380,7 +381,7 @@ class QuotaTestCase(test.TestCase):
|
||||
max = FLAGS.quota_max_injected_file_content_bytes
|
||||
content = ''.join(['a' for i in xrange(max + 1)])
|
||||
files = [('/test/path', content)]
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
self._create_with_injected_files, files)
|
||||
|
||||
def test_allowed_injected_file_path_bytes(self):
|
||||
@@ -398,5 +399,5 @@ class QuotaTestCase(test.TestCase):
|
||||
max = FLAGS.quota_max_injected_file_path_bytes
|
||||
path = ''.join(['a' for i in xrange(max + 1)])
|
||||
files = [(path, 'config = quotatest')]
|
||||
self.assertRaises(quota.QuotaError,
|
||||
self.assertRaises(exception.QuotaError,
|
||||
self._create_with_injected_files, files)
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ class API(base.Base):
|
||||
pid = context.project_id
|
||||
LOG.warn(_("Quota exceeded for %(pid)s, tried to create"
|
||||
" %(size)sG volume") % locals())
|
||||
raise quota.QuotaError(_("Volume quota exceeded. You cannot "
|
||||
raise exception.QuotaError(_("Volume quota exceeded. You cannot "
|
||||
"create a volume of size %sG") % size)
|
||||
|
||||
if availability_zone is None:
|
||||
|
||||
Reference in New Issue
Block a user