Search in sources :

Example 21 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirt.

@Test
public void testManageSnapshotCommandLibvirt() {
    final StoragePool storagePool = Mockito.mock(StoragePool.class);
    ;
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final long snapshotId = 1l;
    final String preSnapshotPath = "/snapshot/path";
    final String snapshotName = "snap";
    final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, storagePool, preSnapshotPath, snapshotName, vmName);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primaryPool = Mockito.mock(KVMStoragePool.class);
    final Domain vm = Mockito.mock(Domain.class);
    final DomainInfo info = Mockito.mock(DomainInfo.class);
    final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
    info.state = state;
    final KVMPhysicalDisk disk = Mockito.mock(KVMPhysicalDisk.class);
    final StorageFilerTO pool = command.getPool();
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(libvirtComputingResource.getDomain(conn, command.getVmName())).thenReturn(vm);
        when(vm.getInfo()).thenReturn(info);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primaryPool);
    when(primaryPool.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
    when(primaryPool.isExternalSnapshot()).thenReturn(false);
    try {
        when(vm.getUUIDString()).thenReturn("cdb18980-546d-4153-b916-70ee9edf0908");
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) LibvirtException(org.libvirt.LibvirtException) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) Connect(org.libvirt.Connect) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) DomainState(org.libvirt.DomainInfo.DomainState) DomainInfo(org.libvirt.DomainInfo) Domain(org.libvirt.Domain) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime2.

@Test
public void testCopyVolumeCommandCloudRuntime2() {
    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 StorageFilerTO pool = command.getPool();
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("error"));
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

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(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, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirtException.

@SuppressWarnings("unchecked")
@Test
public void testManageSnapshotCommandLibvirtException() {
    // Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
    // The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
    final StoragePool pool = Mockito.mock(StoragePool.class);
    ;
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final long snapshotId = 1l;
    final String preSnapshotPath = "/snapshot/path";
    final String snapshotName = "snap";
    final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, pool, preSnapshotPath, snapshotName, vmName);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    // final Connect conn = Mockito.mock(Connect.class);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) LibvirtException(org.libvirt.LibvirtException) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with StoragePool

use of com.cloud.storage.StoragePool in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCopyVolumeCommandCloudRuntime.

@SuppressWarnings("unchecked")
@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(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
    when(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, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

StoragePool (com.cloud.storage.StoragePool)234 Answer (com.cloud.agent.api.Answer)81 Test (org.junit.Test)70 ArrayList (java.util.ArrayList)69 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)63 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)56 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)56 Volume (com.cloud.storage.Volume)55 HashMap (java.util.HashMap)47 VolumeVO (com.cloud.storage.VolumeVO)37 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)36 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)35 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)29 DiskProfile (com.cloud.vm.DiskProfile)29 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)28 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KvmHaBase.NfsStoragePool)28 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)28 KvmStoragePool (com.cloud.hypervisor.kvm.storage.KvmStoragePool)28 AttachAnswer (com.cloud.storage.command.AttachAnswer)28