Liron Ar has uploaded a new change for review. Change subject: core: deleting template with shared volumes should fail ......................................................................
core: deleting template with shared volumes should fail When deleting a template that has disks that other disks were created from the operation should fail to avoid possible deletion of only part of the template/error on the delete attempt as the volume is shared. Change-Id: If781238d7be4768b1086645c64b4ccf807dc6108 Bug-Url: https://bugzilla.redhat.com/953492 Signed-off-by: Liron Aravot <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.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, 35 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/62/22162/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java index 23c4cc8..a00880c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmTemplateCommand.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -24,8 +25,8 @@ import org.ovirt.engine.core.common.businessentities.StorageDomainStatic; import org.ovirt.engine.core.common.businessentities.VM; import org.ovirt.engine.core.common.businessentities.VmTemplate; -import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.utils.Pair; import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.dbbroker.DbFacade; @@ -153,6 +154,27 @@ return false; } + return checkNoDisksBasedOnTemplateDisks(); + } + + private boolean checkNoDisksBasedOnTemplateDisks() { + List<String> disksInfo = null; + for (DiskImage diskImage : imageTemplates) { + List<DiskImage> basedDisks = getDiskImageDAO().getAllSnapshotsForParent(diskImage.getImageId()); + for (DiskImage basedDisk : basedDisks) { + if (disksInfo == null) { + disksInfo = new LinkedList<>(); + } + disksInfo.add(String.format("Disk Alias: %s, Disk Id: %s ", basedDisk.getDiskAlias(), basedDisk.getId())); + } + } + + if (disksInfo != null) { + return failCanDoAction(VdcBllMessages.VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS, + String.format("$disksInfo %s", + String.format(StringUtils.join(disksInfo, "%n")))); + } + return true; } 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 a5a169c..6e7c6b4 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 @@ -348,6 +348,7 @@ // internal const string VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM = // "Cannot delete the template, there are desktop(s) created from template"; VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM(ErrorType.CONFLICT), + VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS(ErrorType.CONFLICT), VMT_CANNOT_CREATE_TEMPLATE_FROM_DOWN_VM(ErrorType.CONFLICT), VMT_CANNOT_REMOVE_BLANK_TEMPLATE(ErrorType.CONFLICT), VMT_CANNOT_EDIT_BLANK_TEMPLATE(ErrorType.CONFLICT), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java index 4c54157..e33bbcb 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogableBase.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.transaction.Transaction; import org.apache.commons.lang.StringUtils; @@ -25,6 +24,7 @@ import org.ovirt.engine.core.dao.AdGroupDAO; import org.ovirt.engine.core.dao.AsyncTaskDAO; import org.ovirt.engine.core.dao.DbUserDAO; +import org.ovirt.engine.core.dao.DiskImageDAO; import org.ovirt.engine.core.dao.PermissionDAO; import org.ovirt.engine.core.dao.RoleDAO; import org.ovirt.engine.core.dao.RoleGroupMapDAO; @@ -630,6 +630,10 @@ return getDbFacade().getNetworkDao(); } + protected DiskImageDAO getDiskImageDAO() { + return getDbFacade().getDiskImageDao(); + } + public AsyncTaskDAO getAsyncTaskDao() { return getDbFacade().getAsyncTaskDao(); } 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 167c94c..48cee87 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -10,6 +10,7 @@ IRS_RESPONSE_ERROR=Storage Manager response error. MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES=Not enough MAC addresses left in MAC Address Pool. VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is being used by the following VMs: ${vmsList}. +VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS=Cannot delete Template. The following Disk(s) are based on the Template disk(s): \n ${disksInfo} VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template does not exist on the following Storage Domains: ${domainsList}.\nEither verify that Template exists on all Storage Domains listed on the domains list,\nor do not send domains list in order to delete all instances of the Template from the system. ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Image does not exist. ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Snapshot does not exist. 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 09d572a..1f02930 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 @@ -40,6 +40,9 @@ @DefaultStringValue("Cannot delete Template. Template is being used by the following VMs: ${vmsList}.") String VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM(); + @DefaultStringValue("Cannot delete Template. The following Disk(s) are based on the Template disk(s): \n ${disksInfo}") + String VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS(); + @DefaultStringValue("Cannot delete Template. The Template does not exist on the following Storage Domains: ${domainsList}.\nEither verify that Template exists on all Storage Domains listed on the domains list,\nor do not send domains list in order to delete all instances of the Template from the system.") String VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH(); 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 c0b95d8..5cc79d4 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 @@ -10,6 +10,7 @@ IRS_RESPONSE_ERROR=Storage Manager response error. MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES=Not enough MAC addresses left in MAC Address Pool. VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is being used by the following VMs: ${vmsList}. +VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS=Cannot delete Template. The following Disk(s) are based on the Template disk(s): \n ${disksInfo} VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template does not exist on the following Storage Domains: ${domainsList}.\nEither verify that Template exists on all Storage Domains listed on the domains list,\nor do not send domains list in order to delete all instances of the Template from the system. ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Image does not exist. ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Snapshot does not exist. 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 7fce703..0027ee2 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 @@ -10,6 +10,7 @@ IRS_RESPONSE_ERROR=Storage Manager response error. MAC_POOL_NOT_ENOUGH_MAC_ADDRESSES=Not enough MAC addresses left in MAC Address Pool. VMT_CANNOT_REMOVE_DETECTED_DERIVED_VM=Cannot delete Template. Template is being used by the following VMs: ${vmsList}. +VMT_CANNOT_REMOVE_DETECTED_DERIVED_DISKS=Cannot delete Template. The following Disk(s) are based on the Template disk(s): \n ${disksInfo} VMT_CANNOT_REMOVE_DOMAINS_LIST_MISMATCH=Cannot delete Template. The Template does not exist on the following Storage Domains: ${domainsList}.\nEither verify that Template exists on all Storage Domains listed on the domains list,\nor do not send domains list in order to delete all instances of the Template from the system. ACTION_TYPE_FAILED_VM_IMAGE_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Image does not exist. ACTION_TYPE_FAILED_VM_SNAPSHOT_DOES_NOT_EXIST=Cannot ${action} ${type}. VM's Snapshot does not exist. -- To view, visit http://gerrit.ovirt.org/22162 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If781238d7be4768b1086645c64b4ccf807dc6108 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liron Ar <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
