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 2016/10/12 19:32:09 UTC
mesos git commit: Added a test for verifying nested container
environment.
Repository: mesos
Updated Branches:
refs/heads/master 6a4296de3 -> 713b784a3
Added a test for verifying nested container environment.
Review: https://reviews.apache.org/r/52774/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/713b784a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/713b784a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/713b784a
Branch: refs/heads/master
Commit: 713b784a3a92d655bd341470a9ed6fb7208466a3
Parents: 6a4296d
Author: Jie Yu <yu...@gmail.com>
Authored: Wed Oct 12 12:31:59 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Oct 12 12:31:59 2016 -0700
----------------------------------------------------------------------
.../nested_mesos_containerizer_tests.cpp | 93 ++++++++++++++++++++
src/tests/mesos.hpp | 13 +++
2 files changed, 106 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/713b784a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
index 9b278e5..c690b41 100644
--- a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
+++ b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
@@ -1433,6 +1433,99 @@ TEST_F(NestedMesosContainerizerTest, ROOT_CGROUPS_WaitAfterDestroy)
ASSERT_NONE(nestedWait.get());
}
+
+// This test verifies that agent environment variables are not leaked
+// to the nested container, and the environment variables specified in
+// the command for the nested container will be honored.
+TEST_F(NestedMesosContainerizerTest, ROOT_CGROUPS_Environment)
+{
+ slave::Flags flags = CreateSlaveFlags();
+ flags.launcher = "linux";
+ flags.isolation = "cgroups/cpu,filesystem/linux,namespaces/pid";
+
+ Fetcher fetcher;
+
+ Try<MesosContainerizer*> create = MesosContainerizer::create(
+ flags,
+ true,
+ &fetcher);
+
+ ASSERT_SOME(create);
+
+ Owned<MesosContainerizer> containerizer(create.get());
+
+ SlaveState state;
+ state.id = SlaveID();
+
+ AWAIT_READY(containerizer->recover(state));
+
+ ContainerID containerId;
+ containerId.set_value(UUID::random().toString());
+
+ Try<string> directory = environment->mkdtemp();
+ ASSERT_SOME(directory);
+
+ Future<bool> launch = containerizer->launch(
+ containerId,
+ None(),
+ createExecutorInfo("executor", "sleep 1000", "cpus:1"),
+ directory.get(),
+ None(),
+ state.id,
+ map<string, string>(),
+ true); // TODO(benh): Ever want to test not checkpointing?
+
+ AWAIT_ASSERT_TRUE(launch);
+
+ // Now launch nested container.
+ ContainerID nestedContainerId;
+ nestedContainerId.mutable_parent()->CopyFrom(containerId);
+ nestedContainerId.set_value(UUID::random().toString());
+
+ // Construct a command that verifies that agent environment
+ // variables are not leaked to the nested container.
+ ostringstream script;
+ script << "#!/bin/sh\n";
+
+ foreachkey (const string& key, os::environment()) {
+ script << "test -z \"$" << key << "\"\n";
+ }
+
+ mesos::Environment environment = createEnvironment(
+ {{"NESTED_MESOS_CONTAINERIZER_TEST", "ENVIRONMENT"}});
+
+ script << "test $NESTED_MESOS_CONTAINERIZER_TEST = ENVIRONMENT\n";
+
+ CommandInfo command = createCommandInfo(script.str());
+ command.mutable_environment()->CopyFrom(environment);
+
+ launch = containerizer->launch(
+ nestedContainerId,
+ command,
+ None(),
+ None(),
+ state.id);
+
+ AWAIT_ASSERT_TRUE(launch);
+
+ Future<Option<ContainerTermination>> wait = containerizer->wait(
+ nestedContainerId);
+
+ AWAIT_READY(wait);
+ ASSERT_SOME(wait.get());
+ ASSERT_TRUE(wait.get()->has_status());
+ EXPECT_WEXITSTATUS_EQ(0, wait.get()->status());
+
+ wait = containerizer->wait(containerId);
+
+ containerizer->destroy(containerId);
+
+ AWAIT_READY(wait);
+ ASSERT_SOME(wait.get());
+ ASSERT_TRUE(wait.get()->has_status());
+ EXPECT_WTERMSIG_EQ(SIGKILL, wait.get()->status());
+}
+
} // namespace tests {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/713b784a/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 5e15f51..9309b5a 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -397,6 +397,19 @@ protected:
containerId; })
+inline mesos::Environment createEnvironment(
+ const hashmap<std::string, std::string>& map)
+{
+ mesos::Environment environment;
+ foreachpair (const std::string& key, const std::string& value, map) {
+ mesos::Environment::Variable* variable = environment.add_variables();
+ variable->set_name(key);
+ variable->set_value(value);
+ }
+ return environment;
+}
+
+
inline ExecutorInfo createExecutorInfo(
const std::string& executorId,
const std::string& command,