From 12ed134f9e78b378b90795ff7ad7fc9946f3b8fb Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Tue, 20 Nov 2012 13:25:36 -0500 Subject: [PATCH] Xenapi: Don't resize down if not auto_disk_config It is not safe to resize down an instance if the filesystem has not been resized first, but with auto_disk_config == False there's no guarantee that it has happened. And not resizing down the disk space with the instance allows for users to have more space on their instance than the type should allow. Fixes bug 1081225 Change-Id: I980c0699dfc272155e274a96d6e08e131c1372d9 --- nova/exception.py | 4 ++++ nova/tests/test_xenapi.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/nova/exception.py b/nova/exception.py index 54b3a17cc..68bc294a3 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -865,6 +865,10 @@ class CannotResizeToSameFlavor(NovaException): message = _("When resizing, instances must change flavor!") +class ResizeError(NovaException): + message = _("Resize error: %(reason)s") + + class ImageTooLarge(NovaException): message = _("Image is larger than instance type allows") diff --git a/nova/tests/test_xenapi.py b/nova/tests/test_xenapi.py index 5253d6292..cf970e486 100644 --- a/nova/tests/test_xenapi.py +++ b/nova/tests/test_xenapi.py @@ -1254,6 +1254,20 @@ class XenAPIMigrateInstance(stubs.XenAPITestBase): dict(base_copy='hurr', cow='durr'), network_info, image_meta, resize_instance=False) + def test_migrate_no_auto_disk_config_no_resize_down(self): + """Resize down should fail when auto_disk_config not set""" + instance_values = self.instance_values + instance_values['root_gb'] = 40 + instance_values['auto_disk_config'] = False + instance = db.instance_create(self.context, instance_values) + xenapi_fake.create_vm(instance.name, 'Running') + instance_type = db.instance_type_get_by_name(self.context, 'm1.small') + conn = xenapi_conn.XenAPIDriver(fake.FakeVirtAPI(), False) + self.assertRaises(exception.ResizeError, + conn.migrate_disk_and_power_off, + self.context, instance, + '127.0.0.1', instance_type, None) + class XenAPIImageTypeTestCase(test.TestCase): """Test ImageType class."""