cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [25/50] [abbrv] git commit: updated refs/heads/4.9-bountycastle-daan to b9ee34f
Date Wed, 28 Sep 2016 09:46:16 GMT
CLOUDSTACK-8751 Added tests


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

Branch: refs/heads/4.9-bountycastle-daan
Commit: f416332994f28c2158b17ee80e2e03f5a69c22c2
Parents: 75f89c7
Author: Bharat Kumar <bharat.kumar@citrix.com>
Authored: Thu Aug 20 17:21:20 2015 +0530
Committer: Bharat Kumar <bharatkumar@Bharat.local>
Committed: Mon Sep 12 15:24:47 2016 +0530

----------------------------------------------------------------------
 .../element/VirtualRouterElementTest.java       | 151 ++++++++++++++++++-
 1 file changed, 150 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f4163329/server/test/com/cloud/network/element/VirtualRouterElementTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/element/VirtualRouterElementTest.java b/server/test/com/cloud/network/element/VirtualRouterElementTest.java
index 6592778..4fbc28e 100644
--- a/server/test/com/cloud/network/element/VirtualRouterElementTest.java
+++ b/server/test/com/cloud/network/element/VirtualRouterElementTest.java
@@ -19,6 +19,7 @@ package com.cloud.network.element;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyList;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.when;
@@ -26,6 +27,11 @@ import static org.mockito.Mockito.when;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.network.dao.NetworkDetailVO;
+import com.cloud.network.dao.NetworkDetailsDao;
+import com.cloud.network.router.VirtualRouter;
+import com.cloud.utils.exception.CloudRuntimeException;
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.cloud.network.router.deployment.RouterDeploymentDefinitionBuilder;
@@ -35,6 +41,8 @@ import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
 import org.mockito.Matchers;
 import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
 
 import com.cloud.cluster.dao.ManagementServerHostDao;
@@ -111,6 +119,7 @@ import com.cloud.vm.dao.NicIpAliasDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.UserVmDetailsDao;
 import com.cloud.vm.dao.VMInstanceDao;
+import org.mockito.stubbing.Answer;
 
 @RunWith(MockitoJUnitRunner.class)
 public class VirtualRouterElementTest {
@@ -127,6 +136,7 @@ public class VirtualRouterElementTest {
     @Mock private ManagementServerHostDao _msHostDao;
     @Mock private NetworkDao _networkDao;
     @Mock private NetworkOfferingDao _networkOfferingDao;
+    @Mock private NetworkDetailsDao _networkDetailsDao;
     @Mock private NicDao _nicDao;
     @Mock private NicIpAliasDao _nicIpAliasDao;
     @Mock private OpRouterMonitorServiceDao _opRouterMonitorServiceDao;
@@ -225,6 +235,62 @@ public class VirtualRouterElementTest {
 
     }
 
+    @Test
+    public void testGetRouters1(){
+        Network networkUpdateInprogress=new NetworkVO(1l,null,null,null,1l,1l,1l,1l,"d","d","d",null,1l,1l,null,true,null,true);
+        mockDAOs((NetworkVO)networkUpdateInprogress,testOffering);
+        //getRoutes should always return the router that is updating.
+        List<DomainRouterVO> routers=virtualRouterElement.getRouters(networkUpdateInprogress);
+        assertTrue(routers.size()==1);
+        assertTrue(routers.get(0).getUpdateState()== VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
+    }
+
+    @Test
+    public void testGetRouters2(){
+        Network networkUpdateInprogress=new NetworkVO(2l,null,null,null,1l,1l,1l,1l,"d","d","d",null,1l,1l,null,true,null,true);
+        mockDAOs((NetworkVO)networkUpdateInprogress,testOffering);
+        //alwyas return backup routers first when both master and backup need update.
+        List<DomainRouterVO> routers=virtualRouterElement.getRouters(networkUpdateInprogress);
+        assertTrue(routers.size()==1);
+        assertTrue(routers.get(0).getRedundantState()==RedundantState.BACKUP && routers.get(0).getUpdateState()==VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
+    }
+
+    @Test
+    public void testGetRouters3(){
+        Network network=new NetworkVO(3l,null,null,null,1l,1l,1l,1l,"d","d","d",null,1l,1l,null,true,null,true);
+        mockDAOs((NetworkVO)network,testOffering);
+        //alwyas return backup routers first when both master and backup need update.
+        List<DomainRouterVO> routers=virtualRouterElement.getRouters(network);
+        assertTrue(routers.size()==4);
+    }
+
+    @Test
+    public void getResourceCountTest(){
+        Network network=new NetworkVO(3l,null,null,null,1l,1l,1l,1l,"d","d","d",null,1l,1l,null,true,null,true);
+        mockDAOs((NetworkVO)network,testOffering);
+        int routers=virtualRouterElement.getResourceCount(network);
+        assertTrue(routers==4);
+    }
+
+    @Test
+    public void completeAggregationCommandTest1() throws AgentUnavailableException,ResourceUnavailableException
{
+        virtualRouterElement._routerMgr = Mockito.mock(VpcVirtualNetworkApplianceManagerImpl.class);
+        virtualRouterElement.routerDeploymentDefinitionBuilder = routerDeploymentDefinitionBuilder;
+        Network network = new NetworkVO(6l, null, null, null, 1l, 1l, 1l, 1l, "d", "d", "d",
null, 1l, 1l, null, true, null, true);
+        when(virtualRouterElement._routerMgr.completeAggregatedExecution(any(Network.class),
anyList())).thenReturn(true);
+        mockDAOs((NetworkVO) network, testOffering);
+        when(virtualRouterElement._routerDao.persist(any(DomainRouterVO.class))).thenAnswer(new
Answer<Object>() {
+            @Override
+            public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
+                Object args[] = invocationOnMock.getArguments();
+                DomainRouterVO router = (DomainRouterVO) args[0];
+                if (router.getUpdateState() != VirtualRouter.UpdateState.UPDATE_COMPLETE)
{
+                    throw new CloudRuntimeException("TestFailed: completeAggregationCommandTest1
failed");
+                } else return null;
+            }
+        });
+        virtualRouterElement.completeAggregatedExecution(network, testDestination);
+    }
     /**
      * @param networks
      * @param offerings
@@ -293,11 +359,94 @@ public class VirtualRouterElementTest {
                 /* haEnabled */ false,
                 /* stopPending */ false,
                 /* vpcId */ null);
-
+        final DomainRouterVO routerNeedUpdateBackup = new DomainRouterVO(/* id */ 2L,
+                /* serviceOfferingId */ 1L,
+                /* elementId */ 0L,
+                "name",
+                /* templateId */0L,
+                HypervisorType.XenServer,
+                /* guestOSId */ 0L,
+                /* domainId */ 0L,
+                /* accountId */ 1L,
+                /* userId */ 1L,
+                /* isRedundantRouter */ false,
+                RedundantState.BACKUP,
+                /* haEnabled */ false,
+                /* stopPending */ false,
+                /* vpcId */ null);
+                routerNeedUpdateBackup.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
+        final DomainRouterVO routerNeedUpdateMaster = new DomainRouterVO(/* id */ 3L,
+                /* serviceOfferingId */ 1L,
+                /* elementId */ 0L,
+                "name",
+                /* templateId */0L,
+                HypervisorType.XenServer,
+                /* guestOSId */ 0L,
+                /* domainId */ 0L,
+                /* accountId */ 1L,
+                /* userId */ 1L,
+                /* isRedundantRouter */ false,
+                RedundantState.MASTER,
+                /* haEnabled */ false,
+                /* stopPending */ false,
+                /* vpcId */ null);
+        routerNeedUpdateMaster.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
+        final DomainRouterVO routerUpdateComplete = new DomainRouterVO(/* id */ 4L,
+                /* serviceOfferingId */ 1L,
+                /* elementId */ 0L,
+                "name",
+                /* templateId */0L,
+                HypervisorType.XenServer,
+                /* guestOSId */ 0L,
+                /* domainId */ 0L,
+                /* accountId */ 1L,
+                /* userId */ 1L,
+                /* isRedundantRouter */ false,
+                RedundantState.UNKNOWN,
+                /* haEnabled */ false,
+                /* stopPending */ false,
+                /* vpcId */ null);
+                routerUpdateComplete.setUpdateState(VirtualRouter.UpdateState.UPDATE_COMPLETE);
+        final DomainRouterVO routerUpdateInProgress = new DomainRouterVO(/* id */ 5L,
+                /* serviceOfferingId */ 1L,
+                /* elementId */ 0L,
+                "name",
+                /* templateId */0L,
+                HypervisorType.XenServer,
+                /* guestOSId */ 0L,
+                /* domainId */ 0L,
+                /* accountId */ 1L,
+                /* userId */ 1L,
+                /* isRedundantRouter */ false,
+                RedundantState.UNKNOWN,
+                /* haEnabled */ false,
+                /* stopPending */ false,
+                /* vpcId */ null);
+                routerUpdateInProgress.setUpdateState(VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
+        List<DomainRouterVO> routerList1=new ArrayList<>();
+        routerList1.add(routerUpdateComplete);
+        routerList1.add(routerNeedUpdateBackup);
+        routerList1.add(routerNeedUpdateMaster);
+        routerList1.add(routerUpdateInProgress);
+        List<DomainRouterVO> routerList2=new ArrayList<>();
+        routerList2.add(routerUpdateComplete);
+        routerList2.add(routerNeedUpdateBackup);
+        routerList2.add(routerNeedUpdateMaster);
+        List<DomainRouterVO> routerList3=new ArrayList<>();
+        routerList3.add(routerUpdateComplete);
+        routerList3.add(routerUpdateInProgress);
         when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(1L);
         when(_templateDao.findRoutingTemplate(HypervisorType.XenServer, "SystemVM Template
(XenServer)")).thenReturn(new VMTemplateVO());
         when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
         when(_routerDao.findById(router.getId())).thenReturn(router);
+        when(_routerDao.listByNetworkAndRole(1l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
+        when(_routerDao.listByNetworkAndRole(2l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList2);
+        when(_routerDao.listByNetworkAndRole(3l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
+        when(_routerDao.listByNetworkAndRole(6l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList3);
+        when(_networkDetailsDao.findDetail(1l, Network.updatingInSequence)).thenReturn(new
NetworkDetailVO(1l,Network.updatingInSequence,"true",true));
+        when(_networkDetailsDao.findDetail(2l, Network.updatingInSequence)).thenReturn(new
NetworkDetailVO(2l,Network.updatingInSequence,"true",true));
+        when(_networkDetailsDao.findDetail(6l, Network.updatingInSequence)).thenReturn(new
NetworkDetailVO(2l,Network.updatingInSequence,"true",true));
+        when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
     }
 
 }


Mime
View raw message