Search in sources :

Example 6 with ResizeVolumeCommand

use of com.cloud.legacymodel.communication.command.ResizeVolumeCommand 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 7 with ResizeVolumeCommand

use of com.cloud.legacymodel.communication.command.ResizeVolumeCommand in project cosmic by MissionCriticalCloud.

the class CloudStackPrimaryDataStoreDriverImpl method resize.

@Override
public void resize(final DataObject data, final AsyncCompletionCallback<CreateCmdResult> callback) {
    final VolumeObject vol = (VolumeObject) data;
    final StoragePool pool = (StoragePool) data.getDataStore();
    final ResizeVolumePayload resizeParameter = (ResizeVolumePayload) vol.getpayload();
    final ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(), resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName);
    final CreateCmdResult result = new CreateCmdResult(null, null);
    try {
        final ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, resizeParameter.hosts, resizeCmd);
        if (answer != null && answer.getResult()) {
            final long finalSize = answer.getNewSize();
            s_logger.debug("Resize: volume started at size " + vol.getSize() + " and ended at size " + finalSize);
            vol.setSize(finalSize);
            vol.update();
        } else if (answer != null) {
            result.setResult(answer.getDetails());
        } else {
            s_logger.debug("return a null answer, mark it as failed for unknown reason");
            result.setResult("return a null answer, mark it as failed for unknown reason");
        }
    } catch (final Exception e) {
        s_logger.debug("sending resize command failed", e);
        result.setResult(e.toString());
    }
    callback.complete(result);
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) ResizeVolumePayload(com.cloud.storage.ResizeVolumePayload) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) VolumeObject(com.cloud.storage.volume.VolumeObject) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) StorageUnavailableException(com.cloud.legacymodel.exceptions.StorageUnavailableException)

Example 8 with ResizeVolumeCommand

use of com.cloud.legacymodel.communication.command.ResizeVolumeCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testResizeVolumeCommand.

@Test
public void testResizeVolumeCommand() {
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final ResizeVolumeCommand resizeCommand = new ResizeVolumeCommand("Test", pool, 1l, 3l, false, "Tests-1");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(resizeCommand, 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) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ResizeVolumeCommand (com.cloud.legacymodel.communication.command.ResizeVolumeCommand)8 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)8 Answer (com.cloud.legacymodel.communication.answer.Answer)6 Test (org.junit.Test)6 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)5 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)4 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)3 Ignore (org.junit.Ignore)3 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)2 LibvirtException (org.libvirt.LibvirtException)2 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)1 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)1 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)1 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 ListVolumeAnswer (com.cloud.legacymodel.communication.answer.ListVolumeAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1