Moti Asayag has uploaded a new change for review. Change subject: engine: Block nic labeling if network assigned to other ......................................................................
engine: Block nic labeling if network assigned to other In case a network that should be attached to a newly labeled nic is already attached to other nic on the host, the action should be blocked. Note that the interfaces are being fetched from the DB in order to preserve the network bootprotocol and prior configuration. Change-Id: I4d3d0b179ea1cdc1ed1e3c9901d8b4813130b9ce Signed-off-by: Moti Asayag <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelNicCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Entities.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, 71 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/31/23031/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelNicCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelNicCommand.java index ff0beb6..5c66c73 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelNicCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelNicCommand.java @@ -30,6 +30,8 @@ public class LabelNicCommand<T extends LabelNicParameters> extends CommandBase<T> { private VdsNetworkInterface nic; + private List<Network> labeledNetworks; + private List<VdsNetworkInterface> hostNics; public LabelNicCommand(T parameters) { super(parameters); @@ -40,7 +42,9 @@ protected void executeCommand() { VdcReturnValueBase result = getBackend().runInternalAction(VdcActionType.PersistentSetupNetworks, - new AddNetworksByLabelParametersBuilder().buildParameters(getNic(), getLabel())); + new AddNetworksByLabelParametersBuilder().buildParameters(getNic(), + getLabel(), + getClusterNetworksByLabel())); if (result.getSucceeded()) { getReturnValue().setActionReturnValue(getLabel()); } else { @@ -70,7 +74,51 @@ return failCanDoAction(VdcBllMessages.IMPROPER_INTERFACE_IS_LABELED); } + for (VdsNetworkInterface nic : getHostInterfaces()) { + if (!StringUtils.equals(nic.getName(), getNicName()) && nic.getLabels() != null + && nic.getLabels().contains(getLabel())) { + return failCanDoAction(VdcBllMessages.OTHER_INTERFACE_ALREADY_LABELED, "$LabeledNic " + nic.getName()); + } + } + + List<String> assignedNetworks = validateNetworksNotAssignedToIncorrectNics(); + if (!assignedNetworks.isEmpty()) { + return failCanDoAction(VdcBllMessages.LABELED_NETWORK_ATTACHED_TO_WRONG_INTERFACE, "$AssignedNetworks " + + StringUtils.join(assignedNetworks.toArray(new String[assignedNetworks.size()]), ", ")); + } + return true; + } + + private List<VdsNetworkInterface> getHostInterfaces() { + if (hostNics == null) { + hostNics = getDbFacade().getInterfaceDao().getAllInterfacesForVds(getVdsId()); + } + + return hostNics; + } + + public List<String> validateNetworksNotAssignedToIncorrectNics() { + Map<String, VdsNetworkInterface> nicsByNetworkName = Entities.hostInterfacesByNetworkName(getHostInterfaces()); + List<String> badlyAssignedNetworks = new ArrayList<>(); + for (Network network : getClusterNetworksByLabel()) { + if (nicsByNetworkName.containsKey(network.getName())) { + VdsNetworkInterface assignedNic = nicsByNetworkName.get(network.getName()); + if (!StringUtils.equals(getNicName(), NetworkUtils.stripVlan(assignedNic.getName()))) { + badlyAssignedNetworks.add(network.getName()); + } + } + } + + return badlyAssignedNetworks; + } + + private List<Network> getClusterNetworksByLabel() { + if (labeledNetworks == null) { + labeledNetworks = getNetworkDAO().getAllByLabelForCluster(getLabel(), getVds().getVdsGroupId()); + } + + return labeledNetworks; } @Override @@ -104,9 +152,10 @@ private class AddNetworksByLabelParametersBuilder extends NetworkParametersBuilder { - public SetupNetworksParameters buildParameters(VdsNetworkInterface nic, String label) { + public SetupNetworksParameters buildParameters(VdsNetworkInterface nic, + String label, + List<Network> labeledNetworks) { SetupNetworksParameters parameters = createSetupNetworksParameters(nic.getVdsId()); - List<Network> labeledNetworks = getNetworkDAO().getAllByLabelForCluster(label, getVds().getVdsGroupId()); Set<Network> networkToAdd = getNetworksToConfigure(parameters.getInterfaces(), labeledNetworks); VdsNetworkInterface nicToConfigure = getNicToConfigure(parameters.getInterfaces(), nic.getId()); if (nicToConfigure == null) { diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Entities.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Entities.java index 74b08d3..e636023 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Entities.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/Entities.java @@ -65,7 +65,9 @@ if (entityList != null) { Map<String, E> map = new HashMap<String, E>(); for (E e : entityList) { - map.put(e.getNetworkName(), e); + if (e.getNetworkName() != null) { + map.put(e.getNetworkName(), e); + } } return map; } else { 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 cdcf44e..0f5b63b 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 @@ -484,6 +484,8 @@ IMPROPER_INTERFACE_IS_LABELED(ErrorType.BAD_PARAMETERS), INTERFACE_ALREADY_LABELED(ErrorType.CONFLICT), INTERFACE_NOT_LABELED(ErrorType.CONFLICT), + LABELED_NETWORK_ATTACHED_TO_WRONG_INTERFACE(ErrorType.CONFLICT), + OTHER_INTERFACE_ALREADY_LABELED(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VNIC_PROFILE_NOT_EXISTS(ErrorType.BAD_PARAMETERS), ACTION_TYPE_FAILED_VNIC_PROFILE_NAME_IN_USE(ErrorType.CONFLICT), ACTION_TYPE_FAILED_VNIC_PROFILE_IN_USE(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 7a56e12..3406974 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -476,6 +476,8 @@ 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. +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. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. ERROR_CANNOT_RECOVERY_STORAGE_POOL_STORAGE_TYPE_MISSMATCH=Cannot recover Data Center. Mismatch between Storage Domain type and Data Center type. ERROR_CANNOT_DETACH_LAST_STORAGE_DOMAIN=Cannot remove the master Storage Domain from the Data Center without another active Storage Domain to take its place.\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 de306a7..e65a46c 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 @@ -1319,6 +1319,12 @@ @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 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(); + + @DefaultStringValue("Cannot ${action} ${type}. The label is already defined on other interface ${LabeledNic} on the host.") + String OTHER_INTERFACE_ALREADY_LABELED(); + @DefaultStringValue("Cannot recover Data Center with active Data Storage Domain in Data Center.") String ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS(); 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 d920d25..ed19224 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 @@ -456,6 +456,9 @@ 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. +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. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. ERROR_CANNOT_RECOVERY_STORAGE_POOL_STORAGE_TYPE_MISSMATCH=Cannot recover Data Center. Mismatch between Storage Domain type and Data Center type. ERROR_CANNOT_DETACH_LAST_STORAGE_DOMAIN=Cannot remove the master Storage Domain from the Data Center without another active Storage Domain to take its place.\n\ 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 96c2d09..d48248e 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 @@ -480,6 +480,9 @@ 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. +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. ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover Data Center with active Data Storage Domain in Data Center. ERROR_CANNOT_RECOVERY_STORAGE_POOL_STORAGE_TYPE_MISSMATCH=Cannot recover Data Center. Mismatch between Storage Domain type and Data Center type. ERROR_CANNOT_DETACH_LAST_STORAGE_DOMAIN=Cannot remove the master Storage Domain from the Data Center without another active Storage Domain to take its place.\n\ -- To view, visit http://gerrit.ovirt.org/23031 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4d3d0b179ea1cdc1ed1e3c9901d8b4813130b9ce Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
