Skip to content

Commit af0c1e4

Browse files
nvazquezrafaelweingartner
authored andcommitted
Fix DirectNetworkGuru canHandle checks for lowercase isolation methods (#3010)
1 parent c6e53f6 commit af0c1e4

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
2424
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
25+
import org.apache.commons.collections.CollectionUtils;
2526
import org.apache.log4j.Logger;
2627

2728
import com.cloud.dc.DataCenter;
@@ -119,10 +120,18 @@ public boolean isMyTrafficType(TrafficType type) {
119120
return false;
120121
}
121122

123+
/**
124+
* Return true if the physical network isolation method contains the expected isolation method for this guru
125+
*/
122126
protected boolean isMyIsolationMethod(PhysicalNetwork physicalNetwork) {
123127
for (IsolationMethod m : _isolationMethods) {
124-
if (physicalNetwork.getIsolationMethods().contains(m.toString())) {
125-
return true;
128+
List<String> isolationMethods = physicalNetwork.getIsolationMethods();
129+
if (CollectionUtils.isNotEmpty(isolationMethods)) {
130+
for (String method : isolationMethods) {
131+
if (method.equalsIgnoreCase(m.toString())) {
132+
return true;
133+
}
134+
}
126135
}
127136
}
128137
return false;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.guru;
18+
19+
import com.cloud.network.PhysicalNetwork;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
import org.mockito.Mock;
23+
import org.mockito.MockitoAnnotations;
24+
25+
import java.util.Arrays;
26+
27+
import static org.junit.Assert.assertTrue;
28+
import static org.mockito.Mockito.when;
29+
30+
public class DirectNetworkGuruTest {
31+
32+
DirectNetworkGuru guru = new DirectNetworkGuru();
33+
34+
@Mock
35+
PhysicalNetwork physicalNetwork;
36+
37+
@Before
38+
public void setup() throws Exception {
39+
MockitoAnnotations.initMocks(this);
40+
when(physicalNetwork.getIsolationMethods()).thenReturn(Arrays.asList("VXLAN", "VLAN"));
41+
}
42+
43+
@Test
44+
public void testIsMyIsolationMethodUppercaseMethods() {
45+
assertTrue(guru.isMyIsolationMethod(physicalNetwork));
46+
}
47+
48+
@Test
49+
public void testIsMyIsolationMethodLowercaseMethods() {
50+
when(physicalNetwork.getIsolationMethods()).thenReturn(Arrays.asList("vxlan", "vlan"));
51+
assertTrue(guru.isMyIsolationMethod(physicalNetwork));
52+
}
53+
}

0 commit comments

Comments
 (0)