Sahina Bose has uploaded a new change for review. Change subject: engine: Validate on network remove/modify ......................................................................
engine: Validate on network remove/modify Validate that gluster bricks do not use the network on modification of networks with gluster role Change-Id: I5e1fb2a64e68d8b8e4574c8bf3ca0c8aeb03e744 Bug-Url: https://bugzilla.redhat.com/1222503 Signed-off-by: Sahina Bose <sab...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelperTest.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/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 6 files changed, 77 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/38/41538/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java index a8d6199..c0bd262 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelper.java @@ -25,6 +25,7 @@ import org.ovirt.engine.core.common.action.SetupNetworksParameters; import org.ovirt.engine.core.common.businessentities.Entities; import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; @@ -139,6 +140,7 @@ validateNetworkQos(); validateNotRemovingLabeledNetworks(); validateCustomProperties(); + validateNotRemovingGlusterBrickNetworks(); return translateViolations(); } @@ -159,6 +161,22 @@ } else { validateNicForNotRemovingLabeledNetworks(network, nic); } + } + } + } + + private void validateNotRemovingGlusterBrickNetworks() { + for (String network : removedNetworks) { + Network removedNetwork = getExistingClusterNetworks().get(network); + if (removedNetwork == null || removedNetwork.getCluster() == null + || !removedNetwork.getCluster().isGluster()) { + continue; + } + List<GlusterBrickEntity> bricks = + getDbFacade().getGlusterBrickDao().getAllByClusterAndNetworkId(vds.getVdsGroupId(), + removedNetwork.getId()); + if (!bricks.isEmpty()) { + addViolation(VdcBllMessages.ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK, network); } } } @@ -635,6 +653,9 @@ if (networkIpAddressWasSameAsHostnameAndChanged(iface)) { addViolation(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED, networkName); } + if (networkIpAddressUsedByBrickChanged(iface, network)) { + addViolation(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE, networkName); + } modifiedNetworks.add(network); } } else { @@ -675,6 +696,35 @@ return false; } + /** + * Checks if a network is configured incorrectly: + * <ul> + * <li>If the network is configured to use static IP address and the interface is used by gluster bricks, then it is + * forbidden to modify the IP address without replacing the bricks.</li> + * </ul> + * + * @param iface + * The network interface which carries the network + * @return <code>true</code> if the network was reconfigured improperly + */ + + private boolean networkIpAddressUsedByBrickChanged(VdsNetworkInterface iface, Network network) { + if (iface.getBootProtocol() == NetworkBootProtocol.STATIC_IP) { + List<GlusterBrickEntity> bricks = + getDbFacade().getGlusterBrickDao() + .getAllByClusterAndNetworkId(vds.getVdsGroupId(), network.getId()); + if (bricks.isEmpty()) { + return false; + } + VdsNetworkInterface existingIface = getExistingIfaceByNetwork(iface.getNetworkName()); + if (existingIface != null) { + String oldAddress = existingIface.getAddress(); + return !StringUtils.equals(oldAddress, iface.getAddress()); + } + } + return false; + } + private NetworkType determineNetworkType(Integer vlanId, boolean vmNetwork) { return vlanId != null ? NetworkType.VLAN : vmNetwork ? NetworkType.VM : NetworkType.NON_VM; } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelperTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelperTest.java index b8af6ce..d9cffcd 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelperTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/network/host/SetupNetworksHelperTest.java @@ -1,5 +1,15 @@ package org.ovirt.engine.core.bll.network.host; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; +import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig; + import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; @@ -32,21 +42,12 @@ import org.ovirt.engine.core.compat.Version; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dao.VdsDAO; +import org.ovirt.engine.core.dao.gluster.GlusterBrickDao; import org.ovirt.engine.core.dao.network.HostNetworkQosDao; import org.ovirt.engine.core.dao.network.InterfaceDao; import org.ovirt.engine.core.dao.network.NetworkDao; import org.ovirt.engine.core.utils.MockConfigRule; import org.ovirt.engine.core.utils.RandomUtils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; -import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig; @RunWith(MockitoJUnitRunner.class) public class SetupNetworksHelperTest { @@ -99,6 +100,9 @@ @Mock private HostNetworkQosDao qosDao; + + @Mock + private GlusterBrickDao brickDao; @Mock private ManagementNetworkUtil managementNetworkUtil; @@ -2282,6 +2286,7 @@ doReturn(mock(VdsDAO.class)).when(dbFacade).getVdsDao(); doReturn(networkDAO).when(dbFacade).getNetworkDao(); doReturn(qosDao).when(dbFacade).getHostNetworkQosDao(); + doReturn(brickDao).when(dbFacade).getGlusterBrickDao(); return helper; } 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 38902b9..98fb738 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 @@ -594,6 +594,7 @@ EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED(ErrorType.NOT_SUPPORTED), NETWORK_LABEL_FORMAT_INVALID(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC(ErrorType.CONFLICT), + ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK(ErrorType.CONFLICT), IMPROPER_INTERFACE_IS_LABELED(ErrorType.BAD_PARAMETERS), IMPROPER_BOND_IS_LABELED(ErrorType.BAD_PARAMETERS), INTERFACE_ALREADY_LABELED(ErrorType.CONFLICT), @@ -614,6 +615,7 @@ ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_UNSET(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_GLUSTER_NETWORK_INUSE(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED(ErrorType.BAD_PARAMETERS), + ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_EXTERNAL_NETWORK_ALREADY_EXISTS(ErrorType.CONFLICT), ACTION_TYPE_FAILED_EXTERNAL_NETWORK_DETAILS_CANNOT_BE_EDITED(ErrorType.NOT_SUPPORTED), ACTION_TYPE_FAILED_EXTERNAL_NETWORK_MUST_BE_VM_NETWORK(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 d3487d4..c0d22d0 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -547,6 +547,7 @@ NETWORK_LABEL_FORMAT_INVALID=Network label must be formed only from: English letters, numbers, hyphen or underscore. ACTION_TYPE_FAILED_NETWORK_ALREADY_LABELED=Cannot ${action} ${type}. The specified network is already labeled. ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC=Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are managed by the label: ${ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC_LIST}. Please remove the label from the network interface in order to remove the network. +ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK=Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are used by gluster volume bricks. Please remove or replace the bricks in order to remove the network. LABELED_NETWORK_ATTACHED_TO_WRONG_INTERFACE=Cannot ${action} ${type}. The following networks are already attached to a different interface on the host: ${AssignedNetworks}. Please remove the networks in order to label the interface. OTHER_INTERFACE_ALREADY_LABELED=Cannot ${action} ${type}. The label is already defined on other interface ${LabeledNic} on the host. @@ -669,6 +670,7 @@ ACTION_TYPE_FAILED_EXTERNAL_NETWORK_CANNOT_HAVE_MTU=Cannot ${action} ${type}. External network cannot have MTU set. ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED=Cannot ${action} ${type}. The management network '${NetworkName}' must be required, please change the network to be required and try again. ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED=Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED_LIST}' cannot be modified without reinstalling the host, since this address was used to create the host's certification. +ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE=Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE_LIST}' cannot be modified without removing or replacing the bricks, since this address was used to create gluster volume bricks. PLUGGED_UNLINKED_VM_INTERFACE_WITH_EXTERNAL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Plugged and unlinked VM network interface with external network is not supported. CANNOT_PREVIEW_ACTIVE_SNAPSHOT=Cannot preview Active VM snapshot. CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\ 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 3bd8209..df7b020 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 @@ -1540,6 +1540,9 @@ @DefaultStringValue("Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are managed by the label: ${ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC_LIST}. Please remove the label from the network interface in order to remove the network.") String ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC(); + @DefaultStringValue("Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are used by gluster volume bricks. Please remove or replace the bricks in order to remove the network.") + String ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK(); + @DefaultStringValue("Cannot ${action} ${type}. The following networks are already attached to a different interface: ${AssignedNetworks}. Please remove the networks in order to label the interface.") String LABELED_NETWORK_ATTACHED_TO_WRONG_INTERFACE(); @@ -1849,6 +1852,9 @@ @DefaultStringValue("Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED_LIST}' cannot be modified without reinstalling the host, since this address was used to create the host's certification.") String ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED(); + @DefaultStringValue("Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE_LIST}' cannot be modified without removing or replacing the bricks, since this address was used to create gluster volume bricks.") + String ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE(); + @DefaultStringValue("Cannot preview Active VM snapshot.") String CANNOT_PREVIEW_ACTIVE_SNAPSHOT(); 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 8748d94..13e9b97 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 @@ -555,6 +555,7 @@ NETWORK_LABEL_FORMAT_INVALID=Network label must be formed only from: English letters, numbers, hyphen or underscore. ACTION_TYPE_FAILED_NETWORK_ALREADY_LABELED=Cannot ${action} ${type}. The specified network is already labeled. ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC=Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are managed by the label: ${ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC_LIST}. Please remove the label from the network interface in order to remove the network. +ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK=Cannot ${action} ${type}. The following networks cannot be removed from the network interface since they are used by gluster volume bricks. Please remove or replace the bricks in order to remove the network. LABELED_NETWORK_ATTACHED_TO_WRONG_INTERFACE=Cannot ${action} ${type}. The following networks are already attached to a different interface: ${AssignedNetworks}. Please remove the networks in order to label the interface. OTHER_INTERFACE_ALREADY_LABELED=Cannot ${action} ${type}. The label is already defined on other interface ${LabeledNic} on the host. @@ -677,6 +678,7 @@ ACTION_TYPE_FAILED_EXTERNAL_NETWORK_CANNOT_HAVE_MTU=Cannot ${action} ${type}. External network cannot have MTU set. ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED=Cannot ${action} ${type}. The management network '${NetworkName}' must be required, please change the network to be required and try again. ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED=Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_CANNOT_BE_CHANGED_LIST}' cannot be modified without reinstalling the host, since this address was used to create the host's certification. +ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE=Cannot ${action} ${type}. The address of the network '${ACTION_TYPE_FAILED_NETWORK_ADDRESS_BRICK_IN_USE_LIST}' cannot be modified without removing or replacing the bricks, since this address was used to create gluster volume bricks. PLUGGED_UNLINKED_VM_INTERFACE_WITH_EXTERNAL_NETWORK_IS_NOT_SUPPORTED=Cannot ${action} ${type}. Plugged and unlinked VM network interface with external network is not supported. CANNOT_PREVIEW_ACTIVE_SNAPSHOT=Cannot preview Active VM snapshot. CONFIG_UNKNOWN_KEY=Illegal configuration entry.\n\ -- To view, visit https://gerrit.ovirt.org/41538 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5e1fb2a64e68d8b8e4574c8bf3ca0c8aeb03e744 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Sahina Bose <sab...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches