Search in sources :

Example 6 with RebootCommand

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

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, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) RebootCommand(com.cloud.agent.api.RebootCommand) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with RebootCommand

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

the class SecondaryStorageManagerImpl method rebootSecStorageVm.

@Override
public boolean rebootSecStorageVm(long secStorageVmId) {
    final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
    if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
        return false;
    }
    if (secStorageVm.getState() == State.Running && secStorageVm.getHostId() != null) {
        final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName(), _itMgr.getExecuteInSequence(secStorageVm.getHypervisorType()));
        final Answer answer = _agentMgr.easySend(secStorageVm.getHostId(), cmd);
        String secondaryStorageVmName = secStorageVm.getHostName();
        if (answer != null && answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(String.format("Successfully reboot secondary storage VM [%s].", secondaryStorageVmName));
            }
            SubscriptionMgr.getInstance().notifySubscribers(ALERT_SUBJECT, this, new SecStorageVmAlertEventArgs(SecStorageVmAlertEventArgs.SSVM_REBOOTED, secStorageVm.getDataCenterId(), secStorageVm.getId(), secStorageVm, null));
            return true;
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(String.format("Unable to reboot secondary storage VM [%s] due to [%s].", secondaryStorageVmName, answer == null ? "answer null" : answer.getDetails()));
            }
            return false;
        }
    } else {
        return startSecStorageVm(secStorageVmId) != null;
    }
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) RebootCommand(com.cloud.agent.api.RebootCommand) SecStorageVmAlertEventArgs(com.cloud.storage.secondary.SecStorageVmAlertEventArgs)

Example 8 with RebootCommand

use of com.cloud.agent.api.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(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, 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 : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) RebootCommand(com.cloud.agent.api.RebootCommand) LibvirtException(org.libvirt.LibvirtException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 9 with RebootCommand

use of com.cloud.agent.api.RebootCommand in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testRebootCommand.

@Test
public void testRebootCommand() {
    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);
    } 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 : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) 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)

Example 10 with RebootCommand

use of com.cloud.agent.api.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(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    try {
        when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
        when(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, 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 : Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) 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)

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