Search in sources :

Example 26 with LibvirtRequestWrapper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper 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 27 with LibvirtRequestWrapper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckSshCommand.

@Test
public void testCheckSshCommand() {
    final String instanceName = "Test";
    final String ip = "127.0.0.1";
    final int port = 22;
    final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    final String privateIp = command.getIp();
    final int cmdPort = command.getPort();
    when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.connect(privateIp, cmdPort)).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)).getVirtRouterResource();
    verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
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) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) Test(org.junit.Test)

Example 28 with LibvirtRequestWrapper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCheckSshCommandFailure.

@Test
public void testCheckSshCommandFailure() {
    final String instanceName = "Test";
    final String ip = "127.0.0.1";
    final int port = 22;
    final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
    final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
    final String privateIp = command.getIp();
    final int cmdPort = command.getPort();
    when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
    when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
    verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
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) CheckSshCommand(com.cloud.legacymodel.communication.command.CheckSshCommand) VirtualRoutingResource(com.cloud.common.virtualnetwork.VirtualRoutingResource) Test(org.junit.Test)

Example 29 with LibvirtRequestWrapper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreateStoragePoolCommand.

@Test
public void testCreateStoragePoolCommand() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final CreateStoragePoolCommand command = new CreateStoragePoolCommand(true, pool);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(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) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) CreateStoragePoolCommand(com.cloud.legacymodel.communication.command.CreateStoragePoolCommand) Test(org.junit.Test)

Example 30 with LibvirtRequestWrapper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testAttachIsoCommand.

@Test
public void testAttachIsoCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } 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)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } 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) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) AttachIsoCommand(com.cloud.legacymodel.communication.command.AttachIsoCommand) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Aggregations

LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)112 Test (org.junit.Test)111 Answer (com.cloud.legacymodel.communication.answer.Answer)110 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)110 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)110 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 LibvirtException (org.libvirt.LibvirtException)49 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)44 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)36 Connect (org.libvirt.Connect)34 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)29 StoragePool (com.cloud.legacymodel.storage.StoragePool)28 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)20 NicTO (com.cloud.legacymodel.to.NicTO)19 ArrayList (java.util.ArrayList)18 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)16 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)14 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)13 Domain (org.libvirt.Domain)11 URISyntaxException (java.net.URISyntaxException)10