summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Gordon <jogo@cloudscaling.com>2011-11-10 16:00:08 -0800
committerJoe Gordon <jogo@cloudscaling.com>2011-11-10 16:11:11 -0800
commitfa846dd3430786fe7bc4ed951bb2105f49e50f69 (patch)
treec9309e59c87e3dc38138d239a5b04f0ed24cd017
parent59dfaf9e02ff0064a6844c9c986737267317776f (diff)
downloadnova-fa846dd3430786fe7bc4ed951bb2105f49e50f69.tar.gz
nova-fa846dd3430786fe7bc4ed951bb2105f49e50f69.tar.xz
nova-fa846dd3430786fe7bc4ed951bb2105f49e50f69.zip
Refactor of QuotaError
moved QuotaError from quota.py to exception.py Change-Id: Ic03301492a2df323074d73e8481e0e3aee89f74c
-rw-r--r--nova/api/openstack/contrib/flavorextraspecs.py6
-rw-r--r--nova/api/openstack/contrib/volumetypes.py7
-rw-r--r--nova/api/openstack/server_metadata.py3
-rw-r--r--nova/api/openstack/servers.py3
-rw-r--r--nova/compute/api.py13
-rw-r--r--nova/exception.py5
-rw-r--r--nova/network/manager.py2
-rw-r--r--nova/quota.py5
-rw-r--r--nova/tests/test_network.py3
-rw-r--r--nova/tests/test_quota.py19
-rw-r--r--nova/volume/api.py2
11 files changed, 33 insertions, 35 deletions
diff --git a/nova/api/openstack/contrib/flavorextraspecs.py b/nova/api/openstack/contrib/flavorextraspecs.py
index 8a756f04a..d71e9cf8b 100644
--- a/nova/api/openstack/contrib/flavorextraspecs.py
+++ b/nova/api/openstack/contrib/flavorextraspecs.py
@@ -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
diff --git a/nova/api/openstack/contrib/volumetypes.py b/nova/api/openstack/contrib/volumetypes.py
index d63104a29..64a9e0f02 100644
--- a/nova/api/openstack/contrib/volumetypes.py
+++ b/nova/api/openstack/contrib/volumetypes.py
@@ -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
diff --git a/nova/api/openstack/server_metadata.py b/nova/api/openstack/server_metadata.py
index d764075b7..2d156efbb 100644
--- a/nova/api/openstack/server_metadata.py
+++ b/nova/api/openstack/server_metadata.py
@@ -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):
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index ba9dd4ec3..539fd8778 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -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))
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 820a7b9b6..2b0db25f4 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -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)
diff --git a/nova/exception.py b/nova/exception.py
index 129dc775f..d749d89a0 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -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
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 2c5d0b5cb..96d6dee00 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -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,
diff --git a/nova/quota.py b/nova/quota.py
index 771477747..e9ec4142f 100644
--- a/nova/quota.py
+++ b/nova/quota.py
@@ -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
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 759650839..3b043e793 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -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)
diff --git a/nova/tests/test_quota.py b/nova/tests/test_quota.py
index 6b39adab2..449f37572 100644
--- a/nova/tests/test_quota.py
+++ b/nova/tests/test_quota.py
@@ -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)
diff --git a/nova/volume/api.py b/nova/volume/api.py
index 34103a1f3..b4d5ac48d 100644
--- a/nova/volume/api.py
+++ b/nova/volume/api.py
@@ -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: