Search in sources :

Example 6 with NiciraNvpApiException

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());
}
Also used : Answer(com.cloud.agent.api.Answer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 7 with NiciraNvpApiException

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);
    }
}
Also used : DeleteLogicalRouterPortAnswer(com.cloud.agent.api.DeleteLogicalRouterPortAnswer) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 8 with NiciraNvpApiException

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);
    }
}
Also used : NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 9 with NiciraNvpApiException

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());
}
Also used : DeleteLogicalRouterAnswer(com.cloud.agent.api.DeleteLogicalRouterAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) DeleteLogicalRouterCommand(com.cloud.agent.api.DeleteLogicalRouterCommand) Test(org.junit.Test)

Example 10 with NiciraNvpApiException

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());
}
Also used : DeleteLogicalSwitchCommand(com.cloud.agent.api.DeleteLogicalSwitchCommand) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) Test(org.junit.Test)

Aggregations

NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)39 Test (org.junit.Test)23 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)21 CommandRetryUtility (com.cloud.network.utils.CommandRetryUtility)13 LogicalSwitchPort (com.cloud.network.nicira.LogicalSwitchPort)8 ArrayList (java.util.ArrayList)8 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)7 Answer (com.cloud.agent.api.Answer)6 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)5 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)5 CreateLogicalRouterAnswer (com.cloud.agent.api.CreateLogicalRouterAnswer)4 NatRule (com.cloud.network.nicira.NatRule)4 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer)3 ConfigurePublicIpsOnLogicalRouterCommand (com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand)3 CreateLogicalRouterCommand (com.cloud.agent.api.CreateLogicalRouterCommand)3 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)3 CreateLogicalSwitchCommand (com.cloud.agent.api.CreateLogicalSwitchCommand)3 CreateLogicalSwitchPortAnswer (com.cloud.agent.api.CreateLogicalSwitchPortAnswer)3 ControlClusterStatus (com.cloud.network.nicira.ControlClusterStatus)3 VifAttachment (com.cloud.network.nicira.VifAttachment)3