Skip to content

Commit 541c23e

Browse files
Merge remote-tracking branch 'laszlo/CLOUDSTACK-8279'
This closes #90 Signed-off-by: Rohit Yadav <[email protected]>
2 parents 62e179b + df11bb2 commit 541c23e

File tree

2 files changed

+124
-92
lines changed

2 files changed

+124
-92
lines changed

core/src/com/cloud/agent/api/routing/SetFirewallRulesCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String[][] generateFwRules() {
5353
* each entry format <ip>:protocol:srcport:destport:scidr:
5454
* reverted entry format <ip>:reverted:0:0:0:
5555
*/
56-
if (fwTO.revoked() == true) {
56+
if (fwTO.revoked()) {
5757
StringBuilder sb = new StringBuilder();
5858
/* This entry is added just to make sure atleast there will one entry in the list to get the ipaddress */
5959
sb.append(fwTO.getSrcIp()).append(":reverted:0:0:0:");
@@ -77,7 +77,7 @@ public String[][] generateFwRules() {
7777
if (cidr == null || cidr.isEmpty()) {
7878
sb.append("0.0.0.0/0");
7979
} else {
80-
Boolean firstEntry = true;
80+
boolean firstEntry = true;
8181
for (String tag : cidr) {
8282
if (!firstEntry)
8383
sb.append("-");

core/test/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java

Lines changed: 122 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import static org.junit.Assert.fail;
2525

2626
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
import java.util.Collection;
2729
import java.util.HashMap;
2830
import java.util.LinkedList;
2931
import java.util.List;
@@ -80,6 +82,9 @@
8082
import com.cloud.network.vpc.VpcGateway;
8183
import com.cloud.utils.ExecutionResult;
8284
import com.cloud.utils.net.NetUtils;
85+
import com.google.common.base.Function;
86+
import com.google.common.base.Predicate;
87+
import com.google.common.collect.Collections2;
8388

8489
@RunWith(SpringJUnit4ClassRunner.class)
8590
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@@ -669,7 +674,13 @@ protected SetFirewallRulesCommand generateSetFirewallRulesCommand() {
669674

670675
private void verifyArgs(SetFirewallRulesCommand cmd, String script, String args) {
671676
assertEquals(script, VRScripts.FIREWALL_INGRESS);
672-
assertEquals(args, " -F -a 64.10.10.10:ICMP:0:0:10.10.1.1/24-10.10.1.2/24:,64.10.10.10:TCP:22:80:10.10.1.1/24-10.10.1.2/24:,64.10.10.10:reverted:0:0:0:,");
677+
678+
//Since the arguments are generated with a Set
679+
//one can not make a bet on the order
680+
assertTrue(args.startsWith(" -F -a "));
681+
assertTrue(args.contains("64.10.10.10:ICMP:0:0:10.10.1.1/24-10.10.1.2/24:"));
682+
assertTrue(args.contains("64.10.10.10:reverted:0:0:0:"));
683+
assertTrue(args.contains("64.10.10.10:TCP:22:80:10.10.1.1/24-10.10.1.2/24:"));
673684
}
674685

675686
@Test
@@ -1003,95 +1014,116 @@ protected void verifyFile(AggregationControlCommand cmd, String path, String fil
10031014
assertEquals(path, "/var/cache/cloud/");
10041015
assertTrue(filename.startsWith("VR-"));
10051016
assertTrue(filename.endsWith(".cfg"));
1006-
assertEquals(content, "#Apache CloudStack Virtual Router Config File\n" +
1007-
"<version>\n" +
1008-
"1.0\n" +
1009-
"</version>\n" +
1010-
"<script>\n" +
1011-
"/opt/cloud/bin/ipassoc.sh -A -s -f -l 64.1.1.10/24 -c eth2 -g 64.1.1.1\n" +
1012-
"</script>\n" +
1013-
"<script>\n" +
1014-
"/opt/cloud/bin/ipassoc.sh -D -l 64.1.1.11/24 -c eth2 -g 64.1.1.1\n" +
1015-
"</script>\n" +
1016-
"<script>\n" +
1017-
"/opt/cloud/bin/ipassoc.sh -A -l 65.1.1.11/24 -c eth2 -g 65.1.1.1\n" +
1018-
"</script>\n" +
1019-
"<script>\n" +
1020-
"/opt/cloud/bin/vpc_ipassoc.sh -A -l 64.1.1.10 -c eth2 -g 64.1.1.1 -m 24 -n 64.1.1.0\n" +
1021-
"</script>\n" +
1022-
"<script>\n" +
1023-
"/opt/cloud/bin/vpc_privateGateway.sh -A -l 64.1.1.10 -c eth2\n" +
1024-
"</script>\n" +
1025-
"<script>\n" +
1026-
"/opt/cloud/bin/vpc_ipassoc.sh -D -l 64.1.1.11 -c eth2 -g 64.1.1.1 -m 24 -n 64.1.1.0\n" +
1027-
"</script>\n" +
1028-
"<script>\n" +
1029-
"/opt/cloud/bin/vpc_privateGateway.sh -D -l 64.1.1.11 -c eth2\n" +
1030-
"</script>\n" +
1031-
"<script>\n" +
1032-
"/opt/cloud/bin/vpc_ipassoc.sh -A -l 65.1.1.11 -c eth2 -g 65.1.1.1 -m 24 -n 65.1.1.0\n" +
1033-
"</script>\n" +
1034-
"<script>\n" +
1035-
"/opt/cloud/bin/firewall_ingress.sh -F -a 64.10.10.10:ICMP:0:0:10.10.1.1/24-10.10.1.2/24:,64.10.10.10:TCP:22:80:10.10.1.1/24-10.10.1.2/24:,64.10.10.10:reverted:0:0:0:,\n" +
1036-
"</script>\n" +
1037-
"<script>\n" +
1038-
"/opt/cloud/bin/firewall_nat.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22:80\n" +
1039-
"</script>\n" +
1040-
"<script>\n" +
1041-
"/opt/cloud/bin/firewall_nat.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080:8080\n" +
1042-
"</script>\n" +
1043-
"<script>\n" +
1044-
"/opt/cloud/bin/vpc_portforwarding.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22-80\n" +
1045-
"</script>\n" +
1046-
"<script>\n" +
1047-
"/opt/cloud/bin/vpc_portforwarding.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080-8080\n" +
1048-
"</script>\n" +
1049-
"<script>\n" +
1050-
"/opt/cloud/bin/createIpAlias.sh 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-\n" +
1051-
"</script>\n" +
1052-
"<script>\n" +
1053-
"/opt/cloud/bin/deleteIpAlias.sh 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-- 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-\n" +
1054-
"</script>\n" +
1055-
"<script>\n" +
1056-
"/opt/cloud/bin/dnsmasq.sh 10.1.20.2:10.1.20.1:255.255.255.0:10.1.20.5-10.1.21.2:10.1.21.1:255.255.255.0:10.1.21.5-\n" +
1057-
"</script>\n" +
1058-
"<script>\n" +
1059-
"/opt/cloud/bin/vpn_l2tp.sh -r 10.10.1.10-10.10.1.20 -p sharedkey -s 124.10.10.10 -l 10.10.1.1 -c -C 10.1.1.1/24 -i eth2\n" +
1060-
"</script>\n" +
1061-
"<script>\n" +
1062-
"/opt/cloud/bin/vpn_l2tp.sh -d -s 124.10.10.10 -C 10.1.1.1/24 -i eth2\n" +
1063-
"</script>\n" +
1064-
"<script>\n" +
1065-
"/opt/cloud/bin/vpn_l2tp.sh -r 10.10.1.10-10.10.1.20 -p sharedkey -s 124.10.10.10 -l 10.10.1.1 -c -C 10.1.1.1/24 -i eth1\n" +
1066-
"</script>\n" +
1067-
"<script>\n" +
1068-
"/opt/cloud/bin/firewall_nat.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22:80\n" +
1069-
"</script>\n" +
1070-
"<script>\n" +
1071-
"/opt/cloud/bin/firewall_nat.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080:8080\n" +
1072-
"</script>\n" +
1073-
"<script>\n" +
1074-
"/opt/cloud/bin/vpc_portforwarding.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22-80\n" +
1075-
"</script>\n" +
1076-
"<script>\n" +
1077-
"/opt/cloud/bin/vpc_portforwarding.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080-8080\n" +
1078-
"</script>\n" +
1079-
"<script>\n" +
1080-
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -4 10.1.10.2 -h vm1\n" +
1081-
"</script>\n" +
1082-
"<script>\n" +
1083-
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -h vm1 -6 2001:db8:0:0:0:ff00:42:8329 -u 00:03:00:01:12:34:56:78:90:AB\n" +
1084-
"</script>\n" +
1085-
"<script>\n" +
1086-
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -4 10.1.10.2 -h vm1 -6 2001:db8:0:0:0:ff00:42:8329 -u 00:03:00:01:12:34:56:78:90:AB\n" +
1087-
"</script>\n" +
1088-
"<script>\n" +
1089-
"/opt/cloud/bin/savepassword.sh -v 10.1.10.4 -p 123pass\n" +
1090-
"</script>\n" +
1091-
"<script>\n" +
1092-
"/opt/cloud/bin/vmdata.py -d eyIxMC4xLjEwLjQiOltbInVzZXJkYXRhIiwidXNlci1kYXRhIiwidXNlci1kYXRhIl0sWyJtZXRhZGF0YSIsInNlcnZpY2Utb2ZmZXJpbmciLCJzZXJ2aWNlT2ZmZXJpbmciXSxbIm1ldGFkYXRhIiwiYXZhaWxhYmlsaXR5LXpvbmUiLCJ6b25lTmFtZSJdLFsibWV0YWRhdGEiLCJsb2NhbC1pcHY0IiwiMTAuMS4xMC40Il0sWyJtZXRhZGF0YSIsImxvY2FsLWhvc3RuYW1lIiwidGVzdC12bSJdLFsibWV0YWRhdGEiLCJwdWJsaWMtaXB2NCIsIjExMC4xLjEwLjQiXSxbIm1ldGFkYXRhIiwicHVibGljLWhvc3RuYW1lIiwiaG9zdG5hbWUiXSxbIm1ldGFkYXRhIiwiaW5zdGFuY2UtaWQiLCJpLTQtVk0iXSxbIm1ldGFkYXRhIiwidm0taWQiLCI0Il0sWyJtZXRhZGF0YSIsInB1YmxpYy1rZXlzIiwicHVibGlja2V5Il0sWyJtZXRhZGF0YSIsImNsb3VkLWlkZW50aWZpZXIiLCJDbG91ZFN0YWNrLXt0ZXN0fSJdXX0=\n" +
1093-
"</script>" +
1094-
"\n");
1017+
Collection<String> filteredScripts = Collections2.transform(Collections2.filter (
1018+
Arrays.asList(content.split("</?script>")), new Predicate<String>() {
1019+
1020+
@Override
1021+
public boolean apply(String str) {
1022+
return str.trim().startsWith("/opt/cloud");
1023+
}
1024+
}), new Function<String, String>() {
1025+
1026+
@Override
1027+
public String apply(String str) {
1028+
return str.trim();
1029+
}
1030+
});
1031+
String[] scripts = filteredScripts.toArray(new String[filteredScripts
1032+
.size()]);
1033+
1034+
assertEquals(
1035+
"/opt/cloud/bin/ipassoc.sh -A -s -f -l 64.1.1.10/24 -c eth2 -g 64.1.1.1",
1036+
scripts[0]);
1037+
1038+
assertEquals(
1039+
"/opt/cloud/bin/ipassoc.sh -D -l 64.1.1.11/24 -c eth2 -g 64.1.1.1",
1040+
scripts[1]);
1041+
1042+
assertEquals(
1043+
"/opt/cloud/bin/ipassoc.sh -A -l 65.1.1.11/24 -c eth2 -g 65.1.1.1",
1044+
scripts[2]);
1045+
assertEquals(
1046+
"/opt/cloud/bin/vpc_ipassoc.sh -A -l 64.1.1.10 -c eth2 -g 64.1.1.1 -m 24 -n 64.1.1.0",
1047+
scripts[3]);
1048+
assertEquals(
1049+
"/opt/cloud/bin/vpc_privateGateway.sh -A -l 64.1.1.10 -c eth2",
1050+
scripts[4]);
1051+
assertEquals(
1052+
"/opt/cloud/bin/vpc_ipassoc.sh -D -l 64.1.1.11 -c eth2 -g 64.1.1.1 -m 24 -n 64.1.1.0",
1053+
scripts[5]);
1054+
assertEquals(
1055+
"/opt/cloud/bin/vpc_privateGateway.sh -D -l 64.1.1.11 -c eth2",
1056+
scripts[6]);
1057+
assertEquals(
1058+
"/opt/cloud/bin/vpc_ipassoc.sh -A -l 65.1.1.11 -c eth2 -g 65.1.1.1 -m 24 -n 65.1.1.0",
1059+
scripts[7]);
1060+
//the list generated by SetFirewallCmd is actually generated through a Set
1061+
//therefore we can not bet on the order of the parameters
1062+
assertTrue(
1063+
scripts[8].matches("/opt/cloud/bin/firewall_ingress.sh -F -a .*"));
1064+
assertTrue(
1065+
scripts[8].contains("64.10.10.10:ICMP:0:0:10.10.1.1/24-10.10.1.2/24:"));
1066+
assertTrue(
1067+
scripts[8].contains("64.10.10.10:TCP:22:80:10.10.1.1/24-10.10.1.2/24:"));
1068+
assertTrue(
1069+
scripts[8].contains("64.10.10.10:reverted:0:0:0:"));
1070+
1071+
assertEquals(
1072+
"/opt/cloud/bin/firewall_nat.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22:80",
1073+
scripts[9]);
1074+
assertEquals(
1075+
"/opt/cloud/bin/firewall_nat.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080:8080",
1076+
scripts[10]);
1077+
assertEquals(
1078+
"/opt/cloud/bin/vpc_portforwarding.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22-80",
1079+
scripts[11]);
1080+
assertEquals(
1081+
"/opt/cloud/bin/vpc_portforwarding.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080-8080",
1082+
scripts[12]);
1083+
assertEquals(
1084+
"/opt/cloud/bin/createIpAlias.sh 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-",
1085+
scripts[13]);
1086+
assertEquals(
1087+
"/opt/cloud/bin/deleteIpAlias.sh 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-- 1:169.254.3.10:255.255.255.0-2:169.254.3.11:255.255.255.0-3:169.254.3.12:255.255.255.0-",
1088+
scripts[14]);
1089+
assertEquals(
1090+
"/opt/cloud/bin/dnsmasq.sh 10.1.20.2:10.1.20.1:255.255.255.0:10.1.20.5-10.1.21.2:10.1.21.1:255.255.255.0:10.1.21.5-",
1091+
scripts[15]);
1092+
assertEquals(
1093+
"/opt/cloud/bin/vpn_l2tp.sh -r 10.10.1.10-10.10.1.20 -p sharedkey -s 124.10.10.10 -l 10.10.1.1 -c -C 10.1.1.1/24 -i eth2",
1094+
scripts[16]);
1095+
assertEquals(
1096+
"/opt/cloud/bin/vpn_l2tp.sh -d -s 124.10.10.10 -C 10.1.1.1/24 -i eth2",
1097+
scripts[17]);
1098+
assertEquals(
1099+
"/opt/cloud/bin/vpn_l2tp.sh -r 10.10.1.10-10.10.1.20 -p sharedkey -s 124.10.10.10 -l 10.10.1.1 -c -C 10.1.1.1/24 -i eth1",
1100+
scripts[18]);
1101+
assertEquals(
1102+
"/opt/cloud/bin/firewall_nat.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22:80",
1103+
scripts[19]);
1104+
assertEquals(
1105+
"/opt/cloud/bin/firewall_nat.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080:8080",
1106+
scripts[20]);
1107+
assertEquals(
1108+
"/opt/cloud/bin/vpc_portforwarding.sh -A -P tcp -l 64.1.1.10 -p 22:80 -r 10.10.1.10 -d 22-80",
1109+
scripts[21]);
1110+
assertEquals(
1111+
"/opt/cloud/bin/vpc_portforwarding.sh -D -P udp -l 64.1.1.11 -p 8080:8080 -r 10.10.1.11 -d 8080-8080",
1112+
scripts[22]);
1113+
assertEquals(
1114+
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -4 10.1.10.2 -h vm1",
1115+
scripts[23]);
1116+
assertEquals(
1117+
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -h vm1 -6 2001:db8:0:0:0:ff00:42:8329 -u 00:03:00:01:12:34:56:78:90:AB",
1118+
scripts[24]);
1119+
assertEquals(
1120+
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -4 10.1.10.2 -h vm1 -6 2001:db8:0:0:0:ff00:42:8329 -u 00:03:00:01:12:34:56:78:90:AB",
1121+
scripts[25]);
1122+
assertEquals("/opt/cloud/bin/savepassword.sh -v 10.1.10.4 -p 123pass",
1123+
scripts[26]);
1124+
assertEquals(
1125+
"/opt/cloud/bin/vmdata.py -d eyIxMC4xLjEwLjQiOltbInVzZXJkYXRhIiwidXNlci1kYXRhIiwidXNlci1kYXRhIl0sWyJtZXRhZGF0YSIsInNlcnZpY2Utb2ZmZXJpbmciLCJzZXJ2aWNlT2ZmZXJpbmciXSxbIm1ldGFkYXRhIiwiYXZhaWxhYmlsaXR5LXpvbmUiLCJ6b25lTmFtZSJdLFsibWV0YWRhdGEiLCJsb2NhbC1pcHY0IiwiMTAuMS4xMC40Il0sWyJtZXRhZGF0YSIsImxvY2FsLWhvc3RuYW1lIiwidGVzdC12bSJdLFsibWV0YWRhdGEiLCJwdWJsaWMtaXB2NCIsIjExMC4xLjEwLjQiXSxbIm1ldGFkYXRhIiwicHVibGljLWhvc3RuYW1lIiwiaG9zdG5hbWUiXSxbIm1ldGFkYXRhIiwiaW5zdGFuY2UtaWQiLCJpLTQtVk0iXSxbIm1ldGFkYXRhIiwidm0taWQiLCI0Il0sWyJtZXRhZGF0YSIsInB1YmxpYy1rZXlzIiwicHVibGlja2V5Il0sWyJtZXRhZGF0YSIsImNsb3VkLWlkZW50aWZpZXIiLCJDbG91ZFN0YWNrLXt0ZXN0fSJdXX0=",
1126+
scripts[27]);
10951127
}
10961128

10971129
}

0 commit comments

Comments
 (0)