Search in sources :

Example 26 with RebootCommand

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

the class LibvirtComputingResourceTest method testRebootCommandError.

@Test
public void testRebootCommandError() {
    final Connect conn = Mockito.mock(Connect.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootCommand command = new RebootCommand(vmName, true);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(libvirtComputingResource.rebootVM(conn, command.getVmName())).thenReturn("error");
    } 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) RebootCommand(com.cloud.agent.api.RebootCommand) 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)26 RebootCommand (com.cloud.agent.api.RebootCommand)26 Test (org.junit.Test)10 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)8 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)8 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)8 LibvirtException (org.libvirt.LibvirtException)8 RebootAnswer (com.cloud.agent.api.RebootAnswer)7 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)7 Connect (org.libvirt.Connect)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)5 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)5 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)4 StartAnswer (com.cloud.agent.api.StartAnswer)4 StopAnswer (com.cloud.agent.api.StopAnswer)4 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)4 AttachAnswer (com.cloud.storage.command.AttachAnswer)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3