Search in sources :

Example 1 with PrimaryStorageDownloadCommand

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();
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.model.enumeration.ImageFormat) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 2 with PrimaryStorageDownloadCommand

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();
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.model.enumeration.ImageFormat) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 3 with PrimaryStorageDownloadCommand

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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) ImageFormat(com.cloud.model.enumeration.ImageFormat) Test(org.junit.Test)

Example 4 with PrimaryStorageDownloadCommand

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());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with PrimaryStorageDownloadCommand

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();
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) PrimaryStorageDownloadCommand(com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.model.enumeration.ImageFormat) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)5 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 PrimaryStorageDownloadCommand (com.cloud.legacymodel.communication.command.PrimaryStorageDownloadCommand)5 Test (org.junit.Test)5 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)4 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)4 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 StoragePool (com.cloud.legacymodel.storage.StoragePool)4 ImageFormat (com.cloud.model.enumeration.ImageFormat)4 ArrayList (java.util.ArrayList)3 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1