Search in sources :

Example 1 with BackupSnapshotCommand

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

the class LibvirtComputingResourceTest method testBackupSnapshotCommandLibvirtException.

@Test
public void testBackupSnapshotCommandLibvirtException() {
    // 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 accountId = 1l;
    final String volumePath = "/123/vol";
    final String vmName = "Test";
    final int wait = 0;
    final long snapshotId = 1l;
    final String snapshotName = "snap";
    final Long dcId = 1l;
    final Long volumeId = 1l;
    final Long secHostId = 1l;
    final String snapshotUuid = "9a0afe7c-26a7-4585-bf87-abf82ae106d9";
    final String prevBackupUuid = "003a0cc2-2e04-417a-bee0-534ef1724561";
    final boolean isVolumeInactive = false;
    final String prevSnapshotUuid = "1791efae-f22d-474b-87c6-92547d6c5877";
    final BackupSnapshotCommand command = new BackupSnapshotCommand(secondaryStorageUrl, dcId, accountId, volumeId, snapshotId, secHostId, volumePath, pool, snapshotUuid, snapshotName, prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, wait);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    // final Connect conn = Mockito.mock(Connect.class);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).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)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : BackupSnapshotCommand(com.cloud.legacymodel.communication.command.BackupSnapshotCommand) 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) LibvirtException(org.libvirt.LibvirtException) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Aggregations

NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)1 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)1 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)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 BackupSnapshotCommand (com.cloud.legacymodel.communication.command.BackupSnapshotCommand)1 StoragePool (com.cloud.legacymodel.storage.StoragePool)1 Test (org.junit.Test)1 LibvirtException (org.libvirt.LibvirtException)1