use of com.cloud.network.nicira.NiciraNvpApiException in project cloudstack by apache.
the class NiciraNvpRequestWrapperTest method testCreateLogicalSwitchCommandWrapper.
@Test
public void testCreateLogicalSwitchCommandWrapper() {
final NiciraNvpApi niciraNvpApi = Mockito.mock(NiciraNvpApi.class);
final NiciraNvpUtilities niciraNvpUtilities = Mockito.mock(NiciraNvpUtilities.class);
final LogicalSwitch logicalSwitch = Mockito.mock(LogicalSwitch.class);
final String transportUuid = "d2e05a9e-7120-4487-a5fc-414ab36d9345";
final String transportType = "stt";
final String name = "logicalswitch";
final String ownerName = "owner";
final CreateLogicalSwitchCommand command = new CreateLogicalSwitchCommand(transportUuid, transportType, name, ownerName);
final String truncated = "lswitch-" + command.getName();
when(niciraNvpResource.getNiciraNvpUtilities()).thenReturn(niciraNvpUtilities);
when(niciraNvpUtilities.createLogicalSwitch()).thenReturn(logicalSwitch);
when(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN)).thenReturn(truncated);
when(niciraNvpResource.getNiciraNvpApi()).thenReturn(niciraNvpApi);
try {
when(niciraNvpApi.createLogicalSwitch(logicalSwitch)).thenReturn(logicalSwitch);
when(logicalSwitch.getUuid()).thenReturn(transportUuid);
} catch (final NiciraNvpApiException e) {
fail(e.getMessage());
}
final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(command, niciraNvpResource);
assertTrue(answer.getResult());
}
use of com.cloud.network.nicira.NiciraNvpApiException in project cloudstack by apache.
the class NiciraNvpDeleteLogicalRouterPortCommandWrapper method execute.
@Override
public Answer execute(DeleteLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
final String logicalRouterUuid = command.getLogicalRouterUuid();
final String logicalRouterPortUuid = command.getLogicalRouterPortUuid();
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
s_logger.debug("Deleting Logical Router Port " + logicalRouterPortUuid + " in Logical Router " + logicalRouterUuid);
try {
niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, logicalRouterPortUuid);
return new DeleteLogicalRouterPortAnswer(command, true, "Logical Router Port " + logicalRouterPortUuid + " deleted");
} catch (NiciraNvpApiException e) {
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, DeleteLogicalRouterPortAnswer.class, e);
}
}
use of com.cloud.network.nicira.NiciraNvpApiException in project cloudstack by apache.
the class NiciraNvpDeleteLogicalSwitchCommandWrapper method execute.
@Override
public Answer execute(final DeleteLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
try {
final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
niciraNvpApi.deleteLogicalSwitch(command.getLogicalSwitchUuid());
return new DeleteLogicalSwitchAnswer(command, true, "Logicalswitch " + command.getLogicalSwitchUuid() + " deleted");
} catch (final NiciraNvpApiException e) {
final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
retryUtility.addRetry(command, NUM_RETRIES);
return retryUtility.retry(command, DeleteLogicalSwitchAnswer.class, e);
}
}
use of com.cloud.network.nicira.NiciraNvpApiException in project cloudstack by apache.
the class NiciraNvpResourceTest method testDeleteLogicalRouterApiException.
@Test
public void testDeleteLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalRouter(eq("aaaaa"));
final DeleteLogicalRouterAnswer dlspa = (DeleteLogicalRouterAnswer) resource.executeRequest(new DeleteLogicalRouterCommand("aaaaa"));
assertFalse(dlspa.getResult());
}
use of com.cloud.network.nicira.NiciraNvpApiException in project cloudstack by apache.
the class NiciraNvpResourceTest method testDeleteLogicalSwitchApiException.
@Test
public void testDeleteLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
resource.configure("NiciraNvpResource", parameters);
doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitch((String) any());
final DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
final DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
assertFalse(dlsa.getResult());
}
Aggregations