Repository: mesos Updated Branches: refs/heads/master f68661e75 -> c321283fc
Passed env vars returned by Isolator::prepare() to executor. Append the environment variables returned by Isolator::prepare() to the list of environment variables being passed to the executor. Added a test to verify that the executor is launched with the said environment variables. Review: https://reviews.apache.org/r/36755 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a3da1a1b Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a3da1a1b Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a3da1a1b Branch: refs/heads/master Commit: a3da1a1b037807d618f6b4d10851a27d247231b8 Parents: f68661e Author: Kapil Arya <[email protected]> Authored: Tue Jul 28 10:09:37 2015 -0700 Committer: Jie Yu <[email protected]> Committed: Tue Jul 28 10:15:18 2015 -0700 ---------------------------------------------------------------------- src/slave/containerizer/mesos/containerizer.cpp | 13 +++- src/tests/containerizer/containerizer_tests.cpp | 62 +++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a3da1a1b/src/slave/containerizer/mesos/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/containerizer.cpp b/src/slave/containerizer/mesos/containerizer.cpp index ecc8659..c0159a0 100644 --- a/src/slave/containerizer/mesos/containerizer.cpp +++ b/src/slave/containerizer/mesos/containerizer.cpp @@ -84,10 +84,10 @@ namespace slave { using mesos::modules::ModuleManager; +using mesos::slave::ContainerPrepareInfo; using mesos::slave::ExecutorLimitation; using mesos::slave::ExecutorRunState; using mesos::slave::Isolator; -using mesos::slave::ContainerPrepareInfo; using state::SlaveState; using state::FrameworkState; @@ -827,6 +827,17 @@ Future<bool> MesosContainerizerProcess::_launch( environment[variable.name()] = variable.value(); } + // Include any environment variables returned from + // Isolator::prepare(). + foreach (const Option<ContainerPrepareInfo>& prepareInfo, prepareInfos) { + if (prepareInfo.isSome() && prepareInfo.get().has_environment()) { + foreach (const Environment::Variable& variable, + prepareInfo.get().environment().variables()) { + environment[variable.name()] = variable.value(); + } + } + } + // Use a pipe to block the child until it's been isolated. int pipes[2]; http://git-wip-us.apache.org/repos/asf/mesos/blob/a3da1a1b/src/tests/containerizer/containerizer_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/containerizer_tests.cpp b/src/tests/containerizer/containerizer_tests.cpp index cbafa42..82baca7 100644 --- a/src/tests/containerizer/containerizer_tests.cpp +++ b/src/tests/containerizer/containerizer_tests.cpp @@ -63,10 +63,10 @@ using mesos::internal::slave::state::FrameworkState; using mesos::internal::slave::state::RunState; using mesos::internal::slave::state::SlaveState; +using mesos::slave::ContainerPrepareInfo; using mesos::slave::ExecutorLimitation; using mesos::slave::ExecutorRunState; using mesos::slave::Isolator; -using mesos::slave::ContainerPrepareInfo; using std::list; using std::map; @@ -297,6 +297,66 @@ TEST_F(MesosContainerizerIsolatorPreparationTest, MultipleScripts) } +// The isolator sets an environment variable for the Executor. The +// Executor then creates a file as pointed to by environment +// varialble. Finally, after the executor has terminated, we check for +// the existence of the file. +TEST_F(MesosContainerizerIsolatorPreparationTest, ExecutorEnvironmentVariable) +{ + string directory = os::getcwd(); // We're inside a temporary sandbox. + string file = path::join(directory, "child.script.executed"); + + Fetcher fetcher; + + ContainerPrepareInfo prepareInfo; + + Environment::Variable* variable = + prepareInfo.mutable_environment()->add_variables(); + + variable->set_name("TEST_ENVIRONMENT"); + variable->set_value(file); + + Try<MesosContainerizer*> containerizer = CreateContainerizer( + &fetcher, + prepareInfo); + + CHECK_SOME(containerizer); + + ContainerID containerId; + containerId.set_value("test_container"); + + Future<bool> launch = containerizer.get()->launch( + containerId, + CREATE_EXECUTOR_INFO("executor", "touch $TEST_ENVIRONMENT"), + directory, + None(), + SlaveID(), + PID<Slave>(), + false); + + // Wait until the launch completes. + AWAIT_READY(launch); + + // Wait for the child (preparation script + executor) to complete. + Future<containerizer::Termination> wait = + containerizer.get()->wait(containerId); + + AWAIT_READY(wait); + + // Check the child exited correctly. + EXPECT_TRUE(wait.get().has_status()); + EXPECT_EQ(0, wait.get().status()); + + // Check the preparation script actually ran. + EXPECT_TRUE(os::exists(file)); + + // Destroy the container. + containerizer.get()->destroy(containerId); + + delete containerizer.get(); +} + + class MesosContainerizerExecuteTest : public TemporaryDirectoryTest {};
