From 34f933065175eb0b9c8a9823d5b31e436bffd33f Mon Sep 17 00:00:00 2001 From: Varun Vasudev Date: Thu, 1 Sep 2016 14:08:51 +0530 Subject: [PATCH] YARN-5596. Fix failing unit test in TestDockerContainerRuntime. Contributed by Sidharta Seethana. (cherry picked from commit 08f55ccbb075b90a6e534f4ac0f9840f2e6890d5) --- .../runtime/DockerLinuxContainerRuntime.java | 6 ++++-- .../runtime/TestDockerContainerRuntime.java | 20 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java index 33b8addb70c..a3aff2ff599 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java @@ -146,6 +146,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { public static final String ENV_DOCKER_CONTAINER_LOCAL_RESOURCE_MOUNTS = "YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS"; + static final String CGROUPS_ROOT_DIRECTORY = "/sys/fs/cgroup"; + private Configuration conf; private DockerClient dockerClient; private PrivilegedOperationExecutor privilegedOperationExecutor; @@ -437,7 +439,6 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { LOCALIZED_RESOURCES); @SuppressWarnings("unchecked") List userLocalDirs = ctx.getExecutionAttribute(USER_LOCAL_DIRS); - Set capabilities = new HashSet<>(Arrays.asList(conf.getStrings( YarnConfiguration.NM_DOCKER_CONTAINER_CAPABILITIES, YarnConfiguration.DEFAULT_NM_DOCKER_CONTAINER_CAPABILITIES))); @@ -449,7 +450,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { .setContainerWorkDir(containerWorkDir.toString()) .setNetworkType(network) .setCapabilities(capabilities) - .addMountLocation("/sys/fs/cgroup", "/sys/fs/cgroup:ro", false); + .addMountLocation(CGROUPS_ROOT_DIRECTORY, + CGROUPS_ROOT_DIRECTORY + ":ro", false); List allDirs = new ArrayList<>(containerLocalDirs); allDirs.addAll(filecacheDirs); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java index a05ff46f9e7..32533940fc7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java @@ -257,6 +257,18 @@ public class TestDockerContainerRuntime { return expectedCapabilitiesString.toString(); } + private String getExpectedCGroupsMountString() { + boolean cGroupsMountExists = new File( + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY).exists(); + + if(cGroupsMountExists) { + return "-v " + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY + + ":" + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY + ":ro "; + } else { + return ""; + } + } + @Test public void testDockerContainerLaunch() throws ContainerExecutionException, PrivilegedOperationException, @@ -276,7 +288,7 @@ public class TestDockerContainerRuntime { .append("--workdir=%3$s ") .append("--net=host ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ") .append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ") @@ -382,7 +394,7 @@ public class TestDockerContainerRuntime { .append("--workdir=%3$s ") .append("--net=" + allowedNetwork + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ") @@ -437,7 +449,7 @@ public class TestDockerContainerRuntime { .append("--workdir=%3$s ") .append("--net=" + customNetwork1 + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ") @@ -474,7 +486,7 @@ public class TestDockerContainerRuntime { .append("--workdir=%3$s ") .append("--net=" + customNetwork2 + " ") .append(getExpectedTestCapabilitiesArgumentString()) - .append("-v /sys/fs/cgroup:/sys/fs/cgroup:ro ") + .append(getExpectedCGroupsMountString()) .append("-v %4$s:%4$s ").append("-v %5$s:%5$s ") .append("-v %6$s:%6$s ").append("-v %7$s:%7$s ") .append("-v %8$s:%8$s ").append("%9$s ")