Search in sources :

Example 1 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testRebootCommandException1.

@Test
public void testRebootCommandException1() {
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String vmName = "Test";
    final RebootCommand command = new RebootCommand(vmName, true);
    when(this.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, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) LibvirtException(org.libvirt.LibvirtException) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 2 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand in project cosmic by MissionCriticalCloud.

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(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(this.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, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 3 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testRebootCommandException2.

@Test
public void testRebootCommandException2() {
    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(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(this.libvirtComputingResource.rebootVm(conn, command.getVmName())).thenThrow(LibvirtException.class);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
    try {
        verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
    } catch (final LibvirtException e) {
        fail(e.getMessage());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) LibvirtUtilitiesHelper(com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 4 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand in project cosmic by MissionCriticalCloud.

the class CitrixRebootRouterCommandWrapper method execute.

@Override
public Answer execute(final RebootRouterCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    final RebootCommand rebootCommand = new RebootCommand(command.getVmName(), true);
    final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase);
    if (answer.getResult()) {
        final String cnct = citrixResourceBase.connect(conn, command.getVmName(), command.getPrivateIpAddress());
        citrixResourceBase.networkUsage(conn, command.getPrivateIpAddress(), "create", null);
        if (cnct == null) {
            return answer;
        } else {
            return new Answer(command, false, cnct);
        }
    }
    return answer;
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) Connection(com.xensource.xenapi.Connection)

Example 5 with RebootCommand

use of com.cloud.legacymodel.communication.command.RebootCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testRebootCommand.

@Test
public void testRebootCommand() {
    final RebootCommand rebootCommand = new RebootCommand("Test", true);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(rebootCommand, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)10 RebootCommand (com.cloud.legacymodel.communication.command.RebootCommand)10 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)5 Test (org.junit.Test)5 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)4 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)4 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)4 LibvirtException (org.libvirt.LibvirtException)4 Connect (org.libvirt.Connect)3 CheckSshAnswer (com.cloud.legacymodel.communication.answer.CheckSshAnswer)2 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)2 Commands (com.cloud.agent.manager.Commands)1 VirtualRoutingResource (com.cloud.common.virtualnetwork.VirtualRoutingResource)1 Zone (com.cloud.db.model.Zone)1 DeployDestination (com.cloud.deploy.DeployDestination)1 AgentControlAnswer (com.cloud.legacymodel.communication.answer.AgentControlAnswer)1 CheckVirtualMachineAnswer (com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer)1 ClusterVMMetaDataSyncAnswer (com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer)1 ConsoleProxyLoadAnswer (com.cloud.legacymodel.communication.answer.ConsoleProxyLoadAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1