Skip to content

Commit 9c4292c

Browse files
widoGabrielBrascher
authored andcommitted
network: Offerings do not have to have Security Grouping enabled (#3112)
Offerings can co-exist where on does provide Security Grouping in the network, but other guest Networks have no Security Grouping. In V(X)LAN isolation environments the L2 separation is handled by V(X)LAN and protection between Instances is handled by Security Grouping. There are multiple scenarios possible where one network has Security Grouping enabled because that is required in that network. In the other network, but in the same zone it could be a choice to have Security Grouping disabled and allow all traffic to flow. Signed-off-by: Wido den Hollander <wido@widodh.nl>
1 parent b363fd4 commit 9c4292c

3 files changed

Lines changed: 99 additions & 26 deletions

File tree

engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,9 +2246,6 @@ public Network createGuestNetwork(final long networkOfferingId, final String nam
22462246
if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)) {
22472247
throw new InvalidParameterValueException("Service SourceNat is not allowed in security group enabled zone");
22482248
}
2249-
if (!_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SecurityGroup)) {
2250-
throw new InvalidParameterValueException("network must have SecurityGroup provider in security group enabled zone");
2251-
}
22522249
}
22532250

22542251
//don't allow eip/elb networks in Advance zone

server/src/main/java/com/cloud/network/guru/DirectNetworkGuru.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,11 @@ public boolean isMyTrafficType(TrafficType type) {
122122
* Return true if the physical network isolation method contains the expected isolation method for this guru
123123
*/
124124
protected boolean isMyIsolationMethod(PhysicalNetwork physicalNetwork) {
125-
for (IsolationMethod m : _isolationMethods) {
125+
for (IsolationMethod m : this.getIsolationMethods()) {
126126
List<String> isolationMethods = physicalNetwork.getIsolationMethods();
127127
if (CollectionUtils.isNotEmpty(isolationMethods)) {
128128
for (String method : isolationMethods) {
129+
s_logger.debug(method + ": " + m.toString());
129130
if (method.equalsIgnoreCase(m.toString())) {
130131
return true;
131132
}
@@ -140,20 +141,11 @@ public TrafficType[] getSupportedTrafficType() {
140141
return TrafficTypes;
141142
}
142143

143-
/**
144-
* True for Advanced zones, with VXLAN isolation method and Security Groups enabled
145-
*/
146-
private boolean isMyIsolationMethodVxlanWithSecurityGroups(NetworkOffering offering, DataCenter dc, PhysicalNetwork physnet) {
147-
return dc.getNetworkType().equals(NetworkType.Advanced) &&
148-
_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.SecurityGroup) &&
149-
physnet.getIsolationMethods().contains("VXLAN");
150-
}
151-
152144
protected boolean canHandle(NetworkOffering offering, DataCenter dc, PhysicalNetwork physnet) {
153-
// this guru handles only Guest networks in Advance zone with source nat service disabled
154-
boolean vxlanWithSecurityGroups = isMyIsolationMethodVxlanWithSecurityGroups(offering, dc, physnet);
155-
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) &&
156-
(isMyIsolationMethod(physnet) || vxlanWithSecurityGroups) && offering.getGuestType() == GuestType.Shared
145+
if (dc.getNetworkType() == NetworkType.Advanced
146+
&& isMyTrafficType(offering.getTrafficType())
147+
&& isMyIsolationMethod(physnet)
148+
&& offering.getGuestType() == GuestType.Shared
157149
&& !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NuageVsp)
158150
&& !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NiciraNvp)) {
159151
return true;
@@ -169,6 +161,7 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
169161
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
170162

171163
if (!canHandle(offering, dc, physnet)) {
164+
s_logger.info("Refusing to design this network");
172165
return null;
173166
}
174167

@@ -222,7 +215,11 @@ public Network design(NetworkOffering offering, DeploymentPlan plan, Network use
222215

223216
protected DirectNetworkGuru() {
224217
super();
225-
_isolationMethods = new IsolationMethod[] { new IsolationMethod("VLAN") };
218+
_isolationMethods = new IsolationMethod[] { new IsolationMethod("VLAN"), new IsolationMethod("VXLAN") };
219+
}
220+
221+
public IsolationMethod[] getIsolationMethods() {
222+
return _isolationMethods;
226223
}
227224

228225
@Override

server/src/test/java/com/cloud/network/guru/DirectNetworkGuruTest.java

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,117 @@
1616
// under the License.
1717
package com.cloud.network.guru;
1818

19-
import com.cloud.network.PhysicalNetwork;
19+
import com.cloud.dc.DataCenter.NetworkType;
20+
import com.cloud.dc.DataCenterVO;
21+
import com.cloud.dc.dao.DataCenterDao;
22+
import com.cloud.deploy.DeploymentPlan;
23+
import com.cloud.network.Network;
24+
import com.cloud.network.NetworkModel;
25+
import com.cloud.network.Networks.TrafficType;
26+
import com.cloud.network.Network.GuestType;
27+
import com.cloud.network.PhysicalNetwork.IsolationMethod;
28+
import com.cloud.network.dao.PhysicalNetworkDao;
29+
import com.cloud.network.dao.PhysicalNetworkVO;
30+
import com.cloud.offering.NetworkOffering;
31+
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
32+
import com.cloud.user.Account;
2033
import org.junit.Before;
2134
import org.junit.Test;
2235
import org.mockito.Mock;
2336
import org.mockito.MockitoAnnotations;
2437

2538
import java.util.Arrays;
2639

40+
import static org.junit.Assert.assertEquals;
41+
import static org.junit.Assert.assertNotNull;
2742
import static org.junit.Assert.assertTrue;
2843
import static org.mockito.Mockito.when;
2944

3045
public class DirectNetworkGuruTest {
3146

32-
DirectNetworkGuru guru = new DirectNetworkGuru();
47+
protected DirectNetworkGuru guru = new DirectNetworkGuru();
3348

3449
@Mock
35-
PhysicalNetwork physicalNetwork;
50+
PhysicalNetworkVO physicalNetwork;
51+
52+
@Mock
53+
DataCenterVO dc;
54+
55+
@Mock
56+
NetworkOffering offering;
57+
58+
@Mock
59+
NetworkOfferingServiceMapDao ntwkOfferingSrvcDao;
60+
61+
@Mock
62+
DataCenterDao dcDao;
63+
64+
@Mock
65+
PhysicalNetworkDao physicalNetworkDao;
66+
67+
@Mock
68+
Network network;
69+
70+
@Mock
71+
NetworkModel networkModel;
72+
73+
@Mock
74+
DeploymentPlan plan;
75+
76+
@Mock
77+
Account owner;
3678

3779
@Before
38-
public void setup() throws Exception {
80+
public void setup() {
3981
MockitoAnnotations.initMocks(this);
82+
guru._ntwkOfferingSrvcDao = ntwkOfferingSrvcDao;
83+
guru._dcDao = dcDao;
84+
guru._physicalNetworkDao = physicalNetworkDao;
85+
guru._networkModel = networkModel;
86+
87+
when(physicalNetwork.getId()).thenReturn(1l);
4088
when(physicalNetwork.getIsolationMethods()).thenReturn(Arrays.asList("VXLAN", "VLAN"));
89+
90+
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
91+
when(dc.getId()).thenReturn(1l);
92+
when(offering.getGuestType()).thenReturn(GuestType.Shared);
93+
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
94+
when(offering.getId()).thenReturn(42l);
95+
when(ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NuageVsp)).thenReturn(false);
96+
when(ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NiciraNvp)).thenReturn(false);
4197
}
4298

4399
@Test
44-
public void testIsMyIsolationMethodUppercaseMethods() {
100+
public void testIsMyIsolationMethod() {
45101
assertTrue(guru.isMyIsolationMethod(physicalNetwork));
46102
}
47103

48104
@Test
49-
public void testIsMyIsolationMethodLowercaseMethods() {
50-
when(physicalNetwork.getIsolationMethods()).thenReturn(Arrays.asList("vxlan", "vlan"));
51-
assertTrue(guru.isMyIsolationMethod(physicalNetwork));
105+
public void testIsolationMethods() {
106+
IsolationMethod[] expected = new IsolationMethod[] { new IsolationMethod("VLAN"), new IsolationMethod("VXLAN") };
107+
assertEquals(expected, guru.getIsolationMethods());
108+
}
109+
110+
@Test
111+
public void testTrafficTypes() {
112+
assertTrue(guru.isMyTrafficType(TrafficType.Guest));
113+
}
114+
115+
@Test
116+
public void testCanHandle() {
117+
assertTrue(guru.canHandle(offering, dc, physicalNetwork));
118+
}
119+
120+
@Test
121+
public void testCanDesign() {
122+
when(dcDao.findById(dc.getId())).thenReturn(dc);
123+
when(plan.getDataCenterId()).thenReturn(1l);
124+
when(plan.getPhysicalNetworkId()).thenReturn(1l);
125+
when(physicalNetworkDao.findById(physicalNetwork.getId())).thenReturn(physicalNetwork);
126+
when(offering.isRedundantRouter()).thenReturn(false);
127+
128+
when(networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.SecurityGroup)).thenReturn(true);
129+
130+
assertNotNull(guru.design(offering, plan, network, owner));
52131
}
53132
}

0 commit comments

Comments
 (0)