Liron Aravot has uploaded a new change for review.

Change subject: core: clear disk device address when it's being unplugged from 
a vm
......................................................................

core: clear disk device address when it's being unplugged from a vm

Change-Id: If82c8983089916ab1c58dd0330442c3aff8d6d02
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1079697
Signed-off-by: Liron Aravot <lara...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotUnPlugDiskFromVmCommand.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
A packaging/dbscripts/upgrade/03_06_0080_clear_address_for_unplugged_disks.sql
6 files changed, 13 insertions(+), 43 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/31007/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
index 9f2f97c..d98575b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
@@ -2,7 +2,6 @@
 
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -30,7 +29,7 @@
 public class HotPlugDiskToVmCommand<T extends HotPlugDiskToVmParameters> 
extends AbstractDiskVmCommand<T> {
 
     private Disk disk;
-    private VmDevice oldVmDevice;
+    protected VmDevice oldVmDevice;
 
     public HotPlugDiskToVmCommand(T parameters) {
         super(parameters);
@@ -132,16 +131,14 @@
 
     @Override
     protected void executeVmCommand() {
-        clearAddressAlreadyInUse();
-
         if (getVm().getStatus().isUpOrPaused()) {
             updateDisksFromDb();
             performPlugCommand(getPlugAction(), getDisk(), oldVmDevice);
         }
 
         // At this point disk is already plugged to or unplugged from VM 
(depends on the command),
-        // so device's 'isPlugged' property should be updated accordingly in DB
-        updateDeviceIsPluggedProperty();
+        // so we can update the needed device properties
+        updateDeviceProperties();
 
         // Now after updating 'isPlugged' property of the plugged/unplugged 
device, its time to
         // update the boot order for all VM devices. Failure to do that 
doesn't change the fact that
@@ -154,27 +151,9 @@
         setSucceeded(true);
     }
 
-    /**
-     * Clear the device address if a device is being hot plugged and its 
stored address is already in use by another
-     * plugged device
-     **/
-    private void clearAddressAlreadyInUse() {
-        if (oldVmDevice.getIsPlugged() || oldVmDevice.getAddress().isEmpty()) {
-            return;
-        }
-        List<VmDevice> devices = 
getVmDeviceDao().getVmDeviceByVmIdAndAddress(getVmId(), 
oldVmDevice.getAddress());
-        for (VmDevice device : devices) {
-            if (!device.getId().equals(oldVmDevice.getId()) && 
device.getIsPlugged()) {
-                oldVmDevice.setAddress("");
-                getVmDeviceDao().clearDeviceAddress(oldVmDevice.getDeviceId());
-                break;
-            }
-        }
-    }
-
-    private void updateDeviceIsPluggedProperty() {
+    protected void updateDeviceProperties() {
         VmDevice device = getVmDeviceDao().get(oldVmDevice.getId());
-        device.setIsPlugged(!oldVmDevice.getIsPlugged());
+        device.setIsPlugged(true);
         getVmDeviceDao().updateHotPlugDisk(device);
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotUnPlugDiskFromVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotUnPlugDiskFromVmCommand.java
index 3e93d6e..229031c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotUnPlugDiskFromVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotUnPlugDiskFromVmCommand.java
@@ -15,6 +15,12 @@
 
     }
 
+    protected void updateDeviceProperties() {
+        oldVmDevice.setIsPlugged(false);
+        oldVmDevice.setAddress("");
+        getVmDeviceDao().update(oldVmDevice);
+    }
+
     @Override
     protected LockProperties applyLockProperties(LockProperties 
lockProperties) {
         return lockProperties.withScope(Scope.Execution);
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
index f97e918..ef90a84 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
@@ -31,8 +31,6 @@
             Guid userID,
             boolean isFiltered);
 
-    List<VmDevice> getVmDeviceByVmIdAndAddress(Guid vmID, String address);
-
     List<VmDevice> getUnmanagedDevicesByVmId(Guid vmId);
 
     boolean isMemBalloonEnabled(Guid vmId);
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
index 3f7b836..f0c4a82 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAODbFacadeImpl.java
@@ -109,15 +109,6 @@
     }
 
     @Override
-    public List<VmDevice> getVmDeviceByVmIdAndAddress(Guid vmId, String 
address) {
-        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
-                .addValue("vm_id", vmId)
-                .addValue("address", address);
-        return getCallsHandler().executeReadList("GetVmDeviceByVmIdAndAddress",
-                createEntityRowMapper(), parameterSource);
-    }
-
-    @Override
     public List<VmDevice> getUnmanagedDevicesByVmId(Guid vmId) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("vm_id", vmId);
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
index 392d71b..e01a8af 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmDeviceDAOTest.java
@@ -102,12 +102,6 @@
     }
 
     @Test
-    public void testGetVmDeviceByVmIdAndAddress() {
-        List<VmDevice> devices = 
dao.getVmDeviceByVmIdAndAddress(EXISTING_VM_ID, "sample");
-        assertTrue("The list should not be empty", !devices.isEmpty());
-    }
-
-    @Test
     public void 
testGetVmDeviceByVmIdTypeAndDeviceFilteringWithoutPermissions() {
         List<VmDevice> devices =
                 dao.getVmDeviceByVmIdTypeAndDevice(EXISTING_VM_ID,
diff --git 
a/packaging/dbscripts/upgrade/03_06_0080_clear_address_for_unplugged_disks.sql 
b/packaging/dbscripts/upgrade/03_06_0080_clear_address_for_unplugged_disks.sql
new file mode 100644
index 0000000..0a9941a
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_06_0080_clear_address_for_unplugged_disks.sql
@@ -0,0 +1,2 @@
+UPDATE vm_device SET address = ''
+WHERE is_managed AND device = 'disk' AND NOT is_plugged;
\ No newline at end of file


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

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

Reply via email to