Search in sources :

Example 16 with StopCommand

use of com.cloud.agent.api.StopCommand in project cloudstack by apache.

the class Ovm3HypervisorResourceTest method stopVmTreatAsStoppedTest.

/* takes too long */
/*
     * @Test
     * public void stopVmTestFail() throws ConfigurationException {
     * stopVm();
     * con.addResult(xen.getVmListXML().replace(vmName, vmName));
     * StopCommand cmd = new StopCommand(vmName, true, true);
     * StopAnswer ra = hypervisor.execute(cmd);
     * results.basicBooleanTest(ra.getResult(), false);
     * }
     */
@Test
public void stopVmTreatAsStoppedTest() throws ConfigurationException {
    hypervisor = vmActionPreparation();
    con.setMethodResponse("list_vms", xen.getMultipleVmsListXML().replace(vmName, vmName + "-hide"));
    StopCommand cmd = new StopCommand(vmName, true, true);
    Answer ra = hypervisor.executeRequest(cmd);
    results.basicBooleanTest(ra.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) StopCommand(com.cloud.agent.api.StopCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) Test(org.junit.Test) CloudStackPluginTest(com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest) NetworkTest(com.cloud.hypervisor.ovm3.objects.NetworkTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 17 with StopCommand

use of com.cloud.agent.api.StopCommand in project cloudstack by apache.

the class Ovm3HypervisorResourceTest method stopVmTest.

@Test
public void stopVmTest() throws ConfigurationException {
    hypervisor = vmActionPreparation();
    con.removeMethodResponse("list_vms");
    con.setResult(xen.getMultipleVmsListXML());
    con.addResult(xen.getMultipleVmsListXML().replace(vmName, vmName + "-hide"));
    StopCommand cmd = new StopCommand(vmName, true, true);
    Answer ra = hypervisor.executeRequest(cmd);
    results.basicBooleanTest(ra.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) StopCommand(com.cloud.agent.api.StopCommand) ConnectionTest(com.cloud.hypervisor.ovm3.objects.ConnectionTest) Test(org.junit.Test) CloudStackPluginTest(com.cloud.hypervisor.ovm3.objects.CloudStackPluginTest) NetworkTest(com.cloud.hypervisor.ovm3.objects.NetworkTest) XenTest(com.cloud.hypervisor.ovm3.objects.XenTest) Ovm3SupportTest(com.cloud.hypervisor.ovm3.support.Ovm3SupportTest) XmlTestResultTest(com.cloud.hypervisor.ovm3.objects.XmlTestResultTest) Ovm3ConfigurationTest(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3ConfigurationTest)

Example 18 with StopCommand

use of com.cloud.agent.api.StopCommand 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 19 with StopCommand

use of com.cloud.agent.api.StopCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testStopCommandNoCheck.

/*
     * New Tests
     */
@Test
public void testStopCommandNoCheck() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final StopCommand command = new StopCommand(vmName, false, false);
    when(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, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).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) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 20 with StopCommand

use of com.cloud.agent.api.StopCommand 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

StopCommand (com.cloud.agent.api.StopCommand)20 Answer (com.cloud.agent.api.Answer)14 Test (org.junit.Test)10 StopAnswer (com.cloud.agent.api.StopAnswer)7 RebootAnswer (com.cloud.agent.api.RebootAnswer)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)4 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)4 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)4 StartAnswer (com.cloud.agent.api.StartAnswer)4 ConfigurationException (javax.naming.ConfigurationException)4 Connect (org.libvirt.Connect)4 LibvirtException (org.libvirt.LibvirtException)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)3 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)3