Skip to content

Commit f8c003d

Browse files
committed
CLOUDSTACK-8279: test fix for java 1.8
The test build on an assumption on the order of items in a Set, while this changed in java 1.8 Signed-off-by: Laszlo Hornyak <[email protected]>
1 parent e6e3a20 commit f8c003d

File tree

1 file changed

+115
-89
lines changed

1 file changed

+115
-89
lines changed

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

Lines changed: 115 additions & 89 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)
@@ -1003,95 +1008,116 @@ protected void verifyFile(AggregationControlCommand cmd, String path, String fil
10031008
assertEquals(path, "/var/cache/cloud/");
10041009
assertTrue(filename.startsWith("VR-"));
10051010
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");
1011+
Collection<String> filteredScripts = Collections2.transform(Collections2.filter (
1012+
Arrays.asList(content.split("</?script>")), new Predicate<String>() {
1013+
1014+
@Override
1015+
public boolean apply(String str) {
1016+
return str.trim().startsWith("/opt/cloud");
1017+
}
1018+
}), new Function<String, String>() {
1019+
1020+
@Override
1021+
public String apply(String str) {
1022+
return str.trim();
1023+
}
1024+
});
1025+
String[] scripts = filteredScripts.toArray(new String[filteredScripts
1026+
.size()]);
1027+
1028+
assertEquals(
1029+
"/opt/cloud/bin/ipassoc.sh -A -s -f -l 64.1.1.10/24 -c eth2 -g 64.1.1.1",
1030+
scripts[0]);
1031+
1032+
assertEquals(
1033+
"/opt/cloud/bin/ipassoc.sh -D -l 64.1.1.11/24 -c eth2 -g 64.1.1.1",
1034+
scripts[1]);
1035+
1036+
assertEquals(
1037+
"/opt/cloud/bin/ipassoc.sh -A -l 65.1.1.11/24 -c eth2 -g 65.1.1.1",
1038+
scripts[2]);
1039+
assertEquals(
1040+
"/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",
1041+
scripts[3]);
1042+
assertEquals(
1043+
"/opt/cloud/bin/vpc_privateGateway.sh -A -l 64.1.1.10 -c eth2",
1044+
scripts[4]);
1045+
assertEquals(
1046+
"/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",
1047+
scripts[5]);
1048+
assertEquals(
1049+
"/opt/cloud/bin/vpc_privateGateway.sh -D -l 64.1.1.11 -c eth2",
1050+
scripts[6]);
1051+
assertEquals(
1052+
"/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",
1053+
scripts[7]);
1054+
//the list generated by SetFirewallCmd is actually generated through a Set
1055+
//therefore we can not bet on the order of the parameters
1056+
assertTrue(
1057+
scripts[8].matches("/opt/cloud/bin/firewall_ingress.sh -F -a .*"));
1058+
assertTrue(
1059+
scripts[8].contains("64.10.10.10:ICMP:0:0:10.10.1.1/24-10.10.1.2/24:"));
1060+
assertTrue(
1061+
scripts[8].contains("64.10.10.10:TCP:22:80:10.10.1.1/24-10.10.1.2/24:"));
1062+
assertTrue(
1063+
scripts[8].contains("64.10.10.10:reverted:0:0:0:"));
1064+
1065+
assertEquals(
1066+
"/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",
1067+
scripts[9]);
1068+
assertEquals(
1069+
"/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",
1070+
scripts[10]);
1071+
assertEquals(
1072+
"/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",
1073+
scripts[11]);
1074+
assertEquals(
1075+
"/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",
1076+
scripts[12]);
1077+
assertEquals(
1078+
"/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-",
1079+
scripts[13]);
1080+
assertEquals(
1081+
"/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-",
1082+
scripts[14]);
1083+
assertEquals(
1084+
"/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-",
1085+
scripts[15]);
1086+
assertEquals(
1087+
"/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",
1088+
scripts[16]);
1089+
assertEquals(
1090+
"/opt/cloud/bin/vpn_l2tp.sh -d -s 124.10.10.10 -C 10.1.1.1/24 -i eth2",
1091+
scripts[17]);
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 eth1",
1094+
scripts[18]);
1095+
assertEquals(
1096+
"/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",
1097+
scripts[19]);
1098+
assertEquals(
1099+
"/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",
1100+
scripts[20]);
1101+
assertEquals(
1102+
"/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",
1103+
scripts[21]);
1104+
assertEquals(
1105+
"/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",
1106+
scripts[22]);
1107+
assertEquals(
1108+
"/opt/cloud/bin/edithosts.sh -m 12:34:56:78:90:AB -4 10.1.10.2 -h vm1",
1109+
scripts[23]);
1110+
assertEquals(
1111+
"/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",
1112+
scripts[24]);
1113+
assertEquals(
1114+
"/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",
1115+
scripts[25]);
1116+
assertEquals("/opt/cloud/bin/savepassword.sh -v 10.1.10.4 -p 123pass",
1117+
scripts[26]);
1118+
assertEquals(
1119+
"/opt/cloud/bin/vmdata.py -d eyIxMC4xLjEwLjQiOltbInVzZXJkYXRhIiwidXNlci1kYXRhIiwidXNlci1kYXRhIl0sWyJtZXRhZGF0YSIsInNlcnZpY2Utb2ZmZXJpbmciLCJzZXJ2aWNlT2ZmZXJpbmciXSxbIm1ldGFkYXRhIiwiYXZhaWxhYmlsaXR5LXpvbmUiLCJ6b25lTmFtZSJdLFsibWV0YWRhdGEiLCJsb2NhbC1pcHY0IiwiMTAuMS4xMC40Il0sWyJtZXRhZGF0YSIsImxvY2FsLWhvc3RuYW1lIiwidGVzdC12bSJdLFsibWV0YWRhdGEiLCJwdWJsaWMtaXB2NCIsIjExMC4xLjEwLjQiXSxbIm1ldGFkYXRhIiwicHVibGljLWhvc3RuYW1lIiwiaG9zdG5hbWUiXSxbIm1ldGFkYXRhIiwiaW5zdGFuY2UtaWQiLCJpLTQtVk0iXSxbIm1ldGFkYXRhIiwidm0taWQiLCI0Il0sWyJtZXRhZGF0YSIsInB1YmxpYy1rZXlzIiwicHVibGlja2V5Il0sWyJtZXRhZGF0YSIsImNsb3VkLWlkZW50aWZpZXIiLCJDbG91ZFN0YWNrLXt0ZXN0fSJdXX0=",
1120+
scripts[27]);
10951121
}
10961122

10971123
}

0 commit comments

Comments
 (0)