Search in sources :

Example 11 with VirtualMachineTO

use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.

the class LibvirtComputingResourceTest method testCreateVMFromSpecWithTopology6.

/**
        This test verifies that CPU topology is properly set for hex-core
     */
@Test
public void testCreateVMFromSpecWithTopology6() {
    final int id = random.nextInt(65534);
    final String name = "test-instance-1";
    final int cpus = 12;
    final int minSpeed = 1024;
    final int maxSpeed = 2048;
    final int minRam = 256 * 1024;
    final int maxRam = 512 * 1024;
    final String os = "Ubuntu";
    final String vncAddr = "";
    final String vncPassword = "mySuperSecretPassword";
    final LibvirtComputingResource lcr = new LibvirtComputingResource();
    final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachine.Type.User, cpus, minSpeed, maxSpeed, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
    to.setVncAddr(vncAddr);
    to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
    final LibvirtVMDef vm = lcr.createVMFromSpec(to);
    vm.setHvsType(hyperVisorType);
    verifyVm(to, vm);
}
Also used : VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) Test(org.junit.Test)

Example 12 with VirtualMachineTO

use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStartCommandLibvirtException.

@SuppressWarnings("unchecked")
@Test
public void testStartCommandLibvirtException() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final com.cloud.host.Host host = Mockito.mock(com.cloud.host.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 LibvirtVMDef vmDef = Mockito.mock(LibvirtVMDef.class);
    final NicTO nic = Mockito.mock(NicTO.class);
    final NicTO[] nics = new NicTO[] { nic };
    final String vmName = "Test";
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
    when(vmSpec.getName()).thenReturn(vmName);
    when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).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)).getStoragePoolMgr();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.agent.api.StartCommand) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) 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) NicTO(com.cloud.agent.api.to.NicTO) Test(org.junit.Test)

Example 13 with VirtualMachineTO

use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.

the class LibvirtComputingResourceTest method testMigrateCommand.

@Test
public void testMigrateCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final Connect dconn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final String destIp = "127.0.0.100";
    final boolean isWindows = false;
    final VirtualMachineTO vmTO = Mockito.mock(VirtualMachineTO.class);
    final boolean executeInSequence = false;
    final MigrateCommand command = new MigrateCommand(vmName, destIp, isWindows, vmTO, executeInSequence);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(libvirtUtilitiesHelper.retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system")).thenReturn(dconn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final InterfaceDef interfaceDef = Mockito.mock(InterfaceDef.class);
    final List<InterfaceDef> ifaces = new ArrayList<InterfaceDef>();
    ifaces.add(interfaceDef);
    when(libvirtComputingResource.getInterfaces(conn, vmName)).thenReturn(ifaces);
    final DiskDef diskDef = Mockito.mock(DiskDef.class);
    final List<DiskDef> disks = new ArrayList<DiskDef>();
    disks.add(diskDef);
    when(libvirtComputingResource.getDisks(conn, vmName)).thenReturn(disks);
    final Domain dm = Mockito.mock(Domain.class);
    try {
        when(conn.domainLookupByName(vmName)).thenReturn(dm);
        when(libvirtComputingResource.getPrivateIp()).thenReturn("127.0.0.1");
        when(dm.getXMLDesc(8)).thenReturn("<domain type='kvm' id='3'>" + "  <devices>" + "    <graphics type='vnc' port='5900' autoport='yes' listen='10.10.10.1'>" + "      <listen type='address' address='10.10.10.1'/>" + "    </graphics>" + "  </devices>" + "</domain>");
        when(dm.getXMLDesc(1)).thenReturn("<domain type='kvm' id='3'>" + "  <devices>" + "    <graphics type='vnc' port='5900' autoport='yes' listen='10.10.10.1'>" + "      <listen type='address' address='10.10.10.1'/>" + "    </graphics>" + "  </devices>" + "</domain>");
        when(dm.isPersistent()).thenReturn(1);
        doNothing().when(dm).undefine();
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    } catch (final Exception 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)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
        verify(libvirtUtilitiesHelper, times(1)).retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system");
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(libvirtComputingResource, times(1)).getInterfaces(conn, vmName);
    verify(libvirtComputingResource, times(1)).getDisks(conn, vmName);
    try {
        verify(conn, times(1)).domainLookupByName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    try {
        verify(dm, times(1)).getXMLDesc(8);
    } catch (final Throwable t) {
        try {
            verify(dm, times(1)).getXMLDesc(1);
        } catch (final LibvirtException e) {
            fail(e.getMessage());
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) MigrateCommand(com.cloud.agent.api.MigrateCommand) InterfaceDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) Domain(org.libvirt.Domain) Test(org.junit.Test)

Example 14 with VirtualMachineTO

use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStartCommandInternalError.

@Test
public void testStartCommandInternalError() {
    final VirtualMachineTO vmSpec = Mockito.mock(VirtualMachineTO.class);
    final com.cloud.host.Host host = Mockito.mock(com.cloud.host.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(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(vmSpec.getNics()).thenReturn(nics);
    when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
    when(vmSpec.getName()).thenReturn(vmName);
    when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
        doThrow(InternalErrorException.class).when(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, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtException(org.libvirt.LibvirtException) StartCommand(com.cloud.agent.api.StartCommand) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) 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) NicTO(com.cloud.agent.api.to.NicTO) Test(org.junit.Test)

Example 15 with VirtualMachineTO

use of com.cloud.agent.api.to.VirtualMachineTO in project cloudstack by apache.

the class NotAValidCommand method testMigrateCommand.

@Test
public void testMigrateCommand() {
    final VirtualMachineTO machineTO = Mockito.mock(VirtualMachineTO.class);
    final MigrateCommand migrateCommand = new MigrateCommand("Test", "127.0.0.1", false, machineTO, false);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(migrateCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) MigrateCommand(com.cloud.agent.api.MigrateCommand) Test(org.junit.Test)

Aggregations

VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)84 NicTO (com.cloud.agent.api.to.NicTO)42 Test (org.junit.Test)33 Answer (com.cloud.agent.api.Answer)32 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)25 HashMap (java.util.HashMap)18 LibvirtException (org.libvirt.LibvirtException)18 StartAnswer (com.cloud.agent.api.StartAnswer)17 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)17 URISyntaxException (java.net.URISyntaxException)16 Connect (org.libvirt.Connect)16 InternalErrorException (com.cloud.exception.InternalErrorException)15 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)14 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 Connection (com.xensource.xenapi.Connection)14 ConfigurationException (javax.naming.ConfigurationException)14 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)13 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)13 StartCommand (com.cloud.agent.api.StartCommand)12 ArrayList (java.util.ArrayList)11