Search in sources :

Example 21 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testResizeVolumeCommandException.

@Test
@Ignore
public void testResizeVolumeCommandException() {
    final String path = "nfs:/127.0.0.1/storage/secondary";
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final Long currentSize = 100l;
    final Long newSize = 200l;
    final boolean shrinkOk = false;
    final String vmInstance = "Test";
    final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool storagePool = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
    when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
    when(vol.getPath()).thenReturn(path);
    when(storagePool.getType()).thenReturn(StoragePoolType.RBD);
    when(vol.getFormat()).thenReturn(PhysicalDiskFormat.FILE);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnection()).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnection();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
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) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) LibvirtException(org.libvirt.LibvirtException) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreateCommandNoTemplate.

@Test
public void testCreateCommandNoTemplate() {
    final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final boolean executeInSequence = false;
    final CreateCommand command = new CreateCommand(diskCharacteristics, pool, executeInSequence);
    final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(primary.createPhysicalDisk(diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), diskCharacteristics.getSize())).thenReturn(vol);
    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(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
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) CreateCommand(com.cloud.legacymodel.communication.command.CreateCommand) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 23 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCopyVolumeCommandPrimaryNotFound.

@Test
public void testCopyVolumeCommandPrimaryNotFound() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long volumeId = 1l;
    final int wait = 0;
    final String volumePath = "/vol/path";
    final boolean toSecondaryStorage = false;
    final boolean executeInSequence = false;
    final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
    final String destVolumeName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondary = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk disk = Mockito.mock(KvmPhysicalDisk.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("not found"));
    when(storagePoolMgr.createStoragePool(pool.getUuid(), pool.getHost(), pool.getPort(), pool.getPath(), pool.getUserInfo(), pool.getType())).thenReturn(primary);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(destVolumeName);
    when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
    when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
    when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
    when(primary.getPhysicalDisk(command.getVolumePath() + ".qcow2")).thenReturn(disk);
    when(storagePoolMgr.copyPhysicalDisk(disk, destVolumeName, primary, 0)).thenReturn(disk);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(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) CopyVolumeCommand(com.cloud.legacymodel.communication.command.CopyVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) 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) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 24 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime.

@Test
public void testCopyVolumeCommandCloudRuntime() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long volumeId = 1l;
    final int wait = 0;
    final String volumePath = "/vol/path";
    final boolean toSecondaryStorage = false;
    final boolean executeInSequence = false;
    final CopyVolumeCommand command = new CopyVolumeCommand(volumeId, volumePath, storagePool, secondaryStoragePoolURL, toSecondaryStorage, wait, executeInSequence);
    final String destVolumeName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final String volumeDestPath = "/volumes/" + command.getVolumeId() + File.separator;
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondary = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(destVolumeName);
    when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
    when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
    when(storagePoolMgr.getStoragePoolByUri(secondaryStoragePoolURL + volumeDestPath)).thenReturn(secondary);
    when(secondary.getPhysicalDisk(command.getVolumePath() + ".qcow2")).thenThrow(CloudRuntimeException.class);
    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 : 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) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) CopyVolumeCommand(com.cloud.legacymodel.communication.command.CopyVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 25 with StorageFilerTO

use of com.cloud.legacymodel.to.StorageFilerTO in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreateCommand.

@Test
public void testCreateCommand() {
    final DiskProfile diskCharacteristics = Mockito.mock(DiskProfile.class);
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final String templateUrl = "http://template";
    final boolean executeInSequence = false;
    final CreateCommand command = new CreateCommand(diskCharacteristics, templateUrl, pool, executeInSequence);
    final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk vol = Mockito.mock(KvmPhysicalDisk.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(primary.getType()).thenReturn(StoragePoolType.CLVM);
    when(this.libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
    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(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
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) CreateCommand(com.cloud.legacymodel.communication.command.CreateCommand) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) DiskProfile(com.cloud.legacymodel.storage.DiskProfile) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Aggregations

StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)36 Answer (com.cloud.legacymodel.communication.answer.Answer)24 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)21 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)20 Test (org.junit.Test)19 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)16 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)16 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)15 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)15 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)10 StoragePool (com.cloud.legacymodel.storage.StoragePool)10 Connection (com.xensource.xenapi.Connection)9 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)8 ResizeVolumeCommand (com.cloud.legacymodel.communication.command.ResizeVolumeCommand)8 VolumeTO (com.cloud.legacymodel.to.VolumeTO)8 SR (com.xensource.xenapi.SR)8 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)7 CopyVolumeCommand (com.cloud.legacymodel.communication.command.CopyVolumeCommand)5 DiskProfile (com.cloud.legacymodel.storage.DiskProfile)5 HashMap (java.util.HashMap)5