use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCheckSshCommand.
@Test
public void testCheckSshCommand() {
final String instanceName = "Test";
final String ip = "127.0.0.1";
final int port = 22;
final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
final String privateIp = command.getIp();
final int cmdPort = command.getPort();
when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testCheckSshCommandFailure.
@Test
public void testCheckSshCommandFailure() {
final String instanceName = "Test";
final String ip = "127.0.0.1";
final int port = 22;
final CheckSshCommand command = new CheckSshCommand(instanceName, ip, port);
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
final String privateIp = command.getIp();
final int cmdPort = command.getPort();
when(this.libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertFalse(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getVirtRouterResource();
verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResource method executeRequest.
@Override
public Answer executeRequest(final Command cmd) {
logger.debug("Processing cmd " + cmd.toString());
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
try {
return wrapper.execute(cmd, this);
} catch (final Exception e) {
logger.debug("Exception was " + e.getMessage());
return Answer.createUnsupportedCommandAnswer(cmd);
}
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testGetVncPortCommand.
@Test
public void testGetVncPortCommand() {
final Connect conn = Mockito.mock(Connect.class);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final GetVncPortCommand command = new GetVncPortCommand(1l, "host");
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
assertTrue(answer.getResult());
verify(this.libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
use of com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper in project cosmic by MissionCriticalCloud.
the class LibvirtComputingResourceTest method testManageSnapshotCommandLibvirtException.
@Test
public void testManageSnapshotCommandLibvirtException() {
// Simple test used to make sure the flow (LibvirtComputingResource => Request => CommandWrapper) is working.
// The code is way to big and complex. Will finish the refactor and come back to this to add more cases.
final StoragePool pool = Mockito.mock(StoragePool.class);
final String volumePath = "/123/vol";
final String vmName = "Test";
final long snapshotId = 1l;
final String preSnapshotPath = "/snapshot/path";
final String snapshotName = "snap";
final ManageSnapshotCommand command = new ManageSnapshotCommand(snapshotId, volumePath, pool, preSnapshotPath, snapshotName, vmName);
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
// final Connect conn = Mockito.mock(Connect.class);
when(this.libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(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(command.getVmName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
}
Aggregations