Catch all vim exceptions in disk_detach #460
Conversation
for f in ex.faultMessage: | ||
logging.warning(f.message) | ||
return err("Failed to detach " + vmdk_path) | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just catch & handle "vim.Fault.VimFault" exception and pass others to caller? This would eliminate if isinstance(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah (forehead hit), yes ! A brain hiccup I guess. Will fix. Thanks.
Fixes #399 |
1ef4ff5
to
dcdcc1c
Compare
except Exception as e: | ||
logging.exception("Failed to find VM uuid=%s (traceback below), " \ | ||
"retrying...", vm_uuid) | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a guarantee that the second search will always complete without exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no guarantee, but we know that on connection timeout retry fixes it, and on other issues we want to rethrow if we fail in retry
LGTM but the error handling seems built with assumptions. |
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str(ex)
logs traceback and exception info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the bug description - there is an example there
LGTM. |
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will leave the disk attached to the VM. Like I'd mentioned in PR #433 (original set of changes) there is nothing the plugin can do to help this situation except log the error. Does the error notify docker that the unmount has failed and docker must keep track that the volume is still in use? The volume remains in attached state if docker doesn't care to unmount again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure what is your question ?
LGTM |
dcdcc1c
to
490821a
Compare
Updated code slightly to print out backtrace (so we know who calls us) rather that exception details (which have nothing beyond "failure reason), which we print anyways). The log looks like this now:
|
Return error message from exception, and logs a warning with traceback. Also change logging in findVMByUuid to be warning (since we retry after the failure) Fixes #381
Fixes #381
test: manually shutdown Photon OS with OS->Shutdown menu in ESXi embedded UI.
Before fix: exception logged and ESX service exit
After fix: exception logged and ESX Service keeps goings
Error report in the log: