use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testOvsSetupBridgeCommandFailure2.
@Test
public void testOvsSetupBridgeCommandFailure2() {
final String name = "Test";
final Long hostId = 1l;
final Long networkId = 1l;
final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName());
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testAttachIsoCommandURISyntaxException.
@SuppressWarnings("unchecked")
@Test
public void testAttachIsoCommandURISyntaxException() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(URISyntaxException.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());
}
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testAttachIsoCommandInternalErrorException.
@SuppressWarnings("unchecked")
@Test
public void testAttachIsoCommandInternalErrorException() {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(InternalErrorException.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());
}
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testOvsSetupBridgeCommand.
@Test
public void testOvsSetupBridgeCommand() {
final String name = "Test";
final Long hostId = 1l;
final Long networkId = 1l;
final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertTrue(answer.getResult());
verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(), command.getBridgeName());
}
use of com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper in project cloudstack by apache.
the class LibvirtComputingResourceTest method testNetworkElementCommand.
@Test
public void testNetworkElementCommand() {
final CheckRouterCommand command = new CheckRouterCommand();
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.executeRequest(command)).thenReturn(new CheckRouterAnswer(command, "mock_resource"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, libvirtComputingResource);
assertFalse(answer.getResult());
}
Aggregations