Search in sources :

Example 11 with LibvirtVmDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testcreateVmFromSpec.

/**
 * This test tests if the Agent can handle a vmSpec coming from a >4.1 management server.
 */
@Test
public void testcreateVmFromSpec() {
    final int id = this._random.nextInt(65534);
    final String name = "test-instance-1";
    final int cpus = this._random.nextInt(2) + 1;
    final int minRam = 256 * 1024;
    final int maxRam = 512 * 1024;
    final String os = "Ubuntu";
    final String vncPassword = "mySuperSecretPassword";
    final LibvirtComputingResource lcr = new LibvirtComputingResource();
    final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachineType.User, cpus, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
    to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
    final LibvirtVmDef vm = lcr.createVmFromSpec(to);
    vm.setHvsType(this._hyperVisorType);
    verifyVm(to, vm);
}
Also used : LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) Test(org.junit.Test)

Example 12 with LibvirtVmDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testStartCommandLibvirtException.

@Test
public void testStartCommandLibvirtException() {
    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 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())).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)).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) Host(com.cloud.legacymodel.dc.Host) 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 13 with LibvirtVmDef

use of com.cloud.agent.resource.kvm.xml.LibvirtVmDef in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testcreateVmFromSpecLegacy.

/**
 * This test tests if the Agent can handle a vmSpec coming from a <=4.1 management server.
 */
@Test
public void testcreateVmFromSpecLegacy() {
    final int id = this._random.nextInt(65534);
    final String name = "test-instance-1";
    final int cpus = this._random.nextInt(2) + 1;
    final int minRam = 256 * 1024;
    final int maxRam = 512 * 1024;
    final String os = "Ubuntu";
    final String vncPassword = "mySuperSecretPassword";
    final LibvirtComputingResource lcr = new LibvirtComputingResource();
    final VirtualMachineTO to = new VirtualMachineTO(id, name, VirtualMachineType.User, cpus, minRam, maxRam, BootloaderType.HVM, os, false, false, vncPassword);
    to.setUuid("b0f0a72d-7efb-3cad-a8ff-70ebf30b3af9");
    final LibvirtVmDef vm = lcr.createVmFromSpec(to);
    vm.setHvsType(this._hyperVisorType);
    verifyVm(to, vm);
}
Also used : LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) Test(org.junit.Test)

Aggregations

LibvirtVmDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef)13 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)12 Test (org.junit.Test)11 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)8 NicTO (com.cloud.legacymodel.to.NicTO)8 LibvirtException (org.libvirt.LibvirtException)8 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)7 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)7 Answer (com.cloud.legacymodel.communication.answer.Answer)7 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)7 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)7 StartCommand (com.cloud.legacymodel.communication.command.StartCommand)7 Host (com.cloud.legacymodel.dc.Host)7 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)7 URISyntaxException (java.net.URISyntaxException)7 Connect (org.libvirt.Connect)7 VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)3 ClockDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ClockDef)1 ConsoleDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ConsoleDef)1 CpuModeDef (com.cloud.agent.resource.kvm.xml.LibvirtVmDef.CpuModeDef)1