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 2017/11/29 03:35:08 UTC
[1/9] mesos git commit: Refactored MockSlave creation to use
cluster::Slave interfaces.
Repository: mesos
Updated Branches:
refs/heads/master 60d581b6e -> d6d40ecad
Refactored MockSlave creation to use cluster::Slave interfaces.
This patch refactored the tests to use StartSlave for creating
MockSlave. This allows proper initialization and cleanup in the tests
and avoids code duplication.
Review: https://reviews.apache.org/r/64139
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c7304a12
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c7304a12
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c7304a12
Branch: refs/heads/master
Commit: c7304a123c79173af841b33a3db9fb272cc5ba3a
Parents: e1207f9
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Nov 28 16:33:17 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:41:56 2017 -0800
----------------------------------------------------------------------
src/slave/main.cpp | 1 +
src/tests/cluster.cpp | 58 ++-
src/tests/cluster.hpp | 16 +-
src/tests/command_executor_tests.cpp | 17 +-
.../containerizer/ports_isolator_tests.cpp | 8 +-
src/tests/mesos.cpp | 122 ++++++-
src/tests/mesos.hpp | 9 +-
src/tests/mock_slave.cpp | 60 ++--
src/tests/mock_slave.hpp | 38 +-
src/tests/oversubscription_tests.cpp | 17 +-
src/tests/persistent_volume_tests.cpp | 31 +-
src/tests/reservation_tests.cpp | 93 +++--
src/tests/slave_tests.cpp | 353 ++++++++++++-------
13 files changed, 534 insertions(+), 289 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index ac83d41..abe48fd 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -563,6 +563,7 @@ int main(int argc, char** argv)
}
SecretGenerator* secretGenerator = nullptr;
+
#ifdef USE_SSL_SOCKET
if (flags.jwt_secret_key.isSome()) {
Try<string> jwtSecretKey = os::read(flags.jwt_secret_key.get());
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/cluster.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.cpp b/src/tests/cluster.cpp
index ae145fd..4ff9faf 100644
--- a/src/tests/cluster.cpp
+++ b/src/tests/cluster.cpp
@@ -398,7 +398,7 @@ void Master::setAuthorizationCallbacks(Authorizer* authorizer)
}
-Try<process::Owned<Slave>> Slave::start(
+Try<process::Owned<Slave>> Slave::create(
MasterDetector* detector,
const slave::Flags& flags,
const Option<string>& id,
@@ -408,7 +408,8 @@ Try<process::Owned<Slave>> Slave::start(
const Option<mesos::slave::ResourceEstimator*>& resourceEstimator,
const Option<mesos::slave::QoSController*>& qosController,
const Option<mesos::SecretGenerator*>& secretGenerator,
- const Option<Authorizer*>& providedAuthorizer)
+ const Option<Authorizer*>& providedAuthorizer,
+ bool mock)
{
process::Owned<Slave> slave(new Slave());
@@ -552,20 +553,33 @@ Try<process::Owned<Slave>> Slave::start(
}
// Inject all the dependencies.
- slave->slave.reset(new slave::Slave(
- id.isSome() ? id.get() : process::ID::generate("slave"),
- flags,
- detector,
- slave->containerizer,
- &slave->files,
- gc.getOrElse(slave->gc.get()),
- taskStatusUpdateManager.getOrElse(slave->taskStatusUpdateManager.get()),
- resourceEstimator.getOrElse(slave->resourceEstimator.get()),
- qosController.getOrElse(slave->qosController.get()),
- secretGenerator.getOrElse(slave->secretGenerator.get()),
- authorizer));
-
- slave->pid = process::spawn(slave->slave.get());
+ if (mock) {
+ slave->slave.reset(new MockSlave(
+ id.isSome() ? id.get() : process::ID::generate("slave"),
+ flags,
+ detector,
+ slave->containerizer,
+ &slave->files,
+ gc.getOrElse(slave->gc.get()),
+ taskStatusUpdateManager.getOrElse(slave->taskStatusUpdateManager.get()),
+ resourceEstimator.getOrElse(slave->resourceEstimator.get()),
+ qosController.getOrElse(slave->qosController.get()),
+ secretGenerator.getOrElse(slave->secretGenerator.get()),
+ authorizer));
+ } else {
+ slave->slave.reset(new slave::Slave(
+ id.isSome() ? id.get() : process::ID::generate("slave"),
+ flags,
+ detector,
+ slave->containerizer,
+ &slave->files,
+ gc.getOrElse(slave->gc.get()),
+ taskStatusUpdateManager.getOrElse(slave->taskStatusUpdateManager.get()),
+ resourceEstimator.getOrElse(slave->resourceEstimator.get()),
+ qosController.getOrElse(slave->qosController.get()),
+ secretGenerator.getOrElse(slave->secretGenerator.get()),
+ authorizer));
+ }
return slave;
}
@@ -656,6 +670,18 @@ void Slave::terminate()
}
+MockSlave* Slave::mock()
+{
+ return dynamic_cast<MockSlave*>(slave.get());
+}
+
+
+void Slave::start()
+{
+ pid = process::spawn(slave.get());
+}
+
+
void Slave::wait()
{
process::wait(pid);
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/cluster.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.hpp b/src/tests/cluster.hpp
index 4ed12c7..ad2b80e 100644
--- a/src/tests/cluster.hpp
+++ b/src/tests/cluster.hpp
@@ -66,6 +66,7 @@
#include "slave/containerizer/fetcher.hpp"
#include "tests/mock_registrar.hpp"
+#include "tests/mock_slave.hpp"
namespace mesos {
namespace internal {
@@ -148,7 +149,7 @@ private:
class Slave
{
public:
- // Factory method that starts a new slave with the provided flags and
+ // Factory method that creates a new slave with the provided flags and
// injections. The destructor of this object will cleanup some, but not
// all of its state by calling the injections. Cleanup includes:
// * All destructors of each slave dependency created in this factory.
@@ -156,7 +157,7 @@ public:
// will be destroyed before termination.
// * Terminating the slave process.
// * On Linux, we will simulate an OS process exiting.
- static Try<process::Owned<Slave>> start(
+ static Try<process::Owned<Slave>> create(
mesos::master::detector::MasterDetector* detector,
const slave::Flags& flags = slave::Flags(),
const Option<std::string>& id = None(),
@@ -168,7 +169,8 @@ public:
None(),
const Option<mesos::slave::QoSController*>& qosController = None(),
const Option<mesos::SecretGenerator*>& secretGenerator = None(),
- const Option<Authorizer*>& authorizer = None());
+ const Option<Authorizer*>& authorizer = None(),
+ bool mock = false);
~Slave();
@@ -183,6 +185,14 @@ public:
void shutdown();
void terminate();
+ // Returns the pointer to the mock slave object. Returns nullptr if
+ // this is not a mock slave.
+ MockSlave* mock();
+
+ // Start the mock slave as it is not auto started. This is a no-op
+ // if it is a real slave.
+ void start();
+
// The underlying slave process.
process::PID<slave::Slave> pid;
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/command_executor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/command_executor_tests.cpp b/src/tests/command_executor_tests.cpp
index 8d36454..3c5687f 100644
--- a/src/tests/command_executor_tests.cpp
+++ b/src/tests/command_executor_tests.cpp
@@ -375,8 +375,16 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(HTTPCommandExecutorTest, TerminateWithACK)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(flags, &detector, containerizer.get());
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ containerizer.get(),
+ flags,
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
MockScheduler sched;
MesosSchedulerDriver driver(
@@ -410,7 +418,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(HTTPCommandExecutorTest, TerminateWithACK)
.WillOnce(FutureArg<1>(&statusFinished));
Future<Future<Option<ContainerTermination>>> termination;
- EXPECT_CALL(slave, executorTerminated(_, _, _))
+ EXPECT_CALL(*slave.get()->mock(), executorTerminated(_, _, _))
.WillOnce(FutureArg<2>(&termination));
driver.launchTasks(offers->front().id(), {task});
@@ -434,9 +442,6 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(HTTPCommandExecutorTest, TerminateWithACK)
driver.stop();
driver.join();
-
- terminate(slave);
- wait(slave);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/containerizer/ports_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/ports_isolator_tests.cpp b/src/tests/containerizer/ports_isolator_tests.cpp
index 0429003..3438030 100644
--- a/src/tests/containerizer/ports_isolator_tests.cpp
+++ b/src/tests/containerizer/ports_isolator_tests.cpp
@@ -1376,9 +1376,11 @@ TEST_F(NetworkPortsIsolatorTest, ROOT_NC_RecoverNestedBadTask)
flags.isolation = "network/ports";
flags.check_agent_port_range_only = true;
- slave = cluster::Slave::start(detector.get(), flags, slaveId);
+ slave = cluster::Slave::create(detector.get(), flags, slaveId);
ASSERT_SOME(slave);
+ slave.get()->start();
+
// Wait for the slave to re-register.
AWAIT_READY(slaveReregisteredMessage);
@@ -1559,9 +1561,11 @@ TEST_F(NetworkPortsIsolatorTest, ROOT_NC_RecoverNestedGoodTask)
flags.isolation = "network/ports";
flags.check_agent_port_range_only = true;
- slave = cluster::Slave::start(detector.get(), flags, slaveId);
+ slave = cluster::Slave::create(detector.get(), flags, slaveId);
ASSERT_SOME(slave);
+ slave.get()->start();
+
// Wait for the slave to re-register.
AWAIT_READY(slaveReregisteredMessage);
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 0e68ab7..b6daf85 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -323,22 +323,42 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
MasterDetector* detector,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get());
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
Try<Owned<cluster::Slave>> MesosTest::StartSlave(
MasterDetector* detector,
slave::Containerizer* containerizer,
- const Option<slave::Flags>& flags)
+ const Option<slave::Flags>& flags,
+ bool mock)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
- containerizer);
+ containerizer,
+ None(),
+ None(),
+ None(),
+ None(),
+ None(),
+ None(),
+ mock);
+
+ if (slave.isSome() && !mock) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -347,10 +367,16 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
const string& id,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
id);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -360,11 +386,17 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
const string& id,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
id,
containerizer);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -373,12 +405,18 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
slave::GarbageCollector* gc,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
None(),
gc);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -387,7 +425,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -395,6 +433,12 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
resourceEstimator);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -404,7 +448,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -412,6 +456,12 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
resourceEstimator);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -420,7 +470,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
mesos::slave::QoSController* qoSController,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -429,6 +479,12 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
qoSController);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -436,9 +492,10 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
MasterDetector* detector,
slave::Containerizer* containerizer,
mesos::slave::QoSController* qoSController,
- const Option<slave::Flags>& flags)
+ const Option<slave::Flags>& flags,
+ bool mock)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -446,7 +503,16 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
None(),
- qoSController);
+ qoSController,
+ None(),
+ None(),
+ mock);
+
+ if (slave.isSome() && !mock) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -455,7 +521,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
mesos::Authorizer* authorizer,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -466,6 +532,12 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
authorizer);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -475,7 +547,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
mesos::Authorizer* authorizer,
const Option<slave::Flags>& flags)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -486,6 +558,12 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
authorizer);
+
+ if (slave.isSome()) {
+ slave.get()->start();
+ }
+
+ return slave;
}
@@ -494,9 +572,10 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
slave::Containerizer* containerizer,
mesos::SecretGenerator* secretGenerator,
const Option<mesos::Authorizer*>& authorizer,
- const Option<slave::Flags>& flags)
+ const Option<slave::Flags>& flags,
+ bool mock)
{
- return cluster::Slave::start(
+ Try<Owned<cluster::Slave>> slave = cluster::Slave::create(
detector,
flags.isNone() ? CreateSlaveFlags() : flags.get(),
None(),
@@ -506,7 +585,14 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
secretGenerator,
- authorizer);
+ authorizer,
+ mock);
+
+ if (slave.isSome() && !mock) {
+ slave.get()->start();
+ }
+
+ return slave;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index f83b3e0..18f3623 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -182,7 +182,8 @@ protected:
virtual Try<process::Owned<cluster::Slave>> StartSlave(
mesos::master::detector::MasterDetector* detector,
slave::Containerizer* containerizer,
- const Option<slave::Flags>& flags = None());
+ const Option<slave::Flags>& flags = None(),
+ bool mock = false);
// Starts a slave with the specified detector, id, and flags.
virtual Try<process::Owned<cluster::Slave>> StartSlave(
@@ -229,7 +230,8 @@ protected:
mesos::master::detector::MasterDetector* detector,
slave::Containerizer* containerizer,
mesos::slave::QoSController* qosController,
- const Option<slave::Flags>& flags = None());
+ const Option<slave::Flags>& flags = None(),
+ bool mock = false);
// Starts a slave with the specified detector, authorizer, and flags.
virtual Try<process::Owned<cluster::Slave>> StartSlave(
@@ -252,7 +254,8 @@ protected:
slave::Containerizer* containerizer,
mesos::SecretGenerator* secretGenerator,
const Option<mesos::Authorizer*>& authorizer = None(),
- const Option<slave::Flags>& flags = None());
+ const Option<slave::Flags>& flags = None(),
+ bool mock = false);
Option<zookeeper::URL> zookeeperUrl;
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/mock_slave.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.cpp b/src/tests/mock_slave.cpp
index dd74216..6d050ca 100644
--- a/src/tests/mock_slave.cpp
+++ b/src/tests/mock_slave.cpp
@@ -35,9 +35,16 @@
using mesos::master::detector::MasterDetector;
+using mesos::internal::slave::Containerizer;
+using mesos::internal::slave::GarbageCollector;
+using mesos::internal::slave::TaskStatusUpdateManager;
+
using mesos::slave::ContainerTermination;
+using mesos::slave::ResourceEstimator;
+using mesos::slave::QoSController;
using std::list;
+using std::string;
using process::Future;
using process::UPID;
@@ -49,25 +56,6 @@ namespace mesos {
namespace internal {
namespace tests {
-MockGarbageCollector::MockGarbageCollector()
-{
- // NOTE: We use 'EXPECT_CALL' and 'WillRepeatedly' here instead of
- // 'ON_CALL' and 'WillByDefault'. See 'TestContainerizer::SetUp()'
- // for more details.
- EXPECT_CALL(*this, schedule(_, _))
- .WillRepeatedly(Return(Nothing()));
-
- EXPECT_CALL(*this, unschedule(_))
- .WillRepeatedly(Return(true));
-
- EXPECT_CALL(*this, prune(_))
- .WillRepeatedly(Return());
-}
-
-
-MockGarbageCollector::~MockGarbageCollector() {}
-
-
MockResourceEstimator::MockResourceEstimator()
{
ON_CALL(*this, initialize(_))
@@ -104,25 +92,29 @@ MockQoSController::~MockQoSController() {}
MockSlave::MockSlave(
+ const string& id,
const slave::Flags& flags,
MasterDetector* detector,
- slave::Containerizer* containerizer,
- const Option<mesos::slave::QoSController*>& _qosController,
- const Option<mesos::SecretGenerator*>& secretGenerator,
- const Option<mesos::Authorizer*>& authorizer)
+ Containerizer* containerizer,
+ Files* files,
+ GarbageCollector* gc,
+ TaskStatusUpdateManager* taskStatusUpdateManager,
+ ResourceEstimator* resourceEstimator,
+ QoSController* qosController,
+ SecretGenerator* secretGenerator,
+ const Option<Authorizer*>& authorizer)
: slave::Slave(
process::ID::generate("slave"),
flags,
detector,
containerizer,
- &files,
- &gc,
- taskStatusUpdateManager = new slave::TaskStatusUpdateManager(flags),
- &resourceEstimator,
- _qosController.isSome() ? _qosController.get() : &qosController,
- secretGenerator.isSome() ? secretGenerator.get() : nullptr,
- authorizer),
- files(slave::READONLY_HTTP_AUTHENTICATION_REALM)
+ files,
+ gc,
+ taskStatusUpdateManager,
+ resourceEstimator,
+ qosController,
+ secretGenerator,
+ authorizer)
{
// Set up default behaviors, calling the original methods.
EXPECT_CALL(*this, runTask(_, _, _, _, _))
@@ -148,12 +140,6 @@ MockSlave::MockSlave(
}
-MockSlave::~MockSlave()
-{
- delete taskStatusUpdateManager;
-}
-
-
void MockSlave::unmocked_runTask(
const UPID& from,
const FrameworkInfo& frameworkInfo,
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/mock_slave.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.hpp b/src/tests/mock_slave.hpp
index 5ba5da6..d986125 100644
--- a/src/tests/mock_slave.hpp
+++ b/src/tests/mock_slave.hpp
@@ -49,24 +49,6 @@ namespace mesos {
namespace internal {
namespace tests {
-class MockGarbageCollector : public slave::GarbageCollector
-{
-public:
- MockGarbageCollector();
- virtual ~MockGarbageCollector();
-
- MOCK_METHOD2(
- schedule,
- process::Future<Nothing>(const Duration& d, const std::string& path));
- MOCK_METHOD1(
- unschedule,
- process::Future<bool>(const std::string& path));
- MOCK_METHOD1(
- prune,
- void(const Duration& d));
-};
-
-
class MockResourceEstimator : public mesos::slave::ResourceEstimator
{
public:
@@ -106,14 +88,17 @@ class MockSlave : public slave::Slave
{
public:
MockSlave(
+ const std::string& id,
const slave::Flags& flags,
mesos::master::detector::MasterDetector* detector,
slave::Containerizer* containerizer,
- const Option<mesos::slave::QoSController*>& qosController = None(),
- const Option<mesos::SecretGenerator*>& secretGenerator = None(),
- const Option<mesos::Authorizer*>& authorizer = None());
-
- virtual ~MockSlave();
+ Files* files,
+ slave::GarbageCollector* gc,
+ slave::TaskStatusUpdateManager* taskStatusUpdateManager,
+ mesos::slave::ResourceEstimator* resourceEstimator,
+ mesos::slave::QoSController* qosController,
+ SecretGenerator* secretGenerator,
+ const Option<Authorizer*>& authorizer);
MOCK_METHOD5(runTask, void(
const process::UPID& from,
@@ -208,13 +193,6 @@ public:
const process::UPID& from,
const FrameworkID& frameworkId,
const ExecutorID& executorId);
-
-private:
- Files files;
- MockGarbageCollector gc;
- MockResourceEstimator resourceEstimator;
- MockQoSController qosController;
- slave::TaskStatusUpdateManager* taskStatusUpdateManager;
};
} // namespace tests {
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp b/src/tests/oversubscription_tests.cpp
index 2f403d3..57f42e0 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -944,13 +944,21 @@ TEST_F(OversubscriptionTest, ReceiveQoSCorrection)
&corrections,
&Queue<list<QoSCorrection>>::get));
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer, &controller);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ &controller,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
Future<list<QoSCorrection>> qosCorrections;
- EXPECT_CALL(slave, _qosCorrections(_))
+ EXPECT_CALL(*slave.get()->mock(), _qosCorrections(_))
.WillOnce(FutureArg<0>(&qosCorrections));
- spawn(slave);
+ slave.get()->start();
list<QoSCorrection> expected = { QoSCorrection() };
corrections.put(expected);
@@ -960,9 +968,6 @@ TEST_F(OversubscriptionTest, ReceiveQoSCorrection)
ASSERT_EQ(qosCorrections->size(), 1u);
// TODO(nnielsen): Test for equality of QoSCorrections.
-
- terminate(slave);
- wait(slave);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/persistent_volume_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/persistent_volume_tests.cpp b/src/tests/persistent_volume_tests.cpp
index b11d26e..56b5521 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -779,8 +779,16 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
TestContainerizer containerizer(&exec);
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave1(slaveFlags, &detector, &containerizer);
- spawn(slave1);
+ Try<Owned<cluster::Slave>> slave1 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave1);
+ ASSERT_NE(nullptr, slave1.get()->mock());
+
+ slave1.get()->start();
AWAIT_READY(slaveReady);
@@ -820,8 +828,7 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
AWAIT_READY(message);
- terminate(slave1);
- wait(slave1);
+ slave1.get()->terminate();
// Simulate a reboot of the slave machine by modifying the boot ID.
ASSERT_SOME(os::write(slave::paths::getBootIdPath(
@@ -832,19 +839,25 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
// checkpointed resources.
slaveFlags.resources = "disk:1024";
- MockSlave slave2(slaveFlags, &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave2 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave2);
+ ASSERT_NE(nullptr, slave2.get()->mock());
Future<Future<Nothing>> recover;
- EXPECT_CALL(slave2, __recover(_))
+ EXPECT_CALL(*slave2.get()->mock(), __recover(_))
.WillOnce(DoAll(FutureArg<0>(&recover), Return()));
- spawn(slave2);
+ slave2.get()->start();
AWAIT_READY(recover);
AWAIT_FAILED(recover.get());
- terminate(slave2);
- wait(slave2);
+ slave2.get()->terminate();
driver.stop();
driver.join();
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index fa375cd..f29e9bb 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -994,8 +994,16 @@ TEST_P(ReservationTest, CompatibleCheckpointedResources)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave1(slaveFlags, &detector, &containerizer);
- spawn(slave1);
+ Try<Owned<cluster::Slave>> slave1 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave1);
+ ASSERT_NE(nullptr, slave1.get()->mock());
+
+ slave1.get()->start();
AWAIT_READY(slaveReady);
@@ -1041,8 +1049,7 @@ TEST_P(ReservationTest, CompatibleCheckpointedResources)
// Wait until the operation message arrives.
AWAIT_READY(message);
- terminate(slave1);
- wait(slave1);
+ slave1.get()->terminate();
// Simulate a reboot of the slave machine by modifying the boot ID.
ASSERT_SOME(os::write(slave::paths::getBootIdPath(
@@ -1053,13 +1060,20 @@ TEST_P(ReservationTest, CompatibleCheckpointedResources)
// checkpointed resources.
slaveFlags.resources = "cpus:12;mem:2048";
- MockSlave slave2(slaveFlags, &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave2 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave2);
+ ASSERT_NE(nullptr, slave2.get()->mock());
Future<Future<Nothing>> recover;
- EXPECT_CALL(slave2, __recover(_))
+ EXPECT_CALL(*slave2.get()->mock(), __recover(_))
.WillOnce(DoAll(FutureArg<0>(&recover), Return()));
- spawn(slave2);
+ slave2.get()->start();
// Wait for 'recover' to finish.
AWAIT_READY(recover);
@@ -1067,8 +1081,7 @@ TEST_P(ReservationTest, CompatibleCheckpointedResources)
// Expect 'recover' to have completed successfully.
AWAIT_READY(recover.get());
- terminate(slave2);
- wait(slave2);
+ slave2.get()->terminate();
EXPECT_CALL(exec, shutdown(_))
.Times(AtMost(1));
@@ -1104,8 +1117,16 @@ TEST_P(ReservationTest, CompatibleCheckpointedResourcesWithPersistentVolumes)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave1(slaveFlags, &detector, &containerizer);
- spawn(slave1);
+ Try<Owned<cluster::Slave>> slave1 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave1);
+ ASSERT_NE(nullptr, slave1.get()->mock());
+
+ slave1.get()->start();
AWAIT_READY(slaveReady);
@@ -1189,8 +1210,7 @@ TEST_P(ReservationTest, CompatibleCheckpointedResourcesWithPersistentVolumes)
EXPECT_CALL(sched, offerRescinded(&driver, _))
.WillOnce(FutureArg<1>(&rescindedOfferId));
- terminate(slave1);
- wait(slave1);
+ slave1.get()->terminate();
AWAIT_READY(rescindedOfferId);
EXPECT_EQ(rescindedOfferId.get(), offer.id());
@@ -1204,13 +1224,20 @@ TEST_P(ReservationTest, CompatibleCheckpointedResourcesWithPersistentVolumes)
// checkpointed resources.
slaveFlags.resources = "cpus:12;mem:2048;disk:1024";
- MockSlave slave2(slaveFlags, &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave2 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave2);
+ ASSERT_NE(nullptr, slave2.get()->mock());
Future<Future<Nothing>> recover;
- EXPECT_CALL(slave2, __recover(_))
+ EXPECT_CALL(*slave2.get()->mock(), __recover(_))
.WillOnce(DoAll(FutureArg<0>(&recover), Return()));
- spawn(slave2);
+ slave2.get()->start();
// Wait for 'recover' to finish.
AWAIT_READY(recover);
@@ -1218,8 +1245,7 @@ TEST_P(ReservationTest, CompatibleCheckpointedResourcesWithPersistentVolumes)
// Expect that 'recover' will complete successfully.
AWAIT_READY(recover.get());
- terminate(slave2);
- wait(slave2);
+ slave2.get()->terminate();
EXPECT_CALL(exec, shutdown(_))
.Times(AtMost(1));
@@ -1254,8 +1280,16 @@ TEST_P(ReservationTest, IncompatibleCheckpointedResources)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave1(slaveFlags, &detector, &containerizer);
- spawn(slave1);
+ Try<Owned<cluster::Slave>> slave1 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave1);
+ ASSERT_NE(nullptr, slave1.get()->mock());
+
+ slave1.get()->start();
AWAIT_READY(slaveReady);
@@ -1300,8 +1334,7 @@ TEST_P(ReservationTest, IncompatibleCheckpointedResources)
// Wait for the operation message to be delivered.
AWAIT_READY(message);
- terminate(slave1);
- wait(slave1);
+ slave1.get()->terminate();
// Simulate a reboot of the slave machine by modifying the boot ID.
ASSERT_SOME(os::write(slave::paths::getBootIdPath(
@@ -1312,13 +1345,20 @@ TEST_P(ReservationTest, IncompatibleCheckpointedResources)
// checkpointed resources.
slaveFlags.resources = "cpus:4;mem:2048";
- MockSlave slave2(slaveFlags, &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave2 = StartSlave(
+ &detector,
+ &containerizer,
+ slaveFlags,
+ true);
+
+ ASSERT_SOME(slave2);
+ ASSERT_NE(nullptr, slave2.get()->mock());
Future<Future<Nothing>> recover;
- EXPECT_CALL(slave2, __recover(_))
+ EXPECT_CALL(*slave2.get()->mock(), __recover(_))
.WillOnce(DoAll(FutureArg<0>(&recover), Return()));
- spawn(slave2);
+ slave2.get()->start();
// Wait for 'recover' to finish.
AWAIT_READY(recover);
@@ -1326,8 +1366,7 @@ TEST_P(ReservationTest, IncompatibleCheckpointedResources)
// Expect for 'recover' to have failed.
AWAIT_FAILED(recover.get());
- terminate(slave2);
- wait(slave2);
+ slave2.get()->terminate();
EXPECT_CALL(exec, shutdown(_))
.Times(AtMost(1));
http://git-wip-us.apache.org/repos/asf/mesos/blob/c7304a12/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index b780fd1..aeaa923 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -787,7 +787,14 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, GetExecutorInfo)
TestContainerizer containerizer;
StandaloneMasterDetector detector;
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
FrameworkID frameworkId;
frameworkId.set_value("20141010-221431-251662764-60288-32120-0000");
@@ -825,7 +832,8 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, GetExecutorInfo)
labels->add_labels()->CopyFrom(createLabel("label1", "key1"));
labels->add_labels()->CopyFrom(createLabel("label2", "key2"));
- const ExecutorInfo& executor = slave.getExecutorInfo(frameworkInfo, task);
+ const ExecutorInfo& executor =
+ slave.get()->mock()->getExecutorInfo(frameworkInfo, task);
// Now assert that it actually is running mesos-executor without any
// bleedover from the command we intend on running.
@@ -848,7 +856,14 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, GetExecutorInfoForTaskWithContainer)
TestContainerizer containerizer;
StandaloneMasterDetector detector;
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
FrameworkInfo frameworkInfo;
frameworkInfo.mutable_id()->set_value(
@@ -881,7 +896,8 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, GetExecutorInfoForTaskWithContainer)
network->add_ip_addresses()->set_ip_address("4.3.2.1");
network->add_groups("public");
- const ExecutorInfo& executor = slave.getExecutorInfo(frameworkInfo, task);
+ const ExecutorInfo& executor =
+ slave.get()->mock()->getExecutorInfo(frameworkInfo, task);
// Now assert that the executor has both the command and ContainerInfo
EXPECT_FALSE(executor.command().shell());
@@ -925,7 +941,15 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, ROOT_LaunchTaskInfoWithContainerInfo)
Owned<MesosContainerizer> containerizer(_containerizer.get());
StandaloneMasterDetector detector;
- MockSlave slave(flags, &detector, containerizer.get());
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ containerizer.get(),
+ flags,
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
FrameworkInfo frameworkInfo;
frameworkInfo.mutable_id()->set_value(
@@ -961,7 +985,8 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(SlaveTest, ROOT_LaunchTaskInfoWithContainerInfo)
network->add_ip_addresses()->set_ip_address("4.3.2.1");
network->add_groups("public");
- const ExecutorInfo& executor = slave.getExecutorInfo(frameworkInfo, task);
+ const ExecutorInfo& executor =
+ slave.get()->mock()->getExecutorInfo(frameworkInfo, task);
Try<string> sandbox = environment->mkdtemp();
ASSERT_SOME(sandbox);
@@ -1735,8 +1760,19 @@ TEST_F(SlaveTest, GetStateTaskGroupPending)
TestContainerizer containerizer(executorId, executor);
Owned<MasterDetector> detector = master.get()->createDetector();
- MockSlave slave(CreateSlaveFlags(), detector.get(), &containerizer);
- process::PID<Slave> slavePid = spawn(slave);
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ detector.get(),
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
+
+ process::PID<Slave> slavePid = slave.get()->pid;
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -1787,7 +1823,7 @@ TEST_F(SlaveTest, GetStateTaskGroupPending)
// unmocked `_run()` method. Instead, we want to do nothing so that tasks
// remain in the framework's 'pending' list.
Future<Nothing> _run;
- EXPECT_CALL(slave, _run(_, _, _, _, _))
+ EXPECT_CALL(*slave.get()->mock(), _run(_, _, _, _, _))
.WillOnce(FutureSatisfy(&_run));
// The executor should not be launched.
@@ -1834,9 +1870,6 @@ TEST_F(SlaveTest, GetStateTaskGroupPending)
// To confirm the fix for MESOS-7871, we simply verify that the
// agent doesn't crash when this request is made.
AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
-
- terminate(slave);
- wait(slave);
}
@@ -2248,8 +2281,12 @@ TEST_F(SlaveTest, StatisticsEndpointMissingStatistics)
TestContainerizer containerizer(&exec);
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None());
+
+ ASSERT_SOME(slave);
MockScheduler sched;
MesosSchedulerDriver driver(
@@ -2294,7 +2331,7 @@ TEST_F(SlaveTest, StatisticsEndpointMissingStatistics)
.WillOnce(Return(Failure("Injected failure")));
Future<Response> response = process::http::get(
- slave.self(),
+ slave.get()->pid,
"monitor/statistics",
None(),
createBasicAuthHeaders(DEFAULT_CREDENTIAL));
@@ -2309,9 +2346,6 @@ TEST_F(SlaveTest, StatisticsEndpointMissingStatistics)
driver.stop();
driver.join();
-
- terminate(slave);
- wait(slave);
}
@@ -2326,24 +2360,28 @@ TEST_F(SlaveTest, StatisticsEndpointGetResourceUsageFailed)
TestContainerizer containerizer(&exec);
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
- EXPECT_CALL(slave, usage())
+ EXPECT_CALL(*slave.get()->mock(), usage())
.WillOnce(Return(Failure("Resource Collection Failure")));
- spawn(slave);
+ slave.get()->start();
Future<Response> response = process::http::get(
- slave.self(),
+ slave.get()->pid,
"monitor/statistics",
None(),
createBasicAuthHeaders(DEFAULT_CREDENTIAL));
AWAIT_READY(response);
AWAIT_EXPECT_RESPONSE_STATUS_EQ(InternalServerError().status, response);
-
- terminate(slave);
- wait(slave);
}
@@ -4010,8 +4048,16 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
MockScheduler sched;
MesosSchedulerDriver driver(
@@ -4049,8 +4095,8 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
EXPECT_CALL(sched, statusUpdate(&driver, _))
.WillRepeatedly(FutureArg<1>(&status));
- EXPECT_CALL(slave, runTask(_, _, _, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_runTask));
+ EXPECT_CALL(*slave.get()->mock(), runTask(_, _, _, _, _))
+ .WillOnce(Invoke(slave.get()->mock(), &MockSlave::unmocked_runTask));
// Saved arguments from Slave::_run().
Future<list<bool>> unschedules;
@@ -4062,7 +4108,7 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
// later, tie reaching the critical moment when to kill the task to
// a future.
Future<Nothing> _run;
- EXPECT_CALL(slave, _run(_, _, _, _, _))
+ EXPECT_CALL(*slave.get()->mock(), _run(_, _, _, _, _))
.WillOnce(DoAll(FutureSatisfy(&_run),
SaveArg<0>(&unschedules),
SaveArg<1>(&frameworkInfo),
@@ -4075,13 +4121,15 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
AWAIT_READY(_run);
Future<Nothing> killTask;
- EXPECT_CALL(slave, killTask(_, _))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
+ EXPECT_CALL(*slave.get()->mock(), killTask(_, _))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_killTask),
FutureSatisfy(&killTask)));
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
driver.killTask(task.task_id());
@@ -4092,7 +4140,7 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
// since there remain no more tasks.
AWAIT_READY(removeFramework);
- slave.unmocked__run(
+ slave.get()->mock()->unmocked__run(
unschedules, frameworkInfo, executorInfo, task_, taskGroup);
AWAIT_READY(status);
@@ -4100,9 +4148,6 @@ TEST_F(SlaveTest, KillTaskBetweenRunTaskParts)
driver.stop();
driver.join();
-
- terminate(slave);
- wait(slave);
}
@@ -4119,8 +4164,16 @@ TEST_F(SlaveTest, KillMultiplePendingTasks)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
MockScheduler sched;
MesosSchedulerDriver driver(
@@ -4160,9 +4213,9 @@ TEST_F(SlaveTest, KillMultiplePendingTasks)
.WillOnce(FutureArg<1>(&status1))
.WillOnce(FutureArg<1>(&status2));
- EXPECT_CALL(slave, runTask(_, _, _, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_runTask))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_runTask));
+ EXPECT_CALL(*slave.get()->mock(), runTask(_, _, _, _, _))
+ .WillOnce(Invoke(slave.get()->mock(), &MockSlave::unmocked_runTask))
+ .WillOnce(Invoke(slave.get()->mock(), &MockSlave::unmocked_runTask));
// Skip what Slave::_run() normally does, save its arguments for
// later, tie reaching the critical moment when to kill the task to
@@ -4174,7 +4227,7 @@ TEST_F(SlaveTest, KillMultiplePendingTasks)
Option<TaskInfo> task_1, task_2;
Future<Nothing> _run1, _run2;
- EXPECT_CALL(slave, _run(_, _, _, _, _))
+ EXPECT_CALL(*slave.get()->mock(), _run(_, _, _, _, _))
.WillOnce(DoAll(FutureSatisfy(&_run1),
SaveArg<0>(&unschedules1),
SaveArg<1>(&frameworkInfo1),
@@ -4193,15 +4246,18 @@ TEST_F(SlaveTest, KillMultiplePendingTasks)
AWAIT_READY(process::await(_run1, _run2));
Future<Nothing> killTask1, killTask2;
- EXPECT_CALL(slave, killTask(_, _))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
+ EXPECT_CALL(*slave.get()->mock(), killTask(_, _))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_killTask),
FutureSatisfy(&killTask1)))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_killTask),
FutureSatisfy(&killTask2)));
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
driver.killTask(task1.task_id());
@@ -4219,19 +4275,16 @@ TEST_F(SlaveTest, KillMultiplePendingTasks)
AWAIT_READY(removeFramework);
// The `__run` continuations should have no effect.
- slave.unmocked__run(
+ slave.get()->mock()->unmocked__run(
unschedules1, frameworkInfo1, executorInfo1, task_1, taskGroup1);
- slave.unmocked__run(
+ slave.get()->mock()->unmocked__run(
unschedules2, frameworkInfo2, executorInfo2, task_2, taskGroup2);
Clock::settle();
driver.stop();
driver.join();
-
- terminate(slave);
- wait(slave);
}
@@ -4591,8 +4644,16 @@ TEST_F(SlaveTest, ContainerizerUsageFailure)
TestContainerizer containerizer(&exec);
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
MockScheduler sched;
MesosSchedulerDriver driver(
@@ -4638,7 +4699,7 @@ TEST_F(SlaveTest, ContainerizerUsageFailure)
// We expect that the slave will still returns ResourceUsage but no
// statistics will be found.
- Future<ResourceUsage> usage = slave.usage();
+ Future<ResourceUsage> usage = slave.get()->mock()->usage();
AWAIT_READY(usage);
ASSERT_EQ(1, usage->executors_size());
@@ -4649,9 +4710,6 @@ TEST_F(SlaveTest, ContainerizerUsageFailure)
driver.stop();
driver.join();
-
- terminate(slave);
- wait(slave);
}
@@ -5251,8 +5309,16 @@ TEST_F(SlaveTest, TotalSlaveResourcesIncludedInUsage)
slave::Flags flags = CreateSlaveFlags();
flags.resources = "cpus:2;gpus:0;mem:1024;disk:1024;ports:[31000-32000]";
- MockSlave slave(flags, &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ flags,
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
Clock::pause();
@@ -5261,16 +5327,13 @@ TEST_F(SlaveTest, TotalSlaveResourcesIncludedInUsage)
// We expect that the slave will return ResourceUsage with
// total resources reported.
- Future<ResourceUsage> usage = slave.usage();
+ Future<ResourceUsage> usage = slave.get()->mock()->usage();
AWAIT_READY(usage);
// Total resources should match the resources from flag.resources.
EXPECT_EQ(Resources(usage->total()),
Resources::parse(flags.resources.get()).get());
-
- terminate(slave);
- wait(slave);
}
@@ -5288,8 +5351,16 @@ TEST_F(SlaveTest, CheckpointedResourcesIncludedInUsage)
flags.resources = "cpus:2;cpus(role1):3;mem:1024;disk:1024;disk(role1):64;"
"ports:[31000-32000]";
- MockSlave slave(flags, &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ flags,
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
Clock::pause();
@@ -5309,11 +5380,11 @@ TEST_F(SlaveTest, CheckpointedResourcesIncludedInUsage)
{dynamicReservation, persistentVolume};
// Add checkpointed resources.
- slave.checkpointResources(checkpointedResources, true);
+ slave.get()->mock()->checkpointResources(checkpointedResources, true);
// We expect that the slave will return ResourceUsage with
// total and checkpointed slave resources reported.
- Future<ResourceUsage> usage = slave.usage();
+ Future<ResourceUsage> usage = slave.get()->mock()->usage();
AWAIT_READY(usage);
@@ -5323,9 +5394,6 @@ TEST_F(SlaveTest, CheckpointedResourcesIncludedInUsage)
// reservations.
EXPECT_EQ(usageTotalResources.persistentVolumes(), persistentVolume);
EXPECT_TRUE(usageTotalResources.contains(dynamicReservation));
-
- terminate(slave);
- wait(slave);
}
@@ -5951,14 +6019,18 @@ TEST_F(SlaveTest, RunTaskGroupFailedSecretGeneration)
// This pointer is passed to the agent, which will perform the cleanup.
Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
- MockSlave slave(
- CreateSlaveFlags(),
+ Try<Owned<cluster::Slave>> slave = StartSlave(
&detector,
&containerizer,
+ secretGenerator.get(),
None(),
- secretGenerator.get());
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
- spawn(slave);
+ slave.get()->start();
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -6035,8 +6107,9 @@ TEST_F(SlaveTest, RunTaskGroupFailedSecretGeneration)
EXPECT_CALL(*executor, launch(_, _))
.Times(0);
- EXPECT_CALL(slave, executorTerminated(_, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_executorTerminated));
+ EXPECT_CALL(*slave.get()->mock(), executorTerminated(_, _, _))
+ .WillOnce(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_executorTerminated));
Future<v1::scheduler::Event::Update> update1;
Future<v1::scheduler::Event::Update> update2;
@@ -6087,8 +6160,9 @@ TEST_F(SlaveTest, RunTaskGroupFailedSecretGeneration)
// Since this is the only task group for this framework, the
// framework should be removed after secret generation fails.
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
// Acknowledge the status updates so that the agent will remove the framework.
@@ -6120,9 +6194,6 @@ TEST_F(SlaveTest, RunTaskGroupFailedSecretGeneration)
}
AWAIT_READY(removeFramework);
-
- terminate(slave);
- wait(slave);
}
@@ -6151,14 +6222,18 @@ TEST_F(SlaveTest, RunTaskGroupInvalidExecutorSecret)
Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
- MockSlave slave(
- CreateSlaveFlags(),
+ Try<Owned<cluster::Slave>> slave = StartSlave(
&detector,
&containerizer,
+ secretGenerator.get(),
+ None(),
None(),
- secretGenerator.get());
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
- spawn(slave);
+ slave.get()->start();
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -6240,8 +6315,9 @@ TEST_F(SlaveTest, RunTaskGroupInvalidExecutorSecret)
EXPECT_CALL(*executor, launch(_, _))
.Times(0);
- EXPECT_CALL(slave, executorTerminated(_, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_executorTerminated));
+ EXPECT_CALL(*slave.get()->mock(), executorTerminated(_, _, _))
+ .WillOnce(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_executorTerminated));
Future<v1::scheduler::Event::Update> update1;
Future<v1::scheduler::Event::Update> update2;
@@ -6295,8 +6371,9 @@ TEST_F(SlaveTest, RunTaskGroupInvalidExecutorSecret)
// Since this is the only task group for this framework, the
// framework should be removed after secret generation fails.
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
// Acknowledge the status updates so that the agent will remove the framework.
@@ -6328,9 +6405,6 @@ TEST_F(SlaveTest, RunTaskGroupInvalidExecutorSecret)
}
AWAIT_READY(removeFramework);
-
- terminate(slave);
- wait(slave);
}
@@ -6360,14 +6434,18 @@ TEST_F(SlaveTest, RunTaskGroupReferenceTypeSecret)
Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
- MockSlave slave(
- CreateSlaveFlags(),
+ Try<Owned<cluster::Slave>> slave = StartSlave(
&detector,
&containerizer,
+ secretGenerator.get(),
+ None(),
None(),
- secretGenerator.get());
+ true);
- spawn(slave);
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -6449,8 +6527,9 @@ TEST_F(SlaveTest, RunTaskGroupReferenceTypeSecret)
EXPECT_CALL(*executor, launch(_, _))
.Times(0);
- EXPECT_CALL(slave, executorTerminated(_, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_executorTerminated));
+ EXPECT_CALL(*slave.get()->mock(), executorTerminated(_, _, _))
+ .WillOnce(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_executorTerminated));
Future<v1::scheduler::Event::Update> update1;
Future<v1::scheduler::Event::Update> update2;
@@ -6504,8 +6583,9 @@ TEST_F(SlaveTest, RunTaskGroupReferenceTypeSecret)
// Since this is the only task group for this framework, the
// framework should be removed after secret generation fails.
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
// Acknowledge the status updates so that the agent will remove the framework.
@@ -6537,9 +6617,6 @@ TEST_F(SlaveTest, RunTaskGroupReferenceTypeSecret)
}
AWAIT_READY(removeFramework);
-
- terminate(slave);
- wait(slave);
}
@@ -6569,14 +6646,18 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
- MockSlave slave(
- CreateSlaveFlags(),
+ Try<Owned<cluster::Slave>> slave = StartSlave(
&detector,
&containerizer,
+ secretGenerator.get(),
+ None(),
None(),
- secretGenerator.get());
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
- spawn(slave);
+ slave.get()->start();
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -6679,8 +6760,9 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
AWAIT_READY(generate);
Future<Nothing> shutdownExecutor;
- EXPECT_CALL(slave, shutdownExecutor(_, _, _))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_shutdownExecutor),
+ EXPECT_CALL(*slave.get()->mock(), shutdownExecutor(_, _, _))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_shutdownExecutor),
FutureSatisfy(&shutdownExecutor)));
{
@@ -6707,8 +6789,9 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
EXPECT_CALL(*scheduler, failure(_, _))
.WillOnce(FutureSatisfy(&failure));
- EXPECT_CALL(slave, executorTerminated(_, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_executorTerminated));
+ EXPECT_CALL(*slave.get()->mock(), executorTerminated(_, _, _))
+ .WillOnce(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_executorTerminated));
// The tasks will fail to launch because the executor has been shutdown.
Secret authenticationToken;
@@ -6737,8 +6820,9 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
// Since this is the only task group for this framework, the
// framework should be removed after secret generation fails.
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
// Acknowledge the status updates so that the agent will remove the framework.
@@ -6770,9 +6854,6 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
}
AWAIT_READY(removeFramework);
-
- terminate(slave);
- wait(slave);
}
@@ -6987,8 +7068,16 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
StandaloneMasterDetector detector(master.get()->pid);
- MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
- spawn(slave);
+ Try<Owned<cluster::Slave>> slave = StartSlave(
+ &detector,
+ &containerizer,
+ None(),
+ true);
+
+ ASSERT_SOME(slave);
+ ASSERT_NE(nullptr, slave.get()->mock());
+
+ slave.get()->start();
Future<Nothing> connected;
EXPECT_CALL(*scheduler, connected(_))
@@ -7055,8 +7144,9 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
.WillOnce(FutureArg<1>(&update2))
.WillRepeatedly(Return());
- EXPECT_CALL(slave, runTaskGroup(_, _, _, _))
- .WillOnce(Invoke(&slave, &MockSlave::unmocked_runTaskGroup));
+ EXPECT_CALL(*slave.get()->mock(), runTaskGroup(_, _, _, _))
+ .WillOnce(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_runTaskGroup));
// Saved arguments from `Slave::_run()`.
Future<list<bool>> unschedules;
@@ -7069,7 +7159,7 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
// later, till reaching the critical moment when to kill the task
// in the future.
Future<Nothing> _run;
- EXPECT_CALL(slave, _run(_, _, _, _, _))
+ EXPECT_CALL(*slave.get()->mock(), _run(_, _, _, _, _))
.WillOnce(DoAll(FutureSatisfy(&_run),
SaveArg<0>(&unschedules),
SaveArg<1>(&frameworkInfo),
@@ -7115,15 +7205,17 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
AWAIT_READY(_run);
Future<Nothing> killTask;
- EXPECT_CALL(slave, killTask(_, _))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
+ EXPECT_CALL(*slave.get()->mock(), killTask(_, _))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_killTask),
FutureSatisfy(&killTask)));
// Since this is the only task group for this framework, the
// framework should get removed when the task is killed.
Future<Nothing> removeFramework;
- EXPECT_CALL(slave, removeFramework(_))
- .WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
+ EXPECT_CALL(*slave.get()->mock(), removeFramework(_))
+ .WillOnce(DoAll(Invoke(slave.get()->mock(),
+ &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
mesos.send(
@@ -7133,7 +7225,7 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
AWAIT_READY(removeFramework);
- slave.unmocked__run(
+ slave.get()->mock()->unmocked__run(
unschedules, frameworkInfo, executorInfo_, task_, taskGroup_);
AWAIT_READY(update1);
@@ -7145,9 +7237,6 @@ TEST_F(SlaveTest, KillTaskGroupBetweenRunTaskParts)
EXPECT_EQ(TASK_KILLED, update1->status().state());
EXPECT_EQ(TASK_KILLED, update2->status().state());
EXPECT_EQ(tasks, killedTasks);
-
- terminate(slave);
- wait(slave);
}
[6/9] mesos git commit: Moved the logic of setting '/' as rslave into
the launch helper.
Posted by ji...@apache.org.
Moved the logic of setting '/' as rslave into the launch helper.
This patch prepares for the mount propagation support. In the future,
we can no longer set the root mount as rslave bindly because some
mounts need to be shared. Move this logic to the launch helper is a
necessary step. We will add more logic there to selectively mark some
mount as shared, and the rest as slave.
Review: https://reviews.apache.org/r/63211
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e9ba0a19
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e9ba0a19
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e9ba0a19
Branch: refs/heads/master
Commit: e9ba0a191c7f6b35795f2651443e199299b124b2
Parents: a68a61e
Author: Jie Yu <yu...@gmail.com>
Authored: Sat Oct 21 15:02:11 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:45:43 2017 -0800
----------------------------------------------------------------------
.../mesos/isolators/filesystem/linux.cpp | 12 +----
src/slave/containerizer/mesos/launch.cpp | 46 ++++++++++++++++++++
2 files changed, 47 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e9ba0a19/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
index d97f427..f40ded7 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
@@ -350,16 +350,6 @@ Future<Option<ContainerLaunchInfo>> LinuxFilesystemIsolatorProcess::prepare(
ContainerLaunchInfo launchInfo;
launchInfo.add_clone_namespaces(CLONE_NEWNS);
- // Prepare the mounts that will be run in the container's mount
- // namespace right after forking the executor process so that they
- // don't pollute the host mount namespace.
-
- // Make sure mounts in the container mount namespace do not
- // propagate back to the host mount namespace.
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_target("/");
- mount->set_flags(MS_SLAVE | MS_REC);
-
// Bind mount the sandbox if the container specifies a rootfs.
if (containerConfig.has_rootfs()) {
string sandbox = path::join(
@@ -376,7 +366,7 @@ Future<Option<ContainerLaunchInfo>> LinuxFilesystemIsolatorProcess::prepare(
sandbox + "': " + mkdir.error());
}
- mount = launchInfo.add_mounts();
+ ContainerMountInfo* mount = launchInfo.add_mounts();
mount->set_source(containerConfig.directory());
mount->set_target(sandbox);
mount->set_flags(MS_BIND | MS_REC);
http://git-wip-us.apache.org/repos/asf/mesos/blob/e9ba0a19/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 9e96b2e..0c4bc33 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -21,6 +21,7 @@
#endif // __linux__
#include <string.h>
+#include <algorithm>
#include <iostream>
#include <set>
#include <string>
@@ -240,6 +241,39 @@ static void exitWithStatus(int status)
static Try<Nothing> prepareMounts(const ContainerLaunchInfo& launchInfo)
{
#ifdef __linux__
+ bool cloneMountNamespace = std::find(
+ launchInfo.clone_namespaces().begin(),
+ launchInfo.clone_namespaces().end(),
+ CLONE_NEWNS) != launchInfo.clone_namespaces().end();
+
+ if (!cloneMountNamespace) {
+ // Mounts are not supported if the mount namespace is not cloned.
+ // Otherwise, we'll pollute the parent mount namespace.
+ return Nothing();
+ }
+
+ // If there is no shared mount (i.e., "bidirectional" propagation),
+ // mark the root as recursively slave propagation (i.e.,
+ // --make-rslave) so that mounts do not leak to parent mount
+ // namespace.
+ bool hasSharedMount = std::find_if(
+ launchInfo.mounts().begin(),
+ launchInfo.mounts().end(),
+ [](const ContainerMountInfo& mount) {
+ return (mount.flags() & MS_SHARED) != 0;
+ }) != launchInfo.mounts().end();
+
+ if (!hasSharedMount) {
+ Try<Nothing> mnt =
+ fs::mount(None(), "/", None(), MS_SLAVE | MS_REC, None());
+
+ if (mnt.isError()) {
+ return Error("Failed to mark '/' as rslave: " + mnt.error());
+ }
+
+ cout << "Marked '/' as rslave" << endl;
+ }
+
foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
Try<Nothing> mnt = fs::mount(
(mount.has_source() ? Option<string>(mount.source()) : None()),
@@ -577,6 +611,12 @@ int MesosContainerizerLaunch::execute()
#ifdef __linux__
if (flags.namespace_mnt_target.isSome()) {
+ if (!launchInfo.mounts().empty()) {
+ cerr << "Mounts are not supported if "
+ << "'namespace_mnt_target' is set" << endl;
+ exitWithStatus(EXIT_FAILURE);
+ }
+
string path = path::join(
"/proc",
stringify(flags.namespace_mnt_target.get()),
@@ -592,6 +632,12 @@ int MesosContainerizerLaunch::execute()
}
if (flags.unshare_namespace_mnt) {
+ if (!launchInfo.mounts().empty()) {
+ cerr << "Mounts are not supported if "
+ << "'unshare_namespace_mnt' is set" << endl;
+ exitWithStatus(EXIT_FAILURE);
+ }
+
if (unshare(CLONE_NEWNS) != 0) {
cerr << "Failed to unshare mount namespace: "
<< os::strerror(errno) << endl;
[2/9] mesos git commit: Allowed the injection of secret generator
into the Slave.
Posted by ji...@apache.org.
Allowed the injection of secret generator into the Slave.
Review: https://reviews.apache.org/r/64132
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e1207f9d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e1207f9d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e1207f9d
Branch: refs/heads/master
Commit: e1207f9dc01832844b0166447f48fb256791203b
Parents: 20634c9
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Nov 28 12:31:38 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:41:56 2017 -0800
----------------------------------------------------------------------
src/local/local.cpp | 55 ++++++++++++++++++++++++++++
src/slave/main.cpp | 41 +++++++++++++++++++++
src/slave/slave.cpp | 17 ++-------
src/slave/slave.hpp | 7 ++--
src/tests/cluster.cpp | 43 ++++++++++++++++++++++
src/tests/cluster.hpp | 4 ++
src/tests/mesos.cpp | 23 ++++++++++++
src/tests/mesos.hpp | 9 +++++
src/tests/mock_slave.cpp | 20 ++--------
src/tests/mock_slave.hpp | 10 +----
src/tests/slave_authorization_tests.cpp | 15 +++-----
src/tests/slave_tests.cpp | 45 ++++++++++-------------
12 files changed, 212 insertions(+), 77 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/local/local.cpp
----------------------------------------------------------------------
diff --git a/src/local/local.cpp b/src/local/local.cpp
index 2e141c6..ba1bcf2 100644
--- a/src/local/local.cpp
+++ b/src/local/local.cpp
@@ -21,6 +21,8 @@
#include <string>
#include <vector>
+#include <mesos/authentication/secret_generator.hpp>
+
#include <mesos/authorizer/authorizer.hpp>
#include <mesos/allocator/allocator.hpp>
@@ -54,6 +56,10 @@
#include <stout/try.hpp>
#include <stout/strings.hpp>
+#ifdef USE_SSL_SOCKET
+#include "authentication/executor/jwt_secret_generator.hpp"
+#endif // USE_SSL_SOCKET
+
#include "common/protobuf_utils.hpp"
#include "local.hpp"
@@ -83,12 +89,20 @@
using namespace mesos::internal;
#ifndef __WINDOWS__
using namespace mesos::internal::log;
+#endif // __WINDOWS__
+using mesos::SecretGenerator;
+
+#ifndef __WINDOWS__
using mesos::log::Log;
#endif // __WINDOWS__
using mesos::allocator::Allocator;
+#ifdef USE_SSL_SOCKET
+using mesos::authentication::executor::JWTSecretGenerator;
+#endif // USE_SSL_SOCKET
+
using mesos::master::contender::MasterContender;
using mesos::master::contender::StandaloneMasterContender;
@@ -147,6 +161,7 @@ static vector<TaskStatusUpdateManager*>* taskStatusUpdateManagers = nullptr;
static vector<Fetcher*>* fetchers = nullptr;
static vector<ResourceEstimator*>* resourceEstimators = nullptr;
static vector<QoSController*>* qosControllers = nullptr;
+static vector<SecretGenerator*>* secretGenerators = nullptr;
PID<Master> launch(const Flags& flags, Allocator* _allocator)
@@ -355,6 +370,7 @@ PID<Master> launch(const Flags& flags, Allocator* _allocator)
fetchers = new vector<Fetcher*>();
resourceEstimators = new vector<ResourceEstimator*>();
qosControllers = new vector<QoSController*>();
+ secretGenerators = new vector<SecretGenerator*>();
vector<UPID> pids;
@@ -432,6 +448,37 @@ PID<Master> launch(const Flags& flags, Allocator* _allocator)
qosControllers->push_back(qosController.get());
+ SecretGenerator* secretGenerator = nullptr;
+
+#ifdef USE_SSL_SOCKET
+ if (slaveFlags.jwt_secret_key.isSome()) {
+ Try<string> jwtSecretKey = os::read(slaveFlags.jwt_secret_key.get());
+ if (jwtSecretKey.isError()) {
+ EXIT(EXIT_FAILURE) << "Failed to read the file specified by "
+ << "--jwt_secret_key";
+ }
+
+ // TODO(greggomann): Factor the following code out into a common helper,
+ // since we also do this when loading credentials.
+ Try<os::Permissions> permissions =
+ os::permissions(slaveFlags.jwt_secret_key.get());
+ if (permissions.isError()) {
+ LOG(WARNING) << "Failed to stat jwt secret key file '"
+ << slaveFlags.jwt_secret_key.get()
+ << "': " << permissions.error();
+ } else if (permissions.get().others.rwx) {
+ LOG(WARNING) << "Permissions on executor secret key file '"
+ << slaveFlags.jwt_secret_key.get()
+ << "' are too open; it is recommended that your"
+ << " key file is NOT accessible by others";
+ }
+
+ secretGenerator = new JWTSecretGenerator(jwtSecretKey.get());
+ }
+#endif // USE_SSL_SOCKET
+
+ secretGenerators->push_back(secretGenerator);
+
// Override the default launcher that gets created per agent to
// 'posix' if we're creating multiple agents because the
// LinuxLauncher does not support multiple agents on the same host
@@ -476,6 +523,7 @@ PID<Master> launch(const Flags& flags, Allocator* _allocator)
taskStatusUpdateManagers->back(),
resourceEstimators->back(),
qosControllers->back(),
+ secretGenerators->back(),
authorizer_); // Same authorizer as master.
slaves[containerizer.get()] = slave;
@@ -548,6 +596,13 @@ void shutdown()
delete fetchers;
fetchers = nullptr;
+ foreach (SecretGenerator* secretGenerator, *secretGenerators) {
+ delete secretGenerator;
+ }
+
+ delete secretGenerators;
+ secretGenerators = nullptr;
+
foreach (ResourceEstimator* estimator, *resourceEstimators) {
delete estimator;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index f0716fb..ac83d41 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -50,6 +50,10 @@
#include <stout/try.hpp>
#include <stout/version.hpp>
+#ifdef USE_SSL_SOCKET
+#include "authentication/executor/jwt_secret_generator.hpp"
+#endif // USE_SSL_SOCKET
+
#include "common/build.hpp"
#include "common/http.hpp"
@@ -76,6 +80,12 @@
using namespace mesos::internal;
using namespace mesos::internal::slave;
+using mesos::SecretGenerator;
+
+#ifdef USE_SSL_SOCKET
+using mesos::authentication::executor::JWTSecretGenerator;
+#endif // USE_SSL_SOCKET
+
using mesos::master::detector::MasterDetector;
using mesos::modules::Anonymous;
@@ -552,6 +562,34 @@ int main(int argc, char** argv)
<< qosController.error();
}
+ SecretGenerator* secretGenerator = nullptr;
+#ifdef USE_SSL_SOCKET
+ if (flags.jwt_secret_key.isSome()) {
+ Try<string> jwtSecretKey = os::read(flags.jwt_secret_key.get());
+ if (jwtSecretKey.isError()) {
+ EXIT(EXIT_FAILURE) << "Failed to read the file specified by "
+ << "--jwt_secret_key";
+ }
+
+ // TODO(greggomann): Factor the following code out into a common helper,
+ // since we also do this when loading credentials.
+ Try<os::Permissions> permissions =
+ os::permissions(flags.jwt_secret_key.get());
+ if (permissions.isError()) {
+ LOG(WARNING) << "Failed to stat jwt secret key file '"
+ << flags.jwt_secret_key.get()
+ << "': " << permissions.error();
+ } else if (permissions.get().others.rwx) {
+ LOG(WARNING) << "Permissions on executor secret key file '"
+ << flags.jwt_secret_key.get()
+ << "' are too open; it is recommended that your"
+ << " key file is NOT accessible by others";
+ }
+
+ secretGenerator = new JWTSecretGenerator(jwtSecretKey.get());
+ }
+#endif // USE_SSL_SOCKET
+
Slave* slave = new Slave(
id,
flags,
@@ -562,6 +600,7 @@ int main(int argc, char** argv)
taskStatusUpdateManager,
resourceEstimator.get(),
qosController.get(),
+ secretGenerator,
authorizer_);
process::spawn(slave);
@@ -569,6 +608,8 @@ int main(int argc, char** argv)
delete slave;
+ delete secretGenerator;
+
delete qosController.get();
delete resourceEstimator.get();
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index acee0b8..e156683 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -72,10 +72,6 @@
#include "authentication/cram_md5/authenticatee.hpp"
-#ifdef USE_SSL_SOCKET
-#include "authentication/executor/jwt_secret_generator.hpp"
-#endif // USE_SSL_SOCKET
-
#include "common/build.hpp"
#include "common/protobuf_utils.hpp"
#include "common/resources_utils.hpp"
@@ -116,10 +112,6 @@ using google::protobuf::RepeatedPtrField;
using mesos::SecretGenerator;
-#ifdef USE_SSL_SOCKET
-using mesos::authentication::executor::JWTSecretGenerator;
-#endif // USE_SSL_SOCKET
-
using mesos::authorization::createSubject;
using mesos::executor::Call;
@@ -193,6 +185,7 @@ Slave::Slave(const string& id,
TaskStatusUpdateManager* _taskStatusUpdateManager,
ResourceEstimator* _resourceEstimator,
QoSController* _qosController,
+ SecretGenerator* _secretGenerator,
const Option<Authorizer*>& _authorizer)
: ProcessBase(id),
state(RECOVERING),
@@ -222,9 +215,9 @@ Slave::Slave(const string& id,
executorDirectoryMaxAllowedAge(age(0)),
resourceEstimator(_resourceEstimator),
qosController(_qosController),
+ secretGenerator(_secretGenerator),
authorizer(_authorizer),
- resourceVersions({{Option<ResourceProviderID>::none(), UUID::random()}}),
- secretGenerator(nullptr) {}
+ resourceVersions({{Option<ResourceProviderID>::none(), UUID::random()}}) {}
Slave::~Slave()
@@ -239,8 +232,6 @@ Slave::~Slave()
}
delete authenticatee;
-
- delete secretGenerator;
}
@@ -329,7 +320,6 @@ void Slave::initialize()
#ifdef USE_SSL_SOCKET
if (flags.jwt_secret_key.isSome()) {
Try<string> jwtSecretKey_ = os::read(flags.jwt_secret_key.get());
-
if (jwtSecretKey_.isError()) {
EXIT(EXIT_FAILURE) << "Failed to read the file specified by "
<< "--jwt_secret_key";
@@ -351,7 +341,6 @@ void Slave::initialize()
}
jwtSecretKey = jwtSecretKey_.get();
- secretGenerator = new JWTSecretGenerator(jwtSecretKey.get());
}
if (flags.authenticate_http_executors) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index d538a8b..643d855 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -122,6 +122,7 @@ public:
TaskStatusUpdateManager* taskStatusUpdateManager,
mesos::slave::ResourceEstimator* resourceEstimator,
mesos::slave::QoSController* qosController,
+ mesos::SecretGenerator* secretGenerator,
const Option<Authorizer*>& authorizer);
virtual ~Slave();
@@ -676,6 +677,8 @@ private:
mesos::slave::QoSController* qosController;
+ mesos::SecretGenerator* secretGenerator;
+
const Option<Authorizer*> authorizer;
// The most recent estimate of the total amount of oversubscribed
@@ -689,10 +692,6 @@ private:
// Pending operations or terminal operations that have
// unacknowledged status updates.
hashmap<UUID, OfferOperation*> offerOperations;
-
-protected:
- // Made protected for testing purposes.
- mesos::SecretGenerator* secretGenerator;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/cluster.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.cpp b/src/tests/cluster.cpp
index b854904..ae145fd 100644
--- a/src/tests/cluster.cpp
+++ b/src/tests/cluster.cpp
@@ -62,6 +62,10 @@
#include "linux/cgroups.hpp"
#endif
+#ifdef USE_SSL_SOCKET
+#include "authentication/executor/jwt_secret_generator.hpp"
+#endif // USE_SSL_SOCKET
+
#include "authorizer/local/authorizer.hpp"
#include "common/http.hpp"
@@ -95,6 +99,10 @@
using std::string;
using std::vector;
+#ifdef USE_SSL_SOCKET
+using mesos::authentication::executor::JWTSecretGenerator;
+#endif // USE_SSL_SOCKET
+
using mesos::master::contender::StandaloneMasterContender;
using mesos::master::contender::ZooKeeperMasterContender;
@@ -399,6 +407,7 @@ Try<process::Owned<Slave>> Slave::start(
const Option<slave::TaskStatusUpdateManager*>& taskStatusUpdateManager,
const Option<mesos::slave::ResourceEstimator*>& resourceEstimator,
const Option<mesos::slave::QoSController*>& qosController,
+ const Option<mesos::SecretGenerator*>& secretGenerator,
const Option<Authorizer*>& providedAuthorizer)
{
process::Owned<Slave> slave(new Slave());
@@ -503,6 +512,39 @@ Try<process::Owned<Slave>> Slave::start(
slave->qosController.reset(_qosController.get());
}
+ // If the QoS controller is not provided, create a default one.
+ if (secretGenerator.isNone()) {
+ SecretGenerator* _secretGenerator = nullptr;
+
+#ifdef USE_SSL_SOCKET
+ if (flags.jwt_secret_key.isSome()) {
+ Try<string> jwtSecretKey = os::read(flags.jwt_secret_key.get());
+ if (jwtSecretKey.isError()) {
+ return Error("Failed to read the file specified by --jwt_secret_key");
+ }
+
+ // TODO(greggomann): Factor the following code out into a common helper,
+ // since we also do this when loading credentials.
+ Try<os::Permissions> permissions =
+ os::permissions(flags.jwt_secret_key.get());
+ if (permissions.isError()) {
+ LOG(WARNING) << "Failed to stat jwt secret key file '"
+ << flags.jwt_secret_key.get()
+ << "': " << permissions.error();
+ } else if (permissions.get().others.rwx) {
+ LOG(WARNING) << "Permissions on executor secret key file '"
+ << flags.jwt_secret_key.get()
+ << "' are too open; it is recommended that your"
+ << " key file is NOT accessible by others";
+ }
+
+ _secretGenerator = new JWTSecretGenerator(jwtSecretKey.get());
+ }
+#endif // USE_SSL_SOCKET
+
+ slave->secretGenerator.reset(_secretGenerator);
+ }
+
// If the task status update manager is not provided, create a default one.
if (taskStatusUpdateManager.isNone()) {
slave->taskStatusUpdateManager.reset(
@@ -520,6 +562,7 @@ Try<process::Owned<Slave>> Slave::start(
taskStatusUpdateManager.getOrElse(slave->taskStatusUpdateManager.get()),
resourceEstimator.getOrElse(slave->resourceEstimator.get()),
qosController.getOrElse(slave->qosController.get()),
+ secretGenerator.getOrElse(slave->secretGenerator.get()),
authorizer));
slave->pid = process::spawn(slave->slave.get());
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/cluster.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cluster.hpp b/src/tests/cluster.hpp
index d572a09..4ed12c7 100644
--- a/src/tests/cluster.hpp
+++ b/src/tests/cluster.hpp
@@ -22,6 +22,8 @@
#include <mesos/mesos.hpp>
+#include <mesos/authentication/secret_generator.hpp>
+
#include <mesos/authorizer/authorizer.hpp>
#include <mesos/log/log.hpp>
@@ -165,6 +167,7 @@ public:
const Option<mesos::slave::ResourceEstimator*>& resourceEstimator =
None(),
const Option<mesos::slave::QoSController*>& qosController = None(),
+ const Option<mesos::SecretGenerator*>& secretGenerator = None(),
const Option<Authorizer*>& authorizer = None());
~Slave();
@@ -221,6 +224,7 @@ private:
process::Owned<slave::GarbageCollector> gc;
process::Owned<mesos::slave::QoSController> qosController;
process::Owned<mesos::slave::ResourceEstimator> resourceEstimator;
+ process::Owned<mesos::SecretGenerator> secretGenerator;
process::Owned<slave::TaskStatusUpdateManager> taskStatusUpdateManager;
// Indicates whether or not authorization callbacks were set when this agent
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 3de04dd..0e68ab7 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -464,6 +464,7 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
None(),
+ None(),
authorizer);
}
@@ -483,6 +484,28 @@ Try<Owned<cluster::Slave>> MesosTest::StartSlave(
None(),
None(),
None(),
+ None(),
+ authorizer);
+}
+
+
+Try<Owned<cluster::Slave>> MesosTest::StartSlave(
+ mesos::master::detector::MasterDetector* detector,
+ slave::Containerizer* containerizer,
+ mesos::SecretGenerator* secretGenerator,
+ const Option<mesos::Authorizer*>& authorizer,
+ const Option<slave::Flags>& flags)
+{
+ return cluster::Slave::start(
+ detector,
+ flags.isNone() ? CreateSlaveFlags() : flags.get(),
+ None(),
+ containerizer,
+ None(),
+ None(),
+ None(),
+ None(),
+ secretGenerator,
authorizer);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 7bd16be..f83b3e0 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -245,6 +245,15 @@ protected:
mesos::Authorizer* authorizer,
const Option<slave::Flags>& flags = None());
+ // Starts a slave with the specified detector, containerizer,
+ // secretGenerator, authorizer and flags.
+ virtual Try<process::Owned<cluster::Slave>> StartSlave(
+ mesos::master::detector::MasterDetector* detector,
+ slave::Containerizer* containerizer,
+ mesos::SecretGenerator* secretGenerator,
+ const Option<mesos::Authorizer*>& authorizer = None(),
+ const Option<slave::Flags>& flags = None());
+
Option<zookeeper::URL> zookeeperUrl;
const std::string defaultAgentResourcesString{
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/mock_slave.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.cpp b/src/tests/mock_slave.cpp
index 90c4369..dd74216 100644
--- a/src/tests/mock_slave.cpp
+++ b/src/tests/mock_slave.cpp
@@ -108,8 +108,8 @@ MockSlave::MockSlave(
MasterDetector* detector,
slave::Containerizer* containerizer,
const Option<mesos::slave::QoSController*>& _qosController,
- const Option<mesos::Authorizer*>& authorizer,
- const Option<mesos::SecretGenerator*>& _mockSecretGenerator)
+ const Option<mesos::SecretGenerator*>& secretGenerator,
+ const Option<mesos::Authorizer*>& authorizer)
: slave::Slave(
process::ID::generate("slave"),
flags,
@@ -120,9 +120,9 @@ MockSlave::MockSlave(
taskStatusUpdateManager = new slave::TaskStatusUpdateManager(flags),
&resourceEstimator,
_qosController.isSome() ? _qosController.get() : &qosController,
+ secretGenerator.isSome() ? secretGenerator.get() : nullptr,
authorizer),
- files(slave::READONLY_HTTP_AUTHENTICATION_REALM),
- mockSecretGenerator(_mockSecretGenerator)
+ files(slave::READONLY_HTTP_AUTHENTICATION_REALM)
{
// Set up default behaviors, calling the original methods.
EXPECT_CALL(*this, runTask(_, _, _, _, _))
@@ -154,18 +154,6 @@ MockSlave::~MockSlave()
}
-void MockSlave::initialize()
-{
- Slave::initialize();
-
- if (mockSecretGenerator.isSome()) {
- delete secretGenerator;
- secretGenerator = mockSecretGenerator.get();
- mockSecretGenerator = None();
- }
-}
-
-
void MockSlave::unmocked_runTask(
const UPID& from,
const FrameworkInfo& frameworkInfo,
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/mock_slave.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mock_slave.hpp b/src/tests/mock_slave.hpp
index 7c4d43a..5ba5da6 100644
--- a/src/tests/mock_slave.hpp
+++ b/src/tests/mock_slave.hpp
@@ -110,13 +110,11 @@ public:
mesos::master::detector::MasterDetector* detector,
slave::Containerizer* containerizer,
const Option<mesos::slave::QoSController*>& qosController = None(),
- const Option<mesos::Authorizer*>& authorizer = None(),
- const Option<mesos::SecretGenerator*>& mockSecretGenerator = None());
+ const Option<mesos::SecretGenerator*>& secretGenerator = None(),
+ const Option<mesos::Authorizer*>& authorizer = None());
virtual ~MockSlave();
- void initialize();
-
MOCK_METHOD5(runTask, void(
const process::UPID& from,
const FrameworkInfo& frameworkInfo,
@@ -217,10 +215,6 @@ private:
MockResourceEstimator resourceEstimator;
MockQoSController qosController;
slave::TaskStatusUpdateManager* taskStatusUpdateManager;
-
- // Set to the base class `secretGenerator` in `initialize()`. After
- // `initialize()` has executed, this will be `None()`.
- Option<mesos::SecretGenerator*> mockSecretGenerator;
};
} // namespace tests {
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/slave_authorization_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_authorization_tests.cpp b/src/tests/slave_authorization_tests.cpp
index acd922b..6362fdf 100644
--- a/src/tests/slave_authorization_tests.cpp
+++ b/src/tests/slave_authorization_tests.cpp
@@ -786,16 +786,16 @@ TEST_F(ExecutorAuthorizationTest, FailedSubscribe)
new TestContainerizer(devolve(executorInfo.executor_id()), executor));
// This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* mockSecretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> mockSecretGenerator(new MockSecretGenerator());
- MockSlave slave(
- flags,
+ Try<Owned<cluster::Slave>> slave = StartSlave(
detector.get(),
containerizer.get(),
- None(),
+ mockSecretGenerator.get(),
authorizer.get(),
- mockSecretGenerator);
- spawn(slave);
+ flags);
+
+ ASSERT_SOME(slave);
auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
@@ -915,9 +915,6 @@ TEST_F(ExecutorAuthorizationTest, FailedSubscribe)
EXPECT_EQ(
error->message(),
"Received unexpected '403 Forbidden' () for SUBSCRIBE");
-
- terminate(slave);
- wait(slave);
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/e1207f9d/src/tests/slave_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_tests.cpp b/src/tests/slave_tests.cpp
index a2274b6..b780fd1 100644
--- a/src/tests/slave_tests.cpp
+++ b/src/tests/slave_tests.cpp
@@ -2047,17 +2047,16 @@ TEST_F(SlaveTest, HTTPExecutorBadAuthentication)
Owned<TestContainerizer> containerizer(
new TestContainerizer(devolve(executorInfo.executor_id()), executor));
- // This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* mockSecretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> mockSecretGenerator(new MockSecretGenerator());
- MockSlave slave(
- CreateSlaveFlags(),
+ Try<Owned<cluster::Slave>> slave = StartSlave(
detector.get(),
containerizer.get(),
- None(),
- None(),
- mockSecretGenerator);
- process::PID<Slave> slavePid = spawn(slave);
+ mockSecretGenerator.get());
+
+ ASSERT_SOME(slave);
+
+ process::PID<Slave> slavePid = slave.get()->pid;
auto scheduler = std::make_shared<v1::MockHTTPScheduler>();
@@ -2210,9 +2209,6 @@ TEST_F(SlaveTest, HTTPExecutorBadAuthentication)
response->headers.at("WWW-Authenticate"),
"Invalid JWT: Token signature does not match"));
}
-
- terminate(slave);
- wait(slave);
}
#endif // USE_SSL_SOCKET
@@ -5953,15 +5949,15 @@ TEST_F(SlaveTest, RunTaskGroupFailedSecretGeneration)
StandaloneMasterDetector detector(master.get()->pid);
// This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* secretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
MockSlave slave(
CreateSlaveFlags(),
&detector,
&containerizer,
None(),
- None(),
- secretGenerator);
+ secretGenerator.get());
+
spawn(slave);
Future<Nothing> connected;
@@ -6153,16 +6149,15 @@ TEST_F(SlaveTest, RunTaskGroupInvalidExecutorSecret)
StandaloneMasterDetector detector(master.get()->pid);
- // This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* secretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
MockSlave slave(
CreateSlaveFlags(),
&detector,
&containerizer,
None(),
- None(),
- secretGenerator);
+ secretGenerator.get());
+
spawn(slave);
Future<Nothing> connected;
@@ -6363,16 +6358,15 @@ TEST_F(SlaveTest, RunTaskGroupReferenceTypeSecret)
StandaloneMasterDetector detector(master.get()->pid);
- // This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* secretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
MockSlave slave(
CreateSlaveFlags(),
&detector,
&containerizer,
None(),
- None(),
- secretGenerator);
+ secretGenerator.get());
+
spawn(slave);
Future<Nothing> connected;
@@ -6573,16 +6567,15 @@ TEST_F(SlaveTest, RunTaskGroupGenerateSecretAfterShutdown)
StandaloneMasterDetector detector(master.get()->pid);
- // This pointer is passed to the agent, which will perform the cleanup.
- MockSecretGenerator* secretGenerator = new MockSecretGenerator();
+ Owned<MockSecretGenerator> secretGenerator(new MockSecretGenerator());
MockSlave slave(
CreateSlaveFlags(),
&detector,
&containerizer,
None(),
- None(),
- secretGenerator);
+ secretGenerator.get());
+
spawn(slave);
Future<Nothing> connected;
[5/9] mesos git commit: Added ContainerMountInfo to avoid
pre_exec_commands for mounts.
Posted by ji...@apache.org.
Added ContainerMountInfo to avoid pre_exec_commands for mounts.
Added ContainerMountInfo protobuf in ContainerLaunchInfo. It is used
by isolators and MesosContainerizer to describe mounts. Previously,
the additional mounts for each container is specified using
'pre_exec_commands', which is not very flexible and slow (requires a
fork/exec for each mount).
Review: https://reviews.apache.org/r/63200
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/93ecd696
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/93ecd696
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/93ecd696
Branch: refs/heads/master
Commit: 93ecd69655f06ce2420a499d9f9050cc7592d1c3
Parents: c7304a1
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Sep 4 08:30:07 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:45:38 2017 -0800
----------------------------------------------------------------------
include/mesos/slave/containerizer.proto | 28 ++++++
.../mesos/isolators/docker/volume/isolator.cpp | 19 ++---
.../mesos/isolators/filesystem/linux.cpp | 90 +++++---------------
.../mesos/isolators/filesystem/linux.hpp | 4 -
.../mesos/isolators/filesystem/shared.cpp | 9 +-
.../mesos/isolators/gpu/isolator.cpp | 15 +++-
.../mesos/isolators/namespaces/pid.cpp | 14 +--
.../mesos/isolators/volume/host_path.cpp | 17 ++--
.../mesos/isolators/volume/image.cpp | 15 ++--
.../mesos/isolators/volume/sandbox_path.cpp | 23 +++--
src/slave/containerizer/mesos/launch.cpp | 20 +++++
11 files changed, 133 insertions(+), 121 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/include/mesos/slave/containerizer.proto
----------------------------------------------------------------------
diff --git a/include/mesos/slave/containerizer.proto b/include/mesos/slave/containerizer.proto
index 0f1e1da..5b4dcdd 100644
--- a/include/mesos/slave/containerizer.proto
+++ b/include/mesos/slave/containerizer.proto
@@ -167,6 +167,30 @@ message ContainerConfig {
/**
+ * Describes a single mount for the container.
+ */
+message ContainerMountInfo {
+ // The path to the mount point. It must be an absolute path in the
+ // agent's root filesystem.
+ required string target = 1;
+
+ // The source of the mount. This can be the path to a device, a file
+ // or a directory. The path must be an absolute path in the agent's
+ // root filesystem.
+ optional string source = 2;
+
+ // The type of the filesystem to be mounted.
+ optional string type = 3;
+
+ // Mount flags.
+ optional uint32 flags = 4;
+
+ // Mount options of the filesystem to be used.
+ optional string options = 5;
+}
+
+
+/**
* Protobuf returned by Isolator::prepare(). The command is executed
* by the Launcher in the containerized context.
* Note: Currently, any URIs or Environment in the CommandInfo will be
@@ -210,6 +234,10 @@ message ContainerLaunchInfo {
// from the task working directory when task defines an image.
optional string working_directory = 6;
+ // The additional mounts for the container. The mounts specified in
+ // this list will be mounted in order.
+ repeated ContainerMountInfo mounts = 17;
+
// (Linux only) The capabilities requested for the container.
// The capabilities are set while launching the container.
optional CapabilityInfo effective_capabilities = 7;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp b/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
index ed65568..3e85afb 100644
--- a/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
+++ b/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <process/collect.hpp>
#include <process/id.hpp>
@@ -40,6 +42,7 @@ using mesos::internal::slave::docker::volume::DriverClient;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
using mesos::slave::ContainerLimitation;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::ContainerState;
using mesos::slave::Isolator;
@@ -493,18 +496,10 @@ Future<Option<ContainerLaunchInfo>> DockerVolumeIsolatorProcess::_prepare(
LOG(INFO) << "Mounting docker volume mount point '" << source
<< "' to '" << target << "' for container " << containerId;
- // Launch mount command as a non-shell subprocess to avoid
- // injecting arbitrary shell commands (e.g., user defined
- // 'container_path' in volume can be postfixed with any
- // unsafe arbitrary commands).
- CommandInfo* command = launchInfo.add_pre_exec_commands();
- command->set_shell(false);
- command->set_value("mount");
- command->add_arguments("mount");
- command->add_arguments("-n");
- command->add_arguments("--rbind");
- command->add_arguments(source);
- command->add_arguments(target);
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(source);
+ mount->set_target(target);
+ mount->set_flags(MS_BIND | MS_REC);
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
index faf9490..d97f427 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <list>
#include <sstream>
#include <string>
@@ -58,6 +60,7 @@ using mesos::slave::ContainerConfig;
using mesos::slave::ContainerState;
using mesos::slave::ContainerLaunchInfo;
using mesos::slave::ContainerLimitation;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::Isolator;
namespace mesos {
@@ -347,66 +350,15 @@ Future<Option<ContainerLaunchInfo>> LinuxFilesystemIsolatorProcess::prepare(
ContainerLaunchInfo launchInfo;
launchInfo.add_clone_namespaces(CLONE_NEWNS);
- // Prepare the commands that will be run in the container's mount
- // namespace right after forking the executor process. We use these
- // commands to mount those volumes specified in the container info
- // so that they don't pollute the host mount namespace.
- Try<vector<CommandInfo>> commands =
- getPreExecCommands(containerId, containerConfig);
-
- if (commands.isError()) {
- return Failure("Failed to get pre-exec commands: " + commands.error());
- }
-
- foreach (const CommandInfo& command, commands.get()) {
- launchInfo.add_pre_exec_commands()->CopyFrom(command);
- }
-
- // Currently, we only need to update resources for top level containers.
- if (containerId.has_parent()) {
- return launchInfo;
- }
-
- return update(containerId, containerConfig.executor_info().resources())
- .then([launchInfo]() -> Future<Option<ContainerLaunchInfo>> {
- return launchInfo;
- });
-}
-
-
-Try<vector<CommandInfo>> LinuxFilesystemIsolatorProcess::getPreExecCommands(
- const ContainerID& containerId,
- const ContainerConfig& containerConfig)
-{
- vector<CommandInfo> commands;
+ // Prepare the mounts that will be run in the container's mount
+ // namespace right after forking the executor process so that they
+ // don't pollute the host mount namespace.
// Make sure mounts in the container mount namespace do not
// propagate back to the host mount namespace.
- // NOTE: We cannot simply run `mount --make-rslave /`, for more info
- // please refer to comments in mount.hpp.
- CommandInfo command;
- command.set_shell(false);
- command.set_value(path::join(flags.launcher_dir, "mesos-containerizer"));
- command.add_arguments("mesos-containerizer");
- command.add_arguments(MesosContainerizerMount::NAME);
-
- MesosContainerizerMount::Flags mountFlags;
- mountFlags.operation = MesosContainerizerMount::MAKE_RSLAVE;
- mountFlags.path = "/";
-
- foreachvalue (const flags::Flag& flag, mountFlags) {
- const Option<string> value = flag.stringify(mountFlags);
- if (value.isSome()) {
- command.add_arguments(
- "--" + flag.effective_name().value + "=" + value.get());
- }
- }
-
- commands.push_back(command);
-
- if (!containerConfig.has_container_info()) {
- return commands;
- }
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_target("/");
+ mount->set_flags(MS_SLAVE | MS_REC);
// Bind mount the sandbox if the container specifies a rootfs.
if (containerConfig.has_rootfs()) {
@@ -419,24 +371,26 @@ Try<vector<CommandInfo>> LinuxFilesystemIsolatorProcess::getPreExecCommands(
// comments in 'provisioner/backend.hpp' for details.
Try<Nothing> mkdir = os::mkdir(sandbox);
if (mkdir.isError()) {
- return Error(
+ return Failure(
"Failed to create sandbox mount point at '" +
sandbox + "': " + mkdir.error());
}
- CommandInfo command;
- command.set_shell(false);
- command.set_value("mount");
- command.add_arguments("mount");
- command.add_arguments("-n");
- command.add_arguments("--rbind");
- command.add_arguments(containerConfig.directory());
- command.add_arguments(sandbox);
+ mount = launchInfo.add_mounts();
+ mount->set_source(containerConfig.directory());
+ mount->set_target(sandbox);
+ mount->set_flags(MS_BIND | MS_REC);
+ }
- commands.push_back(command);
+ // Currently, we only need to update resources for top level containers.
+ if (containerId.has_parent()) {
+ return launchInfo;
}
- return commands;
+ return update(containerId, containerConfig.executor_info().resources())
+ .then([launchInfo]() -> Future<Option<ContainerLaunchInfo>> {
+ return launchInfo;
+ });
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/filesystem/linux.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/linux.hpp b/src/slave/containerizer/mesos/isolators/filesystem/linux.hpp
index c7fbda5..6584d1e 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/linux.hpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/linux.hpp
@@ -66,10 +66,6 @@ public:
private:
LinuxFilesystemIsolatorProcess(const Flags& flags);
- Try<std::vector<CommandInfo>> getPreExecCommands(
- const ContainerID& containerId,
- const mesos::slave::ContainerConfig& containerConfig);
-
const Flags flags;
struct Info
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp b/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
index ccd3da2..118f398 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <set>
#include <process/id.hpp>
@@ -35,6 +37,7 @@ using std::string;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
using mesos::slave::ContainerLimitation;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::ContainerState;
using mesos::slave::Isolator;
@@ -209,8 +212,10 @@ Future<Option<ContainerLaunchInfo>> SharedFilesystemIsolatorProcess::prepare(
}
}
- launchInfo.add_pre_exec_commands()->set_value(
- "mount -n --bind " + hostPath + " " + volume.container_path());
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(hostPath);
+ mount->set_target(volume.container_path());
+ mount->set_flags(MS_BIND | MS_REC);
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp b/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
index 4d6f640..7b66426 100644
--- a/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
+++ b/src/slave/containerizer/mesos/isolators/gpu/isolator.cpp
@@ -16,6 +16,8 @@
#include <stdint.h>
+#include <sys/mount.h>
+
// This header include must be enclosed in an `extern "C"` block to
// workaround a bug in glibc <= 2.12 (see MESOS-7378).
//
@@ -65,6 +67,7 @@ using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
using mesos::slave::ContainerLimitation;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::ContainerState;
using mesos::slave::Isolator;
@@ -400,9 +403,15 @@ Future<Option<ContainerLaunchInfo>> NvidiaGpuIsolatorProcess::_prepare(
" '" + target + "': " + mkdir.error());
}
- launchInfo.add_pre_exec_commands()->set_value(
- "mount --no-mtab --rbind --read-only " +
- volume.HOST_PATH() + " " + target);
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(volume.HOST_PATH());
+ mount->set_target(target);
+ mount->set_flags(MS_RDONLY | MS_BIND | MS_REC);
+
+ // NOTE: MS_REMOUNT is needed to make a bind mount read only.
+ mount = launchInfo.add_mounts();
+ mount->set_target(target);
+ mount->set_flags(MS_RDONLY | MS_REMOUNT | MS_BIND | MS_REC);
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp b/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
index 42bc2e1..4f8253b 100644
--- a/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
+++ b/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <process/id.hpp>
#include <stout/strings.hpp>
@@ -29,6 +31,7 @@ using process::Owned;
using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::Isolator;
namespace mesos {
@@ -121,17 +124,18 @@ Future<Option<ContainerLaunchInfo>> NamespacesPidIsolatorProcess::prepare(
// Mount /proc with standard options for the container's pid
// namespace to show the container's pids (and other /proc files),
// not the parent's. This technique was taken from unshare.c in
- // utils-linux for --mount-proc. We use the -n flag so the mount is
- // not added to the mtab where it will not be correctly removed when
- // the namespace terminates.
+ // utils-linux for --mount-proc.
//
// NOTE: 'filesystem/linux' isolator will make sure mounts in the
// child mount namespace will not be propagated back to the host
// mount namespace.
//
// TOOD(jieyu): Consider unmount the existing /proc.
- launchInfo.add_pre_exec_commands()->set_value(
- "mount -n -t proc proc /proc -o nosuid,noexec,nodev");
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source("proc");
+ mount->set_target("/proc");
+ mount->set_type("proc");
+ mount->set_flags(MS_NOSUID | MS_NODEV | MS_NOEXEC);
return launchInfo;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
index 949510a..241a7f6 100644
--- a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <glog/logging.h>
#include <process/id.hpp>
@@ -41,6 +43,7 @@ using process::Owned;
using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::Isolator;
namespace mesos {
@@ -241,16 +244,10 @@ Future<Option<ContainerLaunchInfo>> VolumeHostPathIsolatorProcess::prepare(
}
// TODO(jieyu): Consider the mode in the volume.
- CommandInfo command;
- command.set_shell(false);
- command.set_value("mount");
- command.add_arguments("mount");
- command.add_arguments("-n");
- command.add_arguments("--rbind");
- command.add_arguments(hostPath.get());
- command.add_arguments(mountPoint);
-
- launchInfo.add_pre_exec_commands()->CopyFrom(command);
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(hostPath.get());
+ mount->set_target(mountPoint);
+ mount->set_flags(MS_BIND | MS_REC);
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/volume/image.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/volume/image.cpp b/src/slave/containerizer/mesos/isolators/volume/image.cpp
index 35966aa..15e242d 100644
--- a/src/slave/containerizer/mesos/isolators/volume/image.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/image.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <list>
#include <string>
#include <vector>
@@ -49,6 +51,7 @@ using process::Shared;
using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::Isolator;
namespace mesos {
@@ -229,14 +232,10 @@ Future<Option<ContainerLaunchInfo>> VolumeImageIsolatorProcess::_prepare(
"Provisioned rootfs '" + source + "' does not exist");
}
- CommandInfo* command = launchInfo.add_pre_exec_commands();
- command->set_shell(false);
- command->set_value("mount");
- command->add_arguments("mount");
- command->add_arguments("-n");
- command->add_arguments("--rbind");
- command->add_arguments(source);
- command->add_arguments(target);
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(source);
+ mount->set_target(target);
+ mount->set_flags(MS_BIND | MS_REC);
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp b/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
index ee5ea3d..d8e41c4 100644
--- a/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
@@ -14,6 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <sys/mount.h>
+
#include <glog/logging.h>
#include <process/future.hpp>
@@ -33,6 +35,10 @@
#include "common/validation.hpp"
+#ifdef __linux__
+#include "linux/fs.hpp"
+#endif // __linux__
+
#include "slave/containerizer/mesos/isolators/volume/sandbox_path.hpp"
using std::list;
@@ -46,6 +52,7 @@ using process::Owned;
using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerMountInfo;
using mesos::slave::ContainerState;
using mesos::slave::Isolator;
@@ -357,24 +364,22 @@ Future<Option<ContainerLaunchInfo>> VolumeSandboxPathIsolatorProcess::prepare(
}
if (bindMountSupported) {
+#ifdef __linux__
LOG(INFO) << "Mounting SANDBOX_PATH volume from "
<< "'" << source << "' to '" << target << "' "
<< "for container " << containerId;
- CommandInfo* command = launchInfo.add_pre_exec_commands();
- command->set_shell(false);
- command->set_value("mount");
- command->add_arguments("mount");
- command->add_arguments("-n");
- command->add_arguments("--rbind");
- command->add_arguments(source);
- command->add_arguments(target);
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(source);
+ mount->set_target(target);
+ mount->set_flags(MS_BIND | MS_REC);
+#endif // __linux__
} else {
LOG(INFO) << "Linking SANDBOX_PATH volume from "
<< "'" << source << "' to '" << target << "' "
<< "for container " << containerId;
- Try<Nothing> symlink = fs::symlink(source, target);
+ Try<Nothing> symlink = ::fs::symlink(source, target);
if (symlink.isError()) {
return Failure(
"Failed to symlink '" + source + "' -> '" + target + "'"
http://git-wip-us.apache.org/repos/asf/mesos/blob/93ecd696/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index b1584ff..e61c185 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -73,6 +73,7 @@ using mesos::internal::capabilities::ProcessCapabilities;
#endif // __linux__
using mesos::slave::ContainerLaunchInfo;
+using mesos::slave::ContainerMountInfo;
namespace mesos {
namespace internal {
@@ -421,6 +422,25 @@ int MesosContainerizerLaunch::execute()
}
#endif // __WINDOWS__
+#ifdef __linux__
+ foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
+ Try<Nothing> mnt = fs::mount(
+ (mount.has_source() ? Option<string>(mount.source()) : None()),
+ mount.target(),
+ (mount.has_type() ? Option<string>(mount.type()) : None()),
+ (mount.has_flags() ? mount.flags() : 0),
+ (mount.has_options() ? Option<string>(mount.options()) : None()));
+
+ if (mnt.isError()) {
+ cerr << "Failed to prepare mount '" << JSON::protobuf(mount)
+ << "': " << mnt.error() << endl;
+ exitWithStatus(EXIT_FAILURE);
+ }
+
+ cout << "Prepared mount '" << JSON::protobuf(mount) << "'" << endl;
+ }
+#endif // __linux__
+
// Run additional preparation commands. These are run as the same
// user and with the environment as the agent.
foreach (const CommandInfo& command, launchInfo.pre_exec_commands()) {
[7/9] mesos git commit: Added mount propagation support for HOST_PATH
volumes.
Posted by ji...@apache.org.
Added mount propagation support for HOST_PATH volumes.
This allows a container to declare a host path volume such that the
mounts under that volume can be propagated in both directions.
Previously, all volume mounts are default to use host to container
propagation mode.
Review: https://reviews.apache.org/r/63213
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d6d40eca
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d6d40eca
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d6d40eca
Branch: refs/heads/master
Commit: d6d40ecadf13af74f6fc2bfe702fabbf6f70106b
Parents: 38ccb8c
Author: Jie Yu <yu...@gmail.com>
Authored: Sun Oct 22 21:39:38 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:45:43 2017 -0800
----------------------------------------------------------------------
include/mesos/mesos.proto | 26 ++++
include/mesos/v1/mesos.proto | 26 ++++
.../mesos/isolators/volume/host_path.cpp | 76 ++++++++++--
src/slave/containerizer/mesos/launch.cpp | 120 ++++++++++++++++++-
.../volume_host_path_isolator_tests.cpp | 63 ++++++++++
src/tests/mesos.hpp | 10 +-
6 files changed, 308 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index e194093..8c28b81 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -2659,6 +2659,31 @@ message Image {
/**
+ * Describes how the mount will be propagated for a volume. See the
+ * following doc for more details about mount propagation:
+ * https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
+ */
+message MountPropagation {
+ enum Mode {
+ UNKNOWN = 0;
+
+ // The volume in a container will receive new mounts from the host
+ // or other containers, but filesystems mounted inside the
+ // container won't be propagated to the host or other containers.
+ // This is currently the default behavior for all volumes.
+ HOST_TO_CONTAINER = 1;
+
+ // The volume in a container will receive new mounts from the host
+ // or other containers, and its own mounts will be propagated from
+ // the container to the host or other containers.
+ BIDIRECTIONAL = 2;
+ }
+
+ optional Mode mode = 1;
+}
+
+
+/**
* Describes a volume mapping either from host to container or vice
* versa. Both paths can either refer to a directory or a file.
*/
@@ -2718,6 +2743,7 @@ message Volume {
// Absolute path pointing to a directory or file on the host.
message HostPath {
required string path = 1;
+ optional MountPropagation mount_propagation = 2;
}
// Describe a path from a container's sandbox. The container can
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 6fb1139..35bc6e1 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -2640,6 +2640,31 @@ message Image {
/**
+ * Describes how the mount will be propagated for a volume. See the
+ * following doc for more details about mount propagation:
+ * https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
+ */
+message MountPropagation {
+ enum Mode {
+ UNKNOWN = 0;
+
+ // The volume in a container will receive new mounts from the host
+ // or other containers, but filesystems mounted inside the
+ // container won't be propagated to the host or other containers.
+ // This is currently the default behavior for all volumes.
+ HOST_TO_CONTAINER = 1;
+
+ // The volume in a container will receive new mounts from the host
+ // or other containers, and its own mounts will be propagated from
+ // the container to the host or other containers.
+ BIDIRECTIONAL = 2;
+ }
+
+ optional Mode mode = 1;
+}
+
+
+/**
* Describes a volume mapping either from host to container or vice
* versa. Both paths can either refer to a directory or a file.
*/
@@ -2699,6 +2724,7 @@ message Volume {
// Absolute path pointing to a directory or file on the host.
message HostPath {
required string path = 1;
+ optional MountPropagation mount_propagation = 2;
}
// Describe a path from a container's sandbox. The container can
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
index 241a7f6..409fc14 100644
--- a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
@@ -22,6 +22,7 @@
#include <stout/foreach.hpp>
#include <stout/option.hpp>
+#include <stout/os.hpp>
#include <stout/path.hpp>
#include <stout/strings.hpp>
@@ -32,6 +33,8 @@
#include "common/validation.hpp"
+#include "linux/fs.hpp"
+
#include "slave/containerizer/mesos/isolators/volume/host_path.hpp"
using std::string;
@@ -40,6 +43,8 @@ using process::Failure;
using process::Future;
using process::Owned;
+using mesos::MountPropagation;
+
using mesos::slave::ContainerClass;
using mesos::slave::ContainerConfig;
using mesos::slave::ContainerLaunchInfo;
@@ -109,6 +114,7 @@ Future<Option<ContainerLaunchInfo>> VolumeHostPathIsolatorProcess::prepare(
}
Option<string> hostPath;
+ bool mountPropagationBidirectional = false;
// NOTE: This is the legacy way of specifying the Volume. The
// 'host_path' can be relative in legacy mode, representing
@@ -123,13 +129,21 @@ Future<Option<ContainerLaunchInfo>> VolumeHostPathIsolatorProcess::prepare(
volume.source().type() == Volume::Source::HOST_PATH) {
CHECK(volume.source().has_host_path());
- if (!path::absolute(volume.source().host_path().path())) {
+ const Volume::Source::HostPath& hostPathInfo =
+ volume.source().host_path();
+
+ if (!path::absolute(hostPathInfo.path())) {
return Failure(
- "Path '" + volume.source().host_path().path() + "' "
+ "Path '" + hostPathInfo.path() + "' "
"in HOST_PATH volume is not absolute");
}
- hostPath = volume.source().host_path().path();
+ hostPath = hostPathInfo.path();
+
+ mountPropagationBidirectional =
+ hostPathInfo.has_mount_propagation() &&
+ hostPathInfo.mount_propagation().mode() ==
+ MountPropagation::BIDIRECTIONAL;
}
if (hostPath.isNone()) {
@@ -243,11 +257,57 @@ Future<Option<ContainerLaunchInfo>> VolumeHostPathIsolatorProcess::prepare(
}
}
- // TODO(jieyu): Consider the mode in the volume.
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(hostPath.get());
- mount->set_target(mountPoint);
- mount->set_flags(MS_BIND | MS_REC);
+ if (mountPropagationBidirectional) {
+ // First, find the mount entry that is the parent of the host
+ // volume source. If it is not a shared mount, return a failure.
+
+ // Get realpath here because the mount table uses realpaths.
+ Result<string> realHostPath = os::realpath(hostPath.get());
+ if (!realHostPath.isSome()) {
+ return Failure(
+ "Failed to get the realpath of the host path '" +
+ hostPath.get() + "': " +
+ (realHostPath.isError() ? realHostPath.error() : "Not found"));
+ }
+
+ Try<fs::MountInfoTable::Entry> sourceMountEntry =
+ fs::MountInfoTable::findByTarget(realHostPath.get());
+
+ if (sourceMountEntry.isError()) {
+ return Failure(
+ "Cannot find the mount containing host path '" +
+ hostPath.get() + "': " + sourceMountEntry.error());
+ }
+
+ if (sourceMountEntry->shared().isNone()) {
+ return Failure(
+ "Cannot setup bidirectional mount propagation for host path '" +
+ hostPath.get() + "' because it is not under a shared mount");
+ }
+
+ LOG(INFO) << "Mark '" << sourceMountEntry->target
+ << "' as shared for container " << containerId;
+
+ // This tells the launch helper to NOT mark the mount as slave
+ // (otherwise, the propagation won't work).
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_target(sourceMountEntry->target);
+ mount->set_flags(MS_SHARED);
+ }
+
+ // NOTE: 'hostPath' and 'mountPoint' are equal only when the
+ // container does not define its own image and shares the host
+ // filesystem (otherwise, the mount point should be under
+ // container's rootfs, which won't be equal to 'hostPath'). As a
+ // result, no need for the bind mount because the 'hostPath' is
+ // already accessible in the container.
+ if (hostPath.get() != mountPoint) {
+ // TODO(jieyu): Consider the mode in the volume.
+ ContainerMountInfo* mount = launchInfo.add_mounts();
+ mount->set_source(hostPath.get());
+ mount->set_target(mountPoint);
+ mount->set_flags(MS_BIND | MS_REC);
+ }
}
return launchInfo;
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 0c4bc33..4fabf92 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -31,6 +31,7 @@
#include <process/subprocess.hpp>
+#include <stout/adaptor.hpp>
#include <stout/foreach.hpp>
#include <stout/os.hpp>
#include <stout/protobuf.hpp>
@@ -249,13 +250,33 @@ static Try<Nothing> prepareMounts(const ContainerLaunchInfo& launchInfo)
if (!cloneMountNamespace) {
// Mounts are not supported if the mount namespace is not cloned.
// Otherwise, we'll pollute the parent mount namespace.
+ if (!launchInfo.mounts().empty()) {
+ return Error(
+ "Mounts are not supported if the mount namespace is not cloned");
+ }
+
return Nothing();
}
- // If there is no shared mount (i.e., "bidirectional" propagation),
- // mark the root as recursively slave propagation (i.e.,
- // --make-rslave) so that mounts do not leak to parent mount
- // namespace.
+ // Now, setup the mount propagation for the container.
+ // 1) If there is no shared mount (i.e., "bidirectional"
+ // propagation), mark the root as recursively slave propagation
+ // (i.e., --make-rslave) so that mounts do not leak to parent
+ // mount namespace.
+ // 2) If there exist shared mounts, scan the mount table and mark
+ // the rest as shared mounts one by one.
+ //
+ // TODO(jieyu): Currently, if the container has its own rootfs, the
+ // 'fs::chroot::enter' function will mark `/` as recursively slave.
+ // This will cause problems for shared mounts. As a result,
+ // bidirectional mount propagation does not work for containers that
+ // have rootfses.
+ //
+ // TODO(jieyu): Another caveat right now is that the CNI isolator
+ // will mark `/` as recursively slave in `isolate()` method if the
+ // container joins a named network. As a result, bidirectional mount
+ // propagation currently does not work for containers that want to
+ // join a CNI network.
bool hasSharedMount = std::find_if(
launchInfo.mounts().begin(),
launchInfo.mounts().end(),
@@ -272,9 +293,100 @@ static Try<Nothing> prepareMounts(const ContainerLaunchInfo& launchInfo)
}
cout << "Marked '/' as rslave" << endl;
+ } else {
+ hashset<string> sharedMountTargets;
+ foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
+ // Skip normal mounts.
+ if ((mount.flags() & MS_SHARED) == 0) {
+ continue;
+ }
+
+ sharedMountTargets.insert(mount.target());
+ }
+
+ Try<fs::MountInfoTable> table = fs::MountInfoTable::read();
+ if (table.isError()) {
+ return Error("Failed to get mount table: " + table.error());
+ }
+
+ foreach (const fs::MountInfoTable::Entry& entry,
+ adaptor::reverse(table->entries)) {
+ if (!sharedMountTargets.contains(entry.target)) {
+ Try<Nothing> mnt = fs::mount(
+ None(),
+ entry.target,
+ None(),
+ MS_SLAVE,
+ None());
+
+ if (mnt.isError()) {
+ return Error(
+ "Failed to mark '" + entry.target +
+ "' as slave: " + mnt.error());
+ }
+ }
+ }
}
foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
+ // Skip those mounts that are used for setting up propagation.
+ if ((mount.flags() & MS_SHARED) != 0) {
+ continue;
+ }
+
+ // If bidirectional mount exists, we will not mark `/` as
+ // recursively slave (otherwise, the bidirectional mount
+ // propagation won't work).
+ //
+ // At the same time, we want to prevent mounts in the child
+ // process from being propagated to the host mount namespace,
+ // except for the ones that set the propagation mode to be
+ // bidirectional. This ensures a clean host mount table, and
+ // greatly simplifies the container cleanup.
+ //
+ // If the target of a volume mount is under a non shared mount,
+ // the mount won't be propagated to the host mount namespace,
+ // which is what we want. Otherwise, the volume mount will be
+ // propagated to the host mount namespace, which will make proper
+ // cleanup almost impossible. Therefore, we perform a sanity check
+ // here to make sure the propagation to host mount namespace does
+ // not happen.
+ //
+ // One implication of this check is that: if the target of a
+ // volume mount is under a mount that has to be shared (e.g.,
+ // explicitly specified by the user using 'MountPropagation' in
+ // HOST_PATH volume), the volume mount will fail.
+ //
+ // TODO(jieyu): Some isolators are still using `pre_exe_commands`
+ // to do mounts. Those isolators thus will escape this check. We
+ // should consider forcing all isolators to use
+ // `ContainerMountInfo` for volume mounts.
+ if (hasSharedMount) {
+ Result<string> realTargetPath = os::realpath(mount.target());
+ if (!realTargetPath.isSome()) {
+ return Error(
+ "Failed to get the realpath of the mount target '" +
+ mount.target() + "': " +
+ (realTargetPath.isError() ? realTargetPath.error() : "Not found"));
+ }
+
+ Try<fs::MountInfoTable::Entry> entry =
+ fs::MountInfoTable::findByTarget(realTargetPath.get());
+
+ if (entry.isError()) {
+ return Error(
+ "Cannot find the mount containing the mount target '" +
+ mount.target() + "': " + entry.error());
+ }
+
+ if (entry->shared().isSome()) {
+ return Error(
+ "Cannot perform mount '" + stringify(JSON::protobuf(mount)) +
+ "' because the target is under a shared mount "
+ "'" + entry->target + "'");
+ }
+ }
+
Try<Nothing> mnt = fs::mount(
(mount.has_source() ? Option<string>(mount.source()) : None()),
mount.target(),
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/src/tests/containerizer/volume_host_path_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/volume_host_path_isolator_tests.cpp b/src/tests/containerizer/volume_host_path_isolator_tests.cpp
index 89710f7..271bbbe 100644
--- a/src/tests/containerizer/volume_host_path_isolator_tests.cpp
+++ b/src/tests/containerizer/volume_host_path_isolator_tests.cpp
@@ -21,6 +21,7 @@
#include <process/owned.hpp>
#include <process/gtest.hpp>
+#include <stout/format.hpp>
#include <stout/gtest.hpp>
#include <stout/os.hpp>
#include <stout/path.hpp>
@@ -288,6 +289,68 @@ TEST_F(VolumeHostPathIsolatorTest, ROOT_FileVolumeFromHostSandboxMountPoint)
}
+TEST_F(VolumeHostPathIsolatorTest, ROOT_MountPropagation)
+{
+ slave::Flags flags = CreateSlaveFlags();
+ flags.isolation = "filesystem/linux";
+
+ Fetcher fetcher(flags);
+
+ Try<MesosContainerizer*> create =
+ MesosContainerizer::create(flags, true, &fetcher);
+
+ ASSERT_SOME(create);
+
+ Owned<Containerizer> containerizer(create.get());
+
+ ContainerID containerId;
+ containerId.set_value(UUID::random().toString());
+
+ string mountDirectory = path::join(flags.work_dir, "mount_directory");
+ string mountPoint = path::join(mountDirectory, "mount_point");
+ string filePath = path::join(mountPoint, "foo");
+
+ ASSERT_SOME(os::mkdir(mountPoint));
+
+ ExecutorInfo executor = createExecutorInfo(
+ "test_executor",
+ strings::format(
+ "mount -t tmpfs tmpfs %s; touch %s",
+ mountPoint,
+ filePath).get());
+
+ executor.mutable_container()->CopyFrom(createContainerInfo(
+ None(),
+ {createVolumeHostPath(
+ mountDirectory,
+ mountDirectory,
+ Volume::RW,
+ MountPropagation::BIDIRECTIONAL)}));
+
+ string directory = path::join(flags.work_dir, "sandbox");
+ ASSERT_SOME(os::mkdir(directory));
+
+ Future<Containerizer::LaunchResult> launch = containerizer->launch(
+ containerId,
+ createContainerConfig(None(), executor, directory),
+ map<string, string>(),
+ None());
+
+ AWAIT_READY(launch);
+
+ Future<Option<ContainerTermination>> wait = containerizer->wait(containerId);
+
+ AWAIT_READY(wait);
+ ASSERT_SOME(wait.get());
+ ASSERT_TRUE(wait->get().has_status());
+ EXPECT_WEXITSTATUS_EQ(0, wait->get().status());
+
+ // If the mount propagation has been setup properly, we should see
+ // the file we touch'ed in 'mountPoint'.
+ EXPECT_TRUE(os::exists(filePath));
+}
+
+
class VolumeHostPathIsolatorMesosTest
: public MesosTest,
public WithParamInterface<ParamExecutorType> {};
http://git-wip-us.apache.org/repos/asf/mesos/blob/d6d40eca/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 18f3623..68f78d0 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -673,7 +673,8 @@ template <typename TVolume>
inline TVolume createVolumeHostPath(
const std::string& containerPath,
const std::string& hostPath,
- const typename TVolume::Mode& mode)
+ const typename TVolume::Mode& mode,
+ const Option<MountPropagation::Mode>& mountPropagationMode = None())
{
TVolume volume;
volume.set_container_path(containerPath);
@@ -683,6 +684,13 @@ inline TVolume createVolumeHostPath(
source->set_type(TVolume::Source::HOST_PATH);
source->mutable_host_path()->set_path(hostPath);
+ if (mountPropagationMode.isSome()) {
+ source
+ ->mutable_host_path()
+ ->mutable_mount_propagation()
+ ->set_mode(mountPropagationMode.get());
+ }
+
return volume;
}
[8/9] mesos git commit: Added a findByTarget method for
fs::MountInfoTable.
Posted by ji...@apache.org.
Added a findByTarget method for fs::MountInfoTable.
This method allows us to get the mount table entry that contains the
specified target.
Review: https://reviews.apache.org/r/63212
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/38ccb8c3
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/38ccb8c3
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/38ccb8c3
Branch: refs/heads/master
Commit: 38ccb8c36ee15c403cf30b90992cc2a285e93e8f
Parents: e9ba0a1
Author: Jie Yu <yu...@gmail.com>
Authored: Sun Oct 22 21:38:03 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:45:43 2017 -0800
----------------------------------------------------------------------
src/linux/fs.cpp | 39 +++++++++++++++++++++
src/linux/fs.hpp | 7 ++--
src/tests/containerizer/fs_tests.cpp | 56 +++++++++++++++++++++++++++++++
3 files changed, 100 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/38ccb8c3/src/linux/fs.cpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.cpp b/src/linux/fs.cpp
index c69e7c2..6539f31 100644
--- a/src/linux/fs.cpp
+++ b/src/linux/fs.cpp
@@ -49,6 +49,7 @@ extern "C" {
#include <stout/os.hpp>
#include <stout/os/read.hpp>
+#include <stout/os/realpath.hpp>
#include <stout/os/shell.hpp>
#include <stout/os/stat.hpp>
@@ -233,6 +234,44 @@ Try<MountInfoTable> MountInfoTable::read(
}
+Try<MountInfoTable::Entry> MountInfoTable::findByTarget(
+ const std::string& target)
+{
+ Result<string> realTarget = os::realpath(target);
+ if (!realTarget.isSome()) {
+ return Error(
+ "Failed to get the realpath of '" + target + "'"
+ ": " + (realTarget.isError() ? realTarget.error() : "Not found"));
+ }
+
+ Try<MountInfoTable> table = read(None(), true);
+ if (table.isError()) {
+ return Error("Failed to get mount table: " + table.error());
+ }
+
+ // Trying to find the mount entry that contains the 'realTarget'. We
+ // achieve that by doing a reverse traverse of the mount table to
+ // find the first entry whose target is a prefix of the specified
+ // 'realTarget'.
+ foreach (const Entry& entry, adaptor::reverse(table->entries)) {
+ if (entry.target == realTarget.get()) {
+ return entry;
+ }
+
+ // NOTE: We have to use `path::join(entry.target, "")` here
+ // to make sure the parent is a directory.
+ if (strings::startsWith(realTarget.get(), path::join(entry.target, ""))) {
+ return entry;
+ }
+ }
+
+ // It's unlikely that we cannot find the immediate parent because
+ // '/' is always mounted and will be the immediate parent if no
+ // other mounts found in between.
+ return Error("Not found");
+}
+
+
Try<MountInfoTable::Entry> MountInfoTable::Entry::parse(const string& s)
{
MountInfoTable::Entry entry;
http://git-wip-us.apache.org/repos/asf/mesos/blob/38ccb8c3/src/linux/fs.hpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.hpp b/src/linux/fs.hpp
index cbc8bf7..a79e646 100644
--- a/src/linux/fs.hpp
+++ b/src/linux/fs.hpp
@@ -271,8 +271,11 @@ struct MountInfoTable {
const std::string& lines,
bool hierarchicalSort = true);
- // TODO(jieyu): Introduce 'find' methods to find entries that match
- // the given conditions (e.g., target, root, devno, etc.).
+ // Find the mount table entry by the given target path. If there is
+ // no mount table entry that matches the exact target path, return
+ // the mount table entry that is the immediate parent of the given
+ // target path (similar to `findmnt --target [TARGET]`).
+ static Try<Entry> findByTarget(const std::string& target);
std::vector<Entry> entries;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/38ccb8c3/src/tests/containerizer/fs_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/fs_tests.cpp b/src/tests/containerizer/fs_tests.cpp
index 1022b82..5c0598d 100644
--- a/src/tests/containerizer/fs_tests.cpp
+++ b/src/tests/containerizer/fs_tests.cpp
@@ -32,12 +32,15 @@ extern "C" {
#include <stout/none.hpp>
#include <stout/option.hpp>
#include <stout/os.hpp>
+#include <stout/path.hpp>
#include <stout/try.hpp>
#include <stout/tests/utils.hpp>
#include "linux/fs.hpp"
+#include "tests/environment.hpp"
+
using std::set;
using std::string;
@@ -318,6 +321,59 @@ TEST_F(FsTest, ROOT_SlaveMount)
EXPECT_SOME(fs::unmount(directory));
}
+
+TEST_F(FsTest, ROOT_FindTargetInMountInfoTable)
+{
+ Try<string> base = environment->mkdtemp();
+ ASSERT_SOME(base);
+
+ const string sourceDir = path::join(base.get(), "sourceDir");
+ const string targetDir = path::join(base.get(), "targetDir");
+ const string sourceFile = path::join(base.get(), "sourceFile");
+ const string targetFile = path::join(base.get(), "targetFile");
+
+ // `targetDirUnrelated` is a prefix of `targetDir`, but under the
+ // same base directory.
+ const string sourceDirUnrelated = path::join(base.get(), "source");
+ const string targetDirUnrelated = path::join(base.get(), "target");
+
+ const string file = path::join(targetDir, "file");
+
+ ASSERT_SOME(os::mkdir(sourceDir));
+ ASSERT_SOME(os::mkdir(targetDir));
+ ASSERT_SOME(os::touch(sourceFile));
+ ASSERT_SOME(os::touch(targetFile));
+ ASSERT_SOME(os::mkdir(sourceDirUnrelated));
+ ASSERT_SOME(os::mkdir(targetDirUnrelated));
+
+ ASSERT_SOME(fs::mount(sourceDir, targetDir, None(), MS_BIND, None()));
+ ASSERT_SOME(fs::mount(sourceFile, targetFile, None(), MS_BIND, None()));
+
+ ASSERT_SOME(fs::mount(
+ sourceDirUnrelated,
+ targetDirUnrelated,
+ None(),
+ MS_BIND,
+ None()));
+
+ ASSERT_SOME(os::touch(file));
+
+ Try<MountInfoTable> table = MountInfoTable::read();
+ ASSERT_SOME(table);
+
+ Try<MountInfoTable::Entry> entry = table->findByTarget(targetDir);
+ ASSERT_SOME(entry);
+ EXPECT_EQ(entry->target, targetDir);
+
+ entry = table->findByTarget(file);
+ ASSERT_SOME(entry);
+ EXPECT_EQ(entry->target, targetDir);
+
+ entry = table->findByTarget(targetFile);
+ ASSERT_SOME(entry);
+ EXPECT_EQ(entry->target, targetFile);
+}
+
} // namespace tests {
} // namespace internal {
} // namespace mesos {
[3/9] mesos git commit: Renamed secret key to JWT secret key in the
code base.
Posted by ji...@apache.org.
Renamed secret key to JWT secret key in the code base.
Review: https://reviews.apache.org/r/64109
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/20634c9e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/20634c9e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/20634c9e
Branch: refs/heads/master
Commit: 20634c9e8f182f0cbb3dd38f2e3489315e6f4442
Parents: 86302f5
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Nov 27 18:45:27 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:41:56 2017 -0800
----------------------------------------------------------------------
src/common/http.cpp | 12 ++++++------
src/common/http.hpp | 4 ++--
src/slave/slave.cpp | 16 ++++++++--------
3 files changed, 16 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/20634c9e/src/common/http.cpp
----------------------------------------------------------------------
diff --git a/src/common/http.cpp b/src/common/http.cpp
index 226fed4..3ada1f0 100644
--- a/src/common/http.cpp
+++ b/src/common/http.cpp
@@ -1054,9 +1054,9 @@ Result<process::http::authentication::Authenticator*> createBasicAuthenticator(
Result<process::http::authentication::Authenticator*> createJWTAuthenticator(
const string& realm,
const string& authenticatorName,
- const Option<string>& secretKey)
+ const Option<string>& jwtSecretKey)
{
- if (secretKey.isNone()) {
+ if (jwtSecretKey.isNone()) {
return Error(
"No secret key provided for the default '" +
string(internal::DEFAULT_JWT_HTTP_AUTHENTICATOR) +
@@ -1067,7 +1067,7 @@ Result<process::http::authentication::Authenticator*> createJWTAuthenticator(
<< internal::DEFAULT_JWT_HTTP_AUTHENTICATOR
<< "' HTTP authenticator for realm '" << realm << "'";
- return new JWTAuthenticator(realm, secretKey.get());
+ return new JWTAuthenticator(realm, jwtSecretKey.get());
}
#endif // USE_SSL_SOCKET
@@ -1099,7 +1099,7 @@ Try<Nothing> initializeHttpAuthenticators(
const string& realm,
const vector<string>& authenticatorNames,
const Option<Credentials>& credentials,
- const Option<string>& secretKey)
+ const Option<string>& jwtSecretKey)
{
if (authenticatorNames.empty()) {
return Error(
@@ -1119,7 +1119,7 @@ Try<Nothing> initializeHttpAuthenticators(
} else if (
authenticatorNames[0] == internal::DEFAULT_JWT_HTTP_AUTHENTICATOR) {
authenticator_ =
- createJWTAuthenticator(realm, authenticatorNames[0], secretKey);
+ createJWTAuthenticator(realm, authenticatorNames[0], jwtSecretKey);
#endif // USE_SSL_SOCKET
} else {
authenticator_ = createCustomAuthenticator(realm, authenticatorNames[0]);
@@ -1145,7 +1145,7 @@ Try<Nothing> initializeHttpAuthenticators(
authenticator_ = createBasicAuthenticator(realm, name, credentials);
#ifdef USE_SSL_SOCKET
} else if (name == internal::DEFAULT_JWT_HTTP_AUTHENTICATOR) {
- authenticator_ = createJWTAuthenticator(realm, name, secretKey);
+ authenticator_ = createJWTAuthenticator(realm, name, jwtSecretKey);
#endif // USE_SSL_SOCKET
} else {
authenticator_ = createCustomAuthenticator(realm, name);
http://git-wip-us.apache.org/repos/asf/mesos/blob/20634c9e/src/common/http.hpp
----------------------------------------------------------------------
diff --git a/src/common/http.hpp b/src/common/http.hpp
index 505c6d7..750d3bf 100644
--- a/src/common/http.hpp
+++ b/src/common/http.hpp
@@ -289,7 +289,7 @@ bool authorizeResource(
* @param realm name of the realm.
* @param authenticatorNames a vector of authenticator names.
* @param credentials optional credentials for BasicAuthenticator only.
- * @param secretKey optional secret key for the JWTAuthenticator only.
+ * @param jwtSecretKey optional secret key for the JWTAuthenticator only.
* @return nothing if authenticators are initialized and registered to
* libprocess successfully, or error if authenticators cannot
* be initialized.
@@ -298,7 +298,7 @@ Try<Nothing> initializeHttpAuthenticators(
const std::string& realm,
const std::vector<std::string>& httpAuthenticatorNames,
const Option<Credentials>& credentials = None(),
- const Option<std::string>& secretKey = None());
+ const Option<std::string>& jwtSecretKey = None());
// Logs the request. Route handlers can compose this with the
http://git-wip-us.apache.org/repos/asf/mesos/blob/20634c9e/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index ab3d23d..acee0b8 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -325,12 +325,12 @@ void Slave::initialize()
httpAuthenticators = DEFAULT_BASIC_HTTP_AUTHENTICATOR;
}
- Option<string> secretKey;
+ Option<string> jwtSecretKey;
#ifdef USE_SSL_SOCKET
if (flags.jwt_secret_key.isSome()) {
- Try<string> secretKey_ = os::read(flags.jwt_secret_key.get());
+ Try<string> jwtSecretKey_ = os::read(flags.jwt_secret_key.get());
- if (secretKey_.isError()) {
+ if (jwtSecretKey_.isError()) {
EXIT(EXIT_FAILURE) << "Failed to read the file specified by "
<< "--jwt_secret_key";
}
@@ -350,8 +350,8 @@ void Slave::initialize()
<< " key file is NOT accessible by others";
}
- secretKey = secretKey_.get();
- secretGenerator = new JWTSecretGenerator(secretKey.get());
+ jwtSecretKey = jwtSecretKey_.get();
+ secretGenerator = new JWTSecretGenerator(jwtSecretKey.get());
}
if (flags.authenticate_http_executors) {
@@ -364,7 +364,7 @@ void Slave::initialize()
EXECUTOR_HTTP_AUTHENTICATION_REALM,
strings::split(httpAuthenticators, ","),
httpCredentials,
- secretKey);
+ jwtSecretKey);
if (result.isError()) {
EXIT(EXIT_FAILURE) << result.error();
@@ -377,7 +377,7 @@ void Slave::initialize()
READONLY_HTTP_AUTHENTICATION_REALM,
strings::split(httpAuthenticators, ","),
httpCredentials,
- secretKey);
+ jwtSecretKey);
if (result.isError()) {
EXIT(EXIT_FAILURE) << result.error();
@@ -389,7 +389,7 @@ void Slave::initialize()
READWRITE_HTTP_AUTHENTICATION_REALM,
strings::split(httpAuthenticators, ","),
httpCredentials,
- secretKey);
+ jwtSecretKey);
if (result.isError()) {
EXIT(EXIT_FAILURE) << result.error();
[9/9] mesos git commit: Moved mounts prepare to a helper in
launch.cpp.
Posted by ji...@apache.org.
Moved mounts prepare to a helper in launch.cpp.
Review: https://reviews.apache.org/r/63210
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a68a61e7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a68a61e7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a68a61e7
Branch: refs/heads/master
Commit: a68a61e7deb993f2c318afb3f53ec56011d97972
Parents: 93ecd69
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Oct 20 22:34:43 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:45:43 2017 -0800
----------------------------------------------------------------------
src/slave/containerizer/mesos/launch.cpp | 46 +++++++++++++++++----------
1 file changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/a68a61e7/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index e61c185..9e96b2e 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -237,6 +237,31 @@ static void exitWithStatus(int status)
}
+static Try<Nothing> prepareMounts(const ContainerLaunchInfo& launchInfo)
+{
+#ifdef __linux__
+ foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
+ Try<Nothing> mnt = fs::mount(
+ (mount.has_source() ? Option<string>(mount.source()) : None()),
+ mount.target(),
+ (mount.has_type() ? Option<string>(mount.type()) : None()),
+ (mount.has_flags() ? mount.flags() : 0),
+ (mount.has_options() ? Option<string>(mount.options()) : None()));
+
+ if (mnt.isError()) {
+ return Error(
+ "Failed to mount '" + stringify(JSON::protobuf(mount)) +
+ "': " + mnt.error());
+ }
+
+ cout << "Prepared mount '" << JSON::protobuf(mount) << "'" << endl;
+ }
+#endif // __linux__
+
+ return Nothing();
+}
+
+
static Try<Nothing> installResourceLimits(const RLimitInfo& limits)
{
#ifdef __WINDOWS__
@@ -422,24 +447,11 @@ int MesosContainerizerLaunch::execute()
}
#endif // __WINDOWS__
-#ifdef __linux__
- foreach (const ContainerMountInfo& mount, launchInfo.mounts()) {
- Try<Nothing> mnt = fs::mount(
- (mount.has_source() ? Option<string>(mount.source()) : None()),
- mount.target(),
- (mount.has_type() ? Option<string>(mount.type()) : None()),
- (mount.has_flags() ? mount.flags() : 0),
- (mount.has_options() ? Option<string>(mount.options()) : None()));
-
- if (mnt.isError()) {
- cerr << "Failed to prepare mount '" << JSON::protobuf(mount)
- << "': " << mnt.error() << endl;
- exitWithStatus(EXIT_FAILURE);
- }
-
- cout << "Prepared mount '" << JSON::protobuf(mount) << "'" << endl;
+ Try<Nothing> mount = prepareMounts(launchInfo);
+ if (mount.isError()) {
+ cerr << "Failed to prepare mounts: " << mount.error() << endl;
+ exitWithStatus(EXIT_FAILURE);
}
-#endif // __linux__
// Run additional preparation commands. These are run as the same
// user and with the environment as the agent.
[4/9] mesos git commit: Renamed agent flag '--executor_secret_key' to
'--jwt_secret_key'.
Posted by ji...@apache.org.
Renamed agent flag '--executor_secret_key' to '--jwt_secret_key'.
Now that this is also re-used for authenticating resource provider
initiated requests for managing standalone containers.
Review: https://reviews.apache.org/r/64107
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/86302f5d
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/86302f5d
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/86302f5d
Branch: refs/heads/master
Commit: 86302f5da599fd77fdfe60bd1852c8a296e764d1
Parents: 60d581b
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Nov 27 18:22:43 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Nov 28 18:41:56 2017 -0800
----------------------------------------------------------------------
CHANGELOG | 2 ++
docs/authentication.md | 4 ++--
docs/configuration/agent.md | 7 +++----
docs/upgrades.md | 5 +++++
src/slave/flags.cpp | 10 +++++-----
src/slave/flags.hpp | 2 +-
src/slave/slave.cpp | 18 +++++++++---------
src/tests/executor_http_api_tests.cpp | 2 +-
src/tests/mesos.cpp | 6 +++---
src/tests/mesos.hpp | 2 +-
src/tests/slave_authorization_tests.cpp | 4 ++--
11 files changed, 34 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 08d51df..6eab804 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@ Release Notes - Mesos - Version 1.5.0 (WIP)
This release contains the following new features:
Deprecations/Removals:
+ * Agent flag `--executor_secret_key` has been deprecated. Operators
+ should use `--jwt_secret_key` instead.
Additional API Changes:
* [MESOS-7660] `Filter::refuse_seconds` is now capped to 31536000
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/docs/authentication.md
----------------------------------------------------------------------
diff --git a/docs/authentication.md b/docs/authentication.md
index 0abf069..ab3791b 100644
--- a/docs/authentication.md
+++ b/docs/authentication.md
@@ -133,7 +133,7 @@ token (JWT) HTTP authenticator is loaded to handle executor authentication on
both the executor and operator API endpoints. Note that command and custom
executors not using the HTTP API will remain unauthenticated.
-When a secret key is loaded via the `--executor_secret_key` flag, the agent will
+When a secret key is loaded via the `--jwt_secret_key` flag, the agent will
generate a default JWT for each executor before it is launched. This token is
passed into the executor's environment via the
`MESOS_EXECUTOR_AUTHENTICATION_TOKEN` environment variable. In order to
@@ -146,7 +146,7 @@ In order to upgrade an existing cluster to require executor authentication, the
following procedure should be followed:
1. Upgrade all agents, and provide each agent with a cryptographic key via the
- `--executor_secret_key` flag. This key will be used to sign executor
+ `--jwt_secret_key` flag. This key will be used to sign executor
authentication tokens using the HMAC-SHA256 procedure.
2. Before executor authentication can be enabled successfully, all HTTP
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/docs/configuration/agent.md
----------------------------------------------------------------------
diff --git a/docs/configuration/agent.md b/docs/configuration/agent.md
index f1e0681..83b0823 100644
--- a/docs/configuration/agent.md
+++ b/docs/configuration/agent.md
@@ -718,12 +718,11 @@ in memory. (default: 150)
</tr>
<tr>
<td>
- --executor_secret_key=VALUE
+ --jwt_secret_key=VALUE
</td>
<td>
-Path to a file containing the key used when generating executor
-secrets. This flag is only available when Mesos is built with SSL
-support.
+Path to a file containing the key used when generating JWT secrets.
+This flag is only available when Mesos is built with SSL support.
</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/docs/upgrades.md
----------------------------------------------------------------------
diff --git a/docs/upgrades.md b/docs/upgrades.md
index 0e4015a..33ba4a6 100644
--- a/docs/upgrades.md
+++ b/docs/upgrades.md
@@ -57,6 +57,7 @@ We categorize the changes as follows:
<ul style="padding-left:10px;">
<li>A <a href="#1-5-x-network-ports-isolator">container_ports_watch_interval</a></li>
<li>A <a href="#1-5-x-network-ports-isolator">check_agent_port_range_only</a></li>
+ <li>D <a href="#1-5-x-executor-secret-key">executor_secret_key</a></li>
</ul>
</td>
@@ -377,6 +378,10 @@ We categorize the changes as follows:
* `--container_ports_watch_interval` specifies the interval at which the isolator reconciles port assignments.
* `--check_agent_port_range_only` excludes ports outside the agent's range from port reconcilation.
+<a name="1-5-x-executor-secret-key"></a>
+
+* Agent flag `--executor_secret_key` has been deprecated. Operators should use `--jwt_secret_key` instead.
+
## Upgrading from 1.3.x to 1.4.x ##
<a name="1-4-x-ambient-capabilities"></a>
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/slave/flags.cpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index 0eeecdc..7998d9b 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -396,11 +396,11 @@ mesos::internal::slave::Flags::Flags()
DEFAULT_EXECUTOR_SHUTDOWN_GRACE_PERIOD);
#ifdef USE_SSL_SOCKET
- add(&Flags::executor_secret_key,
- "executor_secret_key",
- "Path to a file containing the key used when generating executor\n"
- "secrets. This flag is only available when Mesos is built with SSL\n"
- "support.");
+ add(&Flags::jwt_secret_key,
+ "jwt_secret_key",
+ flags::DeprecatedName("executor_secret_key"),
+ "Path to a file containing the key used when generating JWT secrets.\n"
+ "This flag is only available when Mesos is built with SSL support.");
#endif // USE_SSL_SOCKET
add(&Flags::gc_delay,
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/slave/flags.hpp
----------------------------------------------------------------------
diff --git a/src/slave/flags.hpp b/src/slave/flags.hpp
index 0c02b49..f25d8af 100644
--- a/src/slave/flags.hpp
+++ b/src/slave/flags.hpp
@@ -82,7 +82,7 @@ public:
Option<Duration> executor_reregistration_retry_interval;
Duration executor_shutdown_grace_period;
#ifdef USE_SSL_SOCKET
- Option<Path> executor_secret_key;
+ Option<Path> jwt_secret_key;
#endif // USE_SSL_SOCKET
Duration gc_delay;
double gc_disk_headroom;
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index cd71647..ab3d23d 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -327,25 +327,25 @@ void Slave::initialize()
Option<string> secretKey;
#ifdef USE_SSL_SOCKET
- if (flags.executor_secret_key.isSome()) {
- Try<string> secretKey_ = os::read(flags.executor_secret_key.get());
+ if (flags.jwt_secret_key.isSome()) {
+ Try<string> secretKey_ = os::read(flags.jwt_secret_key.get());
if (secretKey_.isError()) {
EXIT(EXIT_FAILURE) << "Failed to read the file specified by "
- << "--executor_secret_key";
+ << "--jwt_secret_key";
}
// TODO(greggomann): Factor the following code out into a common helper,
// since we also do this when loading credentials.
Try<os::Permissions> permissions =
- os::permissions(flags.executor_secret_key.get());
+ os::permissions(flags.jwt_secret_key.get());
if (permissions.isError()) {
- LOG(WARNING) << "Failed to stat executor secret key file '"
- << flags.executor_secret_key.get()
+ LOG(WARNING) << "Failed to stat jwt secret key file '"
+ << flags.jwt_secret_key.get()
<< "': " << permissions.error();
} else if (permissions.get().others.rwx) {
LOG(WARNING) << "Permissions on executor secret key file '"
- << flags.executor_secret_key.get()
+ << flags.jwt_secret_key.get()
<< "' are too open; it is recommended that your"
<< " key file is NOT accessible by others";
}
@@ -355,8 +355,8 @@ void Slave::initialize()
}
if (flags.authenticate_http_executors) {
- if (flags.executor_secret_key.isNone()) {
- EXIT(EXIT_FAILURE) << "--executor_secret_key must be specified when "
+ if (flags.jwt_secret_key.isNone()) {
+ EXIT(EXIT_FAILURE) << "--jwt_secret_key must be specified when "
<< "--authenticate_http_executors is set to true";
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/tests/executor_http_api_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/executor_http_api_tests.cpp b/src/tests/executor_http_api_tests.cpp
index 910dbbf..51cca7a 100644
--- a/src/tests/executor_http_api_tests.cpp
+++ b/src/tests/executor_http_api_tests.cpp
@@ -96,7 +96,7 @@ protected:
// currently has SSL as a dependency, so this is only necessary if Mesos was
// built with SSL support.
flags.authenticate_http_executors = false;
- flags.executor_secret_key = None();
+ flags.jwt_secret_key = None();
#endif // USE_SSL_SOCKET
return flags;
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index 9185b5b..3de04dd 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -212,7 +212,7 @@ slave::Flags MesosTest::CreateSlaveFlags()
{
// Create a secret key for executor authentication.
- const string path = path::join(directory.get(), "executor_secret_key");
+ const string path = path::join(directory.get(), "jwt_secret_key");
Try<int_fd> fd = os::open(
path,
@@ -221,12 +221,12 @@ slave::Flags MesosTest::CreateSlaveFlags()
CHECK_SOME(fd);
- CHECK_SOME(os::write(fd.get(), DEFAULT_EXECUTOR_SECRET_KEY))
+ CHECK_SOME(os::write(fd.get(), DEFAULT_JWT_SECRET_KEY))
<< "Failed to write executor secret key to '" << path << "'";
CHECK_SOME(os::close(fd.get()));
- flags.executor_secret_key = path;
+ flags.jwt_secret_key = path;
}
#endif // USE_SSL_SOCKET
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index f02c7c6..7bd16be 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -104,7 +104,7 @@ namespace tests {
constexpr char READONLY_HTTP_AUTHENTICATION_REALM[] = "test-readonly-realm";
constexpr char READWRITE_HTTP_AUTHENTICATION_REALM[] = "test-readwrite-realm";
constexpr char DEFAULT_TEST_ROLE[] = "default-role";
-constexpr char DEFAULT_EXECUTOR_SECRET_KEY[] =
+constexpr char DEFAULT_JWT_SECRET_KEY[] =
"72kUKUFtghAjNbIOvLzfF2RxNBfeM64Bri8g9WhpyaunwqRB/yozHAqSnyHbddAV"
"PcWRQlrJAt871oWgSH+n52vMZ3aVI+AFMzXSo8+sUfMk83IGp0WJefhzeQsjDlGH"
"GYQgCAuGim0BE2X5U+lEue8s697uQpAO8L/FFRuDH2s";
http://git-wip-us.apache.org/repos/asf/mesos/blob/86302f5d/src/tests/slave_authorization_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/slave_authorization_tests.cpp b/src/tests/slave_authorization_tests.cpp
index 11fd0d4..acd922b 100644
--- a/src/tests/slave_authorization_tests.cpp
+++ b/src/tests/slave_authorization_tests.cpp
@@ -844,7 +844,7 @@ TEST_F(ExecutorAuthorizationTest, FailedSubscribe)
.WillOnce(FutureArg<0>(&executorLib));
Owned<JWTSecretGenerator> jwtSecretGenerator(
- new JWTSecretGenerator(DEFAULT_EXECUTOR_SECRET_KEY));
+ new JWTSecretGenerator(DEFAULT_JWT_SECRET_KEY));
// Create a principal which contains an incorrect ContainerID.
hashmap<string, string> claims;
@@ -1069,7 +1069,7 @@ TEST_F(ExecutorAuthorizationTest, FailedApiCalls)
// Generate an authentication token which is signed using the correct key,
// but contains an invalid set of claims.
Owned<JWTSecretGenerator> jwtSecretGenerator(
- new JWTSecretGenerator(DEFAULT_EXECUTOR_SECRET_KEY));
+ new JWTSecretGenerator(DEFAULT_JWT_SECRET_KEY));
Future<Secret> authenticationToken =
jwtSecretGenerator->generate(incorrectPrincipal);