Added filesystem isolator tests to test volumes from the host. Review: https://reviews.apache.org/r/37322
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/03b28b11 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/03b28b11 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/03b28b11 Branch: refs/heads/master Commit: 03b28b11e53fc098f838af5a6fec81c14a025dfb Parents: 512f2bc Author: Jie Yu <[email protected]> Authored: Mon Aug 10 15:12:26 2015 -0700 Committer: Jie Yu <[email protected]> Committed: Wed Aug 12 12:21:00 2015 -0700 ---------------------------------------------------------------------- .../containerizer/filesystem_isolator_tests.cpp | 94 ++++++++++++++++++++ 1 file changed, 94 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/03b28b11/src/tests/containerizer/filesystem_isolator_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp index 7b1f1a3..98320ee 100644 --- a/src/tests/containerizer/filesystem_isolator_tests.cpp +++ b/src/tests/containerizer/filesystem_isolator_tests.cpp @@ -232,6 +232,100 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromSandbox) EXPECT_SOME_EQ("abc\n", os::read(path::join(directory, "tmp", "file"))); } + + +// This test verifies that a volume with an absolute host path as +// well as an absolute container path is properly mounted in the +// container's mount namespace. +TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHost) +{ + slave::Flags flags = CreateSlaveFlags(); + + Try<Owned<MesosContainerizer>> containerizer = createContainerizer(flags); + ASSERT_SOME(containerizer); + + ContainerID containerId; + containerId.set_value(UUID::random().toString()); + + ExecutorInfo executor = CREATE_EXECUTOR_INFO( + "test_executor", + "test -d /tmp/sandbox"); + + executor.mutable_container()->CopyFrom(createContainerInfo( + {CREATE_VOLUME("/tmp", os::getcwd(), Volume::RW)})); + + string directory = path::join(os::getcwd(), "sandbox"); + ASSERT_SOME(os::mkdir(directory)); + + Future<bool> launch = containerizer.get()->launch( + containerId, + executor, + directory, + None(), + SlaveID(), + PID<Slave>(), + false); + + // Wait for the launch to complete. + AWAIT_READY(launch); + + // Wait on the container. + Future<containerizer::Termination> wait = + containerizer.get()->wait(containerId); + + AWAIT_READY(wait); + + // Check the executor exited correctly. + EXPECT_TRUE(wait.get().has_status()); + EXPECT_EQ(0, wait.get().status()); +} + + +// This test verifies that a volume with an absolute host path and a +// relative container path is properly mounted in the container's +// mount namespace. The mount point will be created in the sandbox. +TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromHostSandboxMountPoint) +{ + slave::Flags flags = CreateSlaveFlags(); + + Try<Owned<MesosContainerizer>> containerizer = createContainerizer(flags); + ASSERT_SOME(containerizer); + + ContainerID containerId; + containerId.set_value(UUID::random().toString()); + + ExecutorInfo executor = CREATE_EXECUTOR_INFO( + "test_executor", + "test -d mountpoint/sandbox"); + + executor.mutable_container()->CopyFrom(createContainerInfo( + {CREATE_VOLUME("mountpoint", os::getcwd(), Volume::RW)})); + + string directory = path::join(os::getcwd(), "sandbox"); + ASSERT_SOME(os::mkdir(directory)); + + Future<bool> launch = containerizer.get()->launch( + containerId, + executor, + directory, + None(), + SlaveID(), + PID<Slave>(), + false); + + // Wait for the launch to complete. + AWAIT_READY(launch); + + // Wait on the container. + Future<containerizer::Termination> wait = + containerizer.get()->wait(containerId); + + AWAIT_READY(wait); + + // Check the executor exited correctly. + EXPECT_TRUE(wait.get().has_status()); + EXPECT_EQ(0, wait.get().status()); +} #endif // __linux__ } // namespace tests {
