cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject [2/2] git commit: updated refs/heads/cisco-vnmc-api-integration to 5a427d4
Date Wed, 27 Mar 2013 04:24:43 GMT
Added unit test for Vnmc network element implement() method


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5a427d48
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5a427d48
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5a427d48

Branch: refs/heads/cisco-vnmc-api-integration
Commit: 5a427d48e20f50260b80c57f6e4c3bc6d9057c3f
Parents: 48cbf34
Author: Koushik Das <koushik.das@citrix.com>
Authored: Wed Mar 27 02:22:54 2013 +0530
Committer: Koushik Das <koushik.das@citrix.com>
Committed: Wed Mar 27 02:22:54 2013 +0530

----------------------------------------------------------------------
 .../network/element/CiscoVnmcElementTest.java      |  112 ++++++++++++++-
 1 files changed, 105 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5a427d48/plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java
b/plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java
index 09b1d40..f4160bd 100755
--- a/plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java
+++ b/plugins/network-elements/cisco-vnmc/test/com/cloud/network/element/CiscoVnmcElementTest.java
@@ -16,6 +16,8 @@
 // under the License.
 package com.cloud.network.element;
 
+import java.net.URI;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
@@ -25,29 +27,49 @@ import org.junit.Before;
 import org.junit.Test;
 import org.mockito.internal.matchers.Any;
 
-import com.cloud.api.response.CiscoVnmcResourceResponse;
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand;
+import com.cloud.agent.api.ConfigureNexusVsmForAsaCommand;
+import com.cloud.agent.api.CreateLogicalEdgeFirewallCommand;
+import com.cloud.agent.api.routing.SetSourceNatCommand;
 import com.cloud.configuration.ConfigurationManager;
+import com.cloud.dc.ClusterVSMMapVO;
 import com.cloud.dc.DataCenter;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.dao.ClusterVSMMapDao;
+import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.domain.Domain;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
 import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
+import com.cloud.network.CiscoNexusVSMDeviceVO;
+import com.cloud.network.IpAddress;
 import com.cloud.network.NetworkManager;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.addr.PublicIp;
+import com.cloud.network.cisco.CiscoAsa1000vDeviceVO;
 import com.cloud.network.cisco.CiscoVnmcControllerVO;
+import com.cloud.network.cisco.NetworkAsa1000vMapVO;
+import com.cloud.network.dao.CiscoAsa1000vDao;
+import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
 import com.cloud.network.dao.CiscoVnmcDao;
-import com.cloud.network.dao.CiscoVnmcDaoImpl;
+import com.cloud.network.dao.NetworkAsa1000vMapDao;
 import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.resource.ResourceManager;
 import com.cloud.user.Account;
+import com.cloud.utils.net.Ip;
 import com.cloud.vm.ReservationContext;
 
 import static org.junit.Assert.*;
@@ -56,18 +78,32 @@ import static org.mockito.Mockito.*;
 public class CiscoVnmcElementTest {
 
     CiscoVnmcElement _element = new CiscoVnmcElement();
+    AgentManager _agentMgr = mock(AgentManager.class);
     NetworkManager _networkMgr = mock(NetworkManager.class);
     NetworkModel _networkModel = mock(NetworkModel.class);
+    HostDao _hostDao = mock(HostDao.class);
     NetworkServiceMapDao _ntwkSrvcDao = mock(NetworkServiceMapDao.class);
     ConfigurationManager _configMgr = mock(ConfigurationManager.class);
     CiscoVnmcDao _ciscoVnmcDao = mock(CiscoVnmcDao.class);
+    CiscoAsa1000vDao _ciscoAsa1000vDao = mock(CiscoAsa1000vDao.class);
+    NetworkAsa1000vMapDao _networkAsa1000vMapDao = mock(NetworkAsa1000vMapDao.class);
+    ClusterVSMMapDao _clusterVsmMapDao = mock(ClusterVSMMapDao.class);
+    CiscoNexusVSMDeviceDao _vsmDeviceDao = mock(CiscoNexusVSMDeviceDao.class);
+    VlanDao _vlanDao = mock(VlanDao.class);
 
     @Before
     public void setUp() throws ConfigurationException {
         _element._resourceMgr = mock(ResourceManager.class);
+        _element._agentMgr = _agentMgr;
         _element._networkMgr = _networkMgr;
+        _element._networkModel = _networkModel;
+        _element._hostDao = _hostDao;
         _element._configMgr = _configMgr;
         _element._ciscoVnmcDao = _ciscoVnmcDao;
+        _element._ciscoAsa1000vDao = _ciscoAsa1000vDao;
+        _element._networkAsa1000vMapDao = _networkAsa1000vMapDao;
+        _element._clusterVsmMapDao = _clusterVsmMapDao;
+        _element._vsmDeviceDao = _vsmDeviceDao;
 
         // Standard responses
         when(_networkModel.isProviderForNetwork(Provider.CiscoVnmc, 1L)).thenReturn(true);
@@ -88,10 +124,15 @@ public class CiscoVnmcElementTest {
 
     @Test
     public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
+    	URI uri = URI.create("vlan://123");
+
         Network network = mock(Network.class);
         when(network.getId()).thenReturn(1L);
         when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
         when(network.getDataCenterId()).thenReturn(1L);
+        when(network.getGateway()).thenReturn("1.1.1.1");
+        when(network.getBroadcastUri()).thenReturn(uri);
+        when(network.getCidr()).thenReturn("1.1.1.0/24");
 
         NetworkOffering offering = mock(NetworkOffering.class);
         when(offering.getId()).thenReturn(1L);
@@ -101,21 +142,78 @@ public class CiscoVnmcElementTest {
         DeployDestination dest = mock(DeployDestination.class);
 
         Domain dom = mock(Domain.class);
-        when(dom.getName()).thenReturn("domain");
+        when(dom.getName()).thenReturn("d1");
         Account acc = mock(Account.class);
-        when(acc.getAccountName()).thenReturn("accountname");
+        when(acc.getAccountName()).thenReturn("a1");
         ReservationContext context = mock(ReservationContext.class);
         when(context.getDomain()).thenReturn(dom);
         when(context.getAccount()).thenReturn(acc);
 
         DataCenter dc = mock(DataCenter.class);
         when(_configMgr.getZone(network.getDataCenterId())).thenReturn(dc);
+        when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
 
         @SuppressWarnings("unchecked")
         List<CiscoVnmcControllerVO> devices = mock(List.class);
         when(devices.isEmpty()).thenReturn(false);
-        when(_ciscoVnmcDao.listByPhysicalNetwork(network.getId())).thenReturn(devices);
-        //assertTrue(_element.implement(network, offering, dest, context));
+        when(devices.get(0)).thenReturn(mock(CiscoVnmcControllerVO.class));
+        when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
+
+        CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
+        when(asaVO.getInPortProfile()).thenReturn("foo");
+        when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
+
+        List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
+        asaList.add(asaVO);
+        when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
+
+        when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
+        when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
+        when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
+
+        when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat,
Provider.CiscoVnmc)).thenReturn(true);
+
+        ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
+        when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
+
+        CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
+        when(vsmDevice.getUserName()).thenReturn("foo");
+        when(vsmDevice.getPassword()).thenReturn("bar");
+        when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
+        when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
+
+        HostVO hostVO = mock(HostVO.class);
+        when(hostVO.getId()).thenReturn(1L);
+        when(_hostDao.findById(anyLong())).thenReturn(hostVO);
+
+        Ip ip = mock(Ip.class);
+        when(ip.addr()).thenReturn("1.2.3.4");
+
+        PublicIp publicIp = mock(PublicIp.class);
+        when(publicIp.getAddress()).thenReturn(ip);
+        when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
+        when(publicIp.getAccountId()).thenReturn(1L);
+        when(publicIp.isSourceNat()).thenReturn(true);
+        when(publicIp.getVlanTag()).thenReturn("123");
+        when(publicIp.getGateway()).thenReturn("1.1.1.1");
+        when(publicIp.getNetmask()).thenReturn("1.1.1.1");
+        when(publicIp.getMacAddress()).thenReturn(null);
+        when(publicIp.isOneToOneNat()).thenReturn(true);
+        when(_networkMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
+
+        VlanVO vlanVO = mock(VlanVO.class);
+        when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
+        List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
+        when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
+
+        Answer answer = mock(Answer.class);
+        when(answer.getResult()).thenReturn(true);
+
+        when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
+        when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
+        when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
+        when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
+        
+        assertTrue(_element.implement(network, offering, dest, context));
     }
-
 }


Mime
View raw message