Daniel Erez has uploaded a new change for review.

Change subject: core: update LUN device size using getVmStats
......................................................................

core: update LUN device size using getVmStats

* Handling DirecLUN disks manual resize (user invoked)
  by synchronizing LUNs device sizes upon powering up a VM.

* Similar to disk images, utilized VdsUpdateRunTimeInfo
  in order to retrieve updated information from getVmStats.

* Added buildVmLunDisksData method to VdsBrokerObjectsBuilder
  for de-serializing relevant LUNs data from getVmStats.

* For using batch update, LunDAODbFacadeImpl now extends
  MassOperationsGenericDaoDbFacade.

Note: the functionality is depended on VDSM patch -
      http://gerrit.ovirt.org/22976

Change-Id: Ie0d4d805ca333990ea1f612eb03a87f4a505f4a8
Bug-Url: https://bugzilla.redhat.com/961532
Signed-off-by: Daniel Erez <de...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/LUNs.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAODbFacadeImpl.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/ListVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmStatsVdsBrokerCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/entities/VmInternalData.java
M 
backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfoTest.java
10 files changed, 243 insertions(+), 32 deletions(-)


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

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/LUNs.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/LUNs.java
index f3e55f7..71cc56f 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/LUNs.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/LUNs.java
@@ -1,13 +1,11 @@
 package org.ovirt.engine.core.common.businessentities;
 
-import java.io.Serializable;
-
 import javax.validation.constraints.Size;
 
 import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.compat.Guid;
 
-public class LUNs implements Serializable {
+public class LUNs implements BusinessEntity<String> {
     private static final long serialVersionUID = 3026455643639610091L;
 
     public LUNs() {
@@ -282,4 +280,14 @@
     @Deprecated
     public void setAccessible(boolean accessible) {
     }
+
+    @Override
+    public String getId() {
+        return getLUN_id();
+    }
+
+    @Override
+    public void setId(String id) {
+        setLUN_id(id);
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAO.java
index 09d6732..52c9653 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAO.java
@@ -9,7 +9,7 @@
  *
  *
  */
-public interface LunDAO extends DAO {
+public interface LunDAO extends GenericDao<LUNs, String>, 
MassOperationsDao<LUNs, String> {
     /**
      * Gets the LUN with the specified id.
      *
@@ -43,28 +43,4 @@
      * @return the list of LUNs
      */
     List<LUNs> getAll();
-
-    /**
-     * Saves the supplied LUN instance.
-     *
-     * @param lun
-     *            the LUN
-     */
-    void save(LUNs lun);
-
-    /**
-     * Updates the specified LUN.
-     *
-     * @param lun
-     *            the LUN
-     */
-    void update(LUNs lun);
-
-    /**
-     * Removes the specified LUN.
-     *
-     * @param id
-     *            the LUN id
-     */
-    void remove(String id);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAODbFacadeImpl.java
index 0a3aa58..f20ed49 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LunDAODbFacadeImpl.java
@@ -5,6 +5,7 @@
 import java.util.List;
 
 import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
@@ -12,7 +13,13 @@
  * <code>LunDAODbFacadeImpl</code> provides a concrete implementation of 
{@link LunDAO}. The original code was
  * refactored from the {@link org.ovirt.engine.core.dal.dbbroker.DbFacade} 
class.
  */
-public class LunDAODbFacadeImpl extends BaseDAODbFacade implements LunDAO {
+public class LunDAODbFacadeImpl extends MassOperationsGenericDaoDbFacade<LUNs, 
String> implements LunDAO {
+
+    public LunDAODbFacadeImpl() {
+        super("luns");
+        setProcedureNameForGet("GetLUNByLUNId");
+        setProcedureNameForGetAll("GetAllFromLUNs");
+    }
 
     protected static final RowMapper<LUNs> MAPPER = new RowMapper<LUNs>() {
         @Override
@@ -72,6 +79,16 @@
     }
 
     @Override
+    protected MapSqlParameterSource createIdParameterMapper(String id) {
+        return getCustomMapSqlParameterSource().addValue("LUN_id", id);
+    }
+
+    @Override
+    protected RowMapper<LUNs> createEntityRowMapper() {
+        return MAPPER;
+    }
+
+    @Override
     public void save(LUNs lun) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("LUN_id", lun.getLUN_id())
@@ -108,4 +125,37 @@
 
         getCallsHandler().executeModification("DeleteLUN", parameterSource);
     }
+
+    @Override
+    protected MapSqlParameterSource createFullParametersMapper(LUNs lun) {
+        return createIdParameterMapper(lun.getId())
+                .addValue("physical_volume_id", lun.getphysical_volume_id())
+                .addValue("volume_group_id", lun.getvolume_group_id())
+                .addValue("serial", lun.getSerial())
+                .addValue("lun_mapping", lun.getLunMapping())
+                .addValue("vendor_id", lun.getVendorId())
+                .addValue("product_id", lun.getProductId())
+                .addValue("device_size", lun.getDeviceSize());
+    }
+
+    @Override
+    public MapSqlParameterMapper<LUNs> getBatchMapper() {
+        return new MapSqlParameterMapper<LUNs>() {
+
+            @Override
+            public MapSqlParameterSource map(LUNs lun) {
+                MapSqlParameterSource paramValue = new MapSqlParameterSource()
+                        .addValue("lun_id", lun.getLUN_id())
+                        .addValue("physical_volume_id", 
lun.getphysical_volume_id())
+                        .addValue("volume_group_id", lun.getvolume_group_id())
+                        .addValue("serial", lun.getSerial())
+                        .addValue("lun_mapping", lun.getLunMapping())
+                        .addValue("vendor_id", lun.getVendorId())
+                        .addValue("product_id", lun.getProductId())
+                        .addValue("device_size", lun.getDeviceSize());
+
+                return paramValue;
+            }
+        };
+    }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index 50fde54..c5c39c9 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -22,6 +22,8 @@
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
 import org.ovirt.engine.core.common.businessentities.Entities;
+import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.common.businessentities.LunDisk;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 import org.ovirt.engine.core.common.businessentities.OriginType;
 import org.ovirt.engine.core.common.businessentities.VDS;
@@ -92,6 +94,7 @@
     private final Map<Guid, VmStatistics> _vmStatisticsToSave = new 
HashMap<>();
     private final Map<Guid, List<VmNetworkInterface>> 
_vmInterfaceStatisticsToSave = new HashMap<>();
     private final Map<Guid, DiskImageDynamic> _vmDiskImageDynamicToSave = new 
HashMap<>();
+    private final List<LUNs> _vmLunDisksToSave = new ArrayList<>();
     private final Map<VmDeviceId, VmDevice> vmDeviceToSave = new HashMap<>();
     private final List<VmDevice> newVmDevices = new ArrayList<>();
     private final List<VmDeviceId> removedDeviceIds = new ArrayList<>();
@@ -166,6 +169,7 @@
         
getDbFacade().getVmNetworkStatisticsDao().updateAllInBatch(allVmInterfaceStatistics);
 
         
getDbFacade().getDiskImageDynamicDao().updateAllInBatch(_vmDiskImageDynamicToSave.values());
+        getDbFacade().getLunDao().updateAllInBatch(_vmLunDisksToSave);
         saveVmDevicesToDb();
         saveVmGuestAgentNetworkDevices();
         
ResourceManager.getInstance().getEventListener().addExternallyManagedVms(_externalVmsToAdd);
@@ -939,6 +943,8 @@
 
             prepareGuestAgentNetworkDevicesForUpdate();
 
+            updateLunDisks();
+
         } else if (command.getVDSReturnValue().getExceptionObject() != null) {
             if (command.getVDSReturnValue().getExceptionObject() instanceof 
VDSErrorException) {
                 log.errorFormat("Failed vds listing,  vds = {0} : {1}, error = 
{2}", _vds.getId(),
@@ -981,6 +987,36 @@
                             updateGuestAgentInterfacesChanges(vmDynamic, 
vmGuestAgentInterfaces, guestAgentNicHash);
                             addVmDynamicToList(vmDynamic);
                         }
+                    }
+                }
+            }
+        }
+    }
+
+    protected void updateLunDisks() {
+        // Looping only over powering up VMs as LUN device size
+        // is updated by VDSM only once when running a VM.
+        for (VmDynamic vmDynamic : getPoweringUpVms()) {
+            VmInternalData vmInternalData = 
getRunningVms().get(vmDynamic.getId());
+            if (vmInternalData != null) {
+                Map<String, LUNs> lunsMap = vmInternalData.getLunsMap();
+                List<Disk> vmDisks = 
getDbFacade().getDiskDao().getAllForVm(vmDynamic.getId(), true);
+                for (Disk disk : vmDisks) {
+                    if (disk.getDiskStorageType() != DiskStorageType.LUN) {
+                        continue;
+                    }
+
+                    LUNs lunFromDB = ((LunDisk) disk).getLun();
+                    LUNs lunFromMap = lunsMap.get(lunFromDB.getId());
+
+                    if (lunFromMap != null && lunFromMap.getDeviceSize() != 0
+                            && lunFromMap.getDeviceSize() != 
lunFromDB.getDeviceSize()) {
+                        // Found a mismatch - set LUN for update
+                        log.infoFormat("Updated LUN device size - ID: {0}, 
previous size: {1}, new size: {2}.",
+                                lunFromDB.getLUN_id(), 
lunFromDB.getDeviceSize(), lunFromMap.getDeviceSize());
+
+                        lunFromDB.setDeviceSize(lunFromMap.getDeviceSize());
+                        _vmLunDisksToSave.add(lunFromDB);
                     }
                 }
             }
@@ -2080,6 +2116,23 @@
         return Collections.unmodifiableList(removedDeviceIds);
     }
 
+    /**
+     * An access method for test usages
+     *
+     * @return The LUNs to update in DB
+     */
+    protected List<LUNs> getVmLunDisksToSave() {
+        return Collections.unmodifiableList(_vmLunDisksToSave);
+    }
+
+    protected List<VmDynamic> getPoweringUpVms() {
+        return _poweringUpVms;
+    }
+
+    protected Map<Guid, VmInternalData> getRunningVms() {
+        return _runningVms;
+    }
+
     protected void auditLog(AuditLogableBase auditLogable, AuditLogType 
logType) {
         AuditLogDirector.log(auditLogable, logType);
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/ListVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/ListVDSCommand.java
index 9bb8edb..5366d0b 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/ListVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/ListVDSCommand.java
@@ -25,7 +25,7 @@
         Map<Guid, VmInternalData> returnVMs = new HashMap<Guid, 
VmInternalData>();
         for (int idx = 0; idx < mVmListReturn.mVmList.length; ++idx) {
             VmDynamic dynamicData = 
VdsBrokerObjectsBuilder.buildVMDynamicDataFromList(mVmListReturn.mVmList[idx]);
-            VmInternalData vmData = new VmInternalData(dynamicData, null, 
null);
+            VmInternalData vmData = new VmInternalData(dynamicData, null, 
null, null);
             returnVMs.put(dynamicData.getId(), vmData);
         }
         setReturnValue(returnVMs);
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
index dec1f79..de8d0d6 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
@@ -19,6 +19,7 @@
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.Entities;
+import org.ovirt.engine.core.common.businessentities.LUNs;
 import org.ovirt.engine.core.common.businessentities.SessionState;
 import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StorageType;
@@ -42,6 +43,7 @@
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.utils.EnumUtils;
+import org.ovirt.engine.core.common.utils.SizeConverter;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.RpmVersion;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -97,6 +99,34 @@
         return vmStatistics;
     }
 
+    public static Map<String, LUNs> buildVmLunDisksData(Map<String, Object> 
xmlRpcStruct) {
+        Map<String, Object> disks = (Map<String, Object>) 
xmlRpcStruct.get(VdsProperties.vm_disks);
+        Map<String, LUNs> lunsMap = new HashMap<>();
+
+        if (disks != null) {
+            for (Object diskAsObj : disks.values()) {
+                Map<String, Object> disk = (Map<String, Object>) diskAsObj;
+
+                String lunGuidString = AssignStringValue(disk, 
VdsProperties.lun_guid);
+                if (!StringUtils.isEmpty(lunGuidString)) {
+                    LUNs lun = new LUNs();
+                    lun.setLUN_id(lunGuidString);
+
+                    if (disk.containsKey(VdsProperties.disk_true_size)) {
+                        long sizeInBytes = AssignLongValue(disk, 
VdsProperties.disk_true_size);
+                        int sizeInGB = SizeConverter.convert(
+                                sizeInBytes, SizeConverter.SizeUnit.BYTES, 
SizeConverter.SizeUnit.GB).intValue();
+                        lun.setDeviceSize(sizeInGB);
+                    }
+
+                    lunsMap.put(lunGuidString, lun);
+                }
+            }
+        }
+
+        return lunsMap;
+    }
+
     public static void updateVMDynamicData(VmDynamic vm, Map<String, Object> 
xmlRpcStruct) {
         if (xmlRpcStruct.containsKey(VdsProperties.vm_guid)) {
             vm.setId(new Guid((String) 
xmlRpcStruct.get(VdsProperties.vm_guid)));
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
index ab492f5..2008cad 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java
@@ -170,6 +170,7 @@
     public static final String disk_true_size = "truesize";
     public static final String image_group_id = "imageID";
     public static final String size = "size";
+    public static final String lun_guid = "lunGUID";
 
     // Iso/Floppy related properties
     public static final String iso_list = "isolist";
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmStatsVdsBrokerCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmStatsVdsBrokerCommand.java
index 172c14a..d8c2141 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmStatsVdsBrokerCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmStatsVdsBrokerCommand.java
@@ -29,6 +29,7 @@
         VdsBrokerObjectsBuilder.updateVMDynamicData(vmDynamic, xmlRpcStruct);
         return new VmInternalData(vmDynamic,
                 VdsBrokerObjectsBuilder.buildVMStatisticsData(xmlRpcStruct),
-                
VdsBrokerObjectsBuilder.buildVmGuestAgentInterfacesData(vmDynamic.getId(), 
xmlRpcStruct));
+                
VdsBrokerObjectsBuilder.buildVmGuestAgentInterfacesData(vmDynamic.getId(), 
xmlRpcStruct),
+                VdsBrokerObjectsBuilder.buildVmLunDisksData(xmlRpcStruct));
     }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/entities/VmInternalData.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/entities/VmInternalData.java
index ee51798..e4a3b57 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/entities/VmInternalData.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/entities/VmInternalData.java
@@ -1,7 +1,9 @@
 package org.ovirt.engine.core.vdsbroker.vdsbroker.entities;
 
 import java.util.List;
+import java.util.Map;
 
+import org.ovirt.engine.core.common.businessentities.LUNs;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmGuestAgentInterface;
 import org.ovirt.engine.core.common.businessentities.VmStatistics;
@@ -16,12 +18,17 @@
     private VmStatistics vmStatistics;
     private List<VmGuestAgentInterface> vmGuestAgentInterfaces;
 
+    // A map represents VM's LUN disks (LUN ID -> LUNs object)
+    private Map<String, LUNs> lunsMap;
+
     public VmInternalData(VmDynamic vmDynamic,
             VmStatistics vmStatistics,
-            List<VmGuestAgentInterface> vmGuestAgentInterfaces) {
+            List<VmGuestAgentInterface> vmGuestAgentInterfaces,
+            Map<String, LUNs> lunsMap) {
         this.vmDynamic = vmDynamic;
         this.vmStatistics = vmStatistics;
         this.vmGuestAgentInterfaces = vmGuestAgentInterfaces;
+        this.lunsMap = lunsMap;
     }
 
     public VmDynamic getVmDynamic() {
@@ -48,6 +55,14 @@
         this.vmGuestAgentInterfaces = vmGuestAgentInterfaces;
     }
 
+    public Map<String, LUNs> getLunsMap() {
+        return lunsMap;
+    }
+
+    public void setLunsMap(Map<String, LUNs> lunsMap) {
+        this.lunsMap = lunsMap;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -55,6 +70,7 @@
         result = prime * result + ((vmDynamic == null) ? 0 : 
vmDynamic.hashCode());
         result = prime * result + ((vmGuestAgentInterfaces == null) ? 0 : 
vmGuestAgentInterfaces.hashCode());
         result = prime * result + ((vmStatistics == null) ? 0 : 
vmStatistics.hashCode());
+        result = prime * result + ((lunsMap == null) ? 0 : lunsMap.hashCode());
         return result;
     }
 
@@ -91,6 +107,13 @@
         } else if (!vmStatistics.equals(other.vmStatistics)) {
             return false;
         }
+        if (lunsMap == null) {
+            if (other.lunsMap != null) {
+                return false;
+            }
+        } else if (!lunsMap.equals(other.lunsMap)) {
+            return false;
+        }
         return true;
     }
 
diff --git 
a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfoTest.java
 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfoTest.java
index 21555c1..a4b0f4e 100644
--- 
a/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfoTest.java
+++ 
b/backend/manager/modules/vdsbroker/src/test/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfoTest.java
@@ -20,6 +20,9 @@
 import org.mockito.runners.MockitoJUnitRunner;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.AuditLog;
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.LUNs;
+import org.ovirt.engine.core.common.businessentities.LunDisk;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -30,11 +33,13 @@
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
 import org.ovirt.engine.core.dao.AuditLogDAO;
+import org.ovirt.engine.core.dao.DiskDao;
 import org.ovirt.engine.core.dao.VdsGroupDAO;
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.dao.VmDeviceDAO;
 import org.ovirt.engine.core.utils.MockEJBStrategyRule;
 import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.entities.VmInternalData;
 
 @RunWith(MockitoJUnitRunner.class)
 public class VdsUpdateRunTimeInfoTest {
@@ -44,6 +49,8 @@
 
     private VDS vds;
     HashMap[] vmInfo;
+    List<VmDynamic> poweringUpVms;
+    Map<Guid, VmInternalData> runningVms;
 
     VdsUpdateRunTimeInfo updater;
 
@@ -52,6 +59,9 @@
 
     @Mock
     VmDAO vmDAO;
+
+    @Mock
+    DiskDao diskDAO;
 
     @Mock
     DbFacade dbFacade;
@@ -85,6 +95,16 @@
             @Override
             protected Map[] getVmInfo(List<String> vmsToUpdate) {
                 return vmInfo;
+            }
+
+            @Override
+            protected List<VmDynamic> getPoweringUpVms() {
+                return poweringUpVms;
+            }
+
+            @Override
+            protected Map<Guid, VmInternalData> getRunningVms() {
+                return runningVms;
             }
 
         };
@@ -122,11 +142,60 @@
         assertEquals("wrong number of removed devices", 0, 
updater.getRemovedVmDevices().size());
     }
 
+    @Test
+    public void updateLunDisksNoMismatch() {
+        LUNs lun = new LUNs();
+        lun.setLUN_id(Guid.newGuid().toString());
+        lun.setDeviceSize(10);
+
+        LunDisk lunDisk = new LunDisk();
+        lunDisk.setLun(lun);
+
+        updateLunDisksTest(Collections.singletonMap(lun.getLUN_id(), lun), 
Collections.singletonList((Disk) lunDisk));
+
+        assertEquals("wrong number of LUNs to update", 0, 
updater.getVmLunDisksToSave().size());
+    }
+
+    @Test
+    public void updateLunDisksMismatch() {
+        String lunGuid = Guid.newGuid().toString();
+
+        LUNs lun1 = new LUNs();
+        lun1.setLUN_id(lunGuid);
+        lun1.setDeviceSize(10);
+
+        LUNs lun2 = new LUNs();
+        lun2.setLUN_id(lunGuid);
+        lun2.setDeviceSize(20);
+
+        LunDisk lunDisk = new LunDisk();
+        lunDisk.setLun(lun2);
+
+        updateLunDisksTest(Collections.singletonMap(lun1.getLUN_id(), lun1), 
Collections.singletonList((Disk) lunDisk));
+
+        assertEquals("wrong number of LUNs to update", 1, 
updater.getVmLunDisksToSave().size());
+    }
+
+    private void updateLunDisksTest(Map<String, LUNs> lunsMapFromVmStats, 
List<Disk> vmLunDisksFromDb) {
+        Guid vmId = Guid.newGuid();
+        VmDynamic vmDynamic = new VmDynamic();
+        vmDynamic.setId(vmId);
+        VmInternalData vmInternalData = new VmInternalData(vmDynamic, null, 
null, lunsMapFromVmStats);
+
+        when(diskDAO.getAllForVm(any(Guid.class), 
any(Boolean.class))).thenReturn(vmLunDisksFromDb);
+
+        poweringUpVms = Collections.singletonList(vmDynamic);
+        runningVms = Collections.singletonMap(vmId, vmInternalData);
+
+        updater.updateLunDisks();
+    }
+
     private void initConditions() {
         when(dbFacade.getVdsGroupDao()).thenReturn(groupDAO);
         when(dbFacade.getVmDao()).thenReturn(vmDAO);
         when(dbFacade.getAuditLogDao()).thenReturn(mockAuditLogDao);
         when(dbFacade.getVmDeviceDao()).thenReturn(vmDeviceDAO);
+        when(dbFacade.getDiskDao()).thenReturn(diskDAO);
         when(groupDAO.get((Guid) any())).thenReturn(cluster);
         Map<Guid, VM> emptyMap = Collections.emptyMap();
         when(vmDAO.getAllRunningByVds(vds.getId())).thenReturn(emptyMap);


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

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

Reply via email to