Tal Nisan has uploaded a new change for review.

Change subject: core: Prevent operations on the hosted engine disk
......................................................................

core: Prevent operations on the hosted engine disk

Prevent the hosted engine disk from being removed, attached to a VM or
updated

Change-Id: I75c1deee655278a8f575814aea22965be2bfee55
Bug-Url: https://bugzilla.redhat.com/1167668
Signed-off-by: Tal Nisan <tni...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmDiskCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/StorageConstants.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
11 files changed, 35 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/29/35829/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
index 1821dd3..c076dcb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java
@@ -63,6 +63,12 @@
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
         }
 
+        DiskValidator oldDiskValidator = new DiskValidator(disk);
+        ValidationResult isHostedEngineDisk = 
oldDiskValidator.validateNotHostedEngineDisk();
+        if (!isHostedEngineDisk.isValid()) {
+            return validate(isHostedEngineDisk);
+        }
+
         disk.setReadOnly(getParameters().isReadOnly());
         DiskValidator diskValidator = getDiskValidator(disk);
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
index 9f8016a..6bac5bb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveDiskCommand.java
@@ -15,6 +15,7 @@
 import org.ovirt.engine.core.bll.storage.StoragePoolValidator;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.validator.DiskImagesValidator;
+import org.ovirt.engine.core.bll.validator.DiskValidator;
 import org.ovirt.engine.core.bll.validator.StorageDomainValidator;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
@@ -83,7 +84,9 @@
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST);
         }
 
-        return validateAllVmsForDiskAreDown() &&
+        DiskValidator oldDiskValidator = new DiskValidator(getDisk());
+
+        return validate(oldDiskValidator.validateNotHostedEngineDisk()) && 
validateAllVmsForDiskAreDown() &&
                 canRemoveDiskBasedOnStorageTypeCheck();
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java
index 032675c..7d92a2a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmDiskCommand.java
@@ -135,6 +135,12 @@
             return false;
         }
 
+        DiskValidator oldDiskValidator = getDiskValidator(getOldDisk());
+        ValidationResult isHostedEngineDisk = 
oldDiskValidator.validateNotHostedEngineDisk();
+        if (!isHostedEngineDisk.isValid()) {
+            return validate(isHostedEngineDisk);
+        }
+
         if (!checkDiskUsedAsOvfStore(getOldDisk())) {
             return false;
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
index ce35bb3..be4b5b7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/DiskValidator.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
+import org.ovirt.engine.core.common.constants.StorageConstants;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
 import org.ovirt.engine.core.common.osinfo.OsRepository;
@@ -183,4 +184,12 @@
     private static OsRepository getOsRepository() {
         return SimpleDependecyInjector.getInstance().get(OsRepository.class);
     }
+
+
+    public ValidationResult validateNotHostedEngineDisk() {
+        boolean isHostedEngineDisk = disk.getDiskStorageType() == 
DiskStorageType.LUN &&
+                
StorageConstants.HOSTED_ENGINE_LUN_DISK_ALIAS.equals(disk.getDiskAlias());
+        return isHostedEngineDisk ? new 
ValidationResult(VdcBllMessages.ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK) :
+                ValidationResult.VALID;
+    }
 }
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 dc27391..d9286cf 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
@@ -427,7 +427,7 @@
 
         
when(diskValidator.isReadOnlyPropertyCompatibleWithInterface()).thenReturn(ValidationResult.VALID);
         
when(diskValidator.isDiskInterfaceSupported(any(VM.class))).thenReturn(new 
ValidationResult(VdcBllMessages.ACTION_TYPE_DISK_INTERFACE_UNSUPPORTED));
-        
when(command.getDiskValidator(any(Disk.class))).thenReturn(diskValidator);
+        
when(command.getDiskValidator(parameters.getDiskInfo())).thenReturn(diskValidator);
 
         VmDevice device = createVmDevice(diskImageGuid, vmId);
         doReturn(device).when(vmDeviceDAO).get(device.getId());
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/StorageConstants.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/StorageConstants.java
index 58c1932..31be55e 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/StorageConstants.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/StorageConstants.java
@@ -3,4 +3,6 @@
 public class StorageConstants {
     public static final int SIZE_IS_NOT_AVAILABLE = -1;
     public static final int OVF_MAX_ITEMS_PER_SQL_STATEMENT = 100;
+
+    public static final String HOSTED_ENGINE_LUN_DISK_ALIAS = "hosted_engine";
 }
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 04166ea..b00f8ef 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
@@ -205,6 +205,7 @@
     ACTION_TYPE_FAILED_DISK_LUN_HAS_NO_VALID_TYPE(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_DISK_LUN_INVALID(ErrorType.BAD_PARAMETERS),
+    ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_UNSUPPORTED_DISK_STORAGE_TYPE(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_UNAVAILABLE(ErrorType.BAD_PARAMETERS),
     
ACTION_TYPE_FAILED_STORAGE_DOMAIN_TYPE_UNSUPPORTED(ErrorType.BAD_PARAMETERS),
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 ed54961..bc7f0ec 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -217,6 +217,7 @@
 ACTION_TYPE_FAILED_DISK_LUN_HAS_NO_VALID_TYPE=Cannot ${action} ${type}. The 
provided lun has no valid lun type.
 ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS=Cannot ${action} 
${type}. The provided lun is missing at least one connection parameter 
(address/port/iqn).
 ACTION_TYPE_FAILED_DISK_LUN_INVALID=Cannot ${action} ${type}. The provided LUN 
is not visible by the specified host, please check storage server connectivity.
+ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK=Cannot ${action} ${type}. The disk 
contains the hosted engine.
 ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS=Cannot ${action} ${type}. VM 
migration is in progress
 ACTION_TYPE_FAILED_MIGRATION_TO_SAME_HOST=Cannot ${action} ${type}. source and 
destination is the same.
 ACTION_TYPE_FAILED_DESTINATION_HOST_NOT_IN_DESTINATION_CLUSTER=Cannot 
${action} ${type}. Destination host is not present in destination cluster.
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 c18ea5d..86bedf1 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
@@ -589,6 +589,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. The provided LUN is not 
visible by the specified host, please check storage server connectivity.")
     String ACTION_TYPE_FAILED_DISK_LUN_INVALID();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The disk contains the 
hosted engine.")
+    String ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK();
+
     @DefaultStringValue("Cannot ${action} ${type}. source and destination is 
the same.")
     String ACTION_TYPE_FAILED_MIGRATION_TO_SAME_HOST();
 
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 5d3a3c9..671e232 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
@@ -209,6 +209,7 @@
 ACTION_TYPE_FAILED_DISK_LUN_HAS_NO_VALID_TYPE=Cannot ${action} ${type}. The 
provided lun has no valid lun type.
 ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS=Cannot ${action} 
${type}. The provided lun is missing at least one connection parameter 
(address/port/iqn).
 ACTION_TYPE_FAILED_DISK_LUN_INVALID=Cannot ${action} ${type}. The provided LUN 
is not visible by the specified host, please check storage server connectivity.
+ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK=Cannot ${action} ${type}. The disk 
contains the hosted engine.
 ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS=Cannot ${action} ${type}. VM 
migration is in progress
 ACTION_TYPE_FAILED_MIGRATION_TO_SAME_HOST=Cannot ${action} ${type}. source and 
destination is the same.
 ACTION_TYPE_FAILED_DESTINATION_HOST_NOT_IN_DESTINATION_CLUSTER=Cannot 
${action} ${type}. Destination host is not present in destination cluster.
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 c858906..04ee933 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
@@ -214,6 +214,7 @@
 ACTION_TYPE_FAILED_DISK_LUN_HAS_NO_VALID_TYPE=Cannot ${action} ${type}. The 
provided lun has no valid lun type.
 ACTION_TYPE_FAILED_DISK_LUN_ISCSI_MISSING_CONNECTION_PARAMS=Cannot ${action} 
${type}. The provided lun is missing at least one connection parameter 
(address/port/iqn).
 ACTION_TYPE_FAILED_DISK_LUN_INVALID=Cannot ${action} ${type}. The provided LUN 
is not visible by the specified host, please check storage server connectivity.
+ACTION_TYPE_FAILED_HOSTED_ENGINE_DISK=Cannot ${action} ${type}. The disk 
contains the hosted engine.
 ACTION_TYPE_FAILED_DISK_LUN_IS_ALREADY_IN_USE=Cannot ${action} ${type}. The 
provided lun is used by another disk.
 ACTION_TYPE_FAILED_MIGRATION_IN_PROGRESS=Cannot ${action} ${type}. VM 
migration is in progress
 ACTION_TYPE_FAILED_MIGRATION_TO_SAME_HOST=Cannot ${action} ${type}. source and 
destination is the same.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I75c1deee655278a8f575814aea22965be2bfee55
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Tal Nisan <tni...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to