Maor Lipchuk has uploaded a new change for review. Change subject: core: Block removing network when it's related to iSCSI bond. ......................................................................
core: Block removing network when it's related to iSCSI bond. Add validation which should block remove of network when it is related to the iSCSI bond. Change-Id: I68bd390175d42ee4e33773e12d6184a97a755eed Bug-Url: https://bugzilla.redhat.com/1094196 Signed-off-by: Maor Lipchuk <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/RemoveNetworkCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkValidator.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/dao/IscsiBondDao.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDaoDbFacadeImpl.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/IscsiBondDaoTest.java 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 M packaging/dbscripts/iscsi_bonds_sp.sql 11 files changed, 55 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/13/30913/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/RemoveNetworkCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/RemoveNetworkCommand.java index 1e26af6..2c4515c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/RemoveNetworkCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/dc/RemoveNetworkCommand.java @@ -82,6 +82,7 @@ NetworkValidator validator = new NetworkValidator(getNetworkDAO().get(getNetwork().getId())); return validate(validator.networkIsSet()) && validate(validator.notManagementNetwork()) + && validate(validator.notISCSIBondNetwork()) && validate(validator.networkNotUsedByVms()) && validate(validator.networkNotUsedByTemplates()); } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkValidator.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkValidator.java index 732670e..1146a5c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkValidator.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/NetworkValidator.java @@ -1,10 +1,12 @@ package org.ovirt.engine.core.bll.validator; +import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.ovirt.engine.core.bll.ValidationResult; import org.ovirt.engine.core.common.FeatureSupported; +import org.ovirt.engine.core.common.businessentities.IscsiBond; import org.ovirt.engine.core.common.businessentities.Nameable; import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.VM; @@ -142,10 +144,28 @@ : ValidationResult.VALID; } + public ValidationResult notISCSIBondNetwork() { + List<IscsiBond> iscsiBonds = getDbFacade().getIscsiBondDao().getIscsiBondsByNetworkId(network.getId()); + if (!iscsiBonds.isEmpty()) { + List<String> bondNames = new ArrayList<>(); + for (IscsiBond iscsiBond : iscsiBonds) { + bondNames.add(iscsiBond.getName()); + } + return new ValidationResult(VdcBllMessages.NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK, + getNetworkNameReplacement(), + getIscsiBondsReplacement(bondNames)); + } + return ValidationResult.VALID; + } + private String getNetworkNameReplacement() { return String.format("$NetworkName %s", network.getName()); } + private String getIscsiBondsReplacement(List iscsiBonds) { + return String.format("$IscsiBonds %s", iscsiBonds.toString()); + } + protected ValidationResult networkNotUsed(List<? extends Nameable> entities, VdcBllMessages entitiesReplacement) { if (entities.isEmpty()) { return ValidationResult.VALID; 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 515e9cc..615ee9c 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 @@ -494,6 +494,7 @@ NETWORK_INTERFACE_VM_CANNOT_BE_SET(ErrorType.BAD_PARAMETERS), NETWORK_INTERFACE_NOT_ATTACH_TO_NETWORK(ErrorType.CONFLICT), NETWORK_CANNOT_REMOVE_MANAGEMENT_NETWORK(ErrorType.CONSTRAINT_VIOLATION), + NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK(ErrorType.CONSTRAINT_VIOLATION), NETWORK_BOND_NAME_EXISTS(ErrorType.CONFLICT), NETWORK_BOND_PARAMETERS_INVALID(ErrorType.BAD_PARAMETERS), NETWORK_DEFAULT_UPDATE_NAME_INVALID(ErrorType.BAD_PARAMETERS), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDao.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDao.java index 04f95dd..89645f3 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDao.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDao.java @@ -11,6 +11,8 @@ public List<Guid> getNetworkIdsByIscsiBondId(Guid iscsiBondId); + public List<IscsiBond> getIscsiBondsByNetworkId(Guid netowrkId); + public void addNetworkToIscsiBond(Guid iscsiBondId, Guid networkId); public void removeNetworkFromIscsiBond(Guid iscsiBondId, Guid networkId); diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDaoDbFacadeImpl.java index bb3f925..15197a1 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/IscsiBondDaoDbFacadeImpl.java @@ -30,6 +30,13 @@ } @Override + public List<IscsiBond> getIscsiBondsByNetworkId(Guid netowrkId) { + return getCallsHandler().executeReadList("GetIscsiByNetworkId", + IscsiBondRowMapper.instance, + getCustomMapSqlParameterSource().addValue("network_id", netowrkId)); + } + + @Override public void addNetworkToIscsiBond(Guid iscsiBondId, Guid networkId) { getCallsHandler().executeModification("AddNetworkToIscsiBond", getCustomMapSqlParameterSource() 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 877ff7b..501c1ed 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -611,6 +611,7 @@ VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL=VM can be moved only to a Cluster in the same Data Center. VM_CLUSTER_IS_NOT_VALID=Cannot ${action} ${type}. Cluster ID is not valid. NETWORK_CANNOT_REMOVE_MANAGEMENT_NETWORK=The Management Network ('${NetworkName}') is mandatory and cannot be removed. +NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK=The Management Network ('${NetworkName}') could not be removed since it is part of the following iSCSI bonds: ${IscsiBonds}. Please, remove the network, first from those iSCSI bonds, and try again. NETWORK_OLD_NETWORK_NOT_SPECIFIED=Previous network name is required. ACTION_TYPE_FAILED_DETECTED_ACTIVE_VMS=Cannot ${action} ${type}. Active VMs were detected.\n\ -Please ensure all VMs associated with this Storage Domain are stopped and in the Down state first. diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/IscsiBondDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/IscsiBondDaoTest.java index 86820e0..2fb79b1 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/IscsiBondDaoTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/IscsiBondDaoTest.java @@ -110,6 +110,13 @@ } @Test + public void testGetIscsiBondIdByNetworkId() { + List<IscsiBond> fetchedIscsiBonds = dao.getIscsiBondsByNetworkId(FixturesTool.NETWORK_ENGINE); + assertEquals(1, fetchedIscsiBonds.size()); + assertEquals(FixturesTool.ISCSI_BOND_ID, fetchedIscsiBonds.get(0).getId()); + } + + @Test public void testRemoveNetworkFromIscsiBond() { List<Guid> networks = dao.getNetworkIdsByIscsiBondId(iscsiBondId); networkId = networks.get(0); 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 e96acbb..231671c 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 @@ -1684,6 +1684,9 @@ @DefaultStringValue("The Management Network ('${NetworkName}') is mandatory and cannot be removed.") String NETWORK_CANNOT_REMOVE_MANAGEMENT_NETWORK(); + @DefaultStringValue("The Management Network ('${NetworkName}') could not be removed since it is part of the following iSCSI bonds: ${IscsiBonds}. Please, remove the network, first from those iSCSI bonds, and try again.") + String NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK(); + @DefaultStringValue("Previous network name is required.") String NETWORK_OLD_NETWORK_NOT_SPECIFIED(); 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 4ad7728..ffa006e 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 @@ -581,6 +581,7 @@ VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL=VM can be moved only to a Cluster in the same Data Center. VM_CLUSTER_IS_NOT_VALID=Cannot ${action} ${type}. Cluster ID is not valid. NETWORK_CANNOT_REMOVE_MANAGEMENT_NETWORK=The Management Network ('${NetworkName}') is mandatory and cannot be removed. +NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK=The Management Network ('${NetworkName}') could not be removed since it is part of the following iSCSI bonds: ${IscsiBonds}. Please, remove the network, first from those iSCSI bonds, and try again. NETWORK_OLD_NETWORK_NOT_SPECIFIED=Previous network name is required. ACTION_TYPE_FAILED_DETECTED_ACTIVE_VMS=Cannot ${action} ${type}. Active VMs were detected.\n\ -Please ensure all VMs associated with this Storage Domain are stopped and in the Down state first. 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 081f8e3..c6d5ed4 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 @@ -616,6 +616,7 @@ VM_CANNOT_MOVE_TO_CLUSTER_IN_OTHER_STORAGE_POOL=VM can be moved only to a Cluster in the same Data Center. VM_CLUSTER_IS_NOT_VALID=Cannot ${action} ${type}. Cluster ID is not valid. NETWORK_CANNOT_REMOVE_MANAGEMENT_NETWORK=The Management Network ('${NetworkName}') is mandatory and cannot be removed. +NETWORK_CANNOT_REMOVE_ISCSI_BOND_NETWORK=The Management Network ('${NetworkName}') could not be removed since it is part of the following iSCSI bonds: ${IscsiBonds}. Please, remove the network, first from those iSCSI bonds, and try again. NETWORK_OLD_NETWORK_NOT_SPECIFIED=Previous network name is required. ACTION_TYPE_FAILED_DETECTED_ACTIVE_VMS=Cannot ${action} ${type}. Active VMs were detected.\n\ -Please ensure all VMs associated with this Storage Domain are stopped and in the Down state first. diff --git a/packaging/dbscripts/iscsi_bonds_sp.sql b/packaging/dbscripts/iscsi_bonds_sp.sql index 5d34bd7..9e49220 100644 --- a/packaging/dbscripts/iscsi_bonds_sp.sql +++ b/packaging/dbscripts/iscsi_bonds_sp.sql @@ -41,6 +41,17 @@ LANGUAGE plpgsql; +Create or replace FUNCTION GetIscsiByNetworkId(v_network_id UUID) RETURNS SETOF iscsi_bonds STABLE + AS $procedure$ +BEGIN + RETURN QUERY SELECT iscsi_bonds.* + FROM iscsi_bonds_networks_map, iscsi_bonds + WHERE iscsi_bonds.id = iscsi_bonds_networks_map.iscsi_bond_id + AND network_id = v_network_id; +END; $procedure$ +LANGUAGE plpgsql; + + Create or replace FUNCTION InsertIscsiBond(v_id UUID, v_name VARCHAR(50), v_description VARCHAR(4000), -- To view, visit http://gerrit.ovirt.org/30913 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I68bd390175d42ee4e33773e12d6184a97a755eed Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Maor Lipchuk <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
