Repository: mesos Updated Branches: refs/heads/master 95c9f9571 -> 14f7967ef
Pass LIBPROCESS_IP even when executor environment is specified. If DNS is not available on the agent node and a task is launched which explicitly specifies the executor's environment, LIBPROCESS_IP will not be passed through and the default hostname lookup after spawning the executor process will throw an error. This patch alters the agent to always pass LIBPROCESS_IP, even when the executor environment is specified. Review: https://reviews.apache.org/r/39152 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/14f7967e Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/14f7967e Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/14f7967e Branch: refs/heads/master Commit: 14f7967ef307f3d98e3a4b93d92d6b3a56399b20 Parents: 95c9f95 Author: Greg Mann <[email protected]> Authored: Fri Oct 9 15:01:22 2015 -0700 Committer: Adam B <[email protected]> Committed: Fri Oct 9 15:26:19 2015 -0700 ---------------------------------------------------------------------- src/slave/containerizer/containerizer.cpp | 11 ++++++++++ .../containerizer/mesos_containerizer_tests.cpp | 23 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/14f7967e/src/slave/containerizer/containerizer.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/containerizer.cpp b/src/slave/containerizer/containerizer.cpp index 25c87e9..e710a08 100644 --- a/src/slave/containerizer/containerizer.cpp +++ b/src/slave/containerizer/containerizer.cpp @@ -245,6 +245,17 @@ map<string, string> executorEnvironment( { map<string, string> environment; + // In cases where DNS is not available on the slave, the absence of + // LIBPROCESS_IP in the executor's environment will cause an error when the + // new executor process attempts a hostname lookup. Thus, we pass the slave's + // LIBPROCESS_IP through here, even if the executor environment is specified + // explicitly. Note that a LIBPROCESS_IP present in the provided flags will + // override this value. + Option<string> libprocessIP = os::getenv("LIBPROCESS_IP"); + if (libprocessIP.isSome()) { + environment["LIBPROCESS_IP"] = libprocessIP.get(); + } + if (flags.executor_environment_variables.isSome()) { foreachpair (const string& key, const JSON::Value& value, http://git-wip-us.apache.org/repos/asf/mesos/blob/14f7967e/src/tests/containerizer/mesos_containerizer_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/mesos_containerizer_tests.cpp b/src/tests/containerizer/mesos_containerizer_tests.cpp index 5bc7d40..873acd3 100644 --- a/src/tests/containerizer/mesos_containerizer_tests.cpp +++ b/src/tests/containerizer/mesos_containerizer_tests.cpp @@ -30,6 +30,7 @@ #include <process/future.hpp> #include <process/owned.hpp> +#include <stout/net.hpp> #include <stout/strings.hpp> #include "slave/flags.hpp" @@ -297,10 +298,15 @@ 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 +// variable. Finally, after the executor has terminated, we check for // the existence of the file. TEST_F(MesosContainerizerIsolatorPreparationTest, ExecutorEnvironmentVariable) { + // Set LIBPROCESS_IP so that we can test if it gets passed to the executor. + Option<string> libprocessIP = os::getenv("LIBPROCESS_IP"); + net::IP ip = net::IP(INADDR_LOOPBACK); + os::setenv("LIBPROCESS_IP", stringify(ip)); + string directory = os::getcwd(); // We're inside a temporary sandbox. string file = path::join(directory, "child.script.executed"); @@ -323,9 +329,15 @@ TEST_F(MesosContainerizerIsolatorPreparationTest, ExecutorEnvironmentVariable) ContainerID containerId; containerId.set_value("test_container"); + // Ensure that LIBPROCESS_IP has been passed despite the explicit + // specification of the environment. If so, then touch the test file. + string executorCmd = + "if [ -n \"$LIBPROCESS_IP\" ]; " + "then touch $TEST_ENVIRONMENT; fi"; + Future<bool> launch = containerizer.get()->launch( containerId, - CREATE_EXECUTOR_INFO("executor", "touch $TEST_ENVIRONMENT"), + CREATE_EXECUTOR_INFO("executor", executorCmd), directory, None(), SlaveID(), @@ -351,6 +363,13 @@ TEST_F(MesosContainerizerIsolatorPreparationTest, ExecutorEnvironmentVariable) // Destroy the container. containerizer.get()->destroy(containerId); + // Reset LIBPROCESS_IP if necessary. + if (libprocessIP.isSome()) { + os::setenv("LIBPROCESS_IP", libprocessIP.get()); + } else { + os::unsetenv("LIBPROCESS_IP"); + } + delete containerizer.get(); }
