Skip to content

Commit 085bd3b

Browse files
committed
Merge branch '4.19' into 4.20
2 parents 0b5a5e8 + 0d5047b commit 085bd3b

File tree

10 files changed

+227
-130
lines changed

10 files changed

+227
-130
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/firewall/CreateFirewallRuleCmd.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.apache.commons.collections.CollectionUtils;
2223

2324
import org.apache.cloudstack.acl.RoleType;
2425
import org.apache.cloudstack.api.APICommand;
@@ -40,6 +41,7 @@
4041
import com.cloud.network.IpAddress;
4142
import com.cloud.network.rules.FirewallRule;
4243
import com.cloud.user.Account;
44+
import com.cloud.utils.StringUtils;
4345
import com.cloud.utils.net.NetUtils;
4446

4547
@APICommand(name = "createFirewallRule", description = "Creates a firewall rule for a given IP address", responseObject = FirewallResponse.class, entityType = {FirewallRule.class},
@@ -125,14 +127,13 @@ public void setPublicEndPort(Integer publicEndPort) {
125127

126128
@Override
127129
public List<String> getSourceCidrList() {
128-
if (cidrlist != null) {
130+
if (CollectionUtils.isNotEmpty(cidrlist) && !(cidrlist.size() == 1 && StringUtils.isBlank(cidrlist.get(0)))) {
129131
return cidrlist;
130132
} else {
131-
List<String> oneCidrList = new ArrayList<String>();
133+
List<String> oneCidrList = new ArrayList<>();
132134
oneCidrList.add(NetUtils.ALL_IP4_CIDRS);
133135
return oneCidrList;
134136
}
135-
136137
}
137138

138139
// ///////////////////////////////////////////////////
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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 org.apache.cloudstack.api.command.user.firewall;
18+
19+
import java.util.ArrayList;
20+
import java.util.Arrays;
21+
import java.util.Collections;
22+
import java.util.List;
23+
24+
import org.apache.commons.collections.CollectionUtils;
25+
import org.junit.Assert;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.mockito.junit.MockitoJUnitRunner;
29+
import org.springframework.test.util.ReflectionTestUtils;
30+
31+
import com.cloud.utils.net.NetUtils;
32+
33+
@RunWith(MockitoJUnitRunner.class)
34+
public class CreateFirewallRuleCmdTest {
35+
36+
private void validateAllIp4Cidr(final CreateFirewallRuleCmd cmd) {
37+
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
38+
Assert.assertEquals(1, cmd.getSourceCidrList().size());
39+
Assert.assertEquals(NetUtils.ALL_IP4_CIDRS, cmd.getSourceCidrList().get(0));
40+
}
41+
42+
@Test
43+
public void testGetSourceCidrList_Null() {
44+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
45+
ReflectionTestUtils.setField(cmd, "cidrlist", null);
46+
validateAllIp4Cidr(cmd);
47+
}
48+
49+
@Test
50+
public void testGetSourceCidrList_Empty() {
51+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
52+
ReflectionTestUtils.setField(cmd, "cidrlist", new ArrayList<>());
53+
validateAllIp4Cidr(cmd);
54+
}
55+
56+
@Test
57+
public void testGetSourceCidrList_NullFirstElement() {
58+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
59+
List<String> list = new ArrayList<>();
60+
list.add(null);
61+
ReflectionTestUtils.setField(cmd, "cidrlist", list);
62+
validateAllIp4Cidr(cmd);
63+
}
64+
65+
@Test
66+
public void testGetSourceCidrList_EmptyFirstElement() {
67+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
68+
ReflectionTestUtils.setField(cmd, "cidrlist", Collections.singletonList(" "));
69+
validateAllIp4Cidr(cmd);
70+
}
71+
72+
@Test
73+
public void testGetSourceCidrList_Valid() {
74+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
75+
String cidr = "10.1.1.1/22";
76+
ReflectionTestUtils.setField(cmd, "cidrlist", Collections.singletonList(cidr));
77+
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
78+
Assert.assertEquals(1, cmd.getSourceCidrList().size());
79+
Assert.assertEquals(cidr, cmd.getSourceCidrList().get(0));
80+
}
81+
82+
@Test
83+
public void testGetSourceCidrList_EmptyFirstElementButMore() {
84+
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
85+
String cidr = "10.1.1.1/22";
86+
ReflectionTestUtils.setField(cmd, "cidrlist", Arrays.asList(" ", cidr));
87+
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
88+
Assert.assertEquals(2, cmd.getSourceCidrList().size());
89+
Assert.assertEquals(cidr, cmd.getSourceCidrList().get(1));
90+
}
91+
}

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public interface NetworkOrchestrationService {
8282
ConfigKey<Integer> NetworkLockTimeout = new ConfigKey<Integer>(Integer.class, NetworkLockTimeoutCK, "Network", "600",
8383
"Lock wait timeout (seconds) while implementing network", true, Scope.Global, null);
8484

85+
ConfigKey<String> DeniedRoutes = new ConfigKey<String>(String.class, "denied.routes", "Network", "",
86+
"Routes that are denied, can not be used for Static Routes creation for the VPC Private Gateway", true, ConfigKey.Scope.Zone, null);
87+
8588
ConfigKey<String> GuestDomainSuffix = new ConfigKey<String>(String.class, GuestDomainSuffixCK, "Network", "cloud.internal",
8689
"Default domain name for vms inside virtualized networks fronted by router", true, ConfigKey.Scope.Zone, null);
8790

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4872,7 +4872,7 @@ public String getConfigComponentName() {
48724872

48734873
@Override
48744874
public ConfigKey<?>[] getConfigKeys() {
4875-
return new ConfigKey<?>[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout,
4875+
return new ConfigKey<?>[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, DeniedRoutes,
48764876
GuestDomainSuffix, NetworkThrottlingRate, MinVRVersion,
48774877
PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RollingRestartEnabled,
48784878
TUNGSTEN_ENABLED, NSX_ENABLED };

0 commit comments

Comments
 (0)