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