Moti Asayag has uploaded a new change for review.

Change subject: engine: Prevent vnic live update for if network not on host
......................................................................

engine: Prevent vnic live update for if network not on host

The patch blocks updating a plugged vnic on a running vm to
a network which doesn't exist on the host.

It also fixes a bug of setting an empty vnic profile while
updating a plugged vnic.

Change-Id: I0c9d8f2202efa2e45a2144bbdb70d374bdb9ff6f
Bug-Url: https://bugzilla.redhat.com/1017602
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/UpdateVmInterfaceCommand.java
1 file changed, 23 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/24/20424/1

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 46ff955..67066f1 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
@@ -22,6 +22,7 @@
 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.VdsNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
@@ -29,6 +30,7 @@
 import org.ovirt.engine.core.common.validation.group.UpdateVmNic;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VmNicDeviceVDSParameters;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector;
 import org.ovirt.engine.core.utils.linq.LinqUtils;
@@ -183,7 +185,7 @@
         }
 
         if (!StringUtils.equals(oldIface.getName(), getInterfaceName()) && 
!uniqueInterfaceName(interfaces)) {
-                return false;
+            return false;
         }
 
         // check that not exceeded PCI and IDE limit
@@ -214,7 +216,8 @@
         Network network = 
NetworkHelper.getNetworkByVnicProfileId(getInterface().getVnicProfileId());
         if (getRequiredAction() == RequiredAction.UPDATE_VM_DEVICE) {
             Network oldNetwork = 
NetworkHelper.getNetworkByVnicProfileId(oldIface.getVnicProfileId());
-            if 
(!validate(nicValidator.hotUpdateDoneWithInternalNetwork(oldNetwork, network))) 
{
+            if 
(!validate(nicValidator.hotUpdateDoneWithInternalNetwork(oldNetwork, network))
+                    || !validate(nicValidator.networkExistsOnHost(network))) {
                 return false;
             }
         }
@@ -305,6 +308,22 @@
             super(nic, version, osId);
         }
 
+        public ValidationResult networkExistsOnHost(Network network) {
+            if (network == null) {
+                return ValidationResult.VALID;
+            }
+
+            Guid vdsId = getVmDynamicDao().get(nic.getVmId()).getRunOnVds();
+            List<VdsNetworkInterface> hostNics = 
getDbFacade().getInterfaceDao().getAllInterfacesForVds(vdsId);
+            for (VdsNetworkInterface hostNic : hostNics) {
+                if (network.getName().equals(hostNic.getNetworkName())) {
+                    return ValidationResult.VALID;
+                }
+            }
+
+            return new 
ValidationResult(VdcBllMessages.ACTIVATE_DEACTIVATE_NETWORK_NOT_IN_VDS);
+        }
+
         /**
          * @return An error if hot updated is needed, and either network 
linking is not supported or the NIC has port
          *         mirroring set.
@@ -314,7 +333,7 @@
                 if (!FeatureSupported.networkLinking(version)) {
                     return new 
ValidationResult(VdcBllMessages.HOT_VM_INTERFACE_UPDATE_IS_NOT_SUPPORTED,
                             clusterVersion());
-                } else if (getVnicProfile().isPortMirroring()) {
+                } else if (getVnicProfile() != null && 
getVnicProfile().isPortMirroring()) {
                     return new 
ValidationResult(VdcBllMessages.CANNOT_PERFORM_HOT_UPDATE_WITH_PORT_MIRRORING);
                 }
             }
@@ -347,7 +366,7 @@
             return (oldNetwork == null || !oldNetwork.isExternal())
                     && (newNetwork == null || !newNetwork.isExternal())
                     ? ValidationResult.VALID
-                    : new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_NETWORK_CANNOT_BE_REWIRED);
+                            : new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_EXTERNAL_NETWORK_CANNOT_BE_REWIRED);
         }
     }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c9d8f2202efa2e45a2144bbdb70d374bdb9ff6f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Moti Asayag <masa...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to