|
@@ -533,6 +533,121 @@ public class TestDockerContainerRuntime {
|
|
|
dockerCommands.get(counter));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testDockerContainerLaunchWithoutDefaultImageUpdate()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ conf.setBoolean(YarnConfiguration.NM_DOCKER_IMAGE_UPDATE, false);
|
|
|
+
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+ List<String> dockerCommands = readDockerCommands();
|
|
|
+ Assert.assertEquals(false,
|
|
|
+ conf.getBoolean(YarnConfiguration.NM_DOCKER_IMAGE_UPDATE, false));
|
|
|
+
|
|
|
+ int expected = 13;
|
|
|
+ int counter = 0;
|
|
|
+ Assert.assertEquals(expected, dockerCommands.size());
|
|
|
+ Assert.assertEquals("[docker-command-execution]",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-add=SYS_CHROOT,NET_BIND_SERVICE",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-drop=ALL", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" detach=true", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" group-add=" + String.join(",", groups),
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert
|
|
|
+ .assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " launch-command=bash,/test_container_work_dir/launch_container.sh",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" mounts="
|
|
|
+ + "/test_container_log_dir:/test_container_log_dir:rw,"
|
|
|
+ + "/test_application_local_dir:/test_application_local_dir:rw,"
|
|
|
+ + "/test_filecache_dir:/test_filecache_dir:ro,"
|
|
|
+ + "/test_user_filecache_dir:/test_user_filecache_dir:ro",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " name=container_e11_1518975676334_14532816_01_000001",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" net=host", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" user=" + uidGidPair, dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" workdir=/test_container_work_dir",
|
|
|
+ dockerCommands.get(counter));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testDockerContainerLaunchWithDefaultImageUpdate()
|
|
|
+ throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
+ IOException {
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
+ conf.setBoolean(YarnConfiguration.NM_DOCKER_IMAGE_UPDATE, true);
|
|
|
+
|
|
|
+ runtime.initialize(conf, nmContext);
|
|
|
+ runtime.launchContainer(builder.build());
|
|
|
+
|
|
|
+ ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass(
|
|
|
+ PrivilegedOperation.class);
|
|
|
+
|
|
|
+ //Two invocations expected.
|
|
|
+ verify(mockExecutor, times(2))
|
|
|
+ .executePrivilegedOperation(any(), opCaptor.capture(), any(),
|
|
|
+ any(), anyBoolean(), anyBoolean());
|
|
|
+
|
|
|
+ List<PrivilegedOperation> allCaptures = opCaptor.getAllValues();
|
|
|
+
|
|
|
+ // pull image from remote hub firstly
|
|
|
+ PrivilegedOperation op = allCaptures.get(0);
|
|
|
+ Assert.assertEquals(PrivilegedOperation.OperationType
|
|
|
+ .RUN_DOCKER_CMD, op.getOperationType());
|
|
|
+
|
|
|
+ File commandFile = new File(StringUtils.join(",", op.getArguments()));
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(commandFile);
|
|
|
+ String fileContent = new String(IOUtils.toByteArray(fileInputStream));
|
|
|
+ Assert.assertEquals("[docker-command-execution]\n"
|
|
|
+ + " docker-command=pull\n"
|
|
|
+ + " image=busybox:latest\n", fileContent);
|
|
|
+ fileInputStream.close();
|
|
|
+
|
|
|
+ // launch docker container
|
|
|
+ List<String> dockerCommands = readDockerCommands(2);
|
|
|
+
|
|
|
+ int expected = 13;
|
|
|
+ int counter = 0;
|
|
|
+ Assert.assertEquals(expected, dockerCommands.size());
|
|
|
+ Assert.assertEquals("[docker-command-execution]",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-add=SYS_CHROOT,NET_BIND_SERVICE",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" cap-drop=ALL", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" detach=true", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" docker-command=run", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" group-add=" + String.join(",", groups),
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert
|
|
|
+ .assertEquals(" image=busybox:latest", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " launch-command=bash,/test_container_work_dir/launch_container.sh",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" mounts="
|
|
|
+ + "/test_container_log_dir:/test_container_log_dir:rw,"
|
|
|
+ + "/test_application_local_dir:/test_application_local_dir:rw,"
|
|
|
+ + "/test_filecache_dir:/test_filecache_dir:ro,"
|
|
|
+ + "/test_user_filecache_dir:/test_user_filecache_dir:ro",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(
|
|
|
+ " name=container_e11_1518975676334_14532816_01_000001",
|
|
|
+ dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" net=host", dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" user=" + uidGidPair, dockerCommands.get(counter++));
|
|
|
+ Assert.assertEquals(" workdir=/test_container_work_dir",
|
|
|
+ dockerCommands.get(counter));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testContainerLaunchWithUserRemapping()
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|