AutonomiccsSystemVmDeploymentService implements InitializingBean { protected AutonomiccsSystemVm allocateAndStartTheSystemVm(VMTemplateVO systemVmTemplate, DataCenterDeployment plan, LinkedHashMap<Network, List<? extends NicProfile>> networks, AutonomiccsSystemVm autonomiccsSystemVm) { try { virtualMachineManager.allocate(autonomiccsSystemVm.getInstanceName(), systemVmTemplate, autonomiccsSystemVmServiceOffering, networks, plan, null); autonomiccsSystemVm = autonomiccsSystemVmDao.findById(autonomiccsSystemVm.getId()); virtualMachineManager.advanceStart(autonomiccsSystemVm.getUuid(), null, null); autonomiccsSystemVm = autonomiccsSystemVmDao.findById(autonomiccsSystemVm.getId()); } catch (InsufficientCapacityException | ConcurrentOperationException | ResourceUnavailableException | OperationTimedoutException e) { throw new CloudRuntimeException("An exception occurred when deploying a Autonomiccs system VM.", e); } return autonomiccsSystemVm; }  HostVO searchForRandomHostInCloudToDeployAutonomiccsSystemVm(); HostVO searchForRandomHostInPodToDeployAutonomiccsSystemVm(HostPodVO pod); HostVO searchForAnotherRandomHostToStartSystemVm(VMInstanceVO vmInstance); AutonomiccsSystemVm deploySystemVmWithJava(Long hostId, SystemVmType systemVmType); @Override void afterPropertiesSet();  }
@Test public void allocateAndStartTheSystemVmTest() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 1, 2, 2, 1); }
@Test(expected = CloudRuntimeException.class) public void allocateAndStartTheSystemVmTestInsufficientCapacityException() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, null, null, null); Mockito.doThrow(Mockito.mock(InsufficientCapacityException.class)).when(virtualMachineManager).allocate(Mockito.anyString(), Mockito.any(VMTemplateVO.class), Mockito.any(ServiceOfferingVO.class), Mockito.eq(networks), Mockito.any(DataCenterDeployment.class), Mockito.eq((HypervisorType) null)); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 0, 0, 0, 0); }
@Test(expected = CloudRuntimeException.class) public void allocateAndStartTheSystemVmTestInsufficientCapacityExceptionAtAdvanceStart() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, null, null, null); configureAdvanceStartException(Mockito.mock(InsufficientCapacityException.class), null, null); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 1, 1, 1, 1); }
@Test(expected = CloudRuntimeException.class) public void allocateAndStartTheSystemVmTestConcurrentOperationException() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, null, null, null); configureAdvanceStartException(Mockito.mock(ConcurrentOperationException.class), null, null); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 1, 1, 1, 1); }
@Test(expected = CloudRuntimeException.class) public void allocateAndStartTheSystemVmTestResourceUnavailableException() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, null, null, null); configureAdvanceStartException(Mockito.mock(ResourceUnavailableException.class), null, null); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 1, 1, 1, 1); }
@Test(expected = CloudRuntimeException.class) public void allocateAndStartTheSystemVmTestOperationTimedoutException() throws Exception { LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(); AutonomiccsSystemVm autonomiccsSystemVm = Mockito.mock(AutonomiccsSystemVm.class); configureAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, null, null, null); configureAdvanceStartException(Mockito.mock(OperationTimedoutException.class), null, null); spy.allocateAndStartTheSystemVm(Mockito.mock(VMTemplateVO.class), Mockito.mock(DataCenterDeployment.class), networks, autonomiccsSystemVm); verifyAllocateAndStartTheSystemVmTest(networks, autonomiccsSystemVm, (HypervisorType) null, null, null, 1, 1, 1, 1); }