Alona Kaplan has uploaded a new change for review.

Change subject: engine: Add profile validation to VmNicValidator
......................................................................

engine: Add profile validation to VmNicValidator

The profile validation will return an error if-
   - The profile doesn't exist.
   - The network is not in the current cluster.
   - The profile contains QoS and it is not supported in the current
     cluster's version.
Otherwise it's OK.

Update Add/UpdateVm/TemplateInterface commands to use this validator.

Change-Id: Ic58cbcdc412ca8ae86f7694148725730aa10acb9
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkHelper.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.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
12 files changed, 180 insertions(+), 65 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/18178/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkHelper.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkHelper.java
index 49694eb..9f3ffd4 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkHelper.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/cluster/NetworkHelper.java
@@ -73,8 +73,16 @@
             return null;
         }
 
-        Network retVal = null;
         VnicProfile vnicProfile = 
DbFacade.getInstance().getVnicProfileDao().get(vnicProfileId);
+        return getNetworkByVnicProfile(vnicProfile);
+    }
+
+    public static Network getNetworkByVnicProfile(VnicProfile vnicProfile) {
+        if (vnicProfile == null) {
+            return null;
+        }
+
+        Network retVal = null;
         if (vnicProfile.getNetworkId() != null) {
             retVal = 
DbFacade.getInstance().getNetworkDao().get(vnicProfile.getNetworkId());
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
index ffd932b..29126f2 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/AddVmTemplateInterfaceCommand.java
@@ -6,7 +6,6 @@
 
 import org.ovirt.engine.core.bll.VmCommand;
 import org.ovirt.engine.core.bll.VmTemplateHandler;
-import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.VmNicValidator;
@@ -15,7 +14,6 @@
 import org.ovirt.engine.core.common.action.AddVmTemplateInterfaceParameters;
 import org.ovirt.engine.core.common.businessentities.DiskImageBase;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
-import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
@@ -70,20 +68,9 @@
         Version clusterCompatibilityVersion = 
getVdsGroup().getcompatibility_version();
         VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion);
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())
+                || 
!validate(nicValidator.profileValid(getVmTemplate().getVdsGroupId()))) {
             return false;
-        }
-
-        if (getParameters().getInterface().getVnicProfileId() != null) {
-            // check that the network exists in current cluster
-            Network interfaceNetwork =
-                    
NetworkHelper.getNetworkByVnicProfileId(getParameters().getInterface().getVnicProfileId());
-
-            if (interfaceNetwork == null
-                    || !NetworkHelper.isNetworkInCluster(interfaceNetwork, 
getVmTemplate().getVdsGroupId())) {
-                
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER);
-                return false;
-            }
         }
 
         return true;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
index 3eec8d7..babfa27 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/template/UpdateVmTemplateInterfaceCommand.java
@@ -4,7 +4,6 @@
 
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
-import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.validator.VmNicValidator;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -12,7 +11,6 @@
 import org.ovirt.engine.core.common.action.AddVmTemplateInterfaceParameters;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
-import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
@@ -64,24 +62,13 @@
         Version clusterCompatibilityVersion = 
getVdsGroup().getcompatibility_version();
         VmNicValidator nicValidator = new 
VmNicValidator(getParameters().getInterface(), clusterCompatibilityVersion);
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())
+                || 
!validate(nicValidator.profileValid(getVmTemplate().getVdsGroupId()))) {
             return false;
         }
 
         if (!StringUtils.equals(oldIface.getName(), getInterfaceName()) && 
!interfaceNameUnique(interfaces)) {
             return false;
-        }
-
-        if (getParameters().getInterface().getVnicProfileId() != null) {
-            // check that the network exists in current cluster
-            Network interfaceNetwork =
-                    
NetworkHelper.getNetworkByVnicProfileId(getParameters().getInterface().getVnicProfileId());
-
-            if (interfaceNetwork == null
-                    || !NetworkHelper.isNetworkInCluster(interfaceNetwork, 
getVmTemplate().getVdsGroupId())) {
-                
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER);
-                return false;
-            }
         }
 
         return true;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
index adf0429..45f6e90 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/AddVmInterfaceCommand.java
@@ -6,7 +6,6 @@
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
 import org.ovirt.engine.core.bll.network.MacPoolManager;
-import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.bll.validator.VmNicValidator;
@@ -17,7 +16,6 @@
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
-import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
@@ -133,22 +131,9 @@
         Version compatibilityVersion = 
getVm().getVdsGroupCompatibilityVersion();
         VmNicValidator nicValidator = new VmNicValidator(getInterface(), 
compatibilityVersion);
 
-        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())) {
+        if (!validate(nicValidator.linkedCorrectly()) || 
!validate(nicValidator.emptyNetworkValid())
+                || !validate(nicValidator.profileValid(vm.getVdsGroupId()))) {
             return false;
-        }
-
-        if (getInterface().getVnicProfileId() != null) {
-            // check that the network exists in current cluster
-            Network network = 
NetworkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId());
-
-            if (network == null || !NetworkHelper.isNetworkInCluster(network, 
getVm().getVdsGroupId())) {
-                
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER);
-                return false;
-            } else if (!network.isVmNetwork()) {
-                
addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_NOT_A_VM_NETWORK);
-                addCanDoActionMessage(String.format("$networks %1$s", 
network.getName()));
-                return false;
-            }
         }
 
         if (StringUtils.isNotEmpty(getMacAddress())) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
index f1de649..96cb2b8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
@@ -188,21 +188,12 @@
         if (!validate(nicValidator.unplugPlugNotRequired())
                 || !validate(nicValidator.linkedCorrectly())
                 || !validate(nicValidator.emptyNetworkValid())
-                || !validate(nicValidator.hotUpdatePossible())) {
+                || !validate(nicValidator.hotUpdatePossible())
+                || !validate(nicValidator.profileValid(vm.getVdsGroupId()))) {
             return false;
         }
 
         Network network = null;
-        if (getInterface().getVnicProfileId() != null) {
-
-            network = 
NetworkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId());
-            // check that the network exists in current cluster
-            if (network == null || !NetworkHelper.isNetworkInCluster(network, 
getVm().getVdsGroupId())) {
-                
addCanDoActionMessage(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER);
-                return false;
-            }
-        }
-
         if (getRequiredAction() == RequiredAction.UPDATE_VM_DEVICE) {
             Network oldNetwork = 
NetworkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId());
             if 
(!validate(nicValidator.hotUpdateDoneWithInternalNetwork(oldNetwork, network))) 
{
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
index 3e7a2c9..684f559 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VmNicValidator.java
@@ -1,10 +1,15 @@
 package org.ovirt.engine.core.bll.validator;
 
 import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.bll.network.cluster.NetworkHelper;
 import org.ovirt.engine.core.common.FeatureSupported;
+import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
+import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
 /**
  * A class that can validate a {@link vmNic} is valid from certain aspects.
@@ -40,7 +45,49 @@
                 : ValidationResult.VALID;
     }
 
+    /**
+     * @return 1. An error if- <BR>
+     *         - The profile doesn't exist. <BR>
+     *         - The network is not in the current cluster. <BR>
+     *         - The profile contains QoS and it is not supported in the 
current cluster's version. <BR>
+     *         2.- Otherwise it's OK.
+     */
+    public ValidationResult profileValid(Guid clusterId) {
+        if (nic.getVnicProfileId() != null) {
+            // Check that the profile exists
+            VnicProfile vnicProfile = 
getDbFacade().getVnicProfileDao().get(nic.getVnicProfileId());
+            if (vnicProfile == null) {
+                return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_VNIC_PROFILE_NOT_EXISTS);
+            }
+
+            // Check that the network exists in current cluster
+            Network network = getNetworkByVnicProfile(vnicProfile);
+            if (network == null || !isNetworkInCluster(network, clusterId)) {
+                return new 
ValidationResult(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER);
+            }
+
+            // Check that if the profile contains QoS it is supported in the 
current cluster's version
+            if (!FeatureSupported.networkQoS(version)
+                    && 
getDbFacade().getQosDao().get(vnicProfile.getNetworkQosId()) != null)
+                return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED,
+                        clusterVersion());
+        }
+        return ValidationResult.VALID;
+    }
+
     protected String clusterVersion() {
         return String.format(CLUSTER_VERSION_REPLACEMENT_FORMAT, 
version.getValue());
     }
+
+    protected Network getNetworkByVnicProfile(VnicProfile vnicProfile) {
+        return NetworkHelper.getNetworkByVnicProfile(vnicProfile);
+    }
+
+    protected boolean isNetworkInCluster(Network network, Guid clusterId) {
+        return NetworkHelper.isNetworkInCluster(network, clusterId);
+    }
+
+    protected DbFacade getDbFacade() {
+        return DbFacade.getInstance();
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
index b10f9bb..7bcb6a1 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VmNicValidatorTest.java
@@ -3,6 +3,9 @@
 import static org.junit.Assert.assertThat;
 import static org.junit.matchers.JUnitMatchers.both;
 import static org.junit.matchers.JUnitMatchers.hasItem;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
 import static 
org.ovirt.engine.core.bll.validator.ValidationResultMatchers.failsWith;
 import static 
org.ovirt.engine.core.bll.validator.ValidationResultMatchers.isValid;
@@ -16,11 +19,17 @@
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.ovirt.engine.core.bll.ValidationResult;
+import org.ovirt.engine.core.common.businessentities.network.Network;
+import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
+import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.network.NetworkQoSDao;
+import org.ovirt.engine.core.dao.network.VnicProfileDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -31,6 +40,9 @@
 
     private static final String CLUSTER_VERSION_REPLACEMENT =
             String.format(VmNicValidator.CLUSTER_VERSION_REPLACEMENT_FORMAT, 
CLUSTER_VERSION);
+
+    private final Guid DEFAULT_GUID = Guid.newGuid();
+    private final Guid OTHER_GUID = Guid.newGuid();
 
     @Rule
     public MockConfigRule mockConfigRule = new MockConfigRule();
@@ -43,11 +55,30 @@
 
     private VmNicValidator validator;
 
+    @Mock
+    private DbFacade dbFacade;
+
+    @Mock
+    private VnicProfileDao vnicProfileDao;
+
+    @Mock
+    private NetworkQoSDao networkQosDao;
+
+    @Mock
+    private VnicProfile vnicProfile;
+
+    @Mock
+    private Network network;
+
+    @Mock
+    private NetworkQoS networkQos;
+
     @Before
     public void setup() {
         when(version.getValue()).thenReturn(CLUSTER_VERSION);
 
-        validator = new VmNicValidator(nic, version);
+        validator = spy(new VmNicValidator(nic, version));
+        doReturn(dbFacade).when(validator).getDbFacade();
     }
 
     @Test
@@ -75,7 +106,7 @@
 
     @Test
     public void nullVnicProfileWhenUnlinkingNotSupported() throws Exception {
-        
vnicProfileTest(both(failsWith(VdcBllMessages.NULL_NETWORK_IS_NOT_SUPPORTED))
+        
vnicProfileLinkingTest(both(failsWith(VdcBllMessages.NULL_NETWORK_IS_NOT_SUPPORTED))
                 .and(replacements(hasItem(CLUSTER_VERSION_REPLACEMENT))),
                 false,
                 null);
@@ -83,17 +114,17 @@
 
     @Test
     public void validVnicProfileWhenUnlinkingNotSupported() throws Exception {
-        vnicProfileTest(isValid(), false, VNIC_PROFILE_ID);
+        vnicProfileLinkingTest(isValid(), false, VNIC_PROFILE_ID);
     }
 
     @Test
     public void nullVnicProfileWhenUnlinkingSupported() throws Exception {
-        vnicProfileTest(isValid(), true, null);
+        vnicProfileLinkingTest(isValid(), true, null);
     }
 
     @Test
     public void validVnicProfileWhenUnlinkingSupported() throws Exception {
-        vnicProfileTest(isValid(), true, VNIC_PROFILE_ID);
+        vnicProfileLinkingTest(isValid(), true, VNIC_PROFILE_ID);
     }
 
     private void unlinkingTest(Matcher<ValidationResult> matcher, boolean 
networkLinkingSupported, boolean nicLinked) {
@@ -103,11 +134,83 @@
         assertThat(validator.linkedCorrectly(), matcher);
     }
 
-    private void vnicProfileTest(Matcher<ValidationResult> matcher, boolean 
networkLinkingSupported, Guid vnicProfileId) {
+    private void vnicProfileLinkingTest(Matcher<ValidationResult> matcher,
+            boolean networkLinkingSupported,
+            Guid vnicProfileId) {
         mockConfigRule.mockConfigValue(ConfigValues.NetworkLinkingSupported, 
version, networkLinkingSupported);
         when(nic.getVnicProfileId()).thenReturn(vnicProfileId);
 
         assertThat(validator.emptyNetworkValid(), matcher);
     }
 
+    @Test
+    public void vnicProfileExist() throws Exception {
+        vnicProfileValidationTest(isValid(), true, true, false, false);
+    }
+
+    @Test
+    public void vnicProfileNotExist() throws Exception {
+        
vnicProfileValidationTest(failsWith(VdcBllMessages.ACTION_TYPE_FAILED_VNIC_PROFILE_NOT_EXISTS),
+                false,
+                false,
+                false,
+                false);
+    }
+
+    @Test
+    public void qosSupported() throws Exception {
+        vnicProfileValidationTest(isValid(), true, true, true, true);
+    }
+
+    @Test
+    public void qosNotSupported() throws Exception {
+        
vnicProfileValidationTest(both(failsWith(VdcBllMessages.ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED))
+                .and(replacements(hasItem(CLUSTER_VERSION_REPLACEMENT))), 
true, true, true, false);
+    }
+
+    @Test
+    public void qosNullAndSupported() throws Exception {
+        vnicProfileValidationTest(isValid(), true, true, false, true);
+    }
+
+    @Test
+    public void qosNullAndNotSupported() throws Exception {
+        vnicProfileValidationTest(isValid(), true, true, false, false);
+    }
+
+    @Test
+    public void networkInCluster() throws Exception {
+        vnicProfileValidationTest(isValid(), true, true, false, false);
+    }
+
+    @Test
+    public void networkNotInCluster() throws Exception {
+        
vnicProfileValidationTest(failsWith(VdcBllMessages.NETWORK_NOT_EXISTS_IN_CURRENT_CLUSTER),
+                true,
+                false,
+                false,
+                false);
+    }
+
+    private void vnicProfileValidationTest(Matcher<ValidationResult> matcher,
+            boolean profileExist,
+            boolean networkExist,
+            boolean qosExist,
+            boolean qosSupported) {
+        when(dbFacade.getVnicProfileDao()).thenReturn(vnicProfileDao);
+        when(vnicProfileDao.get(any(Guid.class))).thenReturn(profileExist ? 
vnicProfile : null);
+        when(vnicProfile.getNetworkId()).thenReturn(DEFAULT_GUID);
+
+        doReturn(networkExist ? network : 
null).when(validator).getNetworkByVnicProfile(vnicProfile);
+        
doReturn(networkExist).when(validator).isNetworkInCluster(any(Network.class), 
any(Guid.class));
+
+        when(dbFacade.getQosDao()).thenReturn(networkQosDao);
+        when(networkQosDao.get(any(Guid.class))).thenReturn(qosExist ? 
networkQos : null);
+
+        mockConfigRule.mockConfigValue(ConfigValues.NetworkQoSSupported, 
version, qosSupported);
+        when(nic.getVnicProfileId()).thenReturn(VNIC_PROFILE_ID);
+
+        assertThat(validator.profileValid(OTHER_GUID), matcher);
+    }
+
 }
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 14dd4ad..c9cd911 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
@@ -626,6 +626,7 @@
     HOT_PLUG_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     UNLINKING_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     NULL_NETWORK_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
+    ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED(ErrorType.NOT_SUPPORTED),
     CANNOT_PERFOM_HOT_UPDATE(ErrorType.CONFLICT),
     CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING(ErrorType.CONFLICT),
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 35b30dd..591b0b9 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -811,6 +811,7 @@
 HOT_PLUG_IS_NOT_SUPPORTED=Activate/Deactivate while VM is running, is only 
supported for Clusters of version 3.1 and above.
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
+ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED=Cannot ${action} ${type}. 
There is Network QoS on the profile, this is not supported for clusters of 
version ${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.
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 96d191f..5ba1c8b 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
@@ -2191,6 +2191,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. There is no network on the 
virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.")
     String NULL_NETWORK_IS_NOT_SUPPORTED();
 
+    @DefaultStringValue("Cannot ${action} ${type}. There is Network QoS on the 
profile, this is not supported for clusters of version ${clusterVersion}.")
+    String ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED();
+
     @DefaultStringValue("Cannot ${action} ${type}. Updating the virtual 
machine interface while the virtual machine is running is not supported for 
clusters of version ${clusterVersion}.")
     String HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED();
 
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 65d42ed..5492adb 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
@@ -791,6 +791,7 @@
 HOT_PLUG_IS_NOT_SUPPORTED=Activate/Deactivate while VM is running, is only 
supported for Clusters of version 3.1 and above.
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
+ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED=Cannot ${action} ${type}. 
There is Network QoS on the profile, this is not supported for clusters of 
version ${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.
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 b3458a6..7718ea5 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
@@ -812,6 +812,7 @@
 HOT_PLUG_IS_NOT_SUPPORTED=Activate/Deactivate while VM is running, is only 
supported for Clusters of version 3.1 and above.
 UNLINKING_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Link state is set to 
'Down' on the virtual machine's interface, this is not supported for clusters 
of version ${clusterVersion}.
 NULL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. There is no network on 
the virtual machine's interface, this is not supported for clusters of version 
${clusterVersion}.
+ACTION_TYPE_FAILED_NETWROK_QOS_IS_NOT_SUPPORTED=Cannot ${action} ${type}. 
There is Network QoS on the profile, this is not supported for clusters of 
version ${clusterVersion}.
 HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Updating 
the virtual machine interface while the virtual machine is running is not 
supported for clusters of version ${clusterVersion}.
 CANNOT_PERFOM_HOT_UPDATE=Cannot ${action} ${type}. Updating some of the 
properties is not supported while the interface is plugged into a running 
virtual machine. Please un-plug the interface, update the properties, and then 
plug it back.
 CANNOT_PERFOM_HOT_UPDATE_WITH_PORT_MIRRORING=Cannot ${action} ${type}. Update 
is not possible when 'Port Mirroring' is set on the interface of a running 
virtual machine.


-- 
To view, visit http://gerrit.ovirt.org/18178
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic58cbcdc412ca8ae86f7694148725730aa10acb9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alona Kaplan <alkap...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to