Daniel Erez has uploaded a new change for review.

Change subject: core: prevent disabling VirtIO-SCSI on edit VM
......................................................................

core: prevent disabling VirtIO-SCSI on edit VM

When a disk with VirtIO-SCSI interface is plugged to a VM,
disabling VirtIO-SCSI should be prevented.

Change-Id: Ic2e6c85a2df434de3180f19a32079f276458d372
Signed-off-by: Daniel Erez <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
7 files changed, 44 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/19637/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
index da20d8a..95459f2 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
@@ -24,6 +24,7 @@
 import org.ovirt.engine.core.common.action.WatchdogParameters;
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.DiskInterface;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
@@ -370,6 +371,15 @@
             return 
failCanDoAction(VdcBllMessages.VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL);
         }
 
+        if (Boolean.FALSE.equals(getParameters().isVirtioScsiEnabled())) {
+            List<Disk> allDisks = getDiskDao().getAllForVm(getVmId(), true);
+            for (Disk disk : allDisks) {
+                if (disk.getDiskInterface() == DiskInterface.VirtIO_SCSI) {
+                    return 
failCanDoAction(VdcBllMessages.CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS);
+                }
+            }
+        }
+
         if (getParameters().isVirtioScsiEnabled() != null && !getVm().isDown()
                 && vmDeviceChanged(VmDeviceGeneralType.CONTROLLER, 
getParameters().isVirtioScsiEnabled())) {
             addCanDoActionMessage("$device VirtIO-SCSI");
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
index e7b384d..8316308 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
@@ -12,6 +12,7 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -21,6 +22,9 @@
 import org.mockito.runners.MockitoJUnitRunner;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VmManagementParametersBase;
+import org.ovirt.engine.core.common.businessentities.Disk;
+import org.ovirt.engine.core.common.businessentities.DiskImage;
+import org.ovirt.engine.core.common.businessentities.DiskInterface;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
@@ -32,6 +36,7 @@
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dao.DiskDao;
 import org.ovirt.engine.core.dao.VdsDAO;
 import org.ovirt.engine.core.dao.VmDAO;
 import org.ovirt.engine.core.utils.MockConfigRule;
@@ -50,6 +55,8 @@
     private VmDAO vmDAO;
     @Mock
     private VdsDAO vdsDAO;
+    @Mock
+    private DiskDao diskDAO;
 
     @Mock
     OsRepository osRepository;
@@ -222,6 +229,21 @@
         assertCanDoActionMessage(VdcBllMessages.VM_CANNOT_UPDATE_CLUSTER);
     }
 
+    @Test
+    public void testCannotDisableVirtioScsi() {
+        prepareVmToPassCanDoAction();
+        command.getParameters().setVirtioScsiEnabled(false);
+
+        Disk disk = new DiskImage();
+        disk.setDiskInterface(DiskInterface.VirtIO_SCSI);
+        disk.setPlugged(true);
+
+        mockDiskDaoGetAllForVm(Collections.singletonList(disk), true);
+
+        CanDoActionTestUtils.runAndAssertCanDoActionFailure(command,
+                VdcBllMessages.CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS);
+    }
+
     private void prepareVmToPassCanDoAction() {
         vmStatic.setName("vm1");
         vmStatic.setMemSizeMb(256);
@@ -238,6 +260,11 @@
                         .contains(msg.name()));
     }
 
+    private void mockDiskDaoGetAllForVm(List<Disk> disks, boolean 
onlyPluggedDisks) {
+        doReturn(diskDAO).when(command).getDiskDao();
+        doReturn(disks).when(diskDAO).getAllForVm(vm.getId(), 
onlyPluggedDisks);
+    }
+
     private void mockVmDaoGetVm() {
         doReturn(vmDAO).when(command).getVmDAO();
         when(vmDAO.get(any(Guid.class))).thenReturn(vm);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 59c5bb3..0559f6a 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -673,6 +673,7 @@
     SCSI_GENERIC_IO_IS_NOT_SUPPORTED_FOR_IMAGE_DISK(ErrorType.NOT_SUPPORTED),
     
VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL(ErrorType.INCOMPATIBLE_VERSION),
     CANNOT_PERFORM_ACTION_VIRTIO_SCSI_IS_DISABLED(ErrorType.CONFLICT),
+    CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_QUOTA_NOT_EXIST(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_QUOTA_IS_NOT_VALID(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_NO_QUOTA_SET_FOR_DOMAIN(ErrorType.CONFLICT),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 145ee71..1e430ba 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -861,6 +861,7 @@
 SCSI_GENERIC_IO_IS_NOT_SUPPORTED_FOR_IMAGE_DISK="Cannot ${action} ${type}. 
SCSI Generic IO is not supported for image disk."
 VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL=Virtio-SCSI interface 
is only available on cluster level 3.3 or higher.
 CANNOT_PERFORM_ACTION_VIRTIO_SCSI_IS_DISABLED=Cannot ${action} ${type}. 
VirtIO-SCSI is disabled for the VM
+CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS=Cannot disable VirtIO-SCSI while 
disks that attached with VirtIO-SCSI interface are plugged to the VM.
 
 #Suspected (not in use?)
 USER_PASSWORD_EXPIRED=Cannot Login. User Password has expired, Please change 
your password.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index 0b26802..91f0215 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -2329,6 +2329,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. VirtIO-SCSI is disabled for 
the VM")
     String CANNOT_PERFORM_ACTION_VIRTIO_SCSI_IS_DISABLED();
 
+    @DefaultStringValue("Cannot disable VirtIO-SCSI while disks that attached 
with VirtIO-SCSI interface are plugged to the VM.")
+    String CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS();
+
     // Suspected (not in use?)
     @DefaultStringValue("Cannot Login. User Password has expired, Please 
change your password.")
     String USER_PASSWORD_EXPIRED();
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 7eb9fc0..d81b045 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -839,6 +839,7 @@
 SCSI_GENERIC_IO_IS_NOT_SUPPORTED_FOR_IMAGE_DISK="Cannot ${action} ${type}. 
SCSI Generic IO is not supported for image disk."
 VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL=Virtio-SCSI interface 
is only available on cluster level 3.3 or higher.
 CANNOT_PERFORM_ACTION_VIRTIO_SCSI_IS_DISABLED=Cannot ${action} ${type}. 
VirtIO-SCSI is disabled for the VM
+CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS=Cannot disable VirtIO-SCSI while 
disks that attached with VirtIO-SCSI interface are plugged to the VM.
 
 #Suspected (not in use?)
 USER_PASSWORD_EXPIRED=Cannot Login. User Password has expired, Please change 
your password.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index f486e7f..19a543b 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -861,6 +861,7 @@
 SCSI_GENERIC_IO_IS_NOT_SUPPORTED_FOR_IMAGE_DISK="Cannot ${action} ${type}. 
SCSI Generic IO is not supported for image disk."
 VIRTIO_SCSI_INTERFACE_IS_NOT_AVAILABLE_FOR_CLUSTER_LEVEL=Virtio-SCSI interface 
is only available on cluster level 3.3 or higher.
 CANNOT_PERFORM_ACTION_VIRTIO_SCSI_IS_DISABLED=Cannot ${action} ${type}. 
VirtIO-SCSI is disabled for the VM
+CANNOT_DISABLE_VIRTIO_SCSI_PLUGGED_DISKS=Cannot disable VirtIO-SCSI while 
disks that attached with VirtIO-SCSI interface are plugged to the VM.
 
 #Suspected (not in use?)
 USER_PASSWORD_EXPIRED=Cannot Login. User Password has expired, Please change 
your password.


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

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

Reply via email to