use of com.cloud.exception.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testStartCommandFailedConnect.
@Test
public void testStartCommandFailedConnect() {
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);
doNothing().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());
}
when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(false);
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());
}
}
use of com.cloud.exception.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testStartCommandIsolationEc2.
@Test
public void testStartCommandIsolationEc2() {
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 VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
final NicTO nic = Mockito.mock(NicTO.class);
final NicTO[] nics = new NicTO[] { nic };
final int[] vms = new int[0];
final String vmName = "Test";
final String controlIp = "127.0.0.1";
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);
when(conn.listDomains()).thenReturn(vms);
doNothing().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());
}
when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
try {
doNothing().when(libvirtComputingResource).createVifs(vmSpec, vmDef);
when(libvirtComputingResource.startVm(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
when(nic.getIsolationUri()).thenReturn(new URI("ec2://test"));
when(vmSpec.getBootArgs()).thenReturn("ls -lart");
when(libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
when(nic.getIp()).thenReturn(controlIp);
when(nic.getType()).thenReturn(TrafficType.Control);
when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(controlIp, 30, 5000)).thenReturn(true);
} catch (final InternalErrorException e) {
fail(e.getMessage());
} catch (final LibvirtException 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);
assertTrue(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());
}
}
use of com.cloud.exception.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandInternalErrorException.
@Test
public void testCreatePrivateTemplateFromSnapshotCommandInternalErrorException() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long dcId = 1l;
final Long accountId = 1l;
final Long volumeId = 1l;
final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
final String backedUpSnapshotName = "snap";
final String origTemplateInstallPath = "/install/path/";
final Long newTemplateId = 2l;
final String templateName = "templ";
final int wait = 0;
final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
final String templatePath = "/template/path";
final String localPath = "/mnt/local";
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
final StorageLayer storage = Mockito.mock(StorageLayer.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
when(libvirtComputingResource.getStorage()).thenReturn(storage);
when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
try {
when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenReturn(qcow2Processor);
when(qcow2Processor.process(tmplPath, null, tmplName)).thenThrow(InternalErrorException.class);
} catch (final ConfigurationException e) {
fail(e.getMessage());
} catch (final InternalErrorException 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(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
use of com.cloud.exception.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandConfigurationException.
@Test
public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long dcId = 1l;
final Long accountId = 1l;
final Long volumeId = 1l;
final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
final String backedUpSnapshotName = "snap";
final String origTemplateInstallPath = "/install/path/";
final Long newTemplateId = 2l;
final String templateName = "templ";
final int wait = 0;
final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
final String templatePath = "/template/path";
final String localPath = "/mnt/local";
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
final StorageLayer storage = Mockito.mock(StorageLayer.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
final FormatInfo info = Mockito.mock(FormatInfo.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
when(libvirtComputingResource.getStorage()).thenReturn(storage);
when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
try {
when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenThrow(ConfigurationException.class);
when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
} catch (final ConfigurationException e) {
fail(e.getMessage());
} catch (final InternalErrorException 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(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
use of com.cloud.exception.InternalErrorException in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandIOException.
@Test
public void testCreatePrivateTemplateFromSnapshotCommandIOException() {
final StoragePool pool = Mockito.mock(StoragePool.class);
final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
final Long dcId = 1l;
final Long accountId = 1l;
final Long volumeId = 1l;
final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
final String backedUpSnapshotName = "snap";
final String origTemplateInstallPath = "/install/path/";
final Long newTemplateId = 2l;
final String templateName = "templ";
final int wait = 0;
final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
final String templatePath = "/template/path";
final String localPath = "/mnt/local";
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
final StorageLayer storage = Mockito.mock(StorageLayer.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
final FormatInfo info = Mockito.mock(FormatInfo.class);
when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
when(libvirtComputingResource.getStorage()).thenReturn(storage);
when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
try {
when(libvirtUtilitiesHelper.buildQcow2Processor(storage)).thenReturn(qcow2Processor);
when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
when(location.create(1, true, tmplName)).thenThrow(IOException.class);
} catch (final ConfigurationException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
fail(e.getMessage());
} catch (final IOException 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(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
Aggregations