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 <[email protected]>
---
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, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/32489/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 e8203b1..244638b 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
@@ -1,11 +1,14 @@
 package org.ovirt.engine.core.bll.storage;
 
+import org.ovirt.engine.core.bll.ValidationResult;
 import org.ovirt.engine.core.bll.context.CommandContext;
 
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.Backend;
@@ -20,6 +23,7 @@
 import 
org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.vdsbroker.xmlrpc.XmlRpcStringUtils;
 
 @InternalCommandAttribute
 public class ConnectStorageToVdsCommand<T extends 
StorageServerConnectionParametersBase> extends
@@ -86,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);
@@ -101,4 +109,29 @@
 
         return true;
     }
+
+    private static final List<String> NFS_MANAGED_OPTIONS = 
Arrays.asList("timeo", "retrans", "vfs_type", "protocol_version", "nfsvers", 
"vers", "minorversion", "addr", "clientaddr");
+    private static final List<String> POSIX_MANAGED_OPTIONS = 
Arrays.asList("vfs_type", "addr", "clientaddr");
+
+    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 TreeSet<>(String.CASE_INSENSITIVE_ORDER);
+        optionsKeys.addAll(optionsMap.keySet());
+        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 ba3d76f..a1761eb 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
@@ -819,6 +819,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 a5cba5d..0727f37 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -772,6 +772,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 323ed14..db2c658 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
@@ -2741,6 +2741,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 72154d2..12b3403 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 01f8368..4ace23334c 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
@@ -771,6 +771,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/32489
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icc5a74379de55aa81194298be634f689efd331d5
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to