use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class TemplateManagerImplTest method testTemplateScheduledForDownloadInMultiplePool.
@Test
public void testTemplateScheduledForDownloadInMultiplePool() {
VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
StoragePoolVO mockPool1 = mock(StoragePoolVO.class);
when(mockPool1.getId()).thenReturn(2l);
when(mockPool1.getStatus()).thenReturn(StoragePoolStatus.Up);
when(mockPool1.getDataCenterId()).thenReturn(1l);
StoragePoolVO mockPool2 = mock(StoragePoolVO.class);
when(mockPool2.getId()).thenReturn(3l);
when(mockPool2.getStatus()).thenReturn(StoragePoolStatus.Up);
when(mockPool2.getDataCenterId()).thenReturn(1l);
StoragePoolVO mockPool3 = mock(StoragePoolVO.class);
when(mockPool3.getId()).thenReturn(4l);
when(mockPool3.getStatus()).thenReturn(StoragePoolStatus.Up);
when(mockPool3.getDataCenterId()).thenReturn(2l);
pools.add(mockPool1);
pools.add(mockPool2);
pools.add(mockPool3);
when(mockPrimaryDataStore.getId()).thenReturn(2l);
when(mockTemplate.getId()).thenReturn(202l);
when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
when(primaryDataStoreDao.findById(2l)).thenReturn(mockPool1);
when(primaryDataStoreDao.findById(3l)).thenReturn(mockPool2);
when(primaryDataStoreDao.findById(4l)).thenReturn(mockPool3);
when(primaryDataStoreDao.listByStatus(StoragePoolStatus.Up)).thenReturn(pools);
doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
templateManager._preloadExecutor = preloadExecutor;
templateManager.prepareTemplate(202, 1, null);
assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 2);
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class TemplateManagerImplTest method testTemplateScheduledForDownloadInOnePool.
@Test
public void testTemplateScheduledForDownloadInOnePool() {
VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
StoragePoolVO mockPool = mock(StoragePoolVO.class);
PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
when(mockPrimaryDataStore.getId()).thenReturn(2l);
when(mockPool.getId()).thenReturn(2l);
when(mockPool.getStatus()).thenReturn(StoragePoolStatus.Up);
when(mockPool.getDataCenterId()).thenReturn(1l);
when(mockTemplate.getId()).thenReturn(202l);
when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
when(vmTemplateDao.findById(anyLong())).thenReturn(mockTemplate);
when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
when(primaryDataStoreDao.findById(anyLong())).thenReturn(mockPool);
doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
ExecutorService preloadExecutor = new CustomThreadPoolExecutor(8, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), new NamedThreadFactory("Template-Preloader"));
templateManager._preloadExecutor = preloadExecutor;
templateManager.prepareTemplate(202, 1, 2l);
assertTrue("Test template is scheduled for seeding to on pool", ((CustomThreadPoolExecutor) preloadExecutor).getCount() == 1);
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class TemplateManagerImplTest method testPrepareTemplateNoHostConnectedToPool.
@Test(expected = CloudRuntimeException.class)
public void testPrepareTemplateNoHostConnectedToPool() {
VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
when(mockTemplate.getId()).thenReturn(202l);
StoragePoolVO mockPool = mock(StoragePoolVO.class);
when(mockPool.getId()).thenReturn(2l);
PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
when(mockPrimaryDataStore.getId()).thenReturn(2l);
when(mockPrimaryDataStore.getDataCenterId()).thenReturn(1l);
TemplateDataStoreVO mockTemplateDataStore = mock(TemplateDataStoreVO.class);
when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(null);
when(templateDataStoreDao.findByTemplateZoneDownloadStatus(202l, 1l, VMTemplateStorageResourceAssoc.Status.DOWNLOADED)).thenReturn(mockTemplateDataStore);
when(storagePoolHostDao.listByHostStatus(2l, Status.Up)).thenReturn(null);
templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class TemplateManagerImplTest method testCreatePrivateTemplateRecordForRegionStore.
@Test
public void testCreatePrivateTemplateRecordForRegionStore() throws ResourceAllocationException {
CreateTemplateCmd mockCreateCmd = mock(CreateTemplateCmd.class);
when(mockCreateCmd.getTemplateName()).thenReturn("test");
when(mockCreateCmd.getTemplateTag()).thenReturn(null);
when(mockCreateCmd.getBits()).thenReturn(64);
when(mockCreateCmd.getRequiresHvm()).thenReturn(true);
when(mockCreateCmd.isPasswordEnabled()).thenReturn(false);
when(mockCreateCmd.isPublic()).thenReturn(false);
when(mockCreateCmd.isFeatured()).thenReturn(false);
when(mockCreateCmd.isDynamicallyScalable()).thenReturn(false);
when(mockCreateCmd.getVolumeId()).thenReturn(null);
when(mockCreateCmd.getSnapshotId()).thenReturn(1L);
when(mockCreateCmd.getOsTypeId()).thenReturn(1L);
when(mockCreateCmd.getEventDescription()).thenReturn("test");
when(mockCreateCmd.getDetails()).thenReturn(null);
Account mockTemplateOwner = mock(Account.class);
SnapshotVO mockSnapshot = mock(SnapshotVO.class);
when(snapshotDao.findById(anyLong())).thenReturn(mockSnapshot);
when(mockSnapshot.getVolumeId()).thenReturn(1L);
when(mockSnapshot.getState()).thenReturn(Snapshot.State.BackedUp);
when(mockSnapshot.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.template));
doNothing().when(resourceLimitMgr).checkResourceLimit(any(Account.class), eq(Resource.ResourceType.secondary_storage), anyLong());
GuestOSVO mockGuestOS = mock(GuestOSVO.class);
when(guestOSDao.findById(anyLong())).thenReturn(mockGuestOS);
when(tmpltDao.getNextInSequence(eq(Long.class), eq("id"))).thenReturn(1L);
List<ImageStoreVO> mockRegionStores = new ArrayList<>();
ImageStoreVO mockRegionStore = mock(ImageStoreVO.class);
mockRegionStores.add(mockRegionStore);
when(imgStoreDao.findRegionImageStores()).thenReturn(mockRegionStores);
when(tmpltDao.persist(any(VMTemplateVO.class))).thenAnswer(new Answer<VMTemplateVO>() {
@Override
public VMTemplateVO answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args = invocationOnMock.getArguments();
return (VMTemplateVO) args[0];
}
});
VMTemplateVO template = templateManager.createPrivateTemplateRecord(mockCreateCmd, mockTemplateOwner);
assertTrue("Template in a region store should have cross zones set", template.isCrossZones());
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class TemplateManagerImplTest method testPrepareTemplateIsSeeded.
@Test
public void testPrepareTemplateIsSeeded() {
VMTemplateVO mockTemplate = mock(VMTemplateVO.class);
when(mockTemplate.getId()).thenReturn(202l);
StoragePoolVO mockPool = mock(StoragePoolVO.class);
when(mockPool.getId()).thenReturn(2l);
PrimaryDataStore mockPrimaryDataStore = mock(PrimaryDataStore.class);
when(mockPrimaryDataStore.getId()).thenReturn(2l);
VMTemplateStoragePoolVO mockTemplateStore = mock(VMTemplateStoragePoolVO.class);
when(mockTemplateStore.getDownloadState()).thenReturn(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
when(dataStoreManager.getPrimaryDataStore(anyLong())).thenReturn(mockPrimaryDataStore);
when(vmTemplateDao.findById(anyLong(), anyBoolean())).thenReturn(mockTemplate);
when(vmTemplatePoolDao.findByPoolTemplate(anyLong(), anyLong())).thenReturn(mockTemplateStore);
doNothing().when(mockTemplateStore).setMarkedForGC(anyBoolean());
VMTemplateStoragePoolVO returnObject = templateManager.prepareTemplateForCreate(mockTemplate, (StoragePool) mockPrimaryDataStore);
assertTrue("Test template is already seeded", returnObject == mockTemplateStore);
}
Aggregations