Search in sources :

Example 26 with LibvirtUtilitiesHelper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testAttachIsoCommandLibvirtException.

@SuppressWarnings("unchecked")
@Test
public void testAttachIsoCommandLibvirtException() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
    when(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, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 27 with LibvirtUtilitiesHelper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testNetworkRulesVmSecondaryIpCommand.

@Test
public void testNetworkRulesVmSecondaryIpCommand() {
    final String vmName = "Test";
    final String vmMac = "00:00:00:00";
    final String secondaryIp = "127.0.0.1";
    final boolean action = true;
    final NetworkRulesVmSecondaryIpCommand command = new NetworkRulesVmSecondaryIpCommand(vmName, vmMac, secondaryIp, action);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Connect conn = Mockito.mock(Connect.class);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(libvirtComputingResource.configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction())).thenReturn(true);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    verify(libvirtComputingResource, times(1)).configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction());
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) NetworkRulesVmSecondaryIpCommand(com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with LibvirtUtilitiesHelper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testPrepareForMigrationCommandLibvirtException.

@SuppressWarnings("unchecked")
@Test
public void testPrepareForMigrationCommandLibvirtException() {
    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 VifDriver vifDriver = Mockito.mock(VifDriver.class);
    final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    when(vm.getNics()).thenReturn(new NicTO[] { nicTO });
    when(nicTO.getType()).thenReturn(TrafficType.Guest);
    when(libvirtComputingResource.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(vm, times(1)).getNics();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) NicTO(com.cloud.agent.api.to.NicTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 29 with LibvirtUtilitiesHelper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testModifySshKeysCommand.

@Test
public void testModifySshKeysCommand() {
    final ModifySshKeysCommand command = new ModifySshKeysCommand("", "");
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.retrieveSshKeysPath()).thenReturn("/path/keys");
    when(libvirtUtilitiesHelper.retrieveSshPubKeyPath()).thenReturn("/path/pub/keys");
    when(libvirtUtilitiesHelper.retrieveSshPrvKeyPath()).thenReturn("/path/pvt/keys");
    when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getTimeout();
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 30 with LibvirtUtilitiesHelper

use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper in project cloudstack by apache.

the class LibvirtComputingResourceTest method testGetVncPortCommand.

@Test
public void testGetVncPortCommand() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final GetVncPortCommand command = new GetVncPortCommand(1l, "host");
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(command.getName())).thenReturn(conn);
    } catch (final LibvirtException 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)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getName());
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : UnsupportedAnswer(com.cloud.agent.api.UnsupportedAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.agent.api.Answer)128 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)128 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)128 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)128 Test (org.junit.Test)128 LibvirtException (org.libvirt.LibvirtException)103 Connect (org.libvirt.Connect)72 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)67 UnsupportedAnswer (com.cloud.agent.api.UnsupportedAnswer)66 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)66 AttachAnswer (com.cloud.storage.command.AttachAnswer)61 NicTO (com.cloud.agent.api.to.NicTO)38 InternalErrorException (com.cloud.exception.InternalErrorException)28 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)27 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)25 KvmStoragePoolManager (com.cloud.hypervisor.kvm.storage.KvmStoragePoolManager)24 StoragePool (com.cloud.storage.StoragePool)24 ArrayList (java.util.ArrayList)22 Domain (org.libvirt.Domain)22 URISyntaxException (java.net.URISyntaxException)19