You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/09/24 02:08:00 UTC

mesos git commit: Added MESOS_SANDBOX environment variable in Mesos containerizer.

Repository: mesos
Updated Branches:
  refs/heads/master 1d86932ce -> 721ea1145


Added MESOS_SANDBOX environment variable in Mesos containerizer.

Review: https://reviews.apache.org/r/38693


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/721ea114
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/721ea114
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/721ea114

Branch: refs/heads/master
Commit: 721ea11450329d0f58efe8b17deffb5aa91f6fd1
Parents: 1d86932
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Sep 23 14:48:34 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Sep 23 17:06:59 2015 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/containerizer.cpp |  7 ++-
 src/slave/containerizer/mesos/launch.cpp        |  1 +
 .../containerizer/filesystem_isolator_tests.cpp | 60 ++++++++++++++++++++
 3 files changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/721ea114/src/slave/containerizer/mesos/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp
index 19b63b9..b904b2d 100644
--- a/src/slave/containerizer/mesos/containerizer.cpp
+++ b/src/slave/containerizer/mesos/containerizer.cpp
@@ -771,12 +771,17 @@ Future<bool> MesosContainerizerProcess::_launch(
   // Prepare environment variables for the executor.
   map<string, string> environment = executorEnvironment(
       executorInfo,
-      rootfs.isSome() ? flags.sandbox_directory : directory,
+      directory,
       slaveId,
       slavePid,
       checkpoint,
       flags);
 
+  // TODO(jieyu): Consider moving this to 'executorEnvironment' and
+  // consolidating with docker containerizer.
+  environment["MESOS_SANDBOX"] =
+    rootfs.isSome() ? flags.sandbox_directory : directory;
+
   // Include any enviroment variables from CommandInfo.
   foreach (const Environment::Variable& variable,
            executorInfo.command().environment().variables()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/721ea114/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index be600e3..09d4d8f 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -53,6 +53,7 @@ MesosContainerizerLaunch::Flags::Flags()
       "command",
       "The command to execute.");
 
+  // TODO(jieyu): Consider renaming it to 'sandbox'.
   add(&directory,
       "directory",
       "The directory to chdir to. If rootfs is specified this must\n"

http://git-wip-us.apache.org/repos/asf/mesos/blob/721ea114/src/tests/containerizer/filesystem_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp
index 1478531..41d098c 100644
--- a/src/tests/containerizer/filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/filesystem_isolator_tests.cpp
@@ -844,6 +844,66 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_MultipleContainers)
   EXPECT_TRUE(wait2.get().has_status());
   EXPECT_EQ(0, wait2.get().status());
 }
+
+
+// This test verifies that the environment variables for sandbox
+// (i.e., MESOS_DIRECTORY and MESOS_SANDBOX) are set properly.
+TEST_F(LinuxFilesystemIsolatorTest, ROOT_SandboxEnvironmentVariable)
+{
+  slave::Flags flags = CreateSlaveFlags();
+
+  ContainerID containerId;
+  containerId.set_value(UUID::random().toString());
+
+  string rootfsesDir = slave::provisioner::paths::getContainerDir(
+      slave::paths::getProvisionerDir(flags.work_dir),
+      containerId);
+
+  Try<Owned<MesosContainerizer>> containerizer = createContainerizer(
+      flags,
+      {{"test_image", path::join(rootfsesDir, "test_image")}});
+
+  ASSERT_SOME(containerizer);
+
+  string directory = path::join(os::getcwd(), "sandbox");
+  ASSERT_SOME(os::mkdir(directory));
+
+  Try<string> script = strings::format(
+      "if [ \"$MESOS_DIRECTORY\" != \"%s\" ]; then exit 1; fi &&"
+      "if [ \"$MESOS_SANDBOX\" != \"%s\" ]; then exit 1; fi",
+      directory,
+      flags.sandbox_directory);
+
+  ASSERT_SOME(script);
+
+  ExecutorInfo executor = CREATE_EXECUTOR_INFO(
+      "test_executor",
+      script.get());
+
+  executor.mutable_container()->CopyFrom(createContainerInfo("test_image"));
+
+  Future<bool> launch = containerizer.get()->launch(
+      containerId,
+      executor,
+      directory,
+      None(),
+      SlaveID(),
+      PID<Slave>(),
+      false);
+
+  // Wait for the launch to complete.
+  AWAIT_READY(launch);
+
+  // Wait on the container.
+  Future<containerizer::Termination> wait =
+    containerizer.get()->wait(containerId);
+
+  AWAIT_READY(wait);
+
+  // Check the executor exited correctly.
+  EXPECT_TRUE(wait.get().has_status());
+  EXPECT_EQ(0, wait.get().status());
+}
 #endif // __linux__
 
 } // namespace tests {