Skip to content

Commit d72200b

Browse files
committed
If one of the static nat rules failed to apply on the backend, the end result should be false
1 parent 779989c commit d72200b

5 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎api/src/com/cloud/agent/api/routing/SetFirewallRulesAnswer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class SetFirewallRulesAnswer extends Answer {
2525
protected SetFirewallRulesAnswer() {
2626
}
2727

28-
public SetFirewallRulesAnswer(SetFirewallRulesCommand cmd, Boolean success, String[] results) {
28+
public SetFirewallRulesAnswer(SetFirewallRulesCommand cmd, boolean success, String[] results) {
2929
super(cmd, success, null);
3030
assert (cmd.getRules().length == results.length) : "rules and their results should be the same length don't you think?";
3131
this.results = results;

‎api/src/com/cloud/agent/api/routing/SetPortForwardingRulesAnswer.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ protected SetPortForwardingRulesAnswer() {
2525
super();
2626
}
2727

28-
public SetPortForwardingRulesAnswer(SetPortForwardingRulesCommand cmd, String[] results) {
29-
super(cmd, true, null);
28+
public SetPortForwardingRulesAnswer(SetPortForwardingRulesCommand cmd, String[] results, boolean success) {
29+
super(cmd, success, null);
3030

3131
assert(cmd.getRules().length == results.length) : "Shouldn't the results match the commands?";
3232
this.results = results;

‎api/src/com/cloud/agent/api/routing/SetStaticNatRulesAnswer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected SetStaticNatRulesAnswer() {
2525
super();
2626
}
2727

28-
public SetStaticNatRulesAnswer(SetStaticNatRulesCommand cmd, String[] results, Boolean success) {
28+
public SetStaticNatRulesAnswer(SetStaticNatRulesCommand cmd, String[] results, boolean success) {
2929
super(cmd, success, null);
3030

3131
assert(cmd.getRules().length == results.length) : "Shouldn't the results match the commands?";

‎core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ private Answer execute(SetPortForwardingRulesCommand cmd) {
171171
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
172172
String[] results = new String[cmd.getRules().length];
173173
int i = 0;
174+
175+
boolean endResult = true;
174176
for (PortForwardingRuleTO rule : cmd.getRules()) {
175177
String result = null;
176178
final Script command = new Script(_firewallPath, _timeout, s_logger);
@@ -183,10 +185,15 @@ private Answer execute(SetPortForwardingRulesCommand cmd) {
183185
command.add("-r ", rule.getDstIp());
184186
command.add("-d ", rule.getStringDstPortRange());
185187
result = command.execute();
186-
results[i++] = (!(result == null || result.isEmpty())) ? "Failed" : null;
188+
if (result == null || result.isEmpty()) {
189+
results[i++] = "Failed";
190+
endResult = false;
191+
} else {
192+
results[i++] = null;
193+
}
187194
}
188195

189-
return new SetPortForwardingRulesAnswer(cmd, results);
196+
return new SetPortForwardingRulesAnswer(cmd, results, endResult);
190197
}
191198

192199
private Answer execute(SetStaticNatRulesCommand cmd) {

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,8 @@ protected SetPortForwardingRulesAnswer execute(SetPortForwardingRulesCommand cmd
12441244
String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
12451245
String[] results = new String[cmd.getRules().length];
12461246
int i = 0;
1247+
1248+
boolean endResult = true;
12471249
for (PortForwardingRuleTO rule : cmd.getRules()) {
12481250
StringBuilder args = new StringBuilder();
12491251
args.append(routerIp);
@@ -1256,10 +1258,15 @@ protected SetPortForwardingRulesAnswer execute(SetPortForwardingRulesCommand cmd
12561258

12571259
String result = callHostPlugin(conn, "vmops", "setFirewallRule", "args", args.toString());
12581260

1259-
results[i++] = (result == null || result.isEmpty()) ? "Failed" : null;
1261+
if (result == null || result.isEmpty()) {
1262+
results[i++] = "Failed";
1263+
endResult = false;
1264+
} else {
1265+
results[i++] = null;
1266+
}
12601267
}
12611268

1262-
return new SetPortForwardingRulesAnswer(cmd, results);
1269+
return new SetPortForwardingRulesAnswer(cmd, results, endResult);
12631270
}
12641271

12651272
protected SetStaticNatRulesAnswer execute(SetStaticNatRulesCommand cmd) {

0 commit comments

Comments
 (0)