VMware: Fix deletion of an instance with no files

When a managed object doesn't contain a property, RetrievePropertiesEx
doesn't return None; it doesn't return the property at all. We were
testing for this incorrectly and not handling it in the code.

Change-Id: I77a0ba4eb5a6cc6075db9c67294f30abaa0e474d
This commit is contained in:
Matthew Booth
2014-07-02 11:36:23 +01:00
parent bacac43417
commit 2e7a0181f8
3 changed files with 11 additions and 5 deletions

View File

@@ -242,6 +242,10 @@ class ManagedObject(object):
"""
return self.__getattr__(attr)
def delete(self, attr):
"""Deletes an attribute."""
self.propSet = filter(lambda elem: elem.name != attr, self.propSet)
def __setattr__(self, attr, val):
# TODO(hartsocks): this is adds unnecessary complexity to the class
for prop in self.propSet:

View File

@@ -1444,9 +1444,9 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self._check_vm_info(info, power_state.RUNNING)
instances = self.conn.list_instances()
self.assertEqual(len(instances), 1)
# Overwrite the vmPathName
# Delete the vmPathName
vm = self._get_vm_record()
vm.set("config.files.vmPathName", None)
vm.delete('config.files.vmPathName')
self.conn.destroy(self.context, self.instance, self.network_info)
instances = self.conn.list_instances()
self.assertEqual(len(instances), 0)

View File

@@ -771,10 +771,12 @@ class VMwareVMOps(object):
query = vm_util.get_values_from_object_properties(
self._session, props)
pwr_state = query['runtime.powerState']
vm_config_pathname = query['config.files.vmPathName']
vm_config_pathname = query.get('config.files.vmPathName')
vm_ds_path = None
if vm_config_pathname:
vm_ds_path = ds_util.DatastorePath.parse(vm_config_pathname)
if vm_config_pathname is not None:
vm_ds_path = ds_util.DatastorePath.parse(
vm_config_pathname)
# Power off the VM if it is in PoweredOn state.
if pwr_state == "poweredOn":