Moti Asayag has uploaded a new change for review.

Change subject: engine: Modify VM commands to work with VmNic
......................................................................

engine: Modify VM commands to work with VmNic

The patch modify VM command to prefer using VmNic
type where possible instead of the viewable entity
VmNetworkInterface.

In addition, the Vnic Profile logic for Import Vm/Template
is added to replace the former network-driven behaviour.

Change-Id: I2a5130e1d594a642e18460aa85692d86b8870a52
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVmInterfaceCommand.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/utils/VmDeviceUtils.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/VmInterfaceManagerTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
15 files changed, 93 insertions(+), 89 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/17270/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 109a89c..21e9bf1 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -62,6 +62,7 @@
 import org.ovirt.engine.core.common.businessentities.VolumeType;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
@@ -193,7 +194,7 @@
         getVm().setName(getParameters().getVm().getName());
         getVm().setStoragePoolId(getParameters().getStoragePoolId());
         getParameters().setVm(getVm());
-        for (VmNetworkInterface iface : getVm().getInterfaces()) {
+        for (VmNic iface : getVm().getInterfaces()) {
             iface.setId(Guid.newGuid());
         }
     }
@@ -393,7 +394,7 @@
             return false;
         }
 
-        if (!validateMacAddress(getVm().getInterfaces())) {
+        if (!validateMacAddress(Entities.<VmNic, VmNetworkInterface> 
upcast(getVm().getInterfaces()))) {
             return false;
         }
 
@@ -1013,10 +1014,12 @@
 
         for (VmNetworkInterface iface : getVm().getInterfaces()) {
             initInterface(iface);
-            if (!vmInterfaceManager.isValidVmNetwork(iface, 
networksInClusterByName)) {
+            if (!vmInterfaceManager.isValidVmNetwork(iface,
+                    networksInClusterByName,
+                    getVdsGroup().getcompatibility_version())) {
                 invalidNetworkNames.add(iface.getNetworkName());
                 invalidIfaceNames.add(iface.getName());
-                iface.setNetworkName(null);
+                iface.setVnicProfileId(null);
             }
 
             vmInterfaceManager.add(iface, getCompensationContext(), 
getParameters().isImportAsNewEntity(),
@@ -1027,14 +1030,13 @@
         auditInvalidInterfaces(invalidNetworkNames, invalidIfaceNames);
     }
 
-    private void initInterface(VmNetworkInterface iface) {
+    private void initInterface(VmNic iface) {
         if (iface.getId() == null) {
             iface.setId(Guid.newGuid());
         }
         fillMacAddressIfMissing(iface);
         iface.setVmTemplateId(null);
         iface.setVmId(getVmId());
-        iface.setVmName(getVm().getName());
     }
 
     private void addVmDynamic() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
index f93375b..d93dd07 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmTemplateCommand.java
@@ -191,7 +191,7 @@
             }
         }
         if (retVal) {
-            retVal = validateMacAddress( getVmTemplate().getInterfaces());
+            retVal = validateMacAddress(Entities.<VmNic, VmNetworkInterface> 
upcast(getVmTemplate().getInterfaces()));
         }
         if (!retVal) {
             addCanDoActionMessage(VdcBllMessages.VAR__ACTION__IMPORT);
@@ -378,20 +378,18 @@
             }
             networkName = iface.getNetworkName();
             iface.setVmId(getVmTemplateId());
-            VmNetworkInterface iDynamic = new VmNetworkInterface();
-            VmNetworkStatistics iStat = new VmNetworkStatistics();
-            iDynamic.setStatistics(iStat);
+            VmNic iDynamic = new VmNic();
             iDynamic.setId(iface.getId());
-            iStat.setId(iface.getId());
-            iStat.setVmId(getVmTemplateId());
             iDynamic.setVmTemplateId(getVmTemplateId());
             iDynamic.setName(iface.getName());
-            if (vmInterfaceManager.isValidVmNetwork(iface, 
networksInVdsByName)) {
-                iDynamic.setNetworkName(networkName);
+            if (vmInterfaceManager.isValidVmNetwork(iface,
+                    networksInVdsByName,
+                    getVdsGroup().getcompatibility_version())) {
+                iDynamic.setVnicProfileId(iface.getVnicProfileId());
             } else {
                 invalidNetworkNames.add(iface.getNetworkName());
                 invalidIfaceNames.add(iface.getName());
-                iDynamic.setNetworkName(null);
+                iDynamic.setVnicProfileId(null);
             }
             iDynamic.setLinked(iface.isLinked());
             iDynamic.setSpeed(iface.getSpeed());
@@ -399,7 +397,12 @@
 
             getVmNicDao().save(iDynamic);
             getCompensationContext().snapshotNewEntity(iDynamic);
-            DbFacade.getInstance().getVmNetworkStatisticsDao().save(iStat);
+
+            VmNetworkStatistics iStat = new VmNetworkStatistics();
+            iDynamic.setStatistics(iStat);
+            iStat.setId(iface.getId());
+            iStat.setVmId(getVmTemplateId());
+            getDbFacade().getVmNetworkStatisticsDao().save(iStat);
             getCompensationContext().snapshotNewEntity(iStat);
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
index 640462e..620786f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MoveOrCopyTemplateCommand.java
@@ -32,7 +32,7 @@
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
 import org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId;
 import org.ovirt.engine.core.common.businessentities.VM;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import 
org.ovirt.engine.core.common.vdscommands.GetImageDomainsListVDSCommandParameters;
@@ -54,7 +54,7 @@
     private List<DiskImage> _templateDisks;
     private StorageDomain sourceDomain;
     private Guid sourceDomainId = Guid.Empty;
-    private final static Pattern VALIDATE_MAC_ADDRESS = 
Pattern.compile(VmNetworkInterface.VALID_MAC_ADDRESS_FORMAT);
+    private final static Pattern VALIDATE_MAC_ADDRESS = 
Pattern.compile(VmNic.VALID_MAC_ADDRESS_FORMAT);
 
     /**
      * Constructor for command creation when compensation is applied on startup
@@ -333,16 +333,16 @@
         return permissionCheckSubject;
     }
 
-    protected void fillMacAddressIfMissing(VmNetworkInterface iface) {
+    protected void fillMacAddressIfMissing(VmNic iface) {
         if (StringUtils.isEmpty(iface.getMacAddress())
                 && (MacPoolManager.getInstance().getAvailableMacsCount() >= 
1)) {
             iface.setMacAddress(MacPoolManager.getInstance().allocateNewMac());
         }
     }
 
-    protected boolean validateMacAddress(List<VmNetworkInterface> ifaces) {
+    protected boolean validateMacAddress(List<VmNic> ifaces) {
         int freeMacs = 0;
-        for (VmNetworkInterface iface : ifaces) {
+        for (VmNic iface : ifaces) {
             if (!StringUtils.isEmpty(iface.getMacAddress())) {
                 
if(!VALIDATE_MAC_ADDRESS.matcher(iface.getMacAddress()).matches()) {
                     addCanDoActionMessage("$IfaceName " + iface.getName());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
index 9dc16aa..30991a2 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
@@ -21,7 +21,6 @@
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.tags;
 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;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
@@ -38,7 +37,6 @@
 import org.ovirt.engine.core.dao.TagDAO;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
 import org.ovirt.engine.core.dao.VmDynamicDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.dao.network.VmNicDao;
 import org.ovirt.engine.core.utils.GuidUtils;
 import org.ovirt.engine.core.utils.customprop.ValidationError;
@@ -167,9 +165,9 @@
     }
 
     protected void removeVmNetwork() {
-        List<VmNetworkInterface> interfaces = 
getVmNetworkInterfaceDao().getAllForVm(getVmId());
+        List<VmNic> interfaces = getVmNicDao().getAllForVm(getVmId());
         if (interfaces != null) {
-            for (VmNetworkInterface iface : interfaces) {
+            for (VmNic iface : interfaces) {
                 MacPoolManager.getInstance().freeMac(iface.getMacAddress());
             }
         }
@@ -425,12 +423,6 @@
 
     protected VmDeviceDAO getVmDeviceDao() {
         return getDbFacade().getVmDeviceDao();
-    }
-
-    /** Overriding to allow spying from this package */
-    @Override
-    protected VmNetworkInterfaceDao getVmNetworkInterfaceDao() {
-        return super.getVmNetworkInterfaceDao();
     }
 
     /** Overriding to allow spying from this package */
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java
index 6cc6217..215963f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/VmInterfaceManager.java
@@ -28,17 +28,17 @@
 import org.ovirt.engine.core.utils.transaction.TransactionSupport;
 
 /**
- * Helper class to use for adding/removing {@link VmNetworkInterface}s.
+ * Helper class to use for adding/removing {@link VmNic}s.
  */
 public class VmInterfaceManager {
 
     private Log log = LogFactory.getLog(getClass());
 
     /**
-     * Add a {@link VmNetworkInterface} to the VM. Allocates a MAC from the 
{@link MacPoolManager} if necessary,
-     * otherwise, if {@code ConfigValues.HotPlugEnabled} is true, forces 
adding the MAC address to the
-     * {@link MacPoolManager}. If HotPlug is not enabled tries to add the 
{@link VmNetworkInterface}'s MAC address to
-     * the {@link MacPoolManager}, and throws a {@link VdcBllException} if it 
fails.
+     * Add a {@link VmNic} to the VM. Allocates a MAC from the {@link 
MacPoolManager} if necessary, otherwise, if
+     * {@code ConfigValues.HotPlugEnabled} is true, forces adding the MAC 
address to the {@link MacPoolManager}. If
+     * HotPlug is not enabled tries to add the {@link VmNic}'s MAC address to 
the {@link MacPoolManager}, and throws a
+     * {@link VdcBllException} if it fails.
      *
      * @param iface
      *            The interface to save.
@@ -48,7 +48,7 @@
      *            the compatibility version of the cluster
      * @return <code>true</code> if the MAC wasn't used, <code>false</code> if 
it was.
      */
-    public void add(final VmNetworkInterface iface, CompensationContext 
compensationContext, boolean allocateMac,
+    public void add(final VmNic iface, CompensationContext 
compensationContext, boolean allocateMac,
             Version clusterCompatibilityVersion) {
 
         if (allocateMac) {
@@ -66,7 +66,7 @@
         compensationContext.snapshotNewEntity(iface.getStatistics());
     }
 
-    public void auditLogMacInUse(final VmNetworkInterface iface) {
+    public void auditLogMacInUse(final VmNic iface) {
         TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
             @Override
             public Void runInTransaction() {
@@ -95,15 +95,15 @@
     }
 
     /**
-     * Remove all {@link VmNetworkInterface}s from the VM, and remove the Mac 
addresses from {@link MacPoolManager}.
+     * Remove all {@link VmNic}s from the VM, and remove the Mac addresses 
from {@link MacPoolManager}.
      *
      * @param vmId
      *            The ID of the VM to remove from.
      */
     public void removeAll(Guid vmId) {
-        List<VmNetworkInterface> interfaces = 
getVmNetworkInterfaceDao().getAllForVm(vmId);
+        List<VmNic> interfaces = getVmNicDao().getAllForVm(vmId);
         if (interfaces != null) {
-            for (VmNetworkInterface iface : interfaces) {
+            for (VmNic iface : interfaces) {
                 getMacPoolManager().freeMac(iface.getMacAddress());
                 getVmNicDao().remove(iface.getId());
                 getVmNetworkStatisticsDao().remove(iface.getId());
@@ -113,11 +113,13 @@
 
     /**
      * Checks if a Network is in the given list and is a VM Network
+     *
      * @param iface
      * @param networksByName
+     * @param version
      * @return
      */
-    public boolean isValidVmNetwork(VmNetworkInterface iface, Map<String, 
Network> networksByName) {
+    public boolean isValidVmNetwork(VmNetworkInterface iface, Map<String, 
Network> networksByName, Version version) {
         String networkName = iface.getNetworkName();
         return networkName == null
                 || ((networksByName.containsKey(networkName) && 
networksByName.get(networkName).isVmNetwork()));
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVmInterfaceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVmInterfaceCommand.java
index dd1000c..dd7e451 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVmInterfaceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/vm/RemoveVmInterfaceCommand.java
@@ -8,7 +8,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 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;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 
 public class RemoveVmInterfaceCommand<T extends RemoveVmInterfaceParameters> 
extends VmCommand<T> {
@@ -28,7 +28,7 @@
         
this.setVmName(getVmStaticDAO().get(getParameters().getVmId()).getName());
 
         // return mac to pool
-        VmNetworkInterface iface = 
getVmNetworkInterfaceDao().get(getParameters().getInterfaceId());
+        VmNic iface = getVmNicDao().get(getParameters().getInterfaceId());
 
         if (iface != null) {
             MacPoolManager.getInstance().freeMac(iface.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 bd245a9..8b9d425 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
@@ -124,7 +124,7 @@
                 runVdsCommand(VDSCommandType.UpdateVmInterface,
                         new VmNicDeviceVDSParameters(getVdsId(),
                                 getVm(),
-                                
getVmNetworkInterfaceDao().get(getInterface().getId()),
+                                getVmNicDao().get(getInterface().getId()),
                                 oldVmDevice));
                 break;
             }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
index db8429f..5ed8e30 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/VmDeviceUtils.java
@@ -27,7 +27,6 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmStatic;
 import org.ovirt.engine.core.common.businessentities.VmType;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 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.Config;
@@ -766,7 +765,7 @@
      */
     private static <T extends VmBase> void addImportedInterfaces(T entity, 
List<VmDevice> vmDeviceToUpdate) {
         final Guid id = entity.getId();
-        for (VmNetworkInterface iface : entity.getInterfaces()) {
+        for (VmNic iface : entity.getInterfaces()) {
             Guid deviceId = iface.getId();
             VmDevice vmDevice =
                     addManagedDevice(new VmDeviceId(deviceId, id),
@@ -776,7 +775,7 @@
                             true,
                             false,
                             getAddress(entity, id),
-                            iface.getCustomProperties());
+                            null);
 
             VmDevice exportedDevice = 
entity.getManagedDeviceMap().get(deviceId);
             if (exportedDevice == null) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
index c69e17a..35a01d8 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
@@ -42,7 +42,7 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dao.StorageDomainDAO;
 import org.ovirt.engine.core.dao.VdsDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
+import org.ovirt.engine.core.dao.network.VmNicDao;
 import org.ovirt.engine.core.utils.customprop.ValidationError;
 import org.ovirt.engine.core.utils.customprop.VmPropertiesUtils;
 
@@ -83,7 +83,7 @@
                 // vm has network,
                 // otherwise the vm cannot be run in vdsm
                 if (boot_sequence == BootSequence.N
-                        && 
getVmNetworkInterfaceDao().getAllForVm(vm.getId()).size() == 0) {
+                        && getVmNicDao().getAllForVm(vm.getId()).size() == 0) {
                     return new 
ValidationResult(VdcBllMessages.VM_CANNOT_RUN_FROM_NETWORK_WITHOUT_NETWORK);
                 }
             }
@@ -301,8 +301,8 @@
         return Backend.getInstance();
     }
 
-    protected VmNetworkInterfaceDao getVmNetworkInterfaceDao() {
-        return DbFacade.getInstance().getVmNetworkInterfaceDao();
+    protected VmNicDao getVmNicDao() {
+        return DbFacade.getInstance().getVmNicDao();
     }
 
     protected StorageDomainDAO getStorageDomainDAO() {
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommandTest.java
index cfac985..8625aad 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommandTest.java
@@ -43,7 +43,6 @@
 import org.ovirt.engine.core.dao.VdsDAO;
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -172,7 +171,6 @@
         command = spy(createCommand());
         mockVds();
         when(command.getActionType()).thenReturn(getCommandActionType());
-        
doReturn(mock(VmNetworkInterfaceDao.class)).when(command).getVmNetworkInterfaceDao();
         SnapshotsValidator snapshotsValidator = mock(SnapshotsValidator.class);
         doReturn(snapshotsValidator).when(command).getSnapshotsValidator();
         
doReturn(ValidationResult.VALID).when(snapshotsValidator).vmNotDuringSnapshot(any(Guid.class));
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java
index a240774..15d17a6 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RestoreAllSnapshotCommandTest.java
@@ -29,11 +29,11 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
@@ -44,7 +44,6 @@
 import org.ovirt.engine.core.dao.StoragePoolDAO;
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmDynamicDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -78,9 +77,6 @@
 
     @Mock
     protected SnapshotDao snapshotDao;
-
-    @Mock
-    private VmNetworkInterfaceDao vmNetworkInterfaceDAO;
 
     @Mock
     private MultipleStorageDomainsValidator storageValidator;
@@ -165,7 +161,6 @@
         mockStoragePoolDao();
         mockDynamicVmDao();
         doReturn(snapshotDao).when(spyCommand).getSnapshotDao();
-        
doReturn(vmNetworkInterfaceDAO).when(spyCommand).getVmNetworkInterfaceDao();
     }
 
     private void mockDynamicVmDao() {
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
index ce36b46..8e8e342 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
@@ -49,7 +49,6 @@
 import org.ovirt.engine.core.dao.VdsDAO;
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmStaticDAO;
-import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 import org.ovirt.engine.core.utils.MockEJBStrategyRule;
 import org.ovirt.engine.core.utils.ejb.ContainerManagedResourceType;
@@ -73,8 +72,6 @@
     private BaseDiskDao baseDiskDao;
     @Mock
     private ImageDao imageDao;
-    @Mock
-    private VmNetworkInterfaceDao vmNetworkInterfaceDAO;
     @Mock
     private SnapshotDao snapshotDao;
     @Mock
@@ -252,7 +249,6 @@
 
         });
         doReturn(true).when(command).acquireLockInternal();
-        
doReturn(vmNetworkInterfaceDAO).when(command).getVmNetworkInterfaceDao();
         doReturn(snapshotDao).when(command).getSnapshotDao();
         doReturn(diskImageDao).when(command).getDiskImageDao();
         doReturn(storagePoolDao).when(command).getStoragePoolDAO();
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/VmInterfaceManagerTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/VmInterfaceManagerTest.java
index 45a87bc..4701043 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/VmInterfaceManagerTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/VmInterfaceManagerTest.java
@@ -67,6 +67,9 @@
     @Spy
     private VmInterfaceManager vmInterfaceManager = new VmInterfaceManager();
 
+    @Mock
+    private Version version;
+
     @Before
     public void setupMocks() {
         MockitoAnnotations.initMocks(this);
@@ -88,11 +91,11 @@
 
     @Test
     public void addWithExistingMacAddressSucceed() {
-        VmNetworkInterface iface = createNewInterface();
+        VmNic iface = createNewInterface();
         runAddAndVerify(iface, true, times(1), VERSION_3_2);
     }
 
-    protected void runAddAndVerify(VmNetworkInterface iface,
+    protected void runAddAndVerify(VmNic iface,
             boolean addMacResult,
             VerificationMode addMacVerification,
             Version version) {
@@ -103,7 +106,7 @@
 
     @Test
     public void addAllocateNewMacAddress() {
-        VmNetworkInterface iface = createNewInterface();
+        VmNic iface = createNewInterface();
         String newMac = RandomUtils.instance().nextString(10);
         when(macPoolManager.allocateNewMac()).thenReturn(newMac);
         vmInterfaceManager.add(iface, NoOpCompensationContext.getInstance(), 
true, VERSION_3_2);
@@ -113,31 +116,37 @@
     @Test
     public void isValidVmNetworkForNullNetwork() {
         Network network = createNewNetwork(true, NETWORK_NAME);
-        VmNetworkInterface iface = createNewInterface();
-        assertTrue(vmInterfaceManager.isValidVmNetwork(iface, 
Collections.singletonMap(network.getName(), network)));
+        VmNetworkInterface iface = createNewViewableInterface();
+        assertTrue(vmInterfaceManager.isValidVmNetwork(iface,
+                Collections.singletonMap(network.getName(), network),
+                version));
     }
 
     @Test
     public void isValidVmNetworkForValidNetwork() {
         Network network = createNewNetwork(true, NETWORK_NAME);
-        VmNetworkInterface iface = createNewInterface();
+        VmNetworkInterface iface = createNewViewableInterface();
         iface.setNetworkName(network.getName());
-        assertTrue(vmInterfaceManager.isValidVmNetwork(iface, 
Collections.singletonMap(network.getName(), network)));
+        assertTrue(vmInterfaceManager.isValidVmNetwork(iface,
+                Collections.singletonMap(network.getName(), network),
+                version));
     }
 
     @Test
     public void isValidVmNetworkForNonVmNetwork() {
         Network network = createNewNetwork(false, NETWORK_NAME);
-        VmNetworkInterface iface = createNewInterface();
+        VmNetworkInterface iface = createNewViewableInterface();
         iface.setNetworkName(network.getName());
-        assertFalse(vmInterfaceManager.isValidVmNetwork(iface, 
Collections.singletonMap(network.getName(), network)));
+        assertFalse(vmInterfaceManager.isValidVmNetwork(iface,
+                Collections.singletonMap(network.getName(), network),
+                version));
     }
 
     @Test
     public void isValidVmNetworkForNetworkNotInVds() {
-        VmNetworkInterface iface = createNewInterface();
+        VmNetworkInterface iface = createNewViewableInterface();
         iface.setNetworkName(NETWORK_NAME);
-        assertFalse(vmInterfaceManager.isValidVmNetwork(iface, 
Collections.<String, Network> emptyMap()));
+        assertFalse(vmInterfaceManager.isValidVmNetwork(iface, 
Collections.<String, Network> emptyMap(), version));
     }
 
     @Test
@@ -161,13 +170,13 @@
 
     @Test
     public void removeAll() {
-        List<VmNetworkInterface> interfaces = 
Arrays.asList(createNewInterface(), createNewInterface());
+        List<VmNic> interfaces = Arrays.asList(createNewInterface(), 
createNewInterface());
 
-        
when(vmNetworkInterfaceDAO.getAllForVm(any(Guid.class))).thenReturn(interfaces);
+        when(vmNicDao.getAllForVm(any(Guid.class))).thenReturn(interfaces);
 
         vmInterfaceManager.removeAll(Guid.newGuid());
 
-        for (VmNetworkInterface iface : interfaces) {
+        for (VmNic iface : interfaces) {
             verifyRemoveAllDelegatedCorrectly(iface);
         }
     }
@@ -186,7 +195,7 @@
      * @param addMacVerification
      *            Mode to check (times(1), never(), etc) for {@link 
MacPoolManager#addMac(String)}.
      */
-    protected void verifyAddDelegatedCorrectly(VmNetworkInterface iface, 
VerificationMode addMacVerification) {
+    protected void verifyAddDelegatedCorrectly(VmNic iface, VerificationMode 
addMacVerification) {
         verify(macPoolManager, 
addMacVerification).forceAddMac(iface.getMacAddress());
         verify(vmNicDao).save(iface);
         verify(vmNetworkStatisticsDAO).save(iface.getStatistics());
@@ -198,7 +207,7 @@
      * @param iface
      *            The interface to check for.
      */
-    protected void verifyRemoveAllDelegatedCorrectly(VmNetworkInterface iface) 
{
+    protected void verifyRemoveAllDelegatedCorrectly(VmNic iface) {
         verify(macPoolManager, times(1)).freeMac(iface.getMacAddress());
         verify(vmNicDao).remove(iface.getId());
         verify(vmNetworkStatisticsDAO).remove(iface.getId());
@@ -207,7 +216,14 @@
     /**
      * @return A new interface that can be used in tests.
      */
-    protected VmNetworkInterface createNewInterface() {
+    protected VmNic createNewInterface() {
+        VmNic iface = new VmNic();
+        iface.setId(Guid.newGuid());
+        iface.setMacAddress(RandomUtils.instance().nextString(10));
+        return iface;
+    }
+
+    protected VmNetworkInterface createNewViewableInterface() {
         VmNetworkInterface iface = new VmNetworkInterface();
         iface.setId(Guid.newGuid());
         iface.setMacAddress(RandomUtils.instance().nextString(10));
@@ -234,7 +250,7 @@
         VM vm = new VM();
         vm.setId(Guid.newGuid());
         vm.setName(vmName);
-        VmNetworkInterface vmIface = createNewInterface();
+        VmNetworkInterface vmIface = createNewViewableInterface();
         vmIface.setVmId(vm.getId());
         vmIface.setNetworkName(networkName);
         vm.getInterfaces().add(vmIface);
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
index 7b2b5ea..87b4c5a 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/RunVmValidatorTest.java
@@ -29,12 +29,12 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
-import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.VmNic;
 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.dao.network.VmNetworkInterfaceDao;
+import org.ovirt.engine.core.dao.network.VmNicDao;
 import org.ovirt.engine.core.utils.MockConfigRule;
 import org.ovirt.engine.core.utils.customprop.VmPropertiesUtils;
 import org.ovirt.engine.core.utils.exceptions.InitializationException;
@@ -132,9 +132,9 @@
 
     @Test
     public void testBootFromNetworkNoNetwork() {
-        VmNetworkInterfaceDao dao = mock(VmNetworkInterfaceDao.class);
-        doReturn(new 
ArrayList<VmNetworkInterface>()).when(dao).getAllForVm(any(Guid.class));
-        doReturn(dao).when(runVmValidator).getVmNetworkInterfaceDao();
+        VmNicDao dao = mock(VmNicDao.class);
+        doReturn(new 
ArrayList<VmNic>()).when(dao).getAllForVm(any(Guid.class));
+        doReturn(dao).when(runVmValidator).getVmNicDao();
         validateResult(runVmValidator.validateBootSequence(new VM(), 
BootSequence.N, new ArrayList<Disk>()),
                 false,
                 VdcBllMessages.VM_CANNOT_RUN_FROM_NETWORK_WITHOUT_NETWORK);
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
index 9b5aa45..fd2e90d 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/UpdateVmInterfaceVDSCommand.java
@@ -41,8 +41,9 @@
         deviceStruct.put(VdsProperties.PORT_MIRRORING, vnicProfile != null && 
vnicProfile.isPortMirroring()
                 && network != null ? 
Collections.singletonList(network.getName()) : Collections.<String> 
emptyList());
 
-        if 
(FeatureSupported.deviceCustomProperties(getParameters().getVm().getVdsGroupCompatibilityVersion()))
 {
-            deviceStruct.put(VdsProperties.Custom, 
getParameters().getVmDevice().getCustomProperties());
+        if (vnicProfile != null
+                && 
FeatureSupported.deviceCustomProperties(getParameters().getVm().getVdsGroupCompatibilityVersion()))
 {
+            deviceStruct.put(VdsProperties.Custom, 
vnicProfile.getCustomProperties());
         }
 
         return deviceStruct;


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

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

Reply via email to