Search in sources :

Example 16 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreateVolumeFromSnapshotCommand.

@Test
public void testCreateVolumeFromSnapshotCommand() {
    // This tests asserts to False because there will be a NPE due to UUID static method calls.
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "/opt/storage/";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "uuid:/8edb1156-a851-4914-afc6-468ee52ac861/";
    final String backedUpSnapshotName = "uuid:/8edb1156-a851-4914-afc6-468ee52ac862/";
    final int wait = 0;
    final CreateVolumeFromSnapshotCommand command = new CreateVolumeFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, wait);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmPhysicalDisk snapshot = Mockito.mock(KvmPhysicalDisk.class);
    final KvmStoragePool primaryPool = Mockito.mock(KvmStoragePool.class);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    final String primaryUuid = command.getPrimaryStoragePoolNameLabel();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(secondaryPool);
    when(secondaryPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), primaryUuid)).thenReturn(primaryPool);
    // when(storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool, 0)).thenReturn(disk);
    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(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
    verify(secondaryPool, times(1)).getPhysicalDisk(command.getSnapshotName());
    verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), primaryUuid);
// verify(storagePoolMgr, times(1)).copyPhysicalDisk(snapshot, volUuid, primaryPool, 0);
}
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) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CreateVolumeFromSnapshotCommand(com.cloud.legacymodel.communication.command.CreateVolumeFromSnapshotCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 17 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testGetHostStatsCommand.

@Test
public void testGetHostStatsCommand() {
    Mockito.mock(LibvirtUtilitiesHelper.class);
    final CpuStat cpuStat = Mockito.mock(CpuStat.class);
    final MemStat memStat = Mockito.mock(MemStat.class);
    final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
    final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l);
    when(this.libvirtComputingResource.getCpuStat()).thenReturn(cpuStat);
    when(this.libvirtComputingResource.getMemStat()).thenReturn(memStat);
    when(this.libvirtComputingResource.getNicStats(Matchers.anyString())).thenReturn(new Pair<>(1.0d, 1.0d));
    when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
    when(memStat.getAvailable()).thenReturn(1500.5d);
    when(memStat.getTotal()).thenReturn(15000d);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getCpuStat();
    verify(this.libvirtComputingResource, times(1)).getMemStat();
    verify(cpuStat, times(1)).getCpuUsedPercent();
    verify(memStat, times(1)).getAvailable();
    verify(memStat, times(1)).getTotal();
}
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) CpuStat(com.cloud.utils.linux.CpuStat) MemStat(com.cloud.utils.linux.MemStat) GetHostStatsCommand(com.cloud.legacymodel.communication.command.GetHostStatsCommand) Test(org.junit.Test)

Example 18 with Answer

use of com.cloud.legacymodel.communication.answer.Answer 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(this.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(this.libvirtComputingResource.getStorage()).thenReturn(storage);
    when(this.libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(this.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(this.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, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByUri(command.getSecondaryStorageUrl());
}
Also used : NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StorageLayer(com.cloud.utils.storage.StorageLayer) Processor(com.cloud.common.storageprocessor.Processor) InternalErrorException(com.cloud.legacymodel.exceptions.InternalErrorException) 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) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.common.storageprocessor.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromSnapshotCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) Test(org.junit.Test)

Example 19 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testWatchConsoleProxyLoadCommand.

@Test
public void testWatchConsoleProxyLoadCommand() {
    final int interval = 0;
    final long proxyVmId = 0l;
    final String proxyVmName = "host";
    final String proxyManagementIp = "127.0.0.1";
    final int proxyCmdPort = 0;
    final WatchConsoleProxyLoadCommand command = new WatchConsoleProxyLoadCommand(interval, proxyVmId, proxyVmName, proxyManagementIp, proxyCmdPort);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
}
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) WatchConsoleProxyLoadCommand(com.cloud.legacymodel.communication.command.WatchConsoleProxyLoadCommand) Test(org.junit.Test)

Example 20 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testResizeVolumeCommandSameSize.

@Test
public void testResizeVolumeCommandSameSize() {
    final String path = "nfs:/127.0.0.1/storage/secondary";
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final Long currentSize = 100l;
    final Long newSize = 100l;
    final boolean shrinkOk = false;
    final String vmInstance = "Test";
    final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
}
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) ResizeVolumeCommand(com.cloud.legacymodel.communication.command.ResizeVolumeCommand) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) Test(org.junit.Test)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)342 Test (org.junit.Test)201 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)173 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)116 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)110 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)63 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)58 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)54 LibvirtException (org.libvirt.LibvirtException)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)48 Connection (com.xensource.xenapi.Connection)48 ArrayList (java.util.ArrayList)45 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)39 StoragePool (com.cloud.legacymodel.storage.StoragePool)38 Connect (org.libvirt.Connect)38 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)29 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)29 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)27