// podman versions below 3.3.1 hava a bug where cross-container testing with correct // permissions fails. See JDK-8273216 if (IS_PODMAN && PodmanVersion.VERSION_3_3_1.compareTo(getPodmanVersion()) > 0) { thrownew SkippedException("Podman version too old for this test. Expected >= 3.3.1");
}
// Need to create a custom dockerfile where user name and id, as well as group name and id // of the JVM running in container must match the ones from the inspecting JCMD process.
String content = generateCustomDockerfile();
DockerTestUtils.buildJdkContainerImage(IMAGE_NAME, content);
try {
Process p = startObservedContainer(); long pid = testJcmdGetPid("EventGeneratorLoop");
privatestaticvoid testJcmdHelp(long pid) throws Exception {
System.out.println("TestCase: testJcmdHelp()");
ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getJDKTool("jcmd"), "" + pid, "help");
OutputAnalyzer out = new OutputAnalyzer(pb.start())
.shouldHaveExitValue(0)
.shouldContain("JFR.start")
.shouldContain("VM.version");
}
privatestaticvoid testVmInfo(long pid) throws Exception {
System.out.println("TestCase: testVmInfo()");
ProcessBuilder pb = new ProcessBuilder(JDKToolFinder.getJDKTool("jcmd"), "" + pid, "VM.info");
OutputAnalyzer out = new OutputAnalyzer(pb.start())
.shouldHaveExitValue(0)
.shouldContain("vm_info")
.shouldContain("VM Arguments");
}
// Need to make sure that user name+id and group name+id are created for the image, and // match the host system. This is necessary to allow proper permission/access for JCMD. // For podman --userns=keep-id is sufficient. privatestatic String generateCustomDockerfile() throws Exception {
StringBuilder sb = new StringBuilder();
sb.append(String.format("FROM %s:%s\n", DockerfileConfig.getBaseImageName(),
DockerfileConfig.getBaseImageVersion()));
sb.append("COPY /jdk /jdk\n");
sb.append("ENV JAVA_HOME=/jdk\n");
if (!IS_PODMAN) { // only needed for docker
String uid = getId("-u");
String gid = getId("-g");
String userName = getId("-un");
String groupName = getId("-gn"); // Only needed when run as regular user. UID == 0 should already exist if (!ROOT_UID.equals(uid)) {
sb.append(String.format("RUN groupadd --gid %s %s \n", gid, groupName));
sb.append(String.format("RUN useradd --uid %s --gid %s %s \n", uid, gid, userName));
sb.append(String.format("USER %s \n", userName));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.