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

Catch all vim exceptions in disk_detach #460

Merged
merged 1 commit into from Jun 15, 2016
Merged

Conversation

msterin
Copy link
Contributor

@msterin msterin commented Jun 14, 2016

Fixes #381

  • Catch all vim exceptions in disk_detach
  • Return error message from exception, and log a warning.
  • Also change logging in findVMByUuid to be warning (since we retry after the failure)

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:

6/14/16 02:53:20 1010878803 [INFO   ] *** detachVMDK: /vmfs/volumes/vsan:572904f8c031435f-06/14/16 18:02:52 1011049660 [WARNING] Failed to detach /vmfs/volumes/vsan:572904f8c031435f-3513e0db551fcc82/dockvols/vol.vmdk (The operation is not allowed in the current state.)
(vim.fault.InvalidState) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = 'The operation is not allowed in the current state.',
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) []
}
06/14/16 18:02:52 1011049660 [INFO   ] executeRequest 'detach' completed with ret={u'Error': u'Failed to detach /vmfs/volumes/vsan:572904f8c031435f-3513e0db551fcc82/dockvols/vol.vmdk (The operation is not allowed in the current state.)'}

for f in ex.faultMessage:
logging.warning(f.message)
return err("Failed to detach " + vmdk_path)
except Exception as ex:
Copy link
Contributor

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(...)

Copy link
Contributor Author

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.

@pdhamdhere
Copy link
Contributor

Fixes #399

except Exception as e:
logging.exception("Failed to find VM uuid=%s (traceback below), " \
"retrying...", vm_uuid)
except Exception as ex:
Copy link
Contributor

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?

Copy link
Contributor Author

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

@kerneltime
Copy link
Contributor

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))
Copy link
Contributor

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?

Copy link
Contributor Author

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

@pdhamdhere
Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor Author

@msterin msterin Jun 14, 2016

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 ?

@andrewjstone
Copy link
Contributor

LGTM

@msterin
Copy link
Contributor Author

msterin commented Jun 14, 2016

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:

06/14/16 20:14:51 1011078223 [INFO   ] *** detachVMDK: /vmfs/volumes/vsan:572904f8c031435f-3513e0db551fcc82/dockvols/vol.vmdk from PhotonRC_1 VM uuid = 564d0062-db25-a480-72e2-0596eaf7fcb4
06/14/16 20:14:51 1011078223 [WARNING] Failed to detach /vmfs/volumes/vsan:572904f8c031435f-3513e0db551fcc82/dockvols/vol.vmdk: The operation is not allowed in the current state.
  File "/usr/lib/vmware/vmdkops/bin/vmdk_ops.py", line 652, in disk_detach
    wait_for_tasks(si, [vm.ReconfigVM_Task(spec=spec)])
  File "/usr/lib/vmware/vmdkops/bin/vmdk_ops.py", line 838, in wait_for_tasks
    raise task.info.error

06/14/16 20:14:51 1011078223 [INFO   ] executeRequest 'detach' completed with ret={u'Error': u'Failed to detach /vmfs/volumes/vsan:572904f8c031435f-3513e0db551fcc82/dockvols/vol.vmdk: The operation is not allowed in the current state.'}

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
@msterin msterin merged commit e91738c into master Jun 15, 2016
@msterin msterin deleted the invalid.state.msterin branch June 15, 2016 02:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detach failure during VM shutdown brings ESX service down
6 participants