Search in sources :

Example 1 with CreateLogicalSwitchAnswer

use of com.cloud.agent.api.CreateLogicalSwitchAnswer 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 CreateLogicalSwitchAnswer

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

the class NiciraNvpGuestNetworkGuruTest method testImplementURIException.

@Test
public void testImplementURIException() throws InsufficientVirtualNetworkCapacityException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    //when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork == null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 3 with CreateLogicalSwitchAnswer

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

the class NiciraNvpCreateLogicalSwitchCommandWrapper method execute.

@Override
public Answer execute(final CreateLogicalSwitchCommand command, final NiciraNvpResource niciraNvpResource) {
    final NiciraNvpUtilities niciraNvpUtilities = niciraNvpResource.getNiciraNvpUtilities();
    LogicalSwitch logicalSwitch = niciraNvpUtilities.createLogicalSwitch();
    logicalSwitch.setDisplayName(niciraNvpResource.truncate("lswitch-" + command.getName(), NiciraNvpResource.NAME_MAX_LEN));
    logicalSwitch.setPortIsolationEnabled(false);
    // Set transport binding
    final List<TransportZoneBinding> ltzb = new ArrayList<TransportZoneBinding>();
    ltzb.add(new TransportZoneBinding(command.getTransportUuid(), command.getTransportType()));
    logicalSwitch.setTransportZones(ltzb);
    // Tags set to scope cs_account and account name
    final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
    tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
    logicalSwitch.setTags(tags);
    try {
        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
        logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch);
        final String switchUuid = logicalSwitch.getUuid();
        return new CreateLogicalSwitchAnswer(command, true, "Logicalswitch " + switchUuid + " created", switchUuid);
    } catch (final NiciraNvpApiException e) {
        final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
        retryUtility.addRetry(command, NUM_RETRIES);
        return retryUtility.retry(command, CreateLogicalSwitchAnswer.class, e);
    }
}
Also used : CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NiciraNvpUtilities(com.cloud.network.resource.NiciraNvpUtilities) LogicalSwitch(com.cloud.network.nicira.LogicalSwitch) TransportZoneBinding(com.cloud.network.nicira.TransportZoneBinding) NiciraNvpTag(com.cloud.network.nicira.NiciraNvpTag) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ArrayList(java.util.ArrayList) CommandRetryUtility(com.cloud.network.utils.CommandRetryUtility) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException)

Example 4 with CreateLogicalSwitchAnswer

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

the class NiciraNvpGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 5 with CreateLogicalSwitchAnswer

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

the class NiciraNvpGuestNetworkGuruTest method testImplementWithCidr.

@Test
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapacityException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
    assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
    assertTrue(implementednetwork.getGateway().equals("10.1.1.1"));
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) CreateLogicalSwitchAnswer(com.cloud.agent.api.CreateLogicalSwitchAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Aggregations

CreateLogicalSwitchAnswer (com.cloud.agent.api.CreateLogicalSwitchAnswer)8 Test (org.junit.Test)6 CreateLogicalSwitchCommand (com.cloud.agent.api.CreateLogicalSwitchCommand)4 HostVO (com.cloud.host.HostVO)4 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)4 NetworkVO (com.cloud.network.dao.NetworkVO)4 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)4 LogicalSwitch (com.cloud.network.nicira.LogicalSwitch)4 DataCenter (com.cloud.dc.DataCenter)3 DeployDestination (com.cloud.deploy.DeployDestination)3 Domain (com.cloud.domain.Domain)3 Network (com.cloud.network.Network)3 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)3 NetworkOffering (com.cloud.offering.NetworkOffering)3 Account (com.cloud.user.Account)3 ReservationContext (com.cloud.vm.ReservationContext)3 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 NiciraNvpTag (com.cloud.network.nicira.NiciraNvpTag)1