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/02/09 00:37:33 UTC
[1/2] mesos git commit: Changed ProvisionerAppcTest to use
AppcStoreTest suite.
Repository: mesos
Updated Branches:
refs/heads/master 67017f136 -> 748a60e00
Changed ProvisionerAppcTest to use AppcStoreTest suite.
This change will enable ProvisionerAppcTest suite to reuse common code
like test image creation.
Review: https://reviews.apache.org/r/42157/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/748a60e0
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/748a60e0
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/748a60e0
Branch: refs/heads/master
Commit: 748a60e007c8760b13d0795e8f344231092f1666
Parents: 1ee4ee7
Author: Jojy Varghese <jo...@mesosphere.io>
Authored: Mon Feb 8 15:12:15 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Feb 8 15:37:30 2016 -0800
----------------------------------------------------------------------
.../containerizer/provisioner_appc_tests.cpp | 80 ++------------------
1 file changed, 5 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/748a60e0/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 2ebddbb..e0aa856 100644
--- a/src/tests/containerizer/provisioner_appc_tests.cpp
+++ b/src/tests/containerizer/provisioner_appc_tests.cpp
@@ -250,7 +250,7 @@ TEST_F(AppcStoreTest, Recover)
}
-class ProvisionerAppcTest : public TemporaryDirectoryTest {};
+class ProvisionerAppcTest : public AppcStoreTest {};
#ifdef __linux__
@@ -270,54 +270,9 @@ TEST_F(ProvisionerAppcTest, ROOT_Provision)
Try<Owned<Provisioner>> provisioner = Provisioner::create(flags);
ASSERT_SOME(provisioner);
- // Create a simple image in the store:
- // <store>
- // |--images
- // |--<id>
- // |--manifest
- // |--rootfs/tmp/test
- JSON::Value manifest = JSON::parse(
- "{"
- " \"acKind\": \"ImageManifest\","
- " \"acVersion\": \"0.6.1\","
- " \"name\": \"foo.com/bar\","
- " \"labels\": ["
- " {"
- " \"name\": \"version\","
- " \"value\": \"1.0.0\""
- " },"
- " {"
- " \"name\": \"arch\","
- " \"value\": \"amd64\""
- " },"
- " {"
- " \"name\": \"os\","
- " \"value\": \"linux\""
- " }"
- " ],"
- " \"annotations\": ["
- " {"
- " \"name\": \"created\","
- " \"value\": \"1438983392\""
- " }"
- " ]"
- "}").get();
-
- // The 'imageId' below has the correct format but it's not computed
- // by hashing the tarball of the image. It's OK here as we assume
- // the images under 'images' have passed such check when they are
- // downloaded and validated.
- string imageId =
- "sha512-e77d96aa0240eedf134b8c90baeaf76dca8e78691836301d7498c84020446042e"
- "797b296d6ab296e0954c2626bfb264322ebeb8f447dac4fac6511ea06bc61f0";
-
- string imagePath = path::join(flags.appc_store_dir, "images", imageId);
+ Try<string> createImage = createTestImage(flags.appc_store_dir);
- ASSERT_SOME(os::mkdir(path::join(imagePath, "rootfs", "tmp")));
- ASSERT_SOME(
- os::write(path::join(imagePath, "rootfs", "tmp", "test"), "test"));
- ASSERT_SOME(
- os::write(path::join(imagePath, "manifest"), stringify(manifest)));
+ ASSERT_SOME(createImage);
// Recover. This is when the image in the store is loaded.
AWAIT_READY(provisioner.get()->recover({}, {}));
@@ -381,34 +336,9 @@ TEST_F(ProvisionerAppcTest, Recover)
Try<Owned<Provisioner>> provisioner1 = Provisioner::create(flags);
ASSERT_SOME(provisioner1);
- // Create a simple image in the store:
- // <store>
- // |--images
- // |--<id>
- // |--manifest
- // |--rootfs/tmp/test
- JSON::Value manifest = JSON::parse(
- "{"
- " \"acKind\": \"ImageManifest\","
- " \"acVersion\": \"0.6.1\","
- " \"name\": \"foo.com/bar\""
- "}").get();
+ Try<string> createImage = createTestImage(flags.appc_store_dir);
- // The 'imageId' below has the correct format but it's not computed
- // by hashing the tarball of the image. It's OK here as we assume
- // the images under 'images' have passed such check when they are
- // downloaded and validated.
- string imageId =
- "sha512-e77d96aa0240eedf134b8c90baeaf76dca8e78691836301d7498c84020446042e"
- "797b296d6ab296e0954c2626bfb264322ebeb8f447dac4fac6511ea06bc61f0";
-
- string imagePath = path::join(flags.appc_store_dir, "images", imageId);
-
- ASSERT_SOME(os::mkdir(path::join(imagePath, "rootfs", "tmp")));
- ASSERT_SOME(
- os::write(path::join(imagePath, "rootfs", "tmp", "test"), "test"));
- ASSERT_SOME(
- os::write(path::join(imagePath, "manifest"), stringify(manifest)));
+ ASSERT_SOME(createImage);
// Recover. This is when the image in the store is loaded.
AWAIT_READY(provisioner1.get()->recover({}, {}));
[2/2] mesos git commit: Refactored up the common image creation in
appc tests.
Posted by ji...@apache.org.
Refactored up the common image creation in appc tests.
This change will enable other tests to reuse the common test image
creation logic.
Review: https://reviews.apache.org/r/42156/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1ee4ee79
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1ee4ee79
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1ee4ee79
Branch: refs/heads/master
Commit: 1ee4ee794a20bacd353435e401d15f410fc1d31f
Parents: 67017f1
Author: Jojy Varghese <jo...@mesosphere.io>
Authored: Mon Feb 8 15:09:48 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Feb 8 15:37:30 2016 -0800
----------------------------------------------------------------------
.../containerizer/provisioner_appc_tests.cpp | 145 +++++++++++++------
1 file changed, 98 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/1ee4ee79/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 012dba4..2ebddbb 100644
--- a/src/tests/containerizer/provisioner_appc_tests.cpp
+++ b/src/tests/containerizer/provisioner_appc_tests.cpp
@@ -35,6 +35,8 @@
#include "slave/containerizer/mesos/provisioner/paths.hpp"
#include "slave/containerizer/mesos/provisioner/provisioner.hpp"
+
+#include "slave/containerizer/mesos/provisioner/appc/paths.hpp"
#include "slave/containerizer/mesos/provisioner/appc/store.hpp"
using std::list;
@@ -54,6 +56,7 @@ namespace mesos {
namespace internal {
namespace tests {
+// TODO(jojy): Move AppcSpecTest to its own test file.
class AppcSpecTest : public TemporaryDirectoryTest {};
@@ -123,7 +126,98 @@ TEST_F(AppcSpecTest, ValidateLayout)
}
-class AppcStoreTest : public TemporaryDirectoryTest {};
+class AppcStoreTest : public TemporaryDirectoryTest
+{
+protected:
+ // Reusable method to create a simple test image directory inside the store
+ // directory. The directory structure reflects the Appc image spec.
+ //
+ // @param storeDir Path to the store directory where all images are stored.
+ // @return Path to the test image directory.
+ Try<string> createTestImage(const string& storeDir)
+ {
+ Try<Nothing> mkdir = os::mkdir(storeDir, true);
+ if (mkdir.isError()) {
+ return mkdir.error();
+ }
+
+ // Create a simple image in the store:
+ // <store>
+ // |--images
+ // |--<id>
+ // |--manifest
+ // |--rootfs/tmp/test
+ JSON::Value manifest = JSON::parse(
+ "{"
+ " \"acKind\": \"ImageManifest\","
+ " \"acVersion\": \"0.6.1\","
+ " \"name\": \"foo.com/bar\","
+ " \"labels\": ["
+ " {"
+ " \"name\": \"version\","
+ " \"value\": \"1.0.0\""
+ " },"
+ " {"
+ " \"name\": \"arch\","
+ " \"value\": \"amd64\""
+ " },"
+ " {"
+ " \"name\": \"os\","
+ " \"value\": \"linux\""
+ " }"
+ " ],"
+ " \"annotations\": ["
+ " {"
+ " \"name\": \"created\","
+ " \"value\": \"1438983392\""
+ " }"
+ " ]"
+ "}").get();
+
+ // The 'imageId' below has the correct format but it's not computed
+ // by hashing the tarball of the image. It's OK here as we assume
+ // the images under 'images' have passed such check when they are
+ // downloaded and validated.
+ const string imageId =
+ "sha512-e77d96aa0240eedf134b8c90baeaf76dca8e78691836301d7498c84020446042e"
+ "797b296d6ab296e0954c2626bfb264322ebeb8f447dac4fac6511ea06bc61f0";
+
+ // Create rootfs inside the store directory.
+ const string rootfsPath = paths::getImageRootfsPath(storeDir, imageId);
+
+ Try<Nothing> mkRootfsDir = os::mkdir(rootfsPath);
+ if (mkRootfsDir.isError()) {
+ return mkRootfsDir.error();
+ }
+
+ // Create tmp directory inside rootfs.
+ const string tmpDirPath = path::join(rootfsPath, "tmp");
+
+ Try<Nothing> mkTmpDir = os::mkdir(tmpDirPath);
+ if (mkTmpDir.isError()) {
+ return mkTmpDir.error();
+ }
+
+ // Create test file in the tmp directory.
+ Try<Nothing> testFileWrite =
+ os::write(path::join(tmpDirPath, "test"), "test");
+
+ if (testFileWrite.isError()) {
+ return testFileWrite.error();
+ }
+
+ // Create manifest in the image directory.
+ Try<Nothing> manifestWrite = os::write(
+ paths::getImageManifestPath(storeDir, imageId),
+ stringify(manifest));
+
+ if (manifestWrite.isError()) {
+ return manifestWrite.error();
+ }
+
+ return paths::getImagePath(storeDir, imageId);
+ }
+};
TEST_F(AppcStoreTest, Recover)
@@ -134,54 +228,11 @@ TEST_F(AppcStoreTest, Recover)
Try<Owned<slave::Store>> store = Store::create(flags);
ASSERT_SOME(store);
- // Create a simple image in the store:
- // <store>
- // |--images
- // |--<id>
- // |--manifest
- // |--rootfs/tmp/test
- JSON::Value manifest = JSON::parse(
- "{"
- " \"acKind\": \"ImageManifest\","
- " \"acVersion\": \"0.6.1\","
- " \"name\": \"foo.com/bar\","
- " \"labels\": ["
- " {"
- " \"name\": \"version\","
- " \"value\": \"1.0.0\""
- " },"
- " {"
- " \"name\": \"arch\","
- " \"value\": \"amd64\""
- " },"
- " {"
- " \"name\": \"os\","
- " \"value\": \"linux\""
- " }"
- " ],"
- " \"annotations\": ["
- " {"
- " \"name\": \"created\","
- " \"value\": \"1438983392\""
- " }"
- " ]"
- "}").get();
-
- // The 'imageId' below has the correct format but it's not computed
- // by hashing the tarball of the image. It's OK here as we assume
- // the images under 'images' have passed such check when they are
- // downloaded and validated.
- string imageId =
- "sha512-e77d96aa0240eedf134b8c90baeaf76dca8e78691836301d7498c84020446042e"
- "797b296d6ab296e0954c2626bfb264322ebeb8f447dac4fac6511ea06bc61f0";
+ Try<string> createImage = createTestImage(flags.appc_store_dir);
- string imagePath = path::join(flags.appc_store_dir, "images", imageId);
+ ASSERT_SOME(createImage);
- ASSERT_SOME(os::mkdir(path::join(imagePath, "rootfs", "tmp")));
- ASSERT_SOME(
- os::write(path::join(imagePath, "rootfs", "tmp", "test"), "test"));
- ASSERT_SOME(
- os::write(path::join(imagePath, "manifest"), stringify(manifest)));
+ const string imagePath = createImage.get();
// Recover the image from disk.
AWAIT_READY(store.get()->recover());