Search in sources :

Example 1 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cloudstack by apache.

the class NiciraNvpResourceTest method testCreateLogicalSwitchApiException.

@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner");
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertFalse(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 2 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand 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 3 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testRetries.

@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertTrue(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Example 4 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.

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, null);
    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 5 with CreateLogicalSwitchCommand

use of com.cloud.agent.api.CreateLogicalSwitchCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testCreateLogicalSwitchApiException.

@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final LogicalSwitch ls = mock(LogicalSwitch.class);
    when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
    when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
    final CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String) parameters.get("guid"), "stt", "loigicalswitch", "owner", null);
    final CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
    assertFalse(clsa.getResult());
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) CreateLogicalSwitchCommand(com.cloud.agent.api.CreateLogicalSwitchCommand) Test(org.junit.Test)

Aggregations

CreateLogicalSwitchCommand (com.cloud.agent.api.CreateLogicalSwitchCommand)10 CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)8 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)8 Test (org.junit.Test)8 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)6 Answer (com.cloud.agent.api.Answer)2 HostVO (com.cloud.host.HostVO)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1