Search in sources :

Example 6 with DomainInfo

use of org.libvirt.DomainInfo in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStopCommandCheckVmNOTRunning.

@Test
public void testStopCommandCheckVmNOTRunning() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Domain vm = Mockito.mock(Domain.class);
    final DomainInfo info = Mockito.mock(DomainInfo.class);
    final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN;
    info.state = state;
    final String vmName = "Test";
    final StopCommand command = new StopCommand(vmName, false, true);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
        when(vm.getInfo()).thenReturn(info);
    } 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(2)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) StopCommand(com.cloud.agent.api.StopCommand) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) DomainState(org.libvirt.DomainInfo.DomainState) Connect(org.libvirt.Connect) DomainInfo(org.libvirt.DomainInfo) Domain(org.libvirt.Domain) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 7 with DomainInfo

use of org.libvirt.DomainInfo in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStopCommandCheckException1.

@SuppressWarnings("unchecked")
@Test
public void testStopCommandCheckException1() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final Domain vm = Mockito.mock(Domain.class);
    final DomainInfo info = Mockito.mock(DomainInfo.class);
    final DomainState state = DomainInfo.DomainState.VIR_DOMAIN_RUNNING;
    info.state = state;
    final String vmName = "Test";
    final StopCommand command = new StopCommand(vmName, false, true);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
        when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
        when(vm.getInfo()).thenReturn(info);
    } 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(2)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) StopCommand(com.cloud.agent.api.StopCommand) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) LibvirtException(org.libvirt.LibvirtException) DomainState(org.libvirt.DomainInfo.DomainState) Connect(org.libvirt.Connect) DomainInfo(org.libvirt.DomainInfo) Domain(org.libvirt.Domain) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Aggregations

Domain (org.libvirt.Domain)7 DomainInfo (org.libvirt.DomainInfo)7 Test (org.junit.Test)5 Connect (org.libvirt.Connect)5 Answer (com.cloud.agent.api.Answer)4 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)4 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)4 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)4 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)4 DomainState (org.libvirt.DomainInfo.DomainState)4 LibvirtException (org.libvirt.LibvirtException)4 StopCommand (com.cloud.agent.api.StopCommand)3 VmStatsEntry (com.cloud.agent.api.VmStatsEntry)3 DomainInterfaceStats (org.libvirt.DomainInterfaceStats)3 NodeInfo (org.libvirt.NodeInfo)3 DiskDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef)2 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)2 Calendar (java.util.Calendar)2 DomainBlockStats (org.libvirt.DomainBlockStats)2 ManageSnapshotCommand (com.cloud.agent.api.ManageSnapshotCommand)1