nvazquez commented on code in PR #8530:
URL: https://github.com/apache/cloudstack/pull/8530#discussion_r1633387408
##########
systemvm/debian/opt/cloud/bin/cs/CsHelper.py:
##########
@@ -221,7 +221,7 @@ def save_iptables(command, iptables_file):
def execute2(command, wait=True):
""" Execute command """
- logging.info("Executing: %s" % command)
+ logging.info("Executing2: %s" % command)
Review Comment:
Typo?
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/IpTablesHelper.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.cloudstack.storage.resource;
+
+import com.cloud.utils.script.Script;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+import org.apache.log4j.Logger;
+
+public class IpTablesHelper {
+ public static final Logger LOGGER = Logger.getLogger(IpTablesHelper.class);
+
+ public static final String OUTPUT_CHAIN = "OUTPUT";
+ public static final String INPUT_CHAIN = "INPUT";
+ public static final String INSERT = " -I ";
+ public static final String APPEND = " -A ";
+
+ public static boolean needsAdding(String chain, String rule) {
+ Script command = new Script("/bin/bash", LOGGER);
+ command.add("-c");
+ command.add("iptables -C " + chain + " " + rule);
+
+ String r1 = command.execute();
+ boolean needsAdding = (r1 != null && r1.contains("iptables: Bad rule
(does a matching rule exist in that chain?)."));
+// int rc = Script.runSimpleBashScriptForExitValue(command.toString());
Review Comment:
Leftover commented code :)
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/IpTablesHelper.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.cloudstack.storage.resource;
+
+import com.cloud.utils.script.Script;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+import org.apache.log4j.Logger;
+
+public class IpTablesHelper {
+ public static final Logger LOGGER = Logger.getLogger(IpTablesHelper.class);
+
+ public static final String OUTPUT_CHAIN = "OUTPUT";
+ public static final String INPUT_CHAIN = "INPUT";
+ public static final String INSERT = " -I ";
+ public static final String APPEND = " -A ";
+
+ public static boolean needsAdding(String chain, String rule) {
+ Script command = new Script("/bin/bash", LOGGER);
+ command.add("-c");
+ command.add("iptables -C " + chain + " " + rule);
+
+ String r1 = command.execute();
+ boolean needsAdding = (r1 != null && r1.contains("iptables: Bad rule
(does a matching rule exist in that chain?)."));
Review Comment:
What about checking for the exit value? In case the output of the command
varies it can affect the method's behavior
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/IpTablesHelper.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.cloudstack.storage.resource;
Review Comment:
Missing header
##########
services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/resource/IpTablesHelper.java:
##########
@@ -0,0 +1,50 @@
+package org.apache.cloudstack.storage.resource;
+
+import com.cloud.utils.script.Script;
+import org.apache.cloudstack.storage.template.DownloadManagerImpl;
+import org.apache.log4j.Logger;
+
+public class IpTablesHelper {
+ public static final Logger LOGGER = Logger.getLogger(IpTablesHelper.class);
+
+ public static final String OUTPUT_CHAIN = "OUTPUT";
+ public static final String INPUT_CHAIN = "INPUT";
+ public static final String INSERT = " -I ";
+ public static final String APPEND = " -A ";
+
+ public static boolean needsAdding(String chain, String rule) {
+ Script command = new Script("/bin/bash", LOGGER);
+ command.add("-c");
+ command.add("iptables -C " + chain + " " + rule);
+
+ String r1 = command.execute();
+ boolean needsAdding = (r1 != null && r1.contains("iptables: Bad rule
(does a matching rule exist in that chain?)."));
+// int rc = Script.runSimpleBashScriptForExitValue(command.toString());
+// boolean needsAdding = rc != 0; // (executionResult != null &&
executionResult.contains("iptables: Bad rule (does a matching rule exist in
that chain?)."));
+ LOGGER.debug(String.format("Rule [%s], %s need adding to [%s] : %s",
+ rule,
+ needsAdding ? "does indeed" : "doesn't",
+ chain,
+ r1
+ ));
+ return needsAdding;
+ }
+
+ public static String addConditionally(String chain, boolean insert, String
rule, String errMsg) {
+ LOGGER.info(String.format("Adding rule [%s] to [%s] if required.",
rule, chain));
+ if (needsAdding(chain, rule)) {
+ Script command = new Script("/bin/bash",
DownloadManagerImpl.LOGGER);
Review Comment:
Here we should use its own logger instad of the DownloadManagerImpl one
right?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org