From 3228cac0d1bc42681e82e90dc92b691af09f0fad Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Mon, 20 May 2013 23:03:48 +0000 Subject: Remove ImageTooLarge exception InstanceTypeDiskTooSmall and ImageTooLarge are really two sides of the same coin; an image is larger than the root_gb of the instance_type. Rather than have two exceptions for this, this patch consolidates down to just InstanceTypeDiskTooSmall. Change-Id: I401205072c111a960beb2932c6c1889141ae03c3 --- nova/api/openstack/compute/servers.py | 2 -- nova/compute/api.py | 2 +- nova/exception.py | 4 ---- nova/tests/api/openstack/compute/test_servers.py | 2 +- nova/tests/compute/test_compute.py | 6 +++--- nova/tests/virt/libvirt/test_imagebackend.py | 4 ++-- nova/tests/virt/xenapi/test_vm_utils.py | 9 +++++---- nova/virt/libvirt/imagebackend.py | 2 +- nova/virt/xenapi/vm_utils.py | 2 +- 9 files changed, 14 insertions(+), 19 deletions(-) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 512f8cb7a..7bb7817d6 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -922,7 +922,6 @@ class Controller(wsgi.Controller): msg = "UnicodeError: %s" % unicode(error) raise exc.HTTPBadRequest(explanation=msg) except (exception.ImageNotActive, - exception.ImageTooLarge, exception.InstanceTypeDiskTooSmall, exception.InstanceTypeMemoryTooSmall, exception.InstanceTypeNotFound, @@ -1283,7 +1282,6 @@ class Controller(wsgi.Controller): msg = _("Cannot find image for rebuild") raise exc.HTTPBadRequest(explanation=msg) except (exception.ImageNotActive, - exception.ImageTooLarge, exception.InstanceTypeDiskTooSmall, exception.InstanceTypeMemoryTooSmall, exception.InvalidMetadata) as error: diff --git a/nova/compute/api.py b/nova/compute/api.py index b5a69ea37..eccf13da6 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -513,7 +513,7 @@ class API(base.Base): root_gb = instance_type['root_gb'] if root_gb: if int(image.get('size') or 0) > root_gb * (1024 ** 3): - raise exception.ImageTooLarge() + raise exception.InstanceTypeDiskTooSmall() if int(image.get('min_disk') or 0) > root_gb: raise exception.InstanceTypeDiskTooSmall() diff --git a/nova/exception.py b/nova/exception.py index dfa31941a..6e5e9ce90 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -953,10 +953,6 @@ class ResizeError(NovaException): message = _("Resize error: %(reason)s") -class ImageTooLarge(NovaException): - message = _("Image is larger than instance type allows") - - class InstanceTypeMemoryTooSmall(NovaException): message = _("Instance type's memory is too small for requested image.") diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 11eeff143..7567a8773 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1963,7 +1963,7 @@ class ServersControllerCreateTest(test.TestCase): req.headers["content-type"] = "application/json" with testtools.ExpectedException( webob.exc.HTTPBadRequest, - 'Image is larger than instance type allows'): + "Instance type's disk is too small for requested image."): self.controller.create(req, body) def test_create_instance_invalid_negative_min(self): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 285261e18..f5c23ccee 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -4898,7 +4898,7 @@ class ComputeAPITestCase(BaseTestCase): self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) - self.assertRaises(exception.ImageTooLarge, + self.assertRaises(exception.InstanceTypeDiskTooSmall, self.compute_api.create, self.context, inst_type, self.fake_image['id']) @@ -5675,7 +5675,7 @@ class ComputeAPITestCase(BaseTestCase): self.fake_image['size'] = '1073741825' self.stubs.Set(fake_image._FakeImageService, 'show', self.fake_show) - self.assertRaises(exception.ImageTooLarge, + self.assertRaises(exception.InstanceTypeDiskTooSmall, self.compute_api.rebuild, self.context, instance, self.fake_image['id'], 'new_password') @@ -9057,7 +9057,7 @@ class CheckRequestedImageTestCase(test.TestCase): def test_image_too_large(self): image = dict(id='123', status='active', size='1073741825') - self.assertRaises(exception.ImageTooLarge, + self.assertRaises(exception.InstanceTypeDiskTooSmall, self.compute_api._check_requested_image, self.context, image['id'], image, self.instance_type) diff --git a/nova/tests/virt/libvirt/test_imagebackend.py b/nova/tests/virt/libvirt/test_imagebackend.py index 6548ab76c..50aacba2f 100644 --- a/nova/tests/virt/libvirt/test_imagebackend.py +++ b/nova/tests/virt/libvirt/test_imagebackend.py @@ -284,8 +284,8 @@ class Qcow2TestCase(_ImageTestCase, test.TestCase): self.mox.ReplayAll() image = self.image_class(self.INSTANCE, self.NAME) - self.assertRaises(exception.ImageTooLarge, image.create_image, fn, - self.TEMPLATE_PATH, 1) + self.assertRaises(exception.InstanceTypeDiskTooSmall, + image.create_image, fn, self.TEMPLATE_PATH, 1) self.mox.VerifyAll() diff --git a/nova/tests/virt/xenapi/test_vm_utils.py b/nova/tests/virt/xenapi/test_vm_utils.py index 2180f75f9..57f031a4c 100644 --- a/nova/tests/virt/xenapi/test_vm_utils.py +++ b/nova/tests/virt/xenapi/test_vm_utils.py @@ -253,7 +253,7 @@ class FetchVhdImageTestCase(test.TestCase): self.mox.VerifyAll() - def test_fetch_vhd_image_cleans_up_vid_on_fail(self): + def test_fetch_vhd_image_cleans_up_vdi_on_fail(self): self._apply_stubouts() self._common_params_setup(True) self.mox.StubOutWithMock(self.session, 'call_xenapi') @@ -267,15 +267,16 @@ class FetchVhdImageTestCase(test.TestCase): vm_utils.safe_find_sr(self.session).AndReturn("sr") vm_utils._scan_sr(self.session, "sr") vm_utils._check_vdi_size(self.context, self.session, self.instance, - "vdi").AndRaise(exception.ImageTooLarge) + "vdi").AndRaise(exception.InstanceTypeDiskTooSmall) self.session.call_xenapi("VDI.get_by_uuid", "vdi").AndReturn("ref") vm_utils.destroy_vdi(self.session, "ref") self.mox.ReplayAll() - self.assertRaises(exception.ImageTooLarge, vm_utils._fetch_vhd_image, - self.context, self.session, self.instance, self.image_id) + self.assertRaises(exception.InstanceTypeDiskTooSmall, + vm_utils._fetch_vhd_image, self.context, self.session, + self.instance, self.image_id) self.mox.VerifyAll() diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py index 84686a82a..575ae262e 100755 --- a/nova/virt/libvirt/imagebackend.py +++ b/nova/virt/libvirt/imagebackend.py @@ -258,7 +258,7 @@ class Qcow2(Image): if size and size < disk.get_disk_size(base): LOG.error('%s virtual size larger than flavor root disk size %s' % (base, size)) - raise exception.ImageTooLarge() + raise exception.InstanceTypeDiskTooSmall() if not os.path.exists(self.path): with utils.remove_path_on_error(self.path): copy_qcow2_image(base, self.path, size) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 3f2c6835f..69a944b9b 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -1207,7 +1207,7 @@ def _check_vdi_size(context, session, instance, vdi_uuid): LOG.info(_("Image size %(size_bytes)d exceeded instance_type " "allowed size %(allowed_size_bytes)d"), locals(), instance=instance) - raise exception.ImageTooLarge() + raise exception.InstanceTypeDiskTooSmall() def _fetch_disk_image(context, session, instance, name_label, image_id, -- cgit