use of com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateNODisk.
@Test
public void testPrimaryStorageDownloadCommandNOTemplateNODisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
use of com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateNOQcow2.
@Test
public void testPrimaryStorageDownloadCommandNOTemplateNOQcow2() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final List<KvmPhysicalDisk> spiedDisks = Mockito.spy(disks);
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(spiedDisks);
when(spiedDisks.isEmpty()).thenReturn(false);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
use of com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandTemplateNoDisk.
@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandTemplateNoDisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String name = "Test";
final String url = "http://template/template.qcow2";
final ImageFormat format = ImageFormat.VHD;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.getPhysicalDisk("template.qcow2")).thenReturn(tmplVol);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPoolUuid());
}
use of com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand in project cosmic by MissionCriticalCloud.
the class NotAValidCommand method testPrimaryStorageDownloadCommand.
@Test
public void testPrimaryStorageDownloadCommand() {
final XsHost xsHost = Mockito.mock(XsHost.class);
final StoragePoolVO poolVO = Mockito.mock(StoragePoolVO.class);
final PrimaryStorageDownloadCommand storageDownloadCommand = new PrimaryStorageDownloadCommand("Test", "http://127.0.0.1", ImageFormat.VHD, 1l, poolVO, 200);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(this.citrixResourceBase.getHost()).thenReturn(xsHost);
final Answer answer = wrapper.execute(storageDownloadCommand, this.citrixResourceBase);
verify(this.citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
use of com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateDisk.
@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandNOTemplateDisk() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final List<KvmPhysicalDisk> disks = new ArrayList<>();
final String name = "Test";
final String url = "http://template/";
final ImageFormat format = ImageFormat.QCOW2;
final long accountId = 1l;
final int wait = 0;
final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk tmplVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk primaryVol = Mockito.mock(KvmPhysicalDisk.class);
final KvmPhysicalDisk disk = new KvmPhysicalDisk("/path", "disk.qcow2", primaryPool);
disks.add(disk);
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByUri(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Aggregations