Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
VMware: fix disk extend bug when no space on datastore
In the event that thete is no space on the datastore then ensure
that the disk extension is cleaned up accordingly.

A number of files would be left behind on the datastore.

Change-Id: Ica9daf9151e4fb1874fa8b1d7247080860ef4ae2
Related-Bug: #1255355
  • Loading branch information
gkotton committed Dec 5, 2013
1 parent c7d5047 commit 787d36b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
31 changes: 31 additions & 0 deletions nova/tests/virt/vmwareapi/test_vmwareapi.py
Expand Up @@ -322,6 +322,37 @@ def test_spawn_disk_extend_sparse(self):
'node': self.instance_node})
self._check_vm_info(info, power_state.RUNNING)

def test_spawn_disk_extend_insufficient_disk_space(self):
self.flags(use_linked_clone=True, group='vmware')
self.wait_task = self.conn._session._wait_for_task
self.call_method = self.conn._session._call_method
self.task_ref = None
cached_image = '[fake-ds] vmware_base/fake_image_uuid.80.vmdk'
tmp_file = '[fake-ds] vmware_base/fake_image_uuid.80-flat.vmdk'

def fake_wait_for_task(instance_uuid, task_ref):
if task_ref == self.task_ref:
self.task_ref = None
self.assertTrue(vmwareapi_fake.get_file(cached_image))
self.assertTrue(vmwareapi_fake.get_file(tmp_file))
raise exception.NovaException('No space!')
return self.wait_task(instance_uuid, task_ref)

def fake_call_method(module, method, *args, **kwargs):
task_ref = self.call_method(module, method, *args, **kwargs)
if method == "ExtendVirtualDisk_Task":
self.task_ref = task_ref
return task_ref

self.stubs.Set(self.conn._session, "_call_method", fake_call_method)
self.stubs.Set(self.conn._session, "_wait_for_task",
fake_wait_for_task)

self.assertRaises(exception.NovaException,
self._create_vm)
self.assertFalse(vmwareapi_fake.get_file(cached_image))
self.assertFalse(vmwareapi_fake.get_file(tmp_file))

def test_spawn_disk_invalid_disk_size(self):
self.mox.StubOutWithMock(vmware_images, 'get_vmdk_size_and_properties')
result = [82 * unit.Gi,
Expand Down
14 changes: 12 additions & 2 deletions nova/virt/vmwareapi/vmops.py
Expand Up @@ -141,8 +141,18 @@ def _extend_virtual_disk(self, instance, requested_size, name, dc_ref):
datacenter=dc_ref,
newCapacityKb=requested_size,
eagerZero=False)
self._session._wait_for_task(instance['uuid'],
vmdk_extend_task)
try:
self._session._wait_for_task(instance['uuid'],
vmdk_extend_task)
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.error(_('Extending virtual disk failed with error: %s'),
e, instance=instance)
# Clean up files created during the extend operation
files = [name.replace(".vmdk", "-flat.vmdk"), name]
for file in files:
self._delete_datastore_file(instance, file, dc_ref)

LOG.debug(_("Extended root virtual disk"))

def _delete_datastore_file(self, instance, datastore_path, dc_ref):
Expand Down

0 comments on commit 787d36b

Please sign in to comment.