Skip to content

Commit 317d146

Browse files
Filter empty lines from "docker ls" response (#52081) (#52373)
* Filter empty lines from docker ls response In order to cut down on test time, our docker/vagrant tests build the docker image outside of the vagrant VM. When we get around to launching the Vagrant VM, we mount that already-built docker image to a known location. At that point, we need to load the docker image. But we only want to load it once. As we're running tests, we use "docker ls" to check whether the local image is loaded for use. Empty output from the particular ls invocation means no image is loaded. There was a bug in how we checked this. In Java, splitting an empty string will yield an array containing one empty string. So when we're counting the output from the docker ls command, we need to filter out empty lines in order to proceed to loading the image for docker tests.
1 parent ba81008 commit 317d146

File tree

1 file changed

+7
-1
lines changed
  • qa/os/src/test/java/org/elasticsearch/packaging/util

1 file changed

+7
-1
lines changed

qa/os/src/test/java/org/elasticsearch/packaging/util/Docker.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.nio.file.attribute.PosixFileAttributes;
3232
import java.nio.file.attribute.PosixFilePermission;
3333
import java.util.ArrayList;
34+
import java.util.Arrays;
3435
import java.util.HashMap;
3536
import java.util.List;
3637
import java.util.Map;
@@ -74,7 +75,12 @@ public class Docker {
7475
* @param distribution details about the docker image to potentially load.
7576
*/
7677
public static void ensureImageIsLoaded(Distribution distribution) {
77-
final long count = sh.run("docker image ls --format '{{.Repository}}' " + distribution.flavor.name).stdout.split("\n").length;
78+
Shell.Result result = sh.run("docker image ls --format '{{.Repository}}' " + distribution.flavor.name);
79+
80+
final long count = Arrays.stream(result.stdout.split("\n"))
81+
.map(String::trim)
82+
.filter(s -> s.isEmpty() == false)
83+
.count();
7884

7985
if (count != 0) {
8086
return;

0 commit comments

Comments
 (0)