cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [1/2] Contrail VRouter plugin major bug fixes for CS 4.3
Date Sat, 11 Jan 2014 00:06:42 GMT
Updated Branches:
  refs/heads/4.3 5c4caf0b9 -> dc511dd95


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc511dd9/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
index b4968ac..f05517f 100644
--- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
@@ -23,7 +23,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.cloudstack.network.contrail.management.ContrailManager;
 import org.apache.log4j.Logger;
 
 import com.cloud.dc.VlanVO;
@@ -39,8 +38,10 @@ import net.juniper.contrail.api.types.NetworkIpam;
 import net.juniper.contrail.api.types.Project;
 import net.juniper.contrail.api.types.SubnetType;
 import net.juniper.contrail.api.types.VirtualNetwork;
+import net.juniper.contrail.api.types.VirtualNetworkPolicyType;
 import net.juniper.contrail.api.types.VnSubnetsType;
 import net.juniper.contrail.api.ApiConnector;
+import org.apache.cloudstack.network.contrail.management.ContrailManager;
 
 public class VirtualNetworkModel extends ModelObjectBase {
     private static final Logger s_logger = Logger.getLogger(VirtualNetworkModel.class);
@@ -65,6 +66,7 @@ public class VirtualNetworkModel extends ModelObjectBase {
     private NetworkIpam _ipam;
 
     private FloatingIpPoolModel _fipPoolModel;
+    private NetworkPolicyModel _policyModel;
 
     public VirtualNetworkModel(Network network, String uuid, String name, TrafficType trafficType)
{
         _uuid = uuid;
@@ -132,6 +134,10 @@ public class VirtualNetworkModel extends ModelObjectBase {
             successor.delete(controller);
         }
 
+        if (_policyModel != null) {
+            _policyModel.removeSuccessor(this);
+        }
+
         try {
             api.delete(VirtualNetwork.class, _uuid);
         } catch (IOException ex) {
@@ -180,6 +186,8 @@ public class VirtualNetworkModel extends ModelObjectBase {
                 s_logger.warn("Unable to read virtual-network", ex);
             }
         }
+
+        _id = network.getId();
         
         try {
             _projectId = manager.getProjectId(network.getDomainId(), network.getAccountId());
@@ -225,6 +233,16 @@ public class VirtualNetworkModel extends ModelObjectBase {
                 vn.setUuid(_uuid);
             } 
         }
+
+        if (_policyModel == null) {
+            vn.clearNetworkPolicy();
+        } else if (!_policyModel.hasPolicyRules()) {
+            vn.clearNetworkPolicy();
+            _policyModel.removeSuccessor(this);
+        } else {
+            vn.setNetworkPolicy(_policyModel.getPolicy(), new VirtualNetworkPolicyType(
+                    new VirtualNetworkPolicyType.SequenceType(1, 0), null));
+        }
      
         if (_ipam == null) {
             NetworkIpam ipam = null;
@@ -403,7 +421,23 @@ public class VirtualNetworkModel extends ModelObjectBase {
                     "; db: " + dbSubnets + ", vnc: " + vncSubnets + ", diff: " + diff);
             return false;
         }
-        
+
+        List<ObjectReference<VirtualNetworkPolicyType>> policyRefs = _vn.getNetworkPolicy();
+        if ((policyRefs == null || policyRefs.isEmpty()) && _policyModel != null)
{
+            return false;
+        }
+
+        if ((policyRefs != null && !policyRefs.isEmpty()) && _policyModel
== null) {
+            return false;
+        }
+
+        if (policyRefs != null && !policyRefs.isEmpty() && _policyModel !=
null) {
+            ObjectReference<VirtualNetworkPolicyType> ref = policyRefs.get(0);
+            if (!ref.getUuid().equals(_policyModel.getUuid())) {
+                return false; 
+            }
+        }
+
         for (ModelObject successor: successors()) {
             if (!successor.verify(controller)) {
                 return false;
@@ -415,8 +449,6 @@ public class VirtualNetworkModel extends ModelObjectBase {
     @Override
     public boolean compare(ModelController controller, ModelObject o) {
         VirtualNetworkModel latest;
-        ApiConnector api = controller.getApiAccessor();
-
         assert this._vn != null : "vnc virtual network current is not initialized";
 
         try {
@@ -481,14 +513,64 @@ public class VirtualNetworkModel extends ModelObjectBase {
                     "; db: " + currentSubnets + ", vnc: " + newSubnets + ", diff: " + diff);
             return false;
         }
-                
+
+        List<ObjectReference<VirtualNetworkPolicyType>> currentPolicyRefs = this._vn.getNetworkPolicy();
+        List<ObjectReference<VirtualNetworkPolicyType>> latestPolicyRefs = latest._vn.getNetworkPolicy();
+
+        if (currentPolicyRefs == null && latestPolicyRefs == null) {
+            return true;
+        }
+
+        if ((currentPolicyRefs == null && latestPolicyRefs != null) ||
+                (currentPolicyRefs != null && latestPolicyRefs == null) || 
+                (currentPolicyRefs.size() != latestPolicyRefs.size())) {
+            return false;
+        }
+
+        if (currentPolicyRefs.isEmpty() && latestPolicyRefs.isEmpty()) {
+            return true;
+        }
+
+        //both must be non empty lists
+        ObjectReference<VirtualNetworkPolicyType> ref1 = currentPolicyRefs.get(0);
+        ObjectReference<VirtualNetworkPolicyType> ref2 = latestPolicyRefs.get(0);
+
+        if ((ref1 != null && ref2 == null) || (ref1 == null && ref2 != null))
{
+            return false;
+        }
+
+        if ((ref1.getUuid() != null && ref2.getUuid() == null) || (ref1.getUuid()
== null && ref2.getUuid() != null)) {
+            return false;
+        }
+        if (ref1.getUuid() == null && ref2.getUuid() == null) {
+            return true;
+        }
+        if (!ref1.getUuid().equals(ref2.getUuid())) {
+            return false; 
+        }
         return true;
     }
 
     public FloatingIpPoolModel getFipPoolModel() {
         return _fipPoolModel;
     }
+
     public void setFipPoolModel(FloatingIpPoolModel fipPoolModel) {
         _fipPoolModel = fipPoolModel;
     }
+
+    public NetworkPolicyModel getNetworkPolicyModel() {
+        return _policyModel;
+    }
+
+    public void addToNetworkPolicy(NetworkPolicyModel policyModel) {
+        if (_policyModel != null) {
+            _policyModel.removeSuccessor(this);
+        }
+        _policyModel = policyModel;
+        if (_policyModel != null) {
+            _policyModel.addSuccessor(this);
+        }
+    } 
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc511dd9/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
index ac93cbd..bbff466 100644
--- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
@@ -348,12 +348,12 @@ public class ManagementServerMock {
         }
 
         Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers
=
-                _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrail.getName(),
+                _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(),
                         null, null, null);
         if (providers.second() == 0) {
-            s_logger.debug("Add " + Provider.JuniperContrail.getName() + " to network " +
_znet.getName());
+            s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network
" + _znet.getName());
             PhysicalNetworkServiceProvider provider =
-                    _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrail.getName(),
+                    _networkService.addProviderToPhysicalNetwork(_znet.getId(), Provider.JuniperContrailRouter.getName(),
                             null, null);
             _networkService.updateNetworkServiceProvider(provider.getId(),
                     PhysicalNetworkServiceProvider.State.Enabled.toString(), null);
@@ -369,7 +369,7 @@ public class ManagementServerMock {
                 PhysicalNetworkServiceProvider.State.Enabled.toString(), null, null);
         s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled
providers");
         for (PhysicalNetworkServiceProvider provider: providers.first()) {
-            if (provider.getProviderName().equals(Provider.JuniperContrail.getName())) {
+            if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName()))
{
                 continue;
             }
             s_logger.debug("Disabling " + provider.getProviderName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dc511dd9/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
index 40cd1ea..33e5633 100644
--- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
@@ -203,7 +203,7 @@ public class NetworkProviderTest extends TestCase {
         ManagementServerMock.setParameter(cmd, "accountName", BaseCmd.CommandType.STRING,
system.getAccountName());
         ManagementServerMock.setParameter(cmd, ApiConstants.NAME, BaseCmd.CommandType.STRING,
name);
         ManagementServerMock.setParameter(cmd, "displayText", BaseCmd.CommandType.STRING,
"test network");
-        ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG,
_contrailMgr.getOffering().getId());
+        ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG,
__contrailMgr.getRouterOffering().getId());
         ManagementServerMock.setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
         ManagementServerMock.setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING,
"10.0.1.254");
         ManagementServerMock.setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING,
"255.255.255.0");


Mime
View raw message