Search in sources :

Example 1 with ConfigurePublicIpsOnLogicalRouterCommand

use of com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testConfigurePublicIpsOnLogicalRouterApiException.

@Test
public void testConfigurePublicIpsOnLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
    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());
}
Also used : LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand) Test(org.junit.Test)

Example 2 with ConfigurePublicIpsOnLogicalRouterCommand

use of com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpElementTest method applyIpTest.

@Test
public void applyIpTest() throws ResourceUnavailableException {
    final Network network = mock(Network.class);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final List<PublicIpAddress> ipAddresses = new ArrayList<>();
    final PublicIpAddress pipReleased = mock(PublicIpAddress.class);
    final PublicIpAddress pipAllocated = mock(PublicIpAddress.class);
    final Ip ipReleased = new Ip(NetUtils.ip2Long("42.10.10.10"));
    final Ip ipAllocated = new Ip(NetUtils.ip2Long("10.10.10.10"));
    when(pipAllocated.getState()).thenReturn(IpAddress.State.Allocated);
    when(pipAllocated.getAddress()).thenReturn(ipAllocated);
    when(pipAllocated.getNetmask()).thenReturn("255.255.255.0");
    when(pipReleased.getState()).thenReturn(IpAddress.State.Releasing);
    when(pipReleased.getAddress()).thenReturn(ipReleased);
    when(pipReleased.getNetmask()).thenReturn("255.255.255.0");
    ipAddresses.add(pipAllocated);
    ipAddresses.add(pipReleased);
    final Set<Service> services = new HashSet<>();
    services.add(Service.SourceNat);
    services.add(Service.StaticNat);
    services.add(Service.PortForwarding);
    final List<NiciraNvpDeviceVO> deviceList = new ArrayList<>();
    final NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class);
    final NiciraNvpRouterMappingVO nnrmVO = mock(NiciraNvpRouterMappingVO.class);
    when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(nnrmVO);
    when(nnrmVO.getLogicalRouterUuid()).thenReturn("abcde");
    when(nndVO.getHostId()).thenReturn(NETWORK_ID);
    final HostVO hvo = mock(HostVO.class);
    when(hvo.getId()).thenReturn(NETWORK_ID);
    when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde");
    when(hostDao.findById(NETWORK_ID)).thenReturn(hvo);
    deviceList.add(nndVO);
    when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(deviceList);
    final ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentManager.easySend(eq(NETWORK_ID), any(ConfigurePublicIpsOnLogicalRouterCommand.class))).thenReturn(answer);
    assertTrue(element.applyIps(network, ipAddresses, services));
    verify(agentManager, atLeast(1)).easySend(eq(NETWORK_ID), argThat(new ArgumentMatcher<ConfigurePublicIpsOnLogicalRouterCommand>() {

        @Override
        public boolean matches(final Object argument) {
            final ConfigurePublicIpsOnLogicalRouterCommand command = (ConfigurePublicIpsOnLogicalRouterCommand) argument;
            if (command.getPublicCidrs().size() == 1) {
                return true;
            }
            return false;
        }
    }));
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Ip(com.cloud.legacymodel.network.Ip) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) Service(com.cloud.legacymodel.network.Network.Service) NetworkOrchestrationService(com.cloud.engine.orchestration.service.NetworkOrchestrationService) HostVO(com.cloud.host.HostVO) PublicIpAddress(com.cloud.network.PublicIpAddress) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) Network(com.cloud.legacymodel.network.Network) ArgumentMatcher(org.mockito.ArgumentMatcher) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ConfigurePublicIpsOnLogicalRouterCommand

use of com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand in project cosmic by MissionCriticalCloud.

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<>();
    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<>();
    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());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) LogicalRouterPort(com.cloud.network.nicira.LogicalRouterPort) NiciraNvpApi(com.cloud.network.nicira.NiciraNvpApi) ArrayList(java.util.ArrayList) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand) Test(org.junit.Test)

Example 4 with ConfigurePublicIpsOnLogicalRouterCommand

use of com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpElement method applyIps.

/**
 * From interface IpDeployer
 *
 * @param network
 * @param ipAddress
 * @param services
 * @return
 * @throws ResourceUnavailableException
 */
@Override
public boolean applyIps(final Network network, final List<? extends PublicIpAddress> ipAddress, final Set<Network.Service> services) throws ResourceUnavailableException {
    if (services.contains(Network.Service.SourceNat)) {
        // Only if we need to provide SourceNat we need to configure the logical router
        // SourceNat is required for StaticNat and PortForwarding
        final List<NiciraNvpDeviceVO> devices = this.niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
        if (devices.isEmpty()) {
            s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
            return false;
        }
        final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
        final HostVO niciraNvpHost = this.hostDao.findById(niciraNvpDevice.getHostId());
        this.hostDao.loadDetails(niciraNvpHost);
        final NiciraNvpRouterMappingVO routermapping = this.niciraNvpRouterMappingDao.findByNetworkId(network.getId());
        if (routermapping == null) {
            s_logger.error("No logical router uuid found for network " + network.getDisplayText());
            return false;
        }
        final List<String> cidrs = new ArrayList<>();
        for (final PublicIpAddress ip : ipAddress) {
            if (ip.getState() == IpAddress.State.Releasing) {
                // the Logical Router
                continue;
            }
            cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
        }
        final ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
        final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) this.agentMgr.easySend(niciraNvpHost.getId(), cmd);
        // FIXME answer can be null if the host is down
        return answer.getResult();
    } else {
        s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
    }
    return true;
}
Also used : PublicIpAddress(com.cloud.network.PublicIpAddress) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand)

Example 5 with ConfigurePublicIpsOnLogicalRouterCommand

use of com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand in project cosmic by MissionCriticalCloud.

the class NiciraNvpResourceTest method testConfigurePublicIpsOnLogicalRouterRetry.

@Test
public void testConfigurePublicIpsOnLogicalRouterRetry() throws ConfigurationException, NiciraNvpApiException {
    resource.configure("NiciraNvpResource", parameters);
    final ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
    when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
    when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
    when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa", "bbbbb")).thenThrow(new NiciraNvpApiException("retry 1")).thenThrow(new NiciraNvpApiException("retry 2"));
    final ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) resource.executeRequest(cmd);
    assertFalse(answer.getResult());
}
Also used : ConfigurePublicIpsOnLogicalRouterAnswer(com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer) NiciraNvpApiException(com.cloud.network.nicira.NiciraNvpApiException) ConfigurePublicIpsOnLogicalRouterCommand(com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand) Test(org.junit.Test)

Aggregations

ConfigurePublicIpsOnLogicalRouterCommand (com.cloud.legacymodel.communication.command.ConfigurePublicIpsOnLogicalRouterCommand)5 ConfigurePublicIpsOnLogicalRouterAnswer (com.cloud.legacymodel.communication.answer.ConfigurePublicIpsOnLogicalRouterAnswer)4 Test (org.junit.Test)4 NiciraNvpApiException (com.cloud.network.nicira.NiciraNvpApiException)3 ArrayList (java.util.ArrayList)3 HostVO (com.cloud.host.HostVO)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2 NiciraNvpRouterMappingVO (com.cloud.network.NiciraNvpRouterMappingVO)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 LogicalRouterPort (com.cloud.network.nicira.LogicalRouterPort)2 NetworkOrchestrationService (com.cloud.engine.orchestration.service.NetworkOrchestrationService)1 Answer (com.cloud.legacymodel.communication.answer.Answer)1 Ip (com.cloud.legacymodel.network.Ip)1 Network (com.cloud.legacymodel.network.Network)1 Service (com.cloud.legacymodel.network.Network.Service)1 NiciraNvpApi (com.cloud.network.nicira.NiciraNvpApi)1 NetworkOffering (com.cloud.offering.NetworkOffering)1 HashSet (java.util.HashSet)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1