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 <[email protected]>
---
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, 70 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/30/41930/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 f5ca097..a8e7ffd 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
@@ -20,6 +20,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.Network;
 import 
org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
@@ -122,6 +123,7 @@
         validateNetworkQos();
         validateNotRemovingLabeledNetworks();
         validateCustomProperties();
+        validateNotRemovingGlusterBrickNetworks();
 
         return translateViolations();
     }
@@ -142,6 +144,21 @@
                 } else {
                     validateNicForNotRemovingLabeledNetworks(network, nic);
                 }
+            }
+        }
+    }
+
+    private void validateNotRemovingGlusterBrickNetworks() {
+        for (String network : removedNetworks) {
+            Network removedNetwork = getExistingClusterNetworks().get(network);
+            if (removedNetwork == 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);
             }
         }
     }
@@ -469,6 +486,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 {
@@ -509,6 +529,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.isNotEmpty(oldAddress) && 
!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 4af6322..24195ff 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
@@ -30,6 +30,7 @@
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import 
org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol;
+import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
 import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import org.ovirt.engine.core.common.businessentities.network.ProviderNetwork;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
@@ -39,6 +40,7 @@
 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.InterfaceDao;
 import org.ovirt.engine.core.dao.network.NetworkDao;
 import org.ovirt.engine.core.dao.network.NetworkQoSDao;
@@ -87,6 +89,9 @@
 
     @Mock
     private NetworkQoSDao qosDao;
+
+    @Mock
+    private GlusterBrickDao brickDao;
 
     /* --- Tests for networks functionality --- */
 
@@ -1629,7 +1634,9 @@
      * @return A network with some defaults and the given name,
      */
     private Network createNetwork(String networkName) {
-        return new Network("", "", Guid.newGuid(), networkName, "", "", 0, 
null, false, 0, true);
+        Network net = new Network("", "", Guid.newGuid(), networkName, "", "", 
0, null, false, 0, true);
+        net.setCluster(new NetworkCluster());
+        return net;
     }
 
     /**
@@ -1962,6 +1969,7 @@
         doReturn(mock(VdsDAO.class)).when(dbFacade).getVdsDao();
         doReturn(networkDAO).when(dbFacade).getNetworkDao();
         doReturn(qosDao).when(dbFacade).getNetworkQosDao();
+        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 405ed9a..5e0518f 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
@@ -561,6 +561,7 @@
     NETWORK_LABEL_FORMAT_INVALID(ErrorType.BAD_PARAMETERS),
     
ACTION_TYPE_FAILED_CANNOT_REMOVE_LABELED_NETWORK_FROM_NIC(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_DISPLAY_NETWORK_HAS_NO_BOOT_PROTOCOL(ErrorType.BAD_PARAMETERS),
+    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),
@@ -579,6 +580,7 @@
     ACTION_TYPE_FAILED_MANAGEMENT_NETWORK_REQUIRED(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 b4ee43a..554ca53 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -530,6 +530,7 @@
 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_DISPLAY_NETWORK_HAS_NO_BOOT_PROTOCOL=Cannot ${action} 
${type}. The display network ${DisplayNetwork} must have a DHCP or Static boot 
protocol when configured on a host.
+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: 
${ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK_LIST}. 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.
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.
@@ -627,6 +628,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 0c2fa50..5b264cd 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
@@ -1489,6 +1489,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. The display network 
${DisplayNetwork} must have a DHCP or Static boot protocol when configured on a 
host.")
     String ACTION_TYPE_FAILED_DISPLAY_NETWORK_HAS_NO_BOOT_PROTOCOL();
 
+    @DefaultStringValue("Cannot ${action} ${type}. The following networks 
cannot be removed from the network interface since they are used by gluster 
volume bricks: ${ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK_LIST}. 
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();
 
@@ -1732,6 +1735,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 ae44413..e11abe7 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
@@ -537,6 +537,7 @@
 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_DISPLAY_NETWORK_HAS_NO_BOOT_PROTOCOL=Cannot ${action} 
${type}. The display network ${DisplayNetwork} must have a DHCP or Static boot 
protocol when configured on a host.
+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: 
${ACTION_TYPE_FAILED_CANNOT_REMOVE_NETWORK_FROM_BRICK_LIST}. 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.
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.
@@ -634,6 +635,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/41930
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e1fb2a64e68d8b8e4574c8bf3ca0c8aeb03e744
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Sahina Bose <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to