Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Commit

Permalink
Catch all vim exceptions in disk_detach
Browse files Browse the repository at this point in the history
Return error message from exception, and log a warning.
Also change logging in findVMByUuid to be warning (since we retry after the failure)

Fixes #381
  • Loading branch information
Mark Sterin committed Jun 14, 2016
1 parent ec76d4d commit dcdcc1c
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions esx_service/vmdk_ops.py
Expand Up @@ -307,13 +307,14 @@ def listVMDK(path):

# Return VM managed object, reconnect if needed. Throws if fails twice.
def findVmByUuid(vm_uuid):
vm = None
try:
vm = si.content.searchIndex.FindByUuid(None, vm_uuid, True, False)
if vm:
return vm
except Exception as e:
logging.exception("Failed to find VM uuid=%s (traceback below), " \
"retrying...", vm_uuid)
except Exception as ex:
logging.warning("Failed to find VM by uuid=%s, retrying...\n%s",
vm_uuid, str(ex))
if vm:
return vm
#
# Retry. It can throw if connect/search fails. But search can't return None
# since we get UUID from VMM so VM must exist
Expand Down Expand Up @@ -648,10 +649,10 @@ def disk_detach(vmdk_path, vm):

try:
wait_for_tasks(si, [vm.ReconfigVM_Task(spec=spec)])
except vim.fault.GenericVmConfigFault as ex:
for f in ex.faultMessage:
logging.warning(f.message)
return err("Failed to detach " + vmdk_path)
except vim.Fault.VimFault as ex:
msg = "Failed to detach %s (%s)" % (vmdk_path, ex.msg)
logging.warning(msg + "\n" + str(ex))
return err(msg)

setStatusDetached(vmdk_path)
logging.info("Disk detached %s", vmdk_path)
Expand Down

0 comments on commit dcdcc1c

Please sign in to comment.