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());
}
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());
}
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());
}
}
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());
}
}
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());
}
}
Aggregations