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

Updates in-use volume removal error message #1273

Merged
merged 3 commits into from
May 18, 2017

Conversation

venilnoronha
Copy link
Contributor

@venilnoronha venilnoronha commented May 17, 2017

Description

This PR updates the error message that's printed on removal of in-use volumes. Changes to the error message are as follows. Fixes #1208.

  1. Replaced VMDK path with Volume name.
  2. Added VM name.
  3. Removed VM uuid.

Signature of the getStatusAttached(..) function was modified to return a 4th value i.e. vm_name, which is needed for building the error message in removeVMDK(..).

Test

docker volume rm v2 now displays:

Error response from daemon: unable to remove volume: remove v2: VolumeDriver.Remove: Failed to remove volume v2, in use by VM = ubuntu-VM1.2.

ESX Plugin log at /var/log/vmware/vmdk_ops.log displays:

05/17/17 21:39:41 1835942 [ubuntu-VM0.2-sharedVmfs-0._DEFAULT.v2] [INFO   ] *** removeVMDK: /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111/v2.vmdk
05/17/17 21:39:41 1835942 [ubuntu-VM0.2-sharedVmfs-0._DEFAULT.v2] [WARNING] Disk /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111/v2.vmdk already attached to VM=ubuntu-VM1.2
05/17/17 21:39:41 1835942 [ubuntu-VM0.2-sharedVmfs-0._DEFAULT.v2] [INFO   ] *** removeVMDK: /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111/v2.vmdk is in use, volume = v2 VM = ubuntu-VM1.2 VM-uuid = 564ddf99-d58f-db6e-bf3e-d4afd3377873 ({'Error': 'Disk /vmfs/volumes/sharedVmfs-0/dockvols/11111111-1111-1111-1111-111111111111/v2.vmdk already attached to VM=ubuntu-VM1.2'})
05/17/17 21:39:41 1835942 [ubuntu-VM0.2-sharedVmfs-0._DEFAULT.v2] [INFO   ] executeRequest 'remove' completed with ret={'Error': 'Failed to remove volume v2, in use by VM = ubuntu-VM1.2.'}

Please review and merge.

Thanks,
Venil

vol_name = vmdk_utils.get_volname_from_vmdk_path(vmdk_path)
logging.info("*** removeVMDK: %s is in use, volume = %s VM = %s VM-uuid = %s (%s)",
vmdk_path, vol_name, attached_vm_name, kv_uuid, ret)
return err("Failed to remove volume {0}, in use by VM = {1} VM-uuid = {2}.".format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to remove VM-uuid from the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll fix that.

Copy link
Contributor

@shaominchen shaominchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please update the test result in the PR description.

@venilnoronha
Copy link
Contributor Author

Got that done too.

@@ -1117,7 +1119,7 @@ def setStatusDetached(vmdk_path):


def getStatusAttached(vmdk_path):
'''Returns (attached, uuid, attach_as) tuple. For 'detached' status uuid is None'''
'''Returns (attached, uuid, attach_as, vm_name) tuple. For 'detached' status uuid is None'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is also None in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

@@ -288,7 +288,7 @@ def cloneVMDK(vm_name, vmdk_path, opts={}, vm_uuid=None, datastore_url=None):
lockname = "{}.{}.{}".format(src_datastore, tenant_name, src_volume)
with lockManager.get_lock(lockname):
# Verify if the source volume is in use.
attached, uuid, attach_as = getStatusAttached(src_vmdk_path)
attached, uuid, attach_as, _ = getStatusAttached(src_vmdk_path)
if attached:
if handle_stale_attach(vmdk_path, uuid):
return err("Source volume cannot be in use when cloning")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about changing this error message to:
"Source volume {0} in use by VM {1} and can't be cloned.".format(vol_name, attached_vm_name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1275.

logging.info("*** removeVMDK: %s is in use, VM uuid = %s (%s)", vmdk_path, kv_uuid, ret)
return err("Failed to remove volume {0}, in use by VM uuid = {1}.".format(
vmdk_path, kv_uuid))
if vol_name is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vol_name can't be NULL. This if block can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add this because the function signature is removeVMDK(.., vol_name=None, ..) and there are a few places from where it's called without the vol_name parameter. Making the suggested change will need a modification at vmdk_ops.py#L355 and at multiple locations in vmdk_ops_test.py. I can address that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. I see. You are right.

vol_name = vmdk_utils.get_volname_from_vmdk_path(vmdk_path)
logging.info("*** removeVMDK: %s is in use, volume = %s VM = %s VM-uuid = %s (%s)",
vmdk_path, vol_name, attached_vm_name, kv_uuid, ret)
return err("Failed to remove volume {0}, in use by VM = {1}.".format(vol_name, attached_vm_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume .format can handle NULL attached_vm_name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would print .. in use by VM = None. Is that alright?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error looks weird but that would be stale KV. Fine with me.

logging.info("*** removeVMDK: %s is in use, VM uuid = %s (%s)", vmdk_path, kv_uuid, ret)
return err("Failed to remove volume {0}, in use by VM uuid = {1}.".format(
vmdk_path, kv_uuid))
if vol_name is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. I see. You are right.

vol_name = vmdk_utils.get_volname_from_vmdk_path(vmdk_path)
logging.info("*** removeVMDK: %s is in use, volume = %s VM = %s VM-uuid = %s (%s)",
vmdk_path, vol_name, attached_vm_name, kv_uuid, ret)
return err("Failed to remove volume {0}, in use by VM = {1}.".format(vol_name, attached_vm_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error looks weird but that would be stale KV. Fine with me.

@pdhamdhere pdhamdhere merged commit db554e5 into vmware-archive:master May 18, 2017
@venilnoronha
Copy link
Contributor Author

@pdhamdhere thanks for the merge!

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.

5 participants