From 646bd0465c88ec9dfc33e6e89b3b79911be108d9 Mon Sep 17 00:00:00 2001 From: Balu Dontu Date: Mon, 7 Nov 2016 17:32:57 -0800 Subject: [PATCH 1/5] Confusing error message from volume.create when datastore is not writable - Addressed Mark's comments --- esx_service/vmdk_ops.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index 9a3808cc8..a8e1c7597 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -107,6 +107,8 @@ # Error codes VMCI_ERROR = -1 # VMCI C code uses '-1' to indicate failures ECONNABORTED = 103 # Error on non privileged client +ERR_OSFS_MKDIR_READONLY = 30 # Error on creating a dockvols directory on a non-writable datastore +ERR_OSFS_MKDIR_NOPERMISSION = 13 # Error on creating a dockvols directory on a datastore where permissions are denied # Volume data returned on Get request CAPACITY = 'capacity' @@ -490,24 +492,33 @@ def get_vol_path(datastore, tenant_name=None): if os.path.isdir(path): # If the path exists then return it as is. logging.debug("Found %s, returning", path) - return path + return path, None if not os.path.isdir(dock_vol_path): # The osfs tools are usable for DOCK_VOLS_DIR on all datastores cmd = "{0} {1}".format(OSFS_MKDIR_CMD, dock_vol_path) rc, out = RunCommand(cmd) - if rc != 0: - logging.warning("Failed to create %s", dock_vol_path) - return None + errMsg = None + if rc == ERR_OSFS_MKDIR_READONLY: + errMsg = "{0} creation failed - {1} not writable".format(DOCK_VOLS_DIR, datastore) + elif rc == ERR_OSFS_MKDIR_NOPERMISSION: + errMsg = "{0} creation failed - Permission denied on {1}".format(DOCK_VOLS_DIR, datastore) + else: + logging.warning("Failed to initialize volume path %s", path) + errMsg = "Failed to initialize volume path {0}".format(path) + #creation of dockvols directory failed. + if errMsg is not None: + return None, err(errMsg) if tenant_name and not os.path.isdir(path): cmd = "{0} {1}".format(MKDIR_CMD, path) rc, out = RunCommand(cmd) if rc != 0: - logging.warning("Failed to create %s", path) - return None + logging.warning("Failed to initialize volume path %s", path) + errMsg = "Failed to initialize volume path {0}".format(path) + return None, err(errMsg) logging.info("Created %s", path) - return path + return path, None def parse_vol_name(full_vol_name): """ @@ -599,10 +610,10 @@ def executeRequest(vm_uuid, vm_name, config_path, cmd, full_vol_name, opts): return err(error_info) # get /vmfs/volumes//dockvols path on ESX: - path = get_vol_path(datastore, tenant_name) + path, errMsg = get_vol_path(datastore, tenant_name) logging.debug("executeRequest %s %s", tenant_name, path) if path is None: - return err("Failed to initialize volume path {0}".format(path)) + return errMsg vmdk_path = vmdk_utils.get_vmdk_path(path, vol_name) @@ -1097,7 +1108,7 @@ def set_vol_opts(name, options): return False # get /vmfs/volumes//dockvols path on ESX: - path = get_vol_path(datastore) + path, errMsg = get_vol_path(datastore) if path is None: msg = "Failed to get datastore path {0}".format(path) From 56fe3be681f8cb924c18efdab8328c546bc3f38d Mon Sep 17 00:00:00 2001 From: Balu Dontu Date: Tue, 8 Nov 2016 17:37:39 -0800 Subject: [PATCH 2/5] Addressed review comments from Mark and Prashanth - Use OS errcode function --- esx_service/vmdk_ops.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index a8e1c7597..43710d8bb 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -494,28 +494,20 @@ def get_vol_path(datastore, tenant_name=None): logging.debug("Found %s, returning", path) return path, None + cmd = None if not os.path.isdir(dock_vol_path): # The osfs tools are usable for DOCK_VOLS_DIR on all datastores cmd = "{0} {1}".format(OSFS_MKDIR_CMD, dock_vol_path) - rc, out = RunCommand(cmd) - errMsg = None - if rc == ERR_OSFS_MKDIR_READONLY: - errMsg = "{0} creation failed - {1} not writable".format(DOCK_VOLS_DIR, datastore) - elif rc == ERR_OSFS_MKDIR_NOPERMISSION: - errMsg = "{0} creation failed - Permission denied on {1}".format(DOCK_VOLS_DIR, datastore) - else: - logging.warning("Failed to initialize volume path %s", path) - errMsg = "Failed to initialize volume path {0}".format(path) - #creation of dockvols directory failed. - if errMsg is not None: - return None, err(errMsg) if tenant_name and not os.path.isdir(path): cmd = "{0} {1}".format(MKDIR_CMD, path) - rc, out = RunCommand(cmd) - if rc != 0: - logging.warning("Failed to initialize volume path %s", path) - errMsg = "Failed to initialize volume path {0}".format(path) - return None, err(errMsg) + rc, out = RunCommand(cmd) + if rc != 0: + if tenant_name: + errMsg = "Failed to initialize volume path {0}".format(path) + else: + errMsg = "{0} creation failed - {1} on {2}".format(DOCK_VOLS_DIR, os.strerror(rc), datastore) + logging.warning(errMsg) + return None, err(errMsg) logging.info("Created %s", path) return path, None From 832fbdff1fb093f410949c6697ae3daa51d7a1d5 Mon Sep 17 00:00:00 2001 From: Balu Dontu Date: Tue, 8 Nov 2016 17:40:24 -0800 Subject: [PATCH 3/5] Removed OSFS error code global variables --- esx_service/vmdk_ops.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index 43710d8bb..7a3d4ec2a 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -107,8 +107,6 @@ # Error codes VMCI_ERROR = -1 # VMCI C code uses '-1' to indicate failures ECONNABORTED = 103 # Error on non privileged client -ERR_OSFS_MKDIR_READONLY = 30 # Error on creating a dockvols directory on a non-writable datastore -ERR_OSFS_MKDIR_NOPERMISSION = 13 # Error on creating a dockvols directory on a datastore where permissions are denied # Volume data returned on Get request CAPACITY = 'capacity' From a528ed6ea6a2cc103d06ea7f968107a807882793 Mon Sep 17 00:00:00 2001 From: Balu Dontu Date: Wed, 9 Nov 2016 14:58:41 -0800 Subject: [PATCH 4/5] Fix to make sure dockvols is created before tenant directory is created --- esx_service/vmdk_ops.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index 3361bdd26..f66d0d1c8 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -492,20 +492,22 @@ def get_vol_path(datastore, tenant_name=None): logging.debug("Found %s, returning", path) return path, None - cmd = None if not os.path.isdir(dock_vol_path): # The osfs tools are usable for DOCK_VOLS_DIR on all datastores cmd = "{0} {1}".format(OSFS_MKDIR_CMD, dock_vol_path) + rc, out = RunCommand(cmd) + if rc != 0: + errMsg = "{0} creation failed - {1} on {2}".format(DOCK_VOLS_DIR, os.strerror(rc), datastore) + logging.warning(errMsg) + return None, err(errMsg) if tenant_name and not os.path.isdir(path): + # The mkdir command is used to create "tenant_name" folder inside DOCK_VOLS_DIR on "datastore" cmd = "{0} {1}".format(MKDIR_CMD, path) - rc, out = RunCommand(cmd) - if rc != 0: - if tenant_name: + rc, out = RunCommand(cmd) + if rc != 0: errMsg = "Failed to initialize volume path {0}".format(path) - else: - errMsg = "{0} creation failed - {1} on {2}".format(DOCK_VOLS_DIR, os.strerror(rc), datastore) - logging.warning(errMsg) - return None, err(errMsg) + logging.warning(errMsg) + return None, err(errMsg) logging.info("Created %s", path) return path, None From 11631ab9bf65290e2027470a0773b3fb609dc701 Mon Sep 17 00:00:00 2001 From: Balu Dontu Date: Fri, 11 Nov 2016 15:20:11 -0800 Subject: [PATCH 5/5] Added specific error message during tenane creation failure --- esx_service/vmdk_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esx_service/vmdk_ops.py b/esx_service/vmdk_ops.py index f66d0d1c8..0c9ebac34 100755 --- a/esx_service/vmdk_ops.py +++ b/esx_service/vmdk_ops.py @@ -505,7 +505,7 @@ def get_vol_path(datastore, tenant_name=None): cmd = "{0} {1}".format(MKDIR_CMD, path) rc, out = RunCommand(cmd) if rc != 0: - errMsg = "Failed to initialize volume path {0}".format(path) + errMsg = "Failed to initialize volume path {0} - {1}".format(path, out) logging.warning(errMsg) return None, err(errMsg)