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 2016/03/23 23:45:17 UTC

[1/2] mesos git commit: Added getAppcImage for Appc provisioning tests.

Repository: mesos
Updated Branches:
  refs/heads/master 8d3d47073 -> d5c3771bb


Added getAppcImage for Appc provisioning tests.

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


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

Branch: refs/heads/master
Commit: c8e033023da318fc5fd45c8dd3bce4f1783dd107
Parents: 8d3d470
Author: Jojy Varghese <jo...@mesosphere.io>
Authored: Wed Mar 23 15:41:59 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Mar 23 15:41:59 2016 -0700

----------------------------------------------------------------------
 .../containerizer/provisioner_appc_tests.cpp    | 73 +++++++++++---------
 1 file changed, 39 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c8e03302/src/tests/containerizer/provisioner_appc_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/provisioner_appc_tests.cpp b/src/tests/containerizer/provisioner_appc_tests.cpp
index 069af8a..23a5b10 100644
--- a/src/tests/containerizer/provisioner_appc_tests.cpp
+++ b/src/tests/containerizer/provisioner_appc_tests.cpp
@@ -64,6 +64,41 @@ namespace mesos {
 namespace internal {
 namespace tests {
 
+/**
+ * Helper function that returns a Appc protobuf object for given
+ * parameters.
+ *
+ * @param name Appc image name.
+ * @param arch Machine architecture(e.g, x86, amd64).
+ * @param os Operating system(e.g, linux).
+ * @return Appc protobuff message object.
+ */
+static Image::Appc getAppcImage(
+    const string& name,
+    const string& arch = "amd64",
+    const string& os = "linux")
+{
+  Image::Appc appc;
+  appc.set_name(name);
+
+  Label archLabel;
+  archLabel.set_key("arch");
+  archLabel.set_value(arch);
+
+  Label osLabel;
+  osLabel.set_key("os");
+  osLabel.set_value(os);
+
+  Labels labels;
+  labels.add_labels()->CopyFrom(archLabel);
+  labels.add_labels()->CopyFrom(osLabel);
+
+  appc.mutable_labels()->CopyFrom(labels);
+
+  return appc;
+}
+
+
 // TODO(jojy): Move AppcSpecTest to its own test file.
 class AppcSpecTest : public TemporaryDirectoryTest {};
 
@@ -611,22 +646,7 @@ TEST_F(AppcImageFetcherTest, CURL_SimpleHttpFetch)
       stringify(server.self().address) ,
       imageName).get();
 
-  Image::Appc imageInfo;
-  imageInfo.set_name(discoverableImageName);
-
-  Label archLabel;
-  archLabel.set_key("arch");
-  archLabel.set_value("amd64");
-
-  Label osLabel;
-  osLabel.set_key("os");
-  osLabel.set_value("linux");
-
-  Labels labels;
-  labels.add_labels()->CopyFrom(archLabel);
-  labels.add_labels()->CopyFrom(osLabel);
-
-  imageInfo.mutable_labels()->CopyFrom(labels);
+  Image::Appc appc = getAppcImage(discoverableImageName);
 
   // Create image fetcher.
   Try<Owned<uri::Fetcher>> uriFetcher = uri::fetcher::create();
@@ -646,7 +666,7 @@ TEST_F(AppcImageFetcherTest, CURL_SimpleHttpFetch)
   ASSERT_SOME(mkdir);
 
   // Now fetch the image.
-  AWAIT_READY(fetcher.get()->fetch(imageInfo, imageFetchDir));
+  AWAIT_READY(fetcher.get()->fetch(appc, imageFetchDir));
 
   // Verify that there is an image directory.
   Try<list<string>> imageDirs = os::ls(imageFetchDir);
@@ -683,22 +703,7 @@ TEST_F(AppcImageFetcherTest, SimpleFileFetch)
   // Setup the image bundle.
   prepareImage(imageDirMountPath, imageBundlePath, getManifest());
 
-  Image::Appc imageInfo;
-  imageInfo.set_name("image");
-
-  Label archLabel;
-  archLabel.set_key("arch");
-  archLabel.set_value("amd64");
-
-  Label osLabel;
-  osLabel.set_key("os");
-  osLabel.set_value("linux");
-
-  Labels labels;
-  labels.add_labels()->CopyFrom(archLabel);
-  labels.add_labels()->CopyFrom(osLabel);
-
-  imageInfo.mutable_labels()->CopyFrom(labels);
+  Image::Appc appc = getAppcImage("image");
 
   // Create image fetcher.
   Try<Owned<uri::Fetcher>> uriFetcher = uri::fetcher::create();
@@ -721,7 +726,7 @@ TEST_F(AppcImageFetcherTest, SimpleFileFetch)
   ASSERT_SOME(mkdir);
 
   // Now fetch the image.
-  AWAIT_READY(fetcher.get()->fetch(imageInfo, imageFetchDir));
+  AWAIT_READY(fetcher.get()->fetch(appc, imageFetchDir));
 
   // Verify that there is an image directory.
   Try<list<string>> imageDirs = os::ls(imageFetchDir);


[2/2] mesos git commit: Added Appc provisioner integration test.

Posted by ji...@apache.org.
Added Appc provisioner integration test.

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


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

Branch: refs/heads/master
Commit: d5c3771bbf3ea3edebf3c6215a7ce5e41c423fd0
Parents: c8e0330
Author: Jojy Varghese <jo...@mesosphere.io>
Authored: Wed Mar 23 15:45:07 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Mar 23 15:45:07 2016 -0700

----------------------------------------------------------------------
 .../containerizer/provisioner_appc_tests.cpp    | 164 +++++++++++++++++++
 1 file changed, 164 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d5c3771b/src/tests/containerizer/provisioner_appc_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/provisioner_appc_tests.cpp b/src/tests/containerizer/provisioner_appc_tests.cpp
index 23a5b10..d23a45e 100644
--- a/src/tests/containerizer/provisioner_appc_tests.cpp
+++ b/src/tests/containerizer/provisioner_appc_tests.cpp
@@ -44,6 +44,10 @@
 #include "slave/containerizer/mesos/provisioner/appc/paths.hpp"
 #include "slave/containerizer/mesos/provisioner/appc/store.hpp"
 
+#include "tests/mesos.hpp"
+
+#include "tests/containerizer/rootfs.hpp"
+
 using std::list;
 using std::string;
 using std::vector;
@@ -747,6 +751,166 @@ TEST_F(AppcImageFetcherTest, SimpleFileFetch)
   ASSERT_SOME_EQ("test", os::read(path::join(imageRootfs, "tmp", "test")));
 }
 
+
+#ifdef __linux__
+// Test fixture for Appc image provisioner integration tests. It also provides a
+// helper for creating a base linux image bundle.
+class AppcProvisionerIntegrationTest : public MesosTest
+{
+protected:
+  // Prepares a base 'linux' Appc image bundle from host's rootfs.
+  void prepareImageBundle(const string& imageName, const string& mntDir)
+  {
+    // TODO(jojy): Consider parameterizing the labels for image name decoration.
+    const string imageBundleName = imageName + "-latest-linux-amd64.aci";
+
+    const string imagesPath = path::join(mntDir, "images");
+    const string imagePath = path::join(imagesPath, imageBundleName);
+
+    const string manifest = strings::format(
+        R"~(
+        {
+          "acKind": "ImageManifest",
+            "acVersion": "0.6.1",
+            "name": "%s",
+            "labels": [
+            {
+              "name": "version",
+              "value": "latest"
+            },
+            {
+              "name": "arch",
+              "value": "amd64"
+            },
+            {
+              "name": "os",
+              "value": "linux"
+            }
+          ],
+            "annotations": [
+            {
+              "name": "created",
+              "value": "1438983392"
+            }
+          ]
+        })~",
+        imageName).get();
+
+    const string rootfsPath = path::join(imagePath, "rootfs");
+
+    // Setup image on the server.
+    Try<Owned<Rootfs>> rootfs = LinuxRootfs::create(rootfsPath);
+    ASSERT_SOME(rootfs);
+
+    // 'modules' directory is usually very large and is an easy one to exclude.
+    // TODO(jojy): Consider adding directory exclusion filter in LinuxRootfs.
+    Try<Nothing> rmdir = os::rmdir(path::join(rootfsPath, "lib", "modules"));
+    ASSERT_SOME(rmdir);
+
+    Try<Nothing> manifestWrite = os::write(
+        path::join(imagePath, "manifest"),
+        manifest);
+
+    ASSERT_SOME(manifestWrite);
+
+    const string imageBundlePath = path::join(mntDir, imageBundleName);
+
+    Future<Nothing> future = command::tar(
+        Path("."),
+        Path(imageBundlePath),
+        imagePath,
+        command::Compression::GZIP);
+
+    AWAIT_READY_FOR(future, Seconds(120));
+  }
+};
+
+
+// Tests the Appc image provisioner for a single layered Linux image. The
+// image's rootfs is built from local host's file system.
+TEST_F(AppcProvisionerIntegrationTest, ROOT_SimpleLinuxImageTest)
+{
+  const string imageName = "linux";
+
+  // Represents the directory where image bundles would be mounted.
+  const string mntDir = path::join(os::getcwd(), "mnt");
+
+  // Prepare the image bundle at the mount point.
+  prepareImageBundle(imageName, mntDir);
+
+  // Start master.
+  Try<PID<master::Master>> master = StartMaster();
+  ASSERT_SOME(master);
+
+  // Start agent.
+  slave::Flags flags = CreateSlaveFlags();
+  flags.isolation = "filesystem/linux";
+  flags.image_providers = "APPC";
+  flags.appc_simple_discovery_uri_prefix = path::join(mntDir, "");
+
+  Try<PID<slave::Slave>> slave = StartSlave(flags);
+  ASSERT_SOME(slave);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  Future<vector<Offer>> offers;
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  driver.start();
+
+  AWAIT_READY(offers);
+  ASSERT_EQ(1u, offers->size());
+
+  const Offer& offer = offers.get()[0];
+
+  TaskInfo task = createTask(
+      offer.slave_id(),
+      Resources::parse("cpus:1;mem:128").get(),
+      "ls -al /");
+
+  // Setup image for task.
+  Image::Appc appc = getAppcImage(imageName);
+
+  Image image;
+  image.set_type(Image::APPC);
+  image.mutable_appc()->CopyFrom(appc);
+
+  ContainerInfo* container = task.mutable_container();
+  container->set_type(ContainerInfo::MESOS);
+  container->mutable_mesos()->mutable_image()->CopyFrom(image);
+
+  Future<TaskStatus> statusRunning;
+  Future<TaskStatus> statusFinished;
+
+  EXPECT_CALL(sched, statusUpdate(&driver, _))
+    .WillOnce(FutureArg<1>(&statusRunning))
+    .WillOnce(FutureArg<1>(&statusFinished));
+
+  driver.launchTasks(offer.id(), {task});
+
+  AWAIT_READY_FOR(statusRunning, Seconds(120));
+  EXPECT_EQ(task.task_id(), statusRunning->task_id());
+  EXPECT_EQ(TASK_RUNNING, statusRunning->state());
+
+  AWAIT_READY(statusFinished);
+  EXPECT_EQ(task.task_id(), statusFinished->task_id());
+  EXPECT_EQ(TASK_FINISHED, statusFinished->state());
+
+  driver.stop();
+  driver.join();
+
+  Shutdown();
+}
+#endif
+
+// TODO(jojy): Add integration test for image with dependencies.
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {