Search in sources :

Example 61 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 62 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 63 with LibvirtRequestWrapper

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

the class LibvirtComputingResource method executeRequest.

@Override
public Answer executeRequest(final Command cmd) {
    logger.debug("Processing cmd " + cmd.toString());
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    try {
        return wrapper.execute(cmd, this);
    } catch (final Exception e) {
        logger.debug("Exception was " + e.getMessage());
        return Answer.createUnsupportedCommandAnswer(cmd);
    }
}
Also used : LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) SAXException(org.xml.sax.SAXException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 64 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testGetVncPortCommand.

@Test
public void testGetVncPortCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    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())).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(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) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 65 with LibvirtRequestWrapper

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

the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirtException.

@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(this.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, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } 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) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) LibvirtException(org.libvirt.LibvirtException) ManageSnapshotCommand(com.cloud.legacymodel.communication.command.ManageSnapshotCommand) 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