|
@@ -86,6 +86,7 @@ import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
|
import static org.apache.hadoop.yarn.conf.YarnConfiguration.NM_DOCKER_DEFAULT_RO_MOUNTS;
|
|
|
import static org.apache.hadoop.yarn.conf.YarnConfiguration.NM_DOCKER_DEFAULT_RW_MOUNTS;
|
|
|
+import static org.apache.hadoop.yarn.conf.YarnConfiguration.NM_DOCKER_DEFAULT_TMPFS_MOUNTS;
|
|
|
import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_RUN_PRIVILEGED_CONTAINER;
|
|
|
import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntimeConstants.APPID;
|
|
|
import static org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntimeConstants.APPLICATION_LOCAL_DIRS;
|
|
@@ -1327,6 +1328,154 @@ public class TestDockerContainerRuntime {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testTmpfsMount()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/run");
|
|
|
+
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
|
+ List<String> args = op.getArguments();
|
|
|
+ String dockerCommandFile = args.get(11);
|
|
|
+
|
|
|
+ List<String> dockerCommands = Files.readAllLines(
|
|
|
+ Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ Assert.assertTrue(dockerCommands.contains(" tmpfs=/run"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testTmpfsMountMulti()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/run,/tmp");
|
|
|
+
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
|
+ List<String> args = op.getArguments();
|
|
|
+ String dockerCommandFile = args.get(11);
|
|
|
+
|
|
|
+ List<String> dockerCommands = Files.readAllLines(
|
|
|
+ Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ Assert.assertTrue(dockerCommands.contains(" tmpfs=/run,/tmp"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDefaultTmpfsMounts()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException {
|
|
|
+ conf.setStrings(NM_DOCKER_DEFAULT_TMPFS_MOUNTS, "/run,/var/run");
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/tmpfs");
|
|
|
+
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ PrivilegedOperation op = capturePrivilegedOperationAndVerifyArgs();
|
|
|
+ List<String> args = op.getArguments();
|
|
|
+ String dockerCommandFile = args.get(11);
|
|
|
+
|
|
|
+ List<String> dockerCommands = Files.readAllLines(
|
|
|
+ Paths.get(dockerCommandFile), Charset.forName("UTF-8"));
|
|
|
+
|
|
|
+ Assert.assertTrue(dockerCommands.contains(" tmpfs=/tmpfs,/run,/var/run"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDefaultTmpfsMountsInvalid()
|
|
|
+ throws ContainerExecutionException {
|
|
|
+ conf.setStrings(NM_DOCKER_DEFAULT_TMPFS_MOUNTS, "run,var/run");
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/tmpfs");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail(
|
|
|
+ "Expected a launch container failure due to non-absolute path.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testTmpfsRelativeInvalid() throws ContainerExecutionException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "run");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail(
|
|
|
+ "Expected a launch container failure due to non-absolute path.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testTmpfsColonInvalid() throws ContainerExecutionException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/run:");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail(
|
|
|
+ "Expected a launch container failure due to invalid character.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testTmpfsNulInvalid() throws ContainerExecutionException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+
|
|
|
+ env.put(
|
|
|
+ DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_TMPFS_MOUNTS,
|
|
|
+ "/ru\0n");
|
|
|
+
|
|
|
+ try {
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ Assert.fail(
|
|
|
+ "Expected a launch container failure due to NUL in tmpfs mount.");
|
|
|
+ } catch (ContainerExecutionException e) {
|
|
|
+ LOG.info("Caught expected exception : " + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testDefaultROMounts()
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|