Skip to content

Commit edb00bb

Browse files
committed
Merge branch 'master' into api_refactoring
2 parents 580bf85 + cc3d692 commit edb00bb

8 files changed

Lines changed: 248 additions & 29 deletions

File tree

plugins/hypervisors/vmware/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@
3636
<groupId>com.cloud.com.vmware</groupId>
3737
<artifactId>vmware-vim25</artifactId>
3838
<version>${cs.vmware.api.version}</version>
39-
<scope>provided</scope>
39+
<scope>compile</scope>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.cloud.com.vmware</groupId>
4343
<artifactId>vmware-vim</artifactId>
4444
<version>${cs.vmware.api.version}</version>
45-
<scope>provided</scope>
45+
<scope>compile</scope>
4646
</dependency>
4747
<dependency>
4848
<groupId>com.cloud.com.vmware</groupId>
4949
<artifactId>vmware-apputils</artifactId>
5050
<version>${cs.vmware.api.version}</version>
51-
<scope>provided</scope>
51+
<scope>compile</scope>
5252
</dependency>
5353
<dependency>
5454
<groupId>org.apache.axis</groupId>

plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public Provider getProvider() {
170170
return Provider.NiciraNvp;
171171
}
172172

173-
private boolean canHandle(Network network, Service service) {
173+
protected boolean canHandle(Network network, Service service) {
174174
s_logger.debug("Checking if NiciraNvpElement can handle service "
175175
+ service.getName() + " on network " + network.getDisplayText());
176176
if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
@@ -845,6 +845,7 @@ public boolean applyIps(Network network,
845845
ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(),
846846
niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
847847
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
848+
//FIXME answer can be null if the host is down
848849
return answer.getResult();
849850
}
850851
else {

plugins/network-elements/nicira-nvp/src/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.cloud.agent.api.CreateLogicalSwitchCommand;
3030
import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
3131
import com.cloud.agent.api.DeleteLogicalSwitchCommand;
32+
import com.cloud.dc.DataCenter;
3233
import com.cloud.dc.DataCenter.NetworkType;
3334
import com.cloud.dc.dao.DataCenterDao;
3435
import com.cloud.deploy.DeployDestination;
@@ -119,8 +120,9 @@ public Network design(NetworkOffering offering, DeploymentPlan plan,
119120
Network userSpecified, Account owner) {
120121
// Check of the isolation type of the related physical network is STT
121122
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
122-
if (physnet == null || physnet.getIsolationMethods() == null || !physnet.getIsolationMethods().contains("STT")) {
123-
s_logger.debug("Refusing to design this network, the physical isolation type is not STT");
123+
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
124+
if (!canHandle(offering,dc.getNetworkType(),physnet)) {
125+
s_logger.debug("Refusing to design this network");
124126
return null;
125127
}
126128

@@ -199,6 +201,7 @@ public Network implement(Network network, NetworkOffering offering,
199201
s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString());
200202
} catch (URISyntaxException e) {
201203
s_logger.error("Unable to store logical switch id in broadcast uri, uuid = " + implemented.getUuid(), e);
204+
return null;
202205
}
203206

204207
return implemented;

plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected HttpClient createHttpClient() {
8484
protected HttpMethod createMethod(String type, String uri) throws NiciraNvpApiException {
8585
String url;
8686
try {
87-
url = new URL(_protocol, _host, "/ws.v1/login").toString();
87+
url = new URL(_protocol, _host, uri).toString();
8888
} catch (MalformedURLException e) {
8989
s_logger.error("Unable to build Nicira API URL", e);
9090
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.network.element;
18+
19+
import java.util.Collections;
20+
21+
import javax.naming.ConfigurationException;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
26+
import com.cloud.deploy.DeployDestination;
27+
import com.cloud.domain.Domain;
28+
import com.cloud.exception.ConcurrentOperationException;
29+
import com.cloud.exception.InsufficientCapacityException;
30+
import com.cloud.exception.ResourceUnavailableException;
31+
import com.cloud.network.Network;
32+
import com.cloud.network.Network.GuestType;
33+
import com.cloud.network.Network.Provider;
34+
import com.cloud.network.Network.Service;
35+
import com.cloud.network.NetworkManager;
36+
import com.cloud.network.Networks.BroadcastDomainType;
37+
import com.cloud.network.Networks.TrafficType;
38+
import com.cloud.network.dao.NetworkServiceMapDao;
39+
import com.cloud.offering.NetworkOffering;
40+
import com.cloud.resource.ResourceManager;
41+
import com.cloud.user.Account;
42+
import com.cloud.vm.ReservationContext;
43+
44+
import static org.junit.Assert.*;
45+
import static org.mockito.Mockito.*;
46+
47+
public class NiciraNvpElementTest {
48+
49+
NiciraNvpElement _element = new NiciraNvpElement();
50+
NetworkManager _networkManager = mock(NetworkManager.class);
51+
NetworkServiceMapDao _ntwkSrvcDao = mock (NetworkServiceMapDao.class);
52+
53+
@Before
54+
public void setUp() throws ConfigurationException {
55+
_element._resourceMgr = mock(ResourceManager.class);
56+
_element._networkManager = _networkManager;
57+
_element._ntwkSrvcDao = _ntwkSrvcDao;
58+
59+
// Standard responses
60+
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
61+
62+
_element.configure("NiciraNvpTestElement", Collections.<String, Object> emptyMap());
63+
}
64+
65+
@Test
66+
public void canHandleTest() {
67+
Network net = mock(Network.class);
68+
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
69+
when(net.getId()).thenReturn(42L);
70+
71+
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
72+
// Golden path
73+
assertTrue(_element.canHandle(net, Service.Connectivity));
74+
75+
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
76+
// Only broadcastdomaintype lswitch is supported
77+
assertFalse(_element.canHandle(net, Service.Connectivity));
78+
79+
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
80+
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(false);
81+
// No nvp provider in the network
82+
assertFalse(_element.canHandle(net, Service.Connectivity));
83+
84+
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(false);
85+
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
86+
// NVP provider does not provide Connectivity for this network
87+
assertFalse(_element.canHandle(net, Service.Connectivity));
88+
89+
when(_networkManager.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
90+
// Only service Connectivity is supported
91+
assertFalse(_element.canHandle(net, Service.Dhcp));
92+
93+
}
94+
95+
@Test
96+
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
97+
Network network = mock(Network.class);
98+
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
99+
when(network.getId()).thenReturn(42L);
100+
101+
NetworkOffering offering = mock(NetworkOffering.class);
102+
when(offering.getId()).thenReturn(42L);
103+
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
104+
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
105+
106+
DeployDestination dest = mock(DeployDestination.class);
107+
108+
Domain dom = mock(Domain.class);
109+
when(dom.getName()).thenReturn("domain");
110+
Account acc = mock(Account.class);
111+
when(acc.getAccountName()).thenReturn("accountname");
112+
ReservationContext context = mock(ReservationContext.class);
113+
when(context.getDomain()).thenReturn(dom);
114+
when(context.getAccount()).thenReturn(acc);
115+
116+
//assertTrue(_element.implement(network, offering, dest, context));
117+
}
118+
119+
}

plugins/network-elements/nicira-nvp/test/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,126 @@ public void testImplement() throws InsufficientVirtualNetworkCapcityException {
272272

273273
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
274274
when(answer.getResult()).thenReturn(true);
275+
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
275276
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
276277

277278
Network implementednetwork = guru.implement(network, offering, dest, res);
278279
assertTrue(implementednetwork != null);
279280
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
280281
}
282+
283+
@Test
284+
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapcityException {
285+
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
286+
when(physnetdao.findById((Long) any())).thenReturn(physnet);
287+
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
288+
when(physnet.getId()).thenReturn(42L);
289+
290+
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
291+
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
292+
when(device.getId()).thenReturn(1L);
293+
294+
NetworkOffering offering = mock(NetworkOffering.class);
295+
when(offering.getId()).thenReturn(42L);
296+
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
297+
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
298+
299+
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
300+
301+
DeploymentPlan plan = mock(DeploymentPlan.class);
302+
303+
NetworkVO network = mock(NetworkVO.class);
304+
when(network.getName()).thenReturn("testnetwork");
305+
when(network.getState()).thenReturn(State.Implementing);
306+
when(network.getGateway()).thenReturn("10.1.1.1");
307+
when(network.getCidr()).thenReturn("10.1.1.0/24");
308+
309+
310+
DeployDestination dest = mock(DeployDestination.class);
311+
312+
DataCenter dc = mock(DataCenter.class);
313+
when(dest.getDataCenter()).thenReturn(dc);
314+
315+
HostVO niciraHost = mock(HostVO.class);
316+
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
317+
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
318+
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
319+
when(niciraHost.getId()).thenReturn(42L);
320+
321+
when(netmgr.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
322+
Domain dom = mock(Domain.class);
323+
when(dom.getName()).thenReturn("domain");
324+
Account acc = mock(Account.class);
325+
when(acc.getAccountName()).thenReturn("accountname");
326+
ReservationContext res = mock(ReservationContext.class);
327+
when(res.getDomain()).thenReturn(dom);
328+
when(res.getAccount()).thenReturn(acc);
329+
330+
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
331+
when(answer.getResult()).thenReturn(true);
332+
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
333+
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
334+
335+
Network implementednetwork = guru.implement(network, offering, dest, res);
336+
assertTrue(implementednetwork != null);
337+
assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
338+
assertTrue(implementednetwork.getGateway().equals("10.1.1.1"));
339+
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
340+
}
341+
342+
@Test
343+
public void testImplementURIException() throws InsufficientVirtualNetworkCapcityException {
344+
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
345+
when(physnetdao.findById((Long) any())).thenReturn(physnet);
346+
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
347+
when(physnet.getId()).thenReturn(42L);
348+
349+
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
350+
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
351+
when(device.getId()).thenReturn(1L);
352+
353+
NetworkOffering offering = mock(NetworkOffering.class);
354+
when(offering.getId()).thenReturn(42L);
355+
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
356+
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
357+
358+
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
359+
360+
DeploymentPlan plan = mock(DeploymentPlan.class);
361+
362+
NetworkVO network = mock(NetworkVO.class);
363+
when(network.getName()).thenReturn("testnetwork");
364+
when(network.getState()).thenReturn(State.Implementing);
365+
366+
DeployDestination dest = mock(DeployDestination.class);
367+
368+
DataCenter dc = mock(DataCenter.class);
369+
when(dest.getDataCenter()).thenReturn(dc);
370+
371+
HostVO niciraHost = mock(HostVO.class);
372+
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
373+
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
374+
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
375+
when(niciraHost.getId()).thenReturn(42L);
376+
377+
when(netmgr.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
378+
Domain dom = mock(Domain.class);
379+
when(dom.getName()).thenReturn("domain");
380+
Account acc = mock(Account.class);
381+
when(acc.getAccountName()).thenReturn("accountname");
382+
ReservationContext res = mock(ReservationContext.class);
383+
when(res.getDomain()).thenReturn(dom);
384+
when(res.getAccount()).thenReturn(acc);
385+
386+
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
387+
when(answer.getResult()).thenReturn(true);
388+
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
389+
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
390+
391+
Network implementednetwork = guru.implement(network, offering, dest, res);
392+
assertTrue(implementednetwork == null);
393+
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
394+
}
281395

282396
@Test
283397
public void testShutdown() throws InsufficientVirtualNetworkCapcityException, URISyntaxException {

server/src/com/cloud/network/guru/GuestNetworkGuru.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,7 @@ public IsolationMethod[] getIsolationMethods() {
153153
}
154154

155155
protected abstract boolean canHandle(NetworkOffering offering, final NetworkType networkType, PhysicalNetwork physicalNetwork);
156-
/* protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final List<String> isolationMethods) {
157-
// This guru handles only Guest Isolated network that supports Source nat service
158-
<<<<<<< HEAD
159-
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType())
160-
&& offering.getGuestType() == Network.GuestType.Isolated && !offering.isSystemOnly()) {
161-
=======
162-
if (networkType == NetworkType.Advanced
163-
&& isMyTrafficType(offering.getTrafficType())
164-
&& offering.getGuestType() == Network.GuestType.Isolated
165-
&& isMyIsolationMethod(isolationMethods)) {
166-
>>>>>>> master
167-
return true;
168-
} else {
169-
s_logger.trace("We only take care of non-system Guest networks of type " + GuestType.Isolated + " in zone of type "
170-
+ NetworkType.Advanced);
171-
return false;
172-
}
173-
}
174-
*/
156+
175157
@Override
176158
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
177159
DataCenter dc = _dcDao.findById(plan.getDataCenterId());

vmware-base/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@
4141
<groupId>com.cloud.com.vmware</groupId>
4242
<artifactId>vmware-vim25</artifactId>
4343
<version>${cs.vmware.api.version}</version>
44-
<scope>provided</scope>
44+
<scope>compile</scope>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.cloud.com.vmware</groupId>
4848
<artifactId>vmware-vim</artifactId>
4949
<version>${cs.vmware.api.version}</version>
50-
<scope>provided</scope>
50+
<scope>compile</scope>
5151
</dependency>
5252
<dependency>
5353
<groupId>com.cloud.com.vmware</groupId>
5454
<artifactId>vmware-apputils</artifactId>
5555
<version>${cs.vmware.api.version}</version>
56-
<scope>provided</scope>
56+
<scope>compile</scope>
5757
</dependency>
5858
<dependency>
5959
<groupId>org.apache.axis</groupId>

0 commit comments

Comments
 (0)