You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/04/26 08:19:44 UTC

[1/2] brooklyn-server git commit: Adds BashCommands.waitForFileExists

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 022fb2fb3 -> e3e408af9


Adds BashCommands.waitForFileExists

Also changes waitForFileContents to `cat file` if the check fails

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

Branch: refs/heads/master
Commit: 62315261f7e6b011edccacb72992de61196d11da
Parents: 022fb2f
Author: Aled Sage <al...@gmail.com>
Authored: Fri Apr 21 12:16:56 2017 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Apr 25 17:33:55 2017 +0100

----------------------------------------------------------------------
 .../core/ssh/BashCommandsIntegrationTest.java   | 52 +++++++++++++++-----
 .../apache/brooklyn/util/ssh/BashCommands.java  | 19 +++++++
 2 files changed, 58 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/62315261/core/src/test/java/org/apache/brooklyn/util/core/ssh/BashCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/ssh/BashCommandsIntegrationTest.java b/core/src/test/java/org/apache/brooklyn/util/core/ssh/BashCommandsIntegrationTest.java
index 92be83d..3f99ee3 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/ssh/BashCommandsIntegrationTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/ssh/BashCommandsIntegrationTest.java
@@ -33,8 +33,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.test.BrooklynMgmtUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.task.BasicExecutionContext;
@@ -62,11 +61,10 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Files;
 
-public class BashCommandsIntegrationTest {
+public class BashCommandsIntegrationTest extends BrooklynMgmtUnitTestSupport {
 
     private static final Logger log = LoggerFactory.getLogger(BashCommandsIntegrationTest.class);
     
-    private ManagementContext mgmt;
     private BasicExecutionContext exec;
     
     private File destFile;
@@ -87,7 +85,8 @@ public class BashCommandsIntegrationTest {
     
     @BeforeMethod(alwaysRun=true)
     public void setUp() throws Exception {
-        mgmt = new LocalManagementContextForTests();
+        super.setUp();
+        
         exec = new BasicExecutionContext(mgmt.getExecutionManager());
         
         destFile = Os.newTempFile(getClass(), "commoncommands-test-dest.txt");
@@ -120,14 +119,17 @@ public class BashCommandsIntegrationTest {
     
     @AfterMethod(alwaysRun=true)
     public void tearDown() throws Exception {
-        if (sourceFile1 != null) sourceFile1.delete();
-        if (sourceFile2 != null) sourceFile2.delete();
-        if (destFile != null) destFile.delete();
-        if (localRepoEntityFile != null) localRepoEntityFile.delete();
-        if (tmpSudoersFile != null) tmpSudoersFile.delete();
-        if (localRepoEntityBasePath != null) FileUtils.deleteDirectory(localRepoEntityBasePath);
-        if (loc != null) loc.close();
-        if (mgmt != null) Entities.destroyAll(mgmt);
+        try {
+            if (sourceFile1 != null) sourceFile1.delete();
+            if (sourceFile2 != null) sourceFile2.delete();
+            if (destFile != null) destFile.delete();
+            if (localRepoEntityFile != null) localRepoEntityFile.delete();
+            if (tmpSudoersFile != null) tmpSudoersFile.delete();
+            if (localRepoEntityBasePath != null) FileUtils.deleteDirectory(localRepoEntityBasePath);
+            if (loc != null) loc.close();
+        } finally {
+            super.tearDown();
+        }
     }
     
     @Test(groups="Integration")
@@ -332,6 +334,30 @@ public class BashCommandsIntegrationTest {
         assertFalse(output.contains("Couldn't find"), "output="+output);
     }
     
+    @Test(groups="Integration")
+    public void testWaitForFileExistsWhenAbortingOnFail() throws Exception {
+        String cmd = BashCommands.waitForFileExists(destFile.getAbsolutePath(), Duration.ONE_SECOND, true);
+
+        int exitcode = loc.execCommands("test", ImmutableList.of(cmd));
+        assertEquals(exitcode, 0);
+        
+        destFile.delete();
+        int exitcode2 = loc.execCommands("test", ImmutableList.of(cmd));
+        assertEquals(exitcode2, 1);
+    }
+
+    @Test(groups="Integration")
+    public void testWaitForFileExistsWhenNotAbortingOnFail() throws Exception {
+        String cmd = BashCommands.waitForFileExists(destFile.getAbsolutePath(), Duration.ONE_SECOND, false);
+
+        String output = execRequiringZeroAndReturningStdout(loc, cmd).get();
+        assertFalse(output.contains("Couldn't find"), "output="+output);
+
+        destFile.delete();
+        String output2 = execRequiringZeroAndReturningStdout(loc, cmd).get();
+        assertTrue(output2.contains("Couldn't find"), "output="+output2);
+    }
+    
     @Test(groups="Integration", dependsOnMethods="testSudo")
     public void testWaitForPortFreeWhenAbortingOnTimeout() throws Exception {
         ServerSocket serverSocket = openServerSocket();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/62315261/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java b/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
index 414abc5..fe7c939 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/ssh/BashCommands.java
@@ -493,6 +493,8 @@ public class BashCommands {
                 "    sleep 1",
                 "done",
                 "if test \"$result\" -ne 0; then",
+                "    ls -l "+file+" || true",
+                "    cat "+file+" || true",
                 "    "+ (failOnTimeout ?
                             "echo \"Couldn't find "+desiredContent+" in "+file+"; aborting\" && exit 1" :
                             "echo \"Couldn't find "+desiredContent+" in "+file+"; continuing\""),
@@ -500,6 +502,23 @@ public class BashCommands {
         return Joiner.on("\n").join(commands);
     }
 
+    public static String waitForFileExists(String file, Duration timeout, boolean failOnTimeout) {
+        long secs = Math.max(timeout.toSeconds(), 1);
+        
+        List<String> commands = ImmutableList.of(
+                "for i in {1.."+secs+"}; do",
+                "    [[ -f "+file+" ]] && result=0 || result=$?",
+                "    [ \"$result\" == 0 ] && break",
+                "    sleep 1",
+                "done",
+                "if test \"$result\" -ne 0; then",
+                "    "+ (failOnTimeout ?
+                            "echo \"Couldn't find file "+file+"; aborting\" && exit 1" :
+                            "echo \"Couldn't find file "+file+"; continuing\""),
+                "fi");
+        return Joiner.on("\n").join(commands);
+    }
+
     public static String waitForPortFree(int port, Duration timeout, boolean failOnTimeout) {
         long secs = Math.max(timeout.toSeconds(), 1);
 


[2/2] brooklyn-server git commit: This closes #644

Posted by dr...@apache.org.
This closes #644


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

Branch: refs/heads/master
Commit: e3e408af98d2272f83f889f84f4c40a1796c20a2
Parents: 022fb2f 6231526
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Wed Apr 26 09:18:42 2017 +0100
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Wed Apr 26 09:18:42 2017 +0100

----------------------------------------------------------------------
 .../core/ssh/BashCommandsIntegrationTest.java   | 52 +++++++++++++++-----
 .../apache/brooklyn/util/ssh/BashCommands.java  | 19 +++++++
 2 files changed, 58 insertions(+), 13 deletions(-)
----------------------------------------------------------------------