Search in sources :

Example 6 with StorageFilerTO

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

the class LibvirtComputingResourceTest method testDeleteStoragePoolCommand.

@Test
public void testDeleteStoragePoolCommand() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
    final StorageFilerTO pool = command.getPool();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenReturn(true);
    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)).deleteStoragePool(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) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) DeleteStoragePoolCommand(com.cloud.legacymodel.communication.command.DeleteStoragePoolCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 7 with StorageFilerTO

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

the class LibvirtComputingResourceTest method testResizeVolumeCommandShrink.

@Test
@Ignore
public void testResizeVolumeCommandShrink() {
    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 = true;
    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);
    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);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
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) 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with StorageFilerTO

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

the class LibvirtComputingResourceTest method testResizeVolumeCommandException2.

@Test
public void testResizeVolumeCommandException2() {
    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);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
    when(storagePool.getPhysicalDisk(path)).thenThrow(CloudRuntimeException.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
}
Also used : LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Example 9 with StorageFilerTO

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

the class LibvirtResizeVolumeCommandWrapper method execute.

@Override
public Answer execute(final ResizeVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String volid = command.getPath();
    final long newSize = command.getNewSize();
    final long currentSize = command.getCurrentSize();
    final String vmInstanceName = command.getInstanceName();
    final boolean shrinkOk = command.getShrinkOk();
    final StorageFilerTO spool = command.getPool();
    if (currentSize == newSize) {
        s_logger.info("No need to resize volume: current size " + currentSize + " is same as new size " + newSize);
        return new ResizeVolumeAnswer(command, true, "success", currentSize);
    }
    final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
    final KvmStoragePool pool = storagePoolMgr.getStoragePool(spool.getType(), spool.getUuid());
    final KvmPhysicalDisk vol = pool.getPhysicalDisk(volid);
    final String path = vol.getPath();
    s_logger.debug("Resizing volume: " + path + "," + currentSize + "," + newSize + "," + vol.getFormat() + "," + vmInstanceName + "," + shrinkOk);
    if (pool.getType() == StoragePoolType.RBD) {
        s_logger.debug("Volume " + path + " is on a RBD storage pool. No need to query for additional information.");
    } else if (pool.getType() == StoragePoolType.LVM || pool.getType() == StoragePoolType.CLVM) {
        s_logger.debug("Volume " + path + " can be resized by libvirt. Asking libvirt to resize the volume.");
        final LVM lvm = new LVM(command.getWait());
        try {
            // 1. Resize the logical volume
            lvm.resize(newSize, vol.getPath());
            // 2. If the volume is attached to a virtualmachine, notify libvirt domain of the size change
            libvirtBlockResize(libvirtComputingResource, newSize, vmInstanceName, vol);
        } catch (final LVMException e) {
            // First step went wrong, nothing to clean up. Just return that it didn't work out.
            return new ResizeVolumeAnswer(command, false, e.toString());
        } catch (final LibvirtException e) {
            // Second step went wrong, we should resize the volume back to how it was!
            try {
                lvm.resize(currentSize, vol.getPath());
            } catch (final LVMException e1) {
                s_logger.error("Unable to reverse lv resize: " + e1);
            }
            return new ResizeVolumeAnswer(command, false, e.toString());
        }
    } else if (pool.getType() == StoragePoolType.NetworkFilesystem) {
        if (vol.getFormat() == PhysicalDiskFormat.QCOW2 && shrinkOk) {
            return new ResizeVolumeAnswer(command, false, "Unable to shrink volumes of type " + PhysicalDiskFormat.QCOW2);
        }
        try {
            final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
            final Connect connection = libvirtUtilitiesHelper.getConnection();
            final StorageVol storageVol = connection.storageVolLookupByPath(vol.getPath());
            final VirtualMachine.PowerState state = libvirtComputingResource.getVmState(libvirtUtilitiesHelper.getConnection(), vmInstanceName);
            if (state == VirtualMachine.PowerState.PowerOn) {
                libvirtBlockResize(libvirtComputingResource, newSize, vmInstanceName, vol);
            } else {
                final int flags = shrinkOk ? StorageVol.ResizeFlags.SHRINK : 0;
                storageVol.resize(newSize, flags);
            }
        } catch (final LibvirtException e) {
            return new ResizeVolumeAnswer(command, false, e.toString());
        }
    }
    /* fetch new size as seen from libvirt, don't want to assume anything */
    pool.refresh();
    final long finalSize = pool.getPhysicalDisk(volid).getVirtualSize();
    s_logger.debug("after resize, size reports as " + finalSize + ", requested " + newSize);
    return new ResizeVolumeAnswer(command, true, "success", finalSize);
}
Also used : LVM(com.cloud.agent.resource.kvm.storage.utils.LVM) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) LibvirtException(org.libvirt.LibvirtException) StorageVol(org.libvirt.StorageVol) LVMException(com.cloud.agent.resource.kvm.storage.utils.LVMException) Connect(org.libvirt.Connect) ResizeVolumeAnswer(com.cloud.legacymodel.communication.answer.ResizeVolumeAnswer) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) VirtualMachine(com.cloud.legacymodel.vm.VirtualMachine)

Example 10 with StorageFilerTO

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

the class LibvirtComputingResourceTest method testResizeVolumeCommand.

@Test
@Ignore
public void testResizeVolumeCommand() {
    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 = true;
    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);
    final Connect conn = Mockito.mock(Connect.class);
    final StorageVol v = Mockito.mock(StorageVol.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()).thenReturn(conn);
        when(conn.storageVolLookupByPath(path)).thenReturn(v);
        when(conn.getLibVirVersion()).thenReturn(10010l);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    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(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnection();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StorageVol(org.libvirt.StorageVol) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) 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) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Ignore(org.junit.Ignore) 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