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/08/29 15:55:46 UTC

[11/12] mesos git commit: Adjusted the test helpers for creating host and sandbox path volumes.

Adjusted the test helpers for creating host and sandbox path volumes.

Previously, we used the same helper for creating both host and sandbox
path volumes. This patch split that into two separate helpers.

Review: https://reviews.apache.org/r/61919


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8858df48
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8858df48
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8858df48

Branch: refs/heads/master
Commit: 8858df48abb52fb56dd86859d7efd373cd09d5f8
Parents: 8340b23
Author: Jie Yu <yu...@gmail.com>
Authored: Fri Aug 25 15:19:11 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Aug 29 08:55:32 2017 -0700

----------------------------------------------------------------------
 .../linux_filesystem_isolator_tests.cpp         | 10 ++--
 .../volume_host_path_isolator_tests.cpp         | 12 ++---
 src/tests/mesos.hpp                             | 48 +++++++++++++++++---
 3 files changed, 53 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8858df48/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/linux_filesystem_isolator_tests.cpp b/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
index b47d9eb..1ad9464 100644
--- a/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/linux_filesystem_isolator_tests.cpp
@@ -215,7 +215,7 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_VolumeFromSandbox)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", "tmp", Volume::RW)}));
+      {createVolumeSandboxPath("/tmp", "tmp", Volume::RW)}));
 
   string directory = path::join(flags.work_dir, "sandbox");
   ASSERT_SOME(os::mkdir(directory));
@@ -272,7 +272,7 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_SandboxVolumeOwnership)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", "tmp", Volume::RW)}));
+      {createVolumeSandboxPath("/tmp", "tmp", Volume::RW)}));
 
   string directory = path::join(flags.work_dir, "sandbox");
   ASSERT_SOME(os::mkdir(directory));
@@ -411,7 +411,7 @@ TEST_F(LinuxFilesystemIsolatorTest,
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/absolute_path", "volume", Volume::RW)}));
+      {createVolumeSandboxPath("/absolute_path", "volume", Volume::RW)}));
 
   // Create a persistent volume.
   string volume = slave::paths::getPersistentVolumePath(
@@ -917,7 +917,7 @@ TEST_F(LinuxFilesystemIsolatorMesosTest,
 
   task.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", dir1, Volume::RW)}));
+      {createVolumeHostPath("/tmp", dir1, Volume::RW)}));
 
   // Create the persistent volumes and launch task via `acceptOffers`.
   driver.acceptOffers(
@@ -1048,7 +1048,7 @@ TEST_F(LinuxFilesystemIsolatorMesosTest,
 
   task.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", dir1, Volume::RW)}));
+      {createVolumeHostPath("/tmp", dir1, Volume::RW)}));
 
   Future<TaskStatus> status;
   EXPECT_CALL(sched, statusUpdate(&driver, _))

http://git-wip-us.apache.org/repos/asf/mesos/blob/8858df48/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 5e04b0a..4277f3c 100644
--- a/src/tests/containerizer/volume_host_path_isolator_tests.cpp
+++ b/src/tests/containerizer/volume_host_path_isolator_tests.cpp
@@ -86,7 +86,7 @@ TEST_F(VolumeHostPathIsolatorTest, ROOT_VolumeFromHost)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", sandbox.get(), Volume::RW)}));
+      {createVolumeHostPath("/tmp", sandbox.get(), Volume::RW)}));
 
   string dir = path::join(sandbox.get(), "dir");
   ASSERT_SOME(os::mkdir(dir));
@@ -146,7 +146,7 @@ TEST_F(VolumeHostPathIsolatorTest, ROOT_FileVolumeFromHost)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp/test/file.txt", file, Volume::RW)}));
+      {createVolumeHostPath("/tmp/test/file.txt", file, Volume::RW)}));
 
   string directory = path::join(flags.work_dir, "sandbox");
   ASSERT_SOME(os::mkdir(directory));
@@ -200,7 +200,7 @@ TEST_F(VolumeHostPathIsolatorTest, ROOT_VolumeFromHostSandboxMountPoint)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("mountpoint", sandbox.get(), Volume::RW)}));
+      {createVolumeHostPath("mountpoint", sandbox.get(), Volume::RW)}));
 
   string dir = path::join(sandbox.get(), "dir");
   ASSERT_SOME(os::mkdir(dir));
@@ -260,7 +260,7 @@ TEST_F(VolumeHostPathIsolatorTest, ROOT_FileVolumeFromHostSandboxMountPoint)
 
   executor.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("mountpoint/file.txt", file, Volume::RW)}));
+      {createVolumeHostPath("mountpoint/file.txt", file, Volume::RW)}));
 
   string directory = path::join(flags.work_dir, "sandbox");
   ASSERT_SOME(os::mkdir(directory));
@@ -349,8 +349,8 @@ TEST_F(VolumeHostPathIsolatorMesosTest,
 
   task.mutable_container()->CopyFrom(createContainerInfo(
       "test_image",
-      {createVolumeFromHostPath("/tmp", dir1, Volume::RW),
-       createVolumeFromHostPath("relative_dir", dir2, Volume::RW)}));
+      {createVolumeHostPath("/tmp", dir1, Volume::RW),
+       createVolumeHostPath("relative_dir", dir2, Volume::RW)}));
 
   driver.launchTasks(offer.id(), {task});
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/8858df48/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index f80e5fb..97829a0 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -552,15 +552,36 @@ inline TImage createDockerImage(const std::string& imageName)
 
 
 template <typename TVolume>
-inline TVolume createVolumeFromHostPath(
+inline TVolume createVolumeSandboxPath(
+    const std::string& containerPath,
+    const std::string& sandboxPath,
+    const typename TVolume::Mode& mode)
+{
+  TVolume volume;
+  volume.set_container_path(containerPath);
+  volume.set_mode(mode);
+
+  // TODO(jieyu): Use TVolume::Source::SANDBOX_PATH.
+  volume.set_host_path(sandboxPath);
+
+  return volume;
+}
+
+
+template <typename TVolume>
+inline TVolume createVolumeHostPath(
     const std::string& containerPath,
     const std::string& hostPath,
     const typename TVolume::Mode& mode)
 {
   TVolume volume;
   volume.set_container_path(containerPath);
-  volume.set_host_path(hostPath);
   volume.set_mode(mode);
+
+  typename TVolume::Source* source = volume.mutable_source();
+  source->set_type(TVolume::Source::HOST_PATH);
+  source->mutable_host_path()->set_path(hostPath);
+
   return volume;
 }
 
@@ -1207,9 +1228,16 @@ inline Image createDockerImage(Args&&... args)
 
 
 template <typename... Args>
-inline Volume createVolumeFromHostPath(Args&&... args)
+inline Volume createVolumeSandboxPath(Args&&... args)
+{
+  return common::createVolumeSandboxPath<Volume>(std::forward<Args>(args)...);
+}
+
+
+template <typename... Args>
+inline Volume createVolumeHostPath(Args&&... args)
 {
-  return common::createVolumeFromHostPath<Volume>(std::forward<Args>(args)...);
+  return common::createVolumeHostPath<Volume>(std::forward<Args>(args)...);
 }
 
 
@@ -1433,9 +1461,17 @@ inline mesos::v1::Image createDockerImage(Args&&... args)
 
 
 template <typename... Args>
-inline mesos::v1::Volume createVolumeFromHostPath(Args&&... args)
+inline mesos::v1::Volume createVolumeSandboxPath(Args&&... args)
+{
+  return common::createVolumeSandboxPath<mesos::v1::Volume>(
+      std::forward<Args>(args)...);
+}
+
+
+template <typename... Args>
+inline mesos::v1::Volume createVolumeHostPath(Args&&... args)
 {
-  return common::createVolumeFromHostPath<mesos::v1::Volume>(
+  return common::createVolumeHostPath<mesos::v1::Volume>(
       std::forward<Args>(args)...);
 }