brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/3] git commit: addressed comments for saveIpTablesRules
Date Mon, 20 Oct 2014 16:12:14 GMT
addressed comments for saveIpTablesRules


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ed618ed2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ed618ed2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ed618ed2

Branch: refs/heads/master
Commit: ed618ed24ac4dc29c6597f8a6c6a6493801c1942
Parents: 6f2309b
Author: Andrea Turli <andrea.turli@gmail.com>
Authored: Mon Sep 15 23:06:31 2014 +0200
Committer: Andrea Turli <andrea.turli@gmail.com>
Committed: Mon Sep 15 23:06:31 2014 +0200

----------------------------------------------------------------------
 .../main/java/brooklyn/util/ssh/IptablesCommands.java  | 12 ++++--------
 .../java/brooklyn/util/ssh/IptablesCommandsTest.java   | 13 ++++++-------
 2 files changed, 10 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ed618ed2/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java b/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
index af7878e..c5164aa 100644
--- a/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
+++ b/utils/common/src/main/java/brooklyn/util/ssh/IptablesCommands.java
@@ -19,6 +19,7 @@
 package brooklyn.util.ssh;
 
 import static brooklyn.util.ssh.BashCommands.alternatives;
+import static brooklyn.util.ssh.BashCommands.chain;
 import static brooklyn.util.ssh.BashCommands.installPackage;
 import static brooklyn.util.ssh.BashCommands.sudo;
 
@@ -95,14 +96,9 @@ public class IptablesCommands {
      *
      */
     public static String saveIptablesRules() {
-        return alternatives(sudo("service iptables save"), installPackage("iptables-persistent"));
-    }
-        /*
-        return BashCommands.chain(
-                BashCommands.ifExecutableElse1("apt-get", installPackage("iptables-persistent")),
-                // rhel derivatives already have iptables-save installed
-                BashCommands.ifExecutableElse1("iptables-save", String.format("iptables-save
> %s", filename)));
-        */
+        return alternatives(sudo("service iptables save"),
+                            chain(installPackage("iptables-persistent"), sudo("/etc/init.d/iptables-persistent
save")));
+    }
 
     /**
      * Returns the command that cleans up iptables rules.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ed618ed2/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java b/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java
index b688973..afec6be 100644
--- a/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java
+++ b/utils/common/src/test/java/brooklyn/util/ssh/IptablesCommandsTest.java
@@ -38,13 +38,12 @@ public class IptablesCommandsTest {
     private static final String appendIptablesRuleAll = "( if test \"$UID\" -eq 0; then (
/sbin/iptables -A INPUT -p tcp --dport 3306 -j ACCEPT ); "
             + "else sudo -E -n -S -- /sbin/iptables -A INPUT -p tcp --dport 3306 -j ACCEPT;
fi )";
     private static final String saveIptablesRules = "( ( if test \"$UID\" -eq 0; then ( service
iptables save ); else sudo -E -n -S -- service iptables save; fi ) || " +
-            "( { which zypper && { echo zypper exists, doing refresh && ((
if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks refresh ); else sudo
-E -n -S -- zypper --non-interactive --no-gpg-checks refresh; fi ) || true) && " +
-            "( if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks install
iptables-persistent ); else sudo -E -n -S -- zypper --non-interactive --no-gpg-checks install
iptables-persistent; fi ) ; } ; } || { which apt-get && { echo apt-get exists, doing
update && export DEBIAN_FRONTEND=noninteractive && " +
-            "(( if test \"$UID\" -eq 0; then ( apt-get update ); else sudo -E -n -S -- apt-get
update; fi ) || true) && " +
-            "( if test \"$UID\" -eq 0; then ( apt-get install -y --allow-unauthenticated
iptables-persistent ); else sudo -E -n -S -- apt-get install -y --allow-unauthenticated iptables-persistent;
fi ) ; } ; } || { which yum && { echo yum exists, doing update && " +
-            "(( if test \"$UID\" -eq 0; then ( yum check-update ); else sudo -E -n -S --
yum check-update; fi ) || true) && " +
-            "( if test \"$UID\" -eq 0; then ( yum -y --nogpgcheck install iptables-persistent
); else sudo -E -n -S -- yum -y --nogpgcheck install iptables-persistent; fi ) ; } ; } ||
{ which brew && brew install iptables-persistent ; } || { which port && (
if test \"$UID\" -eq 0; then ( port install iptables-persistent ); else sudo -E -n -S -- port
install iptables-persistent; fi ) ; } || " +
-            "(( echo \"WARNING: no known/successful package manager to install iptables-persistent,
may fail subsequently\" | tee /dev/stderr ) || true) ) )";
+            "( ( { which zypper && { echo zypper exists, doing refresh &&
(( if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks refresh ); else
sudo -E -n -S -- zypper --non-interactive --no-gpg-checks refresh; fi ) || true) &&
( if test \"$UID\" -eq 0; then ( zypper --non-interactive --no-gpg-checks install iptables-persistent
); else sudo -E -n -S -- zypper --non-interactive --no-gpg-checks install iptables-persistent;
fi ) ; } ; } || " +
+            "{ which apt-get && { echo apt-get exists, doing update && export
DEBIAN_FRONTEND=noninteractive && (( if test \"$UID\" -eq 0; then ( apt-get update
); else sudo -E -n -S -- apt-get update; fi ) || true) && ( if test \"$UID\" -eq 0;
then ( apt-get install -y --allow-unauthenticated iptables-persistent ); else sudo -E -n -S
-- apt-get install -y --allow-unauthenticated iptables-persistent; fi ) ; } ; } || " +
+            "{ which yum && { echo yum exists, doing update && (( if test
\"$UID\" -eq 0; then ( yum check-update ); else sudo -E -n -S -- yum check-update; fi ) ||
true) && ( if test \"$UID\" -eq 0; then ( yum -y --nogpgcheck install iptables-persistent
); else sudo -E -n -S -- yum -y --nogpgcheck install iptables-persistent; fi ) ; } ; } ||
" +
+            "{ which brew && brew install iptables-persistent ; } || " +
+            "{ which port && ( if test \"$UID\" -eq 0; then ( port install iptables-persistent
); else sudo -E -n -S -- port install iptables-persistent; fi ) ; } || " +
+            "(( echo \"WARNING: no known/successful package manager to install iptables-persistent,
may fail subsequently\" | tee /dev/stderr ) || true) ) && ( if test \"$UID\" -eq 0;
then ( /etc/init.d/iptables-persistent save ); else sudo -E -n -S -- /etc/init.d/iptables-persistent
save; fi ) ) )";
 
     @Test
     public void testCleanUpIptablesRules() {


Mime
View raw message