Moti Asayag has uploaded a new change for review.

Change subject: engine: Block changing a used label
......................................................................

engine: Block changing a used label

Changing a used label isn't supported and should
be blocked until it does.

Change-Id: I473ff703c35be305abec7b78c44e983c58d4cb03
Bug-Url: https://bugzilla.redhat.com/1091714
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/UpdateNetworkCommand.java
1 file changed, 27 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/71/27571/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/UpdateNetworkCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/UpdateNetworkCommand.java
index 13691fc..0ecc208 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/UpdateNetworkCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/UpdateNetworkCommand.java
@@ -33,6 +33,8 @@
 import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.errors.VdcBLLException;
+import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.validation.group.UpdateEntity;
 import org.ovirt.engine.core.compat.Guid;
@@ -151,7 +153,8 @@
                 Objects.equals(oldNetwork.getProvidedBy(), 
newNetwork.getProvidedBy()) &&
                 Objects.equals(oldNetwork.getStp(), newNetwork.getStp()) &&
                 Objects.equals(oldNetwork.getVlanId(), newNetwork.getVlanId()) 
&&
-                Objects.equals(oldNetwork.isVmNetwork(), 
newNetwork.isVmNetwork());
+                Objects.equals(oldNetwork.isVmNetwork(), 
newNetwork.isVmNetwork() &&
+                Objects.equals(oldNetwork.getLabel(), newNetwork.getLabel()));
     }
 
     private boolean oldAndNewNetworkIsNotExternal() {
@@ -182,22 +185,41 @@
             super(network);
         }
 
-        public ValidationResult notRenamingLabel(String oldLabel) {
-            if (network.getLabel() == null || oldLabel == null || 
network.getLabel().equals(oldLabel)) {
+        public ValidationResult notRenamingLabel(String newLabel) {
+            String oldLabel = network.getLabel();
+            if (oldLabel == null || newLabel == null || 
oldLabel.equals(newLabel)) {
                 return ValidationResult.VALID;
             }
 
             List<VdsNetworkInterface> nics =
                     
getDbFacade().getInterfaceDao().getVdsInterfacesByNetworkId(network.getId());
             for (VdsNetworkInterface nic : nics) {
-                if (NetworkUtils.isLabeled(nic) && 
nic.getLabels().contains(oldLabel)) {
-                    new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_LABEL_RENAMING_NOT_SUPPORTED);
+                VdsNetworkInterface labeledNic = nic;
+                if (NetworkUtils.isVlan(nic)) {
+                    labeledNic = getBaseInterface(nic);
+                }
+
+                if (NetworkUtils.isLabeled(labeledNic) && 
labeledNic.getLabels().contains(oldLabel)) {
+                    return new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_LABEL_RENAMING_NOT_SUPPORTED);
                 }
             }
 
             return ValidationResult.VALID;
         }
 
+        private VdsNetworkInterface getBaseInterface(VdsNetworkInterface vlan) 
{
+            List<VdsNetworkInterface> hostNics =
+                    
getDbFacade().getInterfaceDao().getAllInterfacesForVds(vlan.getVdsId());
+
+            for (VdsNetworkInterface hostNic : hostNics) {
+                if (NetworkUtils.interfaceBasedOn(vlan.getName(), 
hostNic.getName())) {
+                    return hostNic;
+                }
+            }
+
+            throw new 
VdcBLLException(VdcBllErrors.LABELED_NETWORK_INTERFACE_NOT_FOUND);
+        }
+
         public ValidationResult notRenamingUsedNetwork(String networkName) {
             if (StringUtils.equals(network.getName(), networkName)) {
                 return ValidationResult.VALID;


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

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

Reply via email to