mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ji...@apache.org
Subject mesos git commit: Fixed the broken Docker Volume Rootfs Test on Centos7.
Date Sun, 12 Jun 2016 19:01:52 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 9ad4f3fb8 -> defce4de7


Fixed the broken Docker Volume Rootfs Test on Centos7.

This patch splits the test case of DockerVolumeIsolatorTest
ROOT_CommandTaskNoRootfsWithVolumes into two test cases: one for
absolute path and the other is for relative path.

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


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

Branch: refs/heads/master
Commit: defce4de7c274756f6b16e3302fda18c42860ce8
Parents: 9ad4f3f
Author: Guangya Liu <gyliu513@gmail.com>
Authored: Sun Jun 12 12:01:08 2016 -0700
Committer: Jie Yu <yujie.jay@gmail.com>
Committed: Sun Jun 12 12:01:08 2016 -0700

----------------------------------------------------------------------
 .../docker_volume_isolator_tests.cpp            | 233 ++++++++++++++-----
 1 file changed, 175 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/defce4de/src/tests/containerizer/docker_volume_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/docker_volume_isolator_tests.cpp b/src/tests/containerizer/docker_volume_isolator_tests.cpp
index c524f42..8d24583 100644
--- a/src/tests/containerizer/docker_volume_isolator_tests.cpp
+++ b/src/tests/containerizer/docker_volume_isolator_tests.cpp
@@ -798,12 +798,11 @@ TEST_F(DockerVolumeIsolatorTest,
 }
 
 
-// This test verifies that multiple docker volumes with both absolute
-// path and relative path are properly mounted to a container with
-// rootfs, and launches a command task that reads files from the mounted
-// docker volumes.
+// This test verifies that a docker volume with absolute path can
+// be properly mounted to a container with rootfs, and launches a
+// command task that reads files from the mounted docker volume.
 TEST_F(DockerVolumeIsolatorTest,
-       ROOT_INTERNET_CURL_CommandTaskRootfsWithVolumes)
+       ROOT_INTERNET_CURL_CommandTaskRootfsWithAbsolutePathVolume)
 {
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
@@ -855,33 +854,28 @@ TEST_F(DockerVolumeIsolatorTest,
 
   const Offer& offer = offers.get()[0];
 
-  const string key = "iops";
-  const string value = "150";
-
-  hashmap<string, string> options = {{key, value}};
-
-  // Create a volume with relative path.
-  const string driver1 = "driver1";
-  const string name1 = "name1";
-  const string containerPath1 = "tmp/foo1";
-
-  Volume volume1 = createDockerVolume(driver1, name1, containerPath1, options);
-
   // Create a volume with absolute path.
-  const string driver2 = "driver2";
-  const string name2 = "name2";
+  const string volumeDriver = "driver";
+  const string name = "name";
 
-  // Make sure the absolute path exist.
-  const string containerPath2 = path::join(os::getcwd(), "foo2");
-  ASSERT_SOME(os::mkdir(containerPath2));
+  const string containerPath = path::join(os::getcwd(), "foo");
 
-  Volume volume2 = createDockerVolume(driver2, name2, containerPath2);
+  Volume volume = createDockerVolume(volumeDriver, name, containerPath);
+
+  // NOTE: We use a non-shell command here because 'sh' might not be
+  // in the PATH. 'alpine' does not specify env PATH in the image. On
+  // some linux distribution, '/bin' is not in the PATH by default.
+  CommandInfo command;
+  command.set_shell(false);
+  command.set_value("/usr/bin/test");
+  command.add_arguments("test");
+  command.add_arguments("-f");
+  command.add_arguments(containerPath + "/file");
 
   TaskInfo task = createTask(
       offer.slave_id(),
       offer.resources(),
-      "test -f " + containerPath1 + "/file1 && "
-      "test -f " + containerPath2 + "/file2;");
+      command);
 
   Image image;
   image.set_type(Image::DOCKER);
@@ -889,45 +883,170 @@ TEST_F(DockerVolumeIsolatorTest,
 
   ContainerInfo containerInfo;
   containerInfo.set_type(ContainerInfo::MESOS);
-  containerInfo.add_volumes()->CopyFrom(volume1);
-  containerInfo.add_volumes()->CopyFrom(volume2);
+  containerInfo.add_volumes()->CopyFrom(volume);
 
   containerInfo.mutable_mesos()->mutable_image()->CopyFrom(image);
 
   task.mutable_container()->CopyFrom(containerInfo);
 
-  // Create mount point for volume1.
-  const string mountPoint1 = path::join(os::getcwd(), "volume1");
-  ASSERT_SOME(os::mkdir(mountPoint1));
-  ASSERT_SOME(os::touch(path::join(mountPoint1, "file1")));
+  // Create mount point for volume.
+  const string mountPoint = path::join(os::getcwd(), "volume");
+  ASSERT_SOME(os::mkdir(mountPoint));
+  ASSERT_SOME(os::touch(path::join(mountPoint, "file")));
 
-  // Create mount point for volume2.
-  const string mountPoint2 = path::join(os::getcwd(), "volume2");
-  ASSERT_SOME(os::mkdir(mountPoint2));
-  ASSERT_SOME(os::touch(path::join(mountPoint2, "file2")));
+  Future<string> mountName;
 
-  Future<string> mount1Name;
-  Future<string> mount2Name;
-  Future<hashmap<string, string>> mount1Options;
+  EXPECT_CALL(*mockClient, mount(volumeDriver, _, _))
+    .WillOnce(DoAll(FutureArg<1>(&mountName),
+                    Return(mountPoint)));
 
-  EXPECT_CALL(*mockClient, mount(driver1, _, _))
-    .WillOnce(DoAll(FutureArg<1>(&mount1Name),
-                    FutureArg<2>(&mount1Options),
-                    Return(mountPoint1)));
+  Future<string> unmountName;
 
-  EXPECT_CALL(*mockClient, mount(driver2, _, _))
-    .WillOnce(DoAll(FutureArg<1>(&mount2Name),
-                    Return(mountPoint2)));
+  EXPECT_CALL(*mockClient, unmount(volumeDriver, _))
+    .WillOnce(DoAll(FutureArg<1>(&unmountName),
+                    Return(Nothing())));
 
-  Future<string> unmount1Name;
-  Future<string> unmount2Name;
+  Future<TaskStatus> statusRunning;
+  Future<TaskStatus> statusFinished;
 
-  EXPECT_CALL(*mockClient, unmount(driver1, _))
-    .WillOnce(DoAll(FutureArg<1>(&unmount1Name),
-                    Return(Nothing())));
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusRunning))
+    .WillOnce(FutureArg<1>(&statusFinished));
 
-  EXPECT_CALL(*mockClient, unmount(driver2, _))
-    .WillOnce(DoAll(FutureArg<1>(&unmount2Name),
+  driver.launchTasks(offer.id(), {task});
+
+  AWAIT_READY(statusRunning);
+  EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+  // Make sure the docker volume mount parameters are same with the
+  // parameters in `containerInfo`.
+  AWAIT_EXPECT_EQ(name, mountName);
+
+  AWAIT_READY(statusFinished);
+  EXPECT_EQ(TASK_FINISHED, statusFinished->state());
+
+  // Make sure the docker volume unmount parameters are same with
+  // the parameters in `containerInfo`.
+  AWAIT_EXPECT_EQ(name, unmountName);
+
+  driver.stop();
+  driver.join();
+}
+
+
+// This test verifies that a docker volume with relative path can
+// be properly mounted to a container with rootfs, and launches a
+// command task that reads files from the mounted docker volume.
+TEST_F(DockerVolumeIsolatorTest,
+       ROOT_INTERNET_CURL_CommandTaskRootfsWithRelativeVolume)
+{
+  Try<Owned<cluster::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  slave::Flags flags = CreateSlaveFlags();
+  flags.isolation = "docker/volume,docker/runtime,filesystem/linux";
+  flags.image_providers = "docker";
+
+  MockDockerVolumeDriverClient* mockClient =
+      new MockDockerVolumeDriverClient;
+
+  Try<Owned<MesosContainerizer>> containerizer =
+    createContainerizer(flags, Owned<DriverClient>(mockClient));
+
+  ASSERT_SOME(containerizer);
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+
+  Try<Owned<cluster::Slave>> slave = StartSlave(
+      detector.get(),
+      containerizer.get().get(),
+      flags);
+
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+
+  MesosSchedulerDriver driver(
+      &sched,
+      DEFAULT_FRAMEWORK_INFO,
+      master.get()->pid,
+      DEFAULT_CREDENTIAL);
+
+  Future<FrameworkID> frameworkId;
+  EXPECT_CALL(sched, registered(&driver, _, _))
+    .WillOnce(FutureArg<1>(&frameworkId));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(frameworkId);
+
+  AWAIT_READY(offers);
+  ASSERT_NE(0u, offers->size());
+
+  const Offer& offer = offers.get()[0];
+
+  const string key = "iops";
+  const string value = "150";
+
+  hashmap<string, string> options = {{key, value}};
+
+  // Create a volume with relative path.
+  const string volumeDriver = "driver";
+  const string name = "name";
+  const string containerPath = "tmp/foo";
+
+  Volume volume = createDockerVolume(
+      volumeDriver, name, containerPath, options);
+
+  // NOTE: We use a non-shell command here because 'sh' might not be
+  // in the PATH. 'alpine' does not specify env PATH in the image. On
+  // some linux distribution, '/bin' is not in the PATH by default.
+  CommandInfo command;
+  command.set_shell(false);
+  command.set_value("/usr/bin/test");
+  command.add_arguments("test");
+  command.add_arguments("-f");
+  command.add_arguments(containerPath + "/file");
+
+  TaskInfo task = createTask(
+      offer.slave_id(),
+      offer.resources(),
+      command);
+
+  Image image;
+  image.set_type(Image::DOCKER);
+  image.mutable_docker()->set_name("alpine");
+
+  ContainerInfo containerInfo;
+  containerInfo.set_type(ContainerInfo::MESOS);
+  containerInfo.add_volumes()->CopyFrom(volume);
+
+  containerInfo.mutable_mesos()->mutable_image()->CopyFrom(image);
+
+  task.mutable_container()->CopyFrom(containerInfo);
+
+  // Create mount point for volume.
+  const string mountPoint = path::join(os::getcwd(), "volume");
+  ASSERT_SOME(os::mkdir(mountPoint));
+  ASSERT_SOME(os::touch(path::join(mountPoint, "file")));
+
+  Future<string> mountName;
+  Future<hashmap<string, string>> mountOptions;
+
+  EXPECT_CALL(*mockClient, mount(volumeDriver, _, _))
+    .WillOnce(DoAll(FutureArg<1>(&mountName),
+                    FutureArg<2>(&mountOptions),
+                    Return(mountPoint)));
+
+  Future<string> unmountName;
+
+  EXPECT_CALL(*mockClient, unmount(volumeDriver, _))
+    .WillOnce(DoAll(FutureArg<1>(&unmountName),
                     Return(Nothing())));
 
   Future<TaskStatus> statusRunning;
@@ -944,19 +1063,17 @@ TEST_F(DockerVolumeIsolatorTest,
 
   // Make sure the docker volume mount parameters are same with the
   // parameters in `containerInfo`.
-  AWAIT_EXPECT_EQ(name1, mount1Name);
-  AWAIT_EXPECT_EQ(name2, mount2Name);
+  AWAIT_EXPECT_EQ(name, mountName);
 
-  AWAIT_READY(mount1Options);
-  EXPECT_SOME_EQ(value, mount1Options->get(key));
+  AWAIT_READY(mountOptions);
+  EXPECT_SOME_EQ(value, mountOptions->get(key));
 
   AWAIT_READY(statusFinished);
   EXPECT_EQ(TASK_FINISHED, statusFinished->state());
 
   // Make sure the docker volume unmount parameters are same with
   // the parameters in `containerInfo`.
-  AWAIT_EXPECT_EQ(name1, unmount1Name);
-  AWAIT_EXPECT_EQ(name2, unmount2Name);
+  AWAIT_EXPECT_EQ(name, unmountName);
 
   driver.stop();
   driver.join();


Mime
View raw message