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);
}
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());
}
}
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);
}
Aggregations