Moti Asayag has uploaded a new change for review.

Change subject: engine: Display network must have an IP address
......................................................................

engine: Display network must have an IP address

The setup networks should block any request which
configure the display network on the host without
an IP address, either DHCP or by setting a static
IP address.

Change-Id: I14e5a0edae8524a7334609e58934880a722ca87f
Bug-Url: https://bugzilla.redhat.com/955429
Signed-off-by: Moti Asayag <[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, 90 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/16/25016/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 d644bed..4f0e6d4 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
@@ -101,10 +101,30 @@
         validateMTU();
         validateNetworkQos();
         validateNotRemovingLabeledNetworks();
+        validateDisplayNetwork();
 
         return translateViolations();
     }
 
+    private void validateDisplayNetwork() {
+        String displayNetwork = null;
+
+        for (Network network : getExistingClusterNetworks().values()) {
+            if (network.getCluster().isDisplay()) {
+                displayNetwork = network.getName();
+                break;
+            }
+        }
+
+        if (displayNetwork != null && 
Entities.entitiesByName(getNetworks()).containsKey(displayNetwork)) {
+            VdsNetworkInterface nic = 
Entities.hostInterfacesByNetworkName(params.getInterfaces()).get(displayNetwork);
+            if (nic.getBootProtocol() == NetworkBootProtocol.NONE) {
+                
addViolation(VdcBllMessages.ACTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS,
+                        displayNetwork);
+            }
+        }
+    }
+
     private void validateNotRemovingLabeledNetworks() {
         Map<String, VdsNetworkInterface> nicsByName = 
Entities.entitiesByName(params.getInterfaces());
         Map<String, VdsNetworkInterface> hostInterfacesByNetworkName =
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 b9ca651..1fd1ac2 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
@@ -28,6 +28,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;
@@ -1290,6 +1291,55 @@
         validateAndExpectMtuValidation(helper, net, newNet);
     }
 
+    @Test
+    public void displayNetworkWithNoneBootProtocol() {
+        Network net = createDisplayNetwork();
+        mockExistingNetworks(net);
+
+        VdsNetworkInterface nic = createNic("nic0", null);
+        mockExistingIfaces(nic);
+
+        nic.setNetworkName(net.getName());
+        nic.setBootProtocol(NetworkBootProtocol.NONE);
+        SetupNetworksHelper helper = 
createHelper(createParametersForNics(nic));
+
+        validateAndExpectViolation(helper,
+                
VdcBllMessages.ACTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS,
+                net.getName());
+    }
+
+    @Test
+    public void displayNetworkWithDhcpBootProtocol() {
+        Network net = createDisplayNetwork();
+        mockExistingNetworks(net);
+
+        VdsNetworkInterface nic = createNic("nic0", null);
+        mockExistingIfaces(nic);
+
+        nic.setNetworkName(net.getName());
+        nic.setBootProtocol(NetworkBootProtocol.DHCP);
+        SetupNetworksHelper helper = 
createHelper(createParametersForNics(nic));
+
+        validateAndAssertNetworkModified(helper, net);
+    }
+
+    @Test
+    public void removeIpFromdisplayNetwork() {
+        Network net = createDisplayNetwork();
+        mockExistingNetworks(net);
+
+        VdsNetworkInterface nic = createNicSyncedWithNetwork("nic0", net);
+        nic.setBootProtocol(NetworkBootProtocol.DHCP);
+        mockExistingIfaces(nic);
+
+        nic.setBootProtocol(NetworkBootProtocol.NONE);
+        SetupNetworksHelper helper = 
createHelper(createParametersForNics(nic));
+
+        validateAndExpectViolation(helper,
+                
VdcBllMessages.ACTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS,
+                net.getName());
+    }
+
     private void validateAndExpectMtuValidation(SetupNetworksHelper helper, 
Network net1, Network net2) {
         validateAndExpectViolation(helper, 
VdcBllMessages.NETWORK_MTU_DIFFERENCES,
                 String.format("[%s(%s), %s(%d)]",
@@ -1773,7 +1823,21 @@
         return qos;
     }
 
+    public Network createDisplayNetwork() {
+        Network net = createNetwork("display");
+        NetworkCluster networkCluster = new NetworkCluster();
+        networkCluster.setDisplay(true);
+        net.setCluster(networkCluster);
+        return net;
+    }
+
     private void mockExistingNetworks(Network... networks) {
+        for (Network network : networks) {
+            if (network.getCluster() == null) {
+                network.setCluster(new NetworkCluster());
+            }
+        }
+
         
when(networkDAO.getAllForCluster(any(Guid.class))).thenReturn(Arrays.asList(networks));
     }
 
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 4fefc75..43fd28f 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
@@ -498,6 +498,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_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS(ErrorType.BAD_PARAMETERS),
     IMPROPER_INTERFACE_IS_LABELED(ErrorType.BAD_PARAMETERS),
     INTERFACE_ALREADY_LABELED(ErrorType.CONFLICT),
     INTERFACE_NOT_LABELED(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 bd56137..0699cd0 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -489,6 +489,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_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS=Cannot 
${action} ${type}. The display network 
${CTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS_LIST} 
must have a DHCP or Static boot protocol when conifgured on the host.
 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.
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 0509596..2d7c002 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
@@ -1357,6 +1357,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 display network 
${CTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS_LIST} 
must have a DHCP or Static boot protocol when conifgured on the host.")
+    String 
ACTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS();
+
     @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();
 
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 c01b29b..bc24158 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
@@ -493,6 +493,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_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS=Cannot 
${action} ${type}. The display network 
${CTION_TYPE_FAILED_CANNOT_CONFIGURE_DISPLAY_NETWORK_WITHOUT_IP_ADDRESS_LIST} 
must have a DHCP or Static boot protocol when conifgured on the host.
 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.


-- 
To view, visit http://gerrit.ovirt.org/25016
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I14e5a0edae8524a7334609e58934880a722ca87f
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

Reply via email to