Tal Nisan has uploaded a new change for review. Change subject: core: Added validation on managed custom mount option ......................................................................
core: Added validation on managed custom mount option When adding a new NFS/Posix storage server connection, if the custom mount options contains a managed option (i.e. property that the engine is managing directly), the command will fail with a CDA Change-Id: Icc5a74379de55aa81194298be634f689efd331d5 Bug-Url: https://bugzilla.redhat.com/1129597 Signed-off-by: Tal Nisan <tni...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 6 files changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/32372/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java index cddaf17..a52e324 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/ConnectStorageToVdsCommand.java @@ -90,6 +90,10 @@ return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE); } + if ((storageType == StorageType.POSIXFS || storageType == StorageType.NFS) && !validate(validateMountOptions())) { + return false; + } + if (storageType == StorageType.ISCSI) { if (StringUtils.isEmpty(conn.getiqn())) { return failCanDoAction(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_EMPTY_IQN); @@ -105,4 +109,30 @@ return true; } + + private static final List<String> NFS_MANAGED_OPTIONS = Arrays.asList("timeout", "retrans", "vfs_type", "protocol_version", "nfsvers", "vers"); + private static final List<String> POSIX_MANAGED_OPTIONS = Arrays.asList("vfs_type"); + + private ValidationResult validateMountOptions() { + String mountOptions = getConnection().getMountOptions(); + if (StringUtils.isBlank(mountOptions)) { + return ValidationResult.VALID; + } + + List<String> disallowedOptions = + getConnection().getstorage_type() == StorageType.POSIXFS ? POSIX_MANAGED_OPTIONS : NFS_MANAGED_OPTIONS; + Map<String, String> optionsMap = XmlRpcStringUtils.string2Map(mountOptions); + Set<String> optionsKeys = new HashSet<>(); + for (String optionName : optionsMap.keySet()) { + optionsKeys.add(optionName.toLowerCase()); + } + + optionsKeys.retainAll(disallowedOptions); + if (!optionsKeys.isEmpty()) { + addCanDoActionMessageVariable("invalidOptions", StringUtils.join(optionsKeys, ", ")); + return new ValidationResult(VdcBllMessages.VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY); + } + + return ValidationResult.VALID; + } } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java index fac5612..72dd182 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java @@ -826,6 +826,7 @@ VALIDATION_STORAGE_CONNECTION_INVALID(ErrorType.BAD_PARAMETERS), VALIDATION_STORAGE_CONNECTION_INVALID_PORT(ErrorType.BAD_PARAMETERS), VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE(ErrorType.BAD_PARAMETERS), + VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY(ErrorType.BAD_PARAMETERS), VALIDATION_STORAGE_CONNECTION_EMPTY_IQN(ErrorType.BAD_PARAMETERS), VALIDATION_STORAGE_CONNECTION_EMPTY_CONNECTION(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_ACTION_IS_SUPPORTED_ONLY_FOR_ISCSI_DOMAINS(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index 54d5bad..3a307f1 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -779,6 +779,7 @@ VALIDATION_STORAGE_CONNECTION_INVALID=Mount path is illegal, please use [IP:/path or FQDN:/path] convention. VALIDATION_STORAGE_CONNECTION_INVALID_PORT=Invalid value for port, should be an integer greater than 0. VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE=VFS type cannot be empty. +VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY=Cannot ${action} ${type}. Custom mount options contain the following managed options: ${invalidOptions}. VALIDATION_STORAGE_CONNECTION_EMPTY_IQN=Target details cannot be empty. VALIDATION_STORAGE_CONNECTION_EMPTY_CONNECTION=${fieldName} field cannot be empty. VALIDATION_STORAGE_CONNECTION_NFS_RETRANS=NFS Retransmissions should be between 0 and 32767 diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index d70ba58..620ea5d 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -2762,6 +2762,9 @@ @DefaultStringValue("VFS type cannot be empty") String VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE(); + @DefaultStringValue("Cannot ${action} ${type}. Custom mount options contain the following managed options: ${invalidOptions}.") + String VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY(); + @DefaultStringValue("Target details cannot be empty.") String VALIDATION_STORAGE_CONNECTION_EMPTY_IQN(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 888e556..4dfc6f1 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -738,6 +738,7 @@ VALIDATION_STORAGE_CONNECTION_INVALID=Mount path is illegal, please use [IP:/path or FQDN:/path] convention. VALIDATION_STORAGE_CONNECTION_INVALID_PORT=Invalid value for port, should be an integer greater than 0. VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE=VFS type cannot be empty. +VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY=Cannot ${action} ${type}. Custom mount options contain the following managed options: ${invalidOptions}. VALIDATION_STORAGE_CONNECTION_EMPTY_IQN=Target details cannot be empty. VALIDATION_STORAGE_CONNECTION_EMPTY_CONNECTION=${fieldName} field cannot be empty. VALIDATION_STORAGE_CONNECTION_NFS_RETRANS=NFS Retransmissions should be between 0 and 32767 diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 62b5f88..b35d219 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -778,6 +778,7 @@ STORAGE_OPERATION_FAILED_SPM_NETWORK_PROBLEMS=Storage related operations can't be performed while the Storage Pool Manager is down.\nPlease make sure the Storage Pool Manager is up and running, and check network connectivity. VALIDATION_STORAGE_CONNECTION_INVALID=Mount path is illegal, please use [IP:/path or FQDN:/path] convention. VALIDATION_STORAGE_CONNECTION_EMPTY_VFSTYPE=VFS type cannot be empty. +VALIDATION_STORAGE_CONNECTION_MOUNT_OPTIONS_CONTAINS_MANAGED_PROPERTY=Cannot ${action} ${type}. Custom mount options contain the following managed options: ${invalidOptions}. VALIDATION_STORAGE_CONNECTION_EMPTY_IQN=Target details cannot be empty. VALIDATION_STORAGE_CONNECTION_EMPTY_CONNECTION=${fieldName} field cannot be empty. VALIDATION_STORAGE_CONNECTION_NFS_RETRANS=NFS Retransmissions should be between 0 and 32767 -- To view, visit http://gerrit.ovirt.org/32372 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Icc5a74379de55aa81194298be634f689efd331d5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tal Nisan <tni...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches