use of com.cloud.network.nicira.LogicalRouterPort in project cloudstack by apache.
the class NiciraNvpResourceTest method testCreateLogicalRouter.
@Test
public void testCreateLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final LogicalRouter lrc = mock(LogicalRouter.class);
final LogicalRouterPort lrp = mock(LogicalRouterPort.class);
final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff");
when(nvpApi.createLogicalRouter((LogicalRouter) any())).thenReturn(lrc);
when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort) any())).thenReturn(lrp);
when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort) any())).thenReturn(lsp);
final CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
final CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertTrue(clra.getResult());
assertTrue("ccccc".equals(clra.getLogicalRouterUuid()));
verify(nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any());
}
use of com.cloud.network.nicira.LogicalRouterPort in project cloudstack by apache.
the class NiciraNvpResourceTest method testConfigurePublicIpsOnLogicalRouterApiException.
@Test
public void testConfigurePublicIpsOnLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
@SuppressWarnings("unchecked") final List<LogicalRouterPort> list = Collections.EMPTY_LIST;
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa", "bbbbb")).thenReturn(list);
doThrow(new NiciraNvpApiException()).when(nvpApi).updateLogicalRouterPort((String) any(), (LogicalRouterPort) any());
final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertFalse(answer.getResult());
}
use of com.cloud.network.nicira.LogicalRouterPort in project cloudstack by apache.
the class NiciraNvpResourceTest method testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort.
@Test
public void testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
final LogicalRouter lrc = mock(LogicalRouter.class);
final LogicalRouterPort lrp = mock(LogicalRouterPort.class);
final LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff");
when(nvpApi.createLogicalRouter((LogicalRouter) any())).thenReturn(lrc);
when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort) any())).thenReturn(lrp);
when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort) any())).thenReturn(lsp);
when(nvpApi.createLogicalRouterNatRule((String) any(), (NatRule) any())).thenThrow(new NiciraNvpApiException());
final CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
final CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertFalse(clra.getResult());
verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
verify(nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff"));
}
use of com.cloud.network.nicira.LogicalRouterPort in project cloudstack by apache.
the class NiciraNvpRequestWrapperTest method testConfigurePublicIpsOnLogicalRouterCommand.
@Test
public void testConfigurePublicIpsOnLogicalRouterCommand() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final LogicalRouterPort port1 = Mockito.mock(LogicalRouterPort.class);
final List<LogicalRouterPort> listPorts = new ArrayList<LogicalRouterPort>();
listPorts.add(port1);
final String logicalRouterUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String l3GatewayServiceUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final List<String> publicCidrs = new ArrayList<String>();
publicCidrs.add("10.1.1.0/24");
final ConfigurePublicIpsOnLogicalRouterCommand command = new ConfigurePublicIpsOnLogicalRouterCommand(logicalRouterUuid, l3GatewayServiceUuid, publicCidrs);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
when(niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(command.getLogicalRouterUuid(), command.getL3GatewayServiceUuid())).thenReturn(listPorts);
doNothing().when(niciraNvpApi).updateLogicalRouterPort(command.getLogicalRouterUuid(), port1);
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
Aggregations