Search in sources :

Example 91 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testPingTestHostIpCommand.

@Test
public void testPingTestHostIpCommand() {
    final PingTestCommand command = new PingTestCommand("127.0.0.1");
    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) PingTestCommand(com.cloud.legacymodel.communication.command.PingTestCommand) Test(org.junit.Test)

Example 92 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testStorageSubSystemCommand.

@Test
public void testStorageSubSystemCommand() {
    final DiskTO disk = Mockito.mock(DiskTO.class);
    final String vmName = "Test";
    final AttachCommand command = new AttachCommand(disk, vmName);
    final StorageSubsystemCommandHandler handler = Mockito.mock(StorageSubsystemCommandHandler.class);
    when(this.libvirtComputingResource.getStorageHandler()).thenReturn(handler);
    when(handler.handleStorageCommands(command)).thenReturn(new AttachAnswer(disk));
    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) StorageSubsystemCommandHandler(com.cloud.common.storageprocessor.resource.StorageSubsystemCommandHandler) AttachCommand(com.cloud.legacymodel.communication.command.AttachCommand) DiskTO(com.cloud.legacymodel.to.DiskTO) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) Test(org.junit.Test)

Example 93 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testStartCommandUriException.

@Test
public void testStartCommandUriException() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final Host host = Mockito.mock(Host.class);
    final boolean executeInSequence = false;
    final StartCommand command = new StartCommand(vmSpec, host, executeInSequence);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtVmDef vmDef = Mockito.mock(LibvirtVmDef.class);
    final NicTO nic = Mockito.mock(NicTO.class);
    final NicTO[] nics = new NicTO[] { nic };
    final String vmName = "Test";
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachineType.DomainRouter);
    when(vmSpec.getName()).thenReturn(vmName);
    when(this.libvirtComputingResource.createVmFromSpec(vmSpec)).thenReturn(vmDef);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
        doThrow(URISyntaxException.class).when(this.libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    } catch (final URISyntaxException 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)).getConnectionByType(vmDef.getHvsType());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.legacymodel.communication.command.StartCommand) Connect(org.libvirt.Connect) Host(com.cloud.legacymodel.dc.Host) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) 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) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 94 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testStartCommandHostMemory.

@Test
public void testStartCommandHostMemory() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final Host host = Mockito.mock(Host.class);
    final boolean executeInSequence = false;
    final StartCommand command = new StartCommand(vmSpec, host, executeInSequence);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtVmDef vmDef = Mockito.mock(LibvirtVmDef.class);
    final NicTO nic = Mockito.mock(NicTO.class);
    final NicTO[] nics = new NicTO[] { nic };
    final int vmId = 1;
    final int[] vms = new int[] { vmId };
    final Domain dm = Mockito.mock(Domain.class);
    final String vmName = "Test";
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachineType.User);
    when(vmSpec.getName()).thenReturn(vmName);
    when(vmSpec.getMaxRam()).thenReturn(512L);
    when(this.libvirtComputingResource.createVmFromSpec(vmSpec)).thenReturn(vmDef);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
        when(conn.listDomains()).thenReturn(vms);
        when(conn.domainLookupByID(vmId)).thenReturn(dm);
        when(dm.getMaxMemory()).thenReturn(1024L);
        when(dm.getName()).thenReturn(vmName);
        when(this.libvirtComputingResource.getTotalMemory()).thenReturn(2048 * 1024L);
        doNothing().when(this.libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
    } catch (final LibvirtException | InternalErrorException | URISyntaxException e) {
        fail(e.getMessage());
    }
    when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
}
Also used : LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.legacymodel.communication.command.StartCommand) Connect(org.libvirt.Connect) Host(com.cloud.legacymodel.dc.Host) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) 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) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Domain(org.libvirt.Domain) NicTO(com.cloud.legacymodel.to.NicTO) Test(org.junit.Test)

Example 95 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testGetVncPortCommandLibvirtException.

@Test
public void testGetVncPortCommandLibvirtException() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final GetVncPortCommand command = new GetVncPortCommand(1l, "host");
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getName())).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)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getName());
    } 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) GetVncPortCommand(com.cloud.legacymodel.communication.command.GetVncPortCommand) LibvirtException(org.libvirt.LibvirtException) 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