Skip to content

Commit bd8701d

Browse files
authored
Change approach to checking GID in Docker (#62751)
Closes #62466. Since we're still seeing occasional failures when checking the GID of all files in the Docker image due to Elasticsearch running in the background, instead run a new container with ES running at all.
1 parent 228bb64 commit bd8701d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

qa/os/src/test/java/org/elasticsearch/packaging/test/DockerTests.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.elasticsearch.packaging.util.Installation;
2626
import org.elasticsearch.packaging.util.Platforms;
2727
import org.elasticsearch.packaging.util.ServerUtils;
28+
import org.elasticsearch.packaging.util.Shell;
2829
import org.elasticsearch.packaging.util.Shell.Result;
2930
import org.junit.After;
3031
import org.junit.Before;
@@ -45,6 +46,7 @@
4546
import static org.elasticsearch.packaging.util.Docker.existsInContainer;
4647
import static org.elasticsearch.packaging.util.Docker.getContainerLogs;
4748
import static org.elasticsearch.packaging.util.Docker.getImageLabels;
49+
import static org.elasticsearch.packaging.util.Docker.getImageName;
4850
import static org.elasticsearch.packaging.util.Docker.getJson;
4951
import static org.elasticsearch.packaging.util.Docker.mkDirWithPrivilegeEscalation;
5052
import static org.elasticsearch.packaging.util.Docker.removeContainer;
@@ -524,12 +526,17 @@ public void test100NoCoreFilesInImage() {
524526
/**
525527
* Check that there are no files with a GID other than 0.
526528
*/
527-
public void test101AllFilesAreGroupZero() throws Exception {
528-
// We wait for Elasticsearch to finish starting up in order to avoid the situation where `find` traverses the filesystem
529-
// and sees files in a directory listing, which have disappeared by the time `find` tries to examine them. This periodically
530-
// happened with the keystore, for example.
531-
waitForElasticsearch(installation);
532-
final String findResults = sh.run("find . -not -gid 0").stdout;
529+
public void test101AllFilesAreGroupZero() {
530+
// Run a `find` command in a new container without Elasticsearch running, so
531+
// that the results aren't subject to sporadic failures from files appearing /
532+
// disappearing while `find` is traversing the filesystem.
533+
//
534+
// We also create a file under `data/` to ensure that files are created with the
535+
// expected group.
536+
final Shell localSh = new Shell();
537+
final String findResults = localSh.run(
538+
"docker run --rm --tty " + getImageName(distribution) + " bash -c ' touch data/test && find . -not -gid 0 ' "
539+
).stdout;
533540

534541
assertThat("Found some files whose GID != 0", findResults, is(emptyString()));
535542
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public static Shell.Result getContainerLogs() {
639639
return sh.run("docker logs " + containerId);
640640
}
641641

642-
private static String getImageName(Distribution distribution) {
642+
public static String getImageName(Distribution distribution) {
643643
return distribution.flavor.name + (distribution.packaging == Distribution.Packaging.DOCKER_UBI ? "-ubi8" : "") + ":test";
644644
}
645645
}

0 commit comments

Comments
 (0)