VMware: prevent image snapshot if no root disk defined

If there is no root disk defined then the snapshot should
throw an exception.

Change-Id: I0549b8ca9ba41b734277600cb66a74b27ca72d88
Related-bug: #1297605
This commit is contained in:
Gary Kotton
2014-03-26 02:38:22 -07:00
parent 89fd077042
commit e0638e29cd
3 changed files with 14 additions and 0 deletions

View File

@@ -1012,6 +1012,12 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self._create_vm()
self._test_snapshot()
def test_snapshot_no_root_disk(self):
self._iso_disk_type_created(instance_type='m1.micro')
self.assertRaises(error_util.NoRootDiskDefined, self.conn.snapshot,
self.context, self.instance, "Test-Snapshot",
lambda *args, **kwargs: None)
def test_snapshot_non_existent(self):
self._create_instance()
self.assertRaises(exception.InstanceNotFound, self.conn.snapshot,

View File

@@ -149,6 +149,10 @@ class MissingParameter(VMwareDriverException):
msg_fmt = _("Missing parameter : %(param)s")
class NoRootDiskDefined(VMwareDriverException):
msg_fmt = _("No root disk defined.")
class AlreadyExistsException(VMwareDriverException):
msg_fmt = _("Resource already exists.")
code = 409

View File

@@ -760,6 +760,10 @@ class VMwareVMOps(object):
(vmdk_file_path_before_snapshot, adapter_type,
disk_type) = vm_util.get_vmdk_path_and_adapter_type(
hw_devices, uuid=instance['uuid'])
if not vmdk_file_path_before_snapshot:
LOG.debug("No root disk defined. Unable to snapshot.")
raise error_util.NoRootDiskDefined()
datastore_name = ds_util.split_datastore_path(
vmdk_file_path_before_snapshot)[0]
os_type = self._session._call_method(vim_util,