Search in sources :

Example 1 with CreatePrivateTemplateFromVolumeCommand

use of com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromVolumeCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromVolumeCommand.

@Test
public void testCreatePrivateTemplateFromVolumeCommand() {
    // Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
    // The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStorageUrl = "nfs:/127.0.0.1/storage/secondary";
    final long templateId = 1l;
    final long accountId = 1l;
    final String userSpecifiedName = "User";
    final String uniqueName = "Unique";
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final int wait = 0;
    final CreatePrivateTemplateFromVolumeCommand command = new CreatePrivateTemplateFromVolumeCommand(pool, secondaryStorageUrl, templateId, accountId, userSpecifiedName, uniqueName, volumePath, vmName, wait);
    final KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryStorage = Mockito.mock(KvmStoragePool.class);
    // final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByUri(secondaryStorageUrl)).thenReturn(secondaryStorage);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel())).thenThrow(new CloudRuntimeException("error"));
    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(secondaryStorageUrl);
    verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel());
}
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) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) CreatePrivateTemplateFromVolumeCommand(com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromVolumeCommand) Test(org.junit.Test)

Aggregations

NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)1 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)1 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)1 CreatePrivateTemplateFromVolumeCommand (com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromVolumeCommand)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 StoragePool (com.cloud.legacymodel.storage.StoragePool)1 Test (org.junit.Test)1