8221710: [TESTBUG] more configurable parameters for docker testing
Introduced docker test config properties Reviewed-by: lmesnik, iignatyev, egahlin
This commit is contained in:
parent
03ab1404f0
commit
05b294ea97
@ -42,8 +42,6 @@ import jdk.test.lib.Utils;
|
|||||||
|
|
||||||
public class DockerBasicTest {
|
public class DockerBasicTest {
|
||||||
private static final String imageNameAndTag = Common.imageName("basic");
|
private static final String imageNameAndTag = Common.imageName("basic");
|
||||||
// Diganostics: set to false to examine image after the test
|
|
||||||
private static final boolean removeImageAfterTest = true;
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if (!DockerTestUtils.canTestDocker()) {
|
if (!DockerTestUtils.canTestDocker()) {
|
||||||
@ -56,8 +54,9 @@ public class DockerBasicTest {
|
|||||||
testJavaVersion();
|
testJavaVersion();
|
||||||
testHelloDocker();
|
testHelloDocker();
|
||||||
} finally {
|
} finally {
|
||||||
if (removeImageAfterTest)
|
if (!DockerTestUtils.RETAIN_IMAGE_AFTER_TEST) {
|
||||||
DockerTestUtils.removeDockerImage(imageNameAndTag);
|
DockerTestUtils.removeDockerImage(imageNameAndTag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ import java.util.List;
|
|||||||
import jdk.test.lib.Utils;
|
import jdk.test.lib.Utils;
|
||||||
import jdk.test.lib.process.OutputAnalyzer;
|
import jdk.test.lib.process.OutputAnalyzer;
|
||||||
import jdk.test.lib.process.ProcessTools;
|
import jdk.test.lib.process.ProcessTools;
|
||||||
|
import jtreg.SkippedException;
|
||||||
|
|
||||||
|
|
||||||
public class DockerTestUtils {
|
public class DockerTestUtils {
|
||||||
@ -45,8 +46,23 @@ public class DockerTestUtils {
|
|||||||
private static boolean isDockerEngineAvailable = false;
|
private static boolean isDockerEngineAvailable = false;
|
||||||
private static boolean wasDockerEngineChecked = false;
|
private static boolean wasDockerEngineChecked = false;
|
||||||
|
|
||||||
// Diagnostics: set to true to enable more diagnostic info
|
// Use this property to specify docker location on your system.
|
||||||
private static final boolean DEBUG = false;
|
// E.g.: "/usr/local/bin/docker".
|
||||||
|
private static final String DOCKER_COMMAND =
|
||||||
|
System.getProperty("jdk.test.docker.command", "docker");
|
||||||
|
|
||||||
|
// Set this property to true to retain image after test. By default
|
||||||
|
// images are removed after test execution completes.
|
||||||
|
// Retaining the image can be useful for diagnostics and image inspection.
|
||||||
|
// E.g.: start image interactively: docker run -it <IMAGE_NAME>.
|
||||||
|
public static final boolean RETAIN_IMAGE_AFTER_TEST =
|
||||||
|
Boolean.getBoolean("jdk.test.docker.retain.image");
|
||||||
|
|
||||||
|
// Path to a JDK under test.
|
||||||
|
// This may be useful when developing tests on non-Linux platforms.
|
||||||
|
public static final String JDK_UNDER_TEST =
|
||||||
|
System.getProperty("jdk.test.docker.jdk", Utils.TEST_JDK);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimized check of whether the docker engine is available in a given
|
* Optimized check of whether the docker engine is available in a given
|
||||||
@ -76,9 +92,7 @@ public class DockerTestUtils {
|
|||||||
if (isDockerEngineAvailable()) {
|
if (isDockerEngineAvailable()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Docker engine is not available on this system");
|
throw new SkippedException("Docker engine is not available on this system");
|
||||||
System.out.println("This test is SKIPPED");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +108,7 @@ public class DockerTestUtils {
|
|||||||
*/
|
*/
|
||||||
private static boolean isDockerEngineAvailableCheck() throws Exception {
|
private static boolean isDockerEngineAvailableCheck() throws Exception {
|
||||||
try {
|
try {
|
||||||
execute("docker", "ps")
|
execute(DOCKER_COMMAND, "ps")
|
||||||
.shouldHaveExitValue(0)
|
.shouldHaveExitValue(0)
|
||||||
.shouldContain("CONTAINER")
|
.shouldContain("CONTAINER")
|
||||||
.shouldContain("IMAGE");
|
.shouldContain("IMAGE");
|
||||||
@ -126,7 +140,7 @@ public class DockerTestUtils {
|
|||||||
throw new RuntimeException("The docker build directory already exists: " + buildDir);
|
throw new RuntimeException("The docker build directory already exists: " + buildDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path jdkSrcDir = Paths.get(Utils.TEST_JDK);
|
Path jdkSrcDir = Paths.get(JDK_UNDER_TEST);
|
||||||
Path jdkDstDir = buildDir.resolve("jdk");
|
Path jdkDstDir = buildDir.resolve("jdk");
|
||||||
|
|
||||||
Files.createDirectories(jdkDstDir);
|
Files.createDirectories(jdkDstDir);
|
||||||
@ -157,7 +171,7 @@ public class DockerTestUtils {
|
|||||||
DockerfileConfig.getBaseImageVersion());
|
DockerfileConfig.getBaseImageVersion());
|
||||||
|
|
||||||
// Build the docker
|
// Build the docker
|
||||||
execute("docker", "build", "--no-cache", "--tag", imageName, buildDir.toString())
|
execute(DOCKER_COMMAND, "build", "--no-cache", "--tag", imageName, buildDir.toString())
|
||||||
.shouldHaveExitValue(0)
|
.shouldHaveExitValue(0)
|
||||||
.shouldContain("Successfully built");
|
.shouldContain("Successfully built");
|
||||||
}
|
}
|
||||||
@ -174,7 +188,7 @@ public class DockerTestUtils {
|
|||||||
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
|
public static OutputAnalyzer dockerRunJava(DockerRunOptions opts) throws Exception {
|
||||||
ArrayList<String> cmd = new ArrayList<>();
|
ArrayList<String> cmd = new ArrayList<>();
|
||||||
|
|
||||||
cmd.add("docker");
|
cmd.add(DOCKER_COMMAND);
|
||||||
cmd.add("run");
|
cmd.add("run");
|
||||||
if (opts.tty)
|
if (opts.tty)
|
||||||
cmd.add("--tty=true");
|
cmd.add("--tty=true");
|
||||||
@ -201,11 +215,10 @@ public class DockerTestUtils {
|
|||||||
* Remove docker image
|
* Remove docker image
|
||||||
*
|
*
|
||||||
* @param DockerRunOptions optins for running docker
|
* @param DockerRunOptions optins for running docker
|
||||||
* @return output of the command
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static OutputAnalyzer removeDockerImage(String imageNameAndTag) throws Exception {
|
public static void removeDockerImage(String imageNameAndTag) throws Exception {
|
||||||
return execute("docker", "rmi", "--force", imageNameAndTag);
|
execute(DOCKER_COMMAND, "rmi", "--force", imageNameAndTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user