Search in sources :

Example 16 with LibvirtUtilitiesHelper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testAttachIsoCommandURISyntaxException.

@Test
public void testAttachIsoCommandURISyntaxException() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(URISyntaxException.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(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
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) LibvirtException(org.libvirt.LibvirtException) AttachIsoCommand(com.cloud.legacymodel.communication.command.AttachIsoCommand) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 17 with LibvirtUtilitiesHelper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testRebootCommandException1.

@Test
public void testRebootCommandException1() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootCommand command = new RebootCommand(vmName, true);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).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(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
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) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) LibvirtException(org.libvirt.LibvirtException) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 18 with LibvirtUtilitiesHelper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandCloudRuntime.

@Test
public void testCreatePrivateTemplateFromSnapshotCommandCloudRuntime() {
    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 KvmStoragePoolManager storagePoolMgr = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool secondaryPool = Mockito.mock(KvmStoragePool.class);
    final KvmStoragePool snapshotPool = Mockito.mock(KvmStoragePool.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.generateUuidName()).thenReturn(tmplName);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenThrow(CloudRuntimeException.class);
    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 : 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) CreatePrivateTemplateFromSnapshotCommand(com.cloud.legacymodel.communication.command.CreatePrivateTemplateFromSnapshotCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 19 with LibvirtUtilitiesHelper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testAttachIsoCommand.

@Test
public void testAttachIsoCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
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) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) AttachIsoCommand(com.cloud.legacymodel.communication.command.AttachIsoCommand) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 20 with LibvirtUtilitiesHelper

use of com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testPrepareForMigrationCommandInternalErrorException.

@Test
public void testPrepareForMigrationCommandInternalErrorException() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final VirtualMachineTO vm = Mockito.mock(VirtualMachineTO.class);
    final KvmStoragePoolManager storagePoolManager = Mockito.mock(KvmStoragePoolManager.class);
    final NicTO nicTO = Mockito.mock(NicTO.class);
    final DiskTO volume = Mockito.mock(DiskTO.class);
    final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
    when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
    when(nicTO.getType()).thenReturn(TrafficType.Guest);
    when(this.libvirtComputingResource.getVifDriver(nicTO.getType())).thenThrow(InternalErrorException.class);
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
    try {
        when(this.libvirtComputingResource.getVolumePath(conn, volume)).thenReturn("/path");
    } 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, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(vm, times(1)).getNics();
}
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) LibvirtException(org.libvirt.LibvirtException) PrepareForMigrationCommand(com.cloud.legacymodel.communication.command.PrepareForMigrationCommand) Connect(org.libvirt.Connect) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) URISyntaxException(java.net.URISyntaxException) VirtualMachineTO(com.cloud.legacymodel.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) NicTO(com.cloud.legacymodel.to.NicTO) DiskTO(com.cloud.legacymodel.to.DiskTO) Test(org.junit.Test)

Aggregations

LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)61 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 Answer (com.cloud.legacymodel.communication.answer.Answer)61 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)61 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)61 Test (org.junit.Test)61 LibvirtException (org.libvirt.LibvirtException)48 Connect (org.libvirt.Connect)34 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)24 NicTO (com.cloud.legacymodel.to.NicTO)19 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)14 InternalErrorException (com.cloud.legacymodel.exceptions.InternalErrorException)13 VirtualMachineTO (com.cloud.legacymodel.to.VirtualMachineTO)13 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)12 StoragePool (com.cloud.legacymodel.storage.StoragePool)12 Domain (org.libvirt.Domain)11 KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)10 ArrayList (java.util.ArrayList)10 URISyntaxException (java.net.URISyntaxException)9 VifDriver (com.cloud.agent.resource.kvm.vif.VifDriver)8