mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch 'master' into api_refactoring
This commit is contained in:
commit
edb00bb613
@ -36,19 +36,19 @@
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim25</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-apputils</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis</groupId>
|
||||
|
||||
@ -170,7 +170,7 @@ public class NiciraNvpElement extends AdapterBase implements
|
||||
return Provider.NiciraNvp;
|
||||
}
|
||||
|
||||
private boolean canHandle(Network network, Service service) {
|
||||
protected boolean canHandle(Network network, Service service) {
|
||||
s_logger.debug("Checking if NiciraNvpElement can handle service "
|
||||
+ service.getName() + " on network " + network.getDisplayText());
|
||||
if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
|
||||
@ -845,6 +845,7 @@ public class NiciraNvpElement extends AdapterBase implements
|
||||
ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(),
|
||||
niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
|
||||
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
|
||||
//FIXME answer can be null if the host is down
|
||||
return answer.getResult();
|
||||
}
|
||||
else {
|
||||
|
||||
@ -29,6 +29,7 @@ import com.cloud.agent.api.CreateLogicalSwitchAnswer;
|
||||
import com.cloud.agent.api.CreateLogicalSwitchCommand;
|
||||
import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
|
||||
import com.cloud.agent.api.DeleteLogicalSwitchCommand;
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
@ -119,8 +120,9 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
|
||||
Network userSpecified, Account owner) {
|
||||
// Check of the isolation type of the related physical network is STT
|
||||
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
|
||||
if (physnet == null || physnet.getIsolationMethods() == null || !physnet.getIsolationMethods().contains("STT")) {
|
||||
s_logger.debug("Refusing to design this network, the physical isolation type is not STT");
|
||||
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
|
||||
if (!canHandle(offering,dc.getNetworkType(),physnet)) {
|
||||
s_logger.debug("Refusing to design this network");
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -199,6 +201,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
|
||||
s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString());
|
||||
} catch (URISyntaxException e) {
|
||||
s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return implemented;
|
||||
|
||||
@ -84,7 +84,7 @@ public class NiciraNvpApi {
|
||||
protected HttpMethod createMethod(String type, String uri) throws NiciraNvpApiException {
|
||||
String url;
|
||||
try {
|
||||
url = new URL(_protocol, _host, "/ws.v1/login").toString();
|
||||
url = new URL(_protocol, _host, uri).toString();
|
||||
} catch (MalformedURLException e) {
|
||||
s_logger.error("Unable to build Nicira API URL", e);
|
||||
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
|
||||
|
||||
@ -0,0 +1,119 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.domain.Domain;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class NiciraNvpElementTest {
|
||||
|
||||
NiciraNvpElement _element = new NiciraNvpElement();
|
||||
NetworkManager _networkManager = mock(NetworkManager.class);
|
||||
NetworkServiceMapDao _ntwkSrvcDao = mock (NetworkServiceMapDao.class);
|
||||
|
||||
@Before
|
||||
public void setUp() throws ConfigurationException {
|
||||
_element._resourceMgr = mock(ResourceManager.class);
|
||||
_element._networkManager = _networkManager;
|
||||
_element._ntwkSrvcDao = _ntwkSrvcDao;
|
||||
|
||||
// Standard responses
|
||||
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
|
||||
|
||||
_element.configure("NiciraNvpTestElement", Collections.<String, Object> emptyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canHandleTest() {
|
||||
Network net = mock(Network.class);
|
||||
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
|
||||
when(net.getId()).thenReturn(42L);
|
||||
|
||||
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
|
||||
// Golden path
|
||||
assertTrue(_element.canHandle(net, Service.Connectivity));
|
||||
|
||||
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
|
||||
// Only broadcastdomaintype lswitch is supported
|
||||
assertFalse(_element.canHandle(net, Service.Connectivity));
|
||||
|
||||
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
|
||||
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(false);
|
||||
// No nvp provider in the network
|
||||
assertFalse(_element.canHandle(net, Service.Connectivity));
|
||||
|
||||
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(false);
|
||||
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
|
||||
// NVP provider does not provide Connectivity for this network
|
||||
assertFalse(_element.canHandle(net, Service.Connectivity));
|
||||
|
||||
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
|
||||
// Only service Connectivity is supported
|
||||
assertFalse(_element.canHandle(net, Service.Dhcp));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
Network network = mock(Network.class);
|
||||
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
|
||||
when(network.getId()).thenReturn(42L);
|
||||
|
||||
NetworkOffering offering = mock(NetworkOffering.class);
|
||||
when(offering.getId()).thenReturn(42L);
|
||||
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
|
||||
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
|
||||
|
||||
DeployDestination dest = mock(DeployDestination.class);
|
||||
|
||||
Domain dom = mock(Domain.class);
|
||||
when(dom.getName()).thenReturn("domain");
|
||||
Account acc = mock(Account.class);
|
||||
when(acc.getAccountName()).thenReturn("accountname");
|
||||
ReservationContext context = mock(ReservationContext.class);
|
||||
when(context.getDomain()).thenReturn(dom);
|
||||
when(context.getAccount()).thenReturn(acc);
|
||||
|
||||
//assertTrue(_element.implement(network, offering, dest, context));
|
||||
}
|
||||
|
||||
}
|
||||
@ -272,12 +272,126 @@ public class NiciraNvpGuestNetworkGuruTest {
|
||||
|
||||
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
|
||||
when(answer.getResult()).thenReturn(true);
|
||||
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
|
||||
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
|
||||
|
||||
Network implementednetwork = guru.implement(network, offering, dest, res);
|
||||
assertTrue(implementednetwork != null);
|
||||
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapcityException {
|
||||
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(42L);
|
||||
|
||||
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
|
||||
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
|
||||
when(device.getId()).thenReturn(1L);
|
||||
|
||||
NetworkOffering offering = mock(NetworkOffering.class);
|
||||
when(offering.getId()).thenReturn(42L);
|
||||
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
|
||||
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
|
||||
|
||||
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
|
||||
|
||||
DeploymentPlan plan = mock(DeploymentPlan.class);
|
||||
|
||||
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");
|
||||
|
||||
|
||||
DeployDestination dest = mock(DeployDestination.class);
|
||||
|
||||
DataCenter dc = mock(DataCenter.class);
|
||||
when(dest.getDataCenter()).thenReturn(dc);
|
||||
|
||||
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(42L);
|
||||
|
||||
when(netmgr.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
|
||||
Domain dom = mock(Domain.class);
|
||||
when(dom.getName()).thenReturn("domain");
|
||||
Account acc = mock(Account.class);
|
||||
when(acc.getAccountName()).thenReturn("accountname");
|
||||
ReservationContext res = mock(ReservationContext.class);
|
||||
when(res.getDomain()).thenReturn(dom);
|
||||
when(res.getAccount()).thenReturn(acc);
|
||||
|
||||
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
|
||||
when(answer.getResult()).thenReturn(true);
|
||||
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
|
||||
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
|
||||
|
||||
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(42L), (Command)any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImplementURIException() throws InsufficientVirtualNetworkCapcityException {
|
||||
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(42L);
|
||||
|
||||
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
|
||||
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
|
||||
when(device.getId()).thenReturn(1L);
|
||||
|
||||
NetworkOffering offering = mock(NetworkOffering.class);
|
||||
when(offering.getId()).thenReturn(42L);
|
||||
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
|
||||
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
|
||||
|
||||
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
|
||||
|
||||
DeploymentPlan plan = mock(DeploymentPlan.class);
|
||||
|
||||
NetworkVO network = mock(NetworkVO.class);
|
||||
when(network.getName()).thenReturn("testnetwork");
|
||||
when(network.getState()).thenReturn(State.Implementing);
|
||||
|
||||
DeployDestination dest = mock(DeployDestination.class);
|
||||
|
||||
DataCenter dc = mock(DataCenter.class);
|
||||
when(dest.getDataCenter()).thenReturn(dc);
|
||||
|
||||
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(42L);
|
||||
|
||||
when(netmgr.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
|
||||
Domain dom = mock(Domain.class);
|
||||
when(dom.getName()).thenReturn("domain");
|
||||
Account acc = mock(Account.class);
|
||||
when(acc.getAccountName()).thenReturn("accountname");
|
||||
ReservationContext res = mock(ReservationContext.class);
|
||||
when(res.getDomain()).thenReturn(dom);
|
||||
when(res.getAccount()).thenReturn(acc);
|
||||
|
||||
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
|
||||
when(answer.getResult()).thenReturn(true);
|
||||
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
|
||||
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
|
||||
|
||||
Network implementednetwork = guru.implement(network, offering, dest, res);
|
||||
assertTrue(implementednetwork == null);
|
||||
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShutdown() throws InsufficientVirtualNetworkCapcityException, URISyntaxException {
|
||||
|
||||
@ -153,25 +153,7 @@ public abstract class GuestNetworkGuru extends AdapterBase implements NetworkGur
|
||||
}
|
||||
|
||||
protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork);
|
||||
/* protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final List<String> isolationMethods) {
|
||||
// This guru handles only Guest Isolated network that supports Source nat service
|
||||
<<<<<<< HEAD
|
||||
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType())
|
||||
&& offering.getGuestType() == Network.GuestType.Isolated && !offering.isSystemOnly()) {
|
||||
=======
|
||||
if (networkType == NetworkType.Advanced
|
||||
&& isMyTrafficType(offering.getTrafficType())
|
||||
&& offering.getGuestType() == Network.GuestType.Isolated
|
||||
&& isMyIsolationMethod(isolationMethods)) {
|
||||
>>>>>>> master
|
||||
return true;
|
||||
} else {
|
||||
s_logger.trace("We only take care of non-system Guest networks of type " + GuestType.Isolated + " in zone of type "
|
||||
+ NetworkType.Advanced);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
|
||||
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
|
||||
|
||||
@ -41,19 +41,19 @@
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim25</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-vim</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cloud.com.vmware</groupId>
|
||||
<artifactId>vmware-apputils</artifactId>
|
||||
<version>${cs.vmware.api.version}</version>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.axis</groupId>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user