This is an automated email from the ASF dual-hosted git repository.

chhsiao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 7c852a984c61f8ccd60eaf45749603f8f08e3043
Author: Chun-Hung Hsiao <[email protected]>
AuthorDate: Thu Dec 6 15:26:34 2018 -0800

    Tested the `Resource.DiskInfo.Source.vendor` field in related tests.
    
    Review: https://reviews.apache.org/r/69522
---
 src/tests/resources_tests.cpp                      | 32 ++++++++-----
 .../storage_local_resource_provider_tests.cpp      | 53 +++++++++++++++++++---
 2 files changed, 68 insertions(+), 17 deletions(-)

diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index ab42374..5337a5c 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -19,6 +19,7 @@
 #include <set>
 #include <sstream>
 #include <string>
+#include <tuple>
 
 #include <gtest/gtest.h>
 
@@ -2370,10 +2371,11 @@ TEST(DiskResourcesTest, DiskSourceEquals)
 
 class DiskResourcesSourceTest
   : public ::testing::Test,
-    public ::testing::WithParamInterface<std::tr1::tuple<
+    public ::testing::WithParamInterface<std::tuple<
         Resource::DiskInfo::Source::Type,
-        bool,
-        bool>> {};
+        bool, // Whether the disk has the `vendor` field set.
+        bool, // Whether the disk has the `id` field set.
+        bool>> {}; // Whether the disk has the `profile` field set.
 
 
 INSTANTIATE_TEST_CASE_P(
@@ -2386,11 +2388,14 @@ INSTANTIATE_TEST_CASE_P(
             Resource::DiskInfo::Source::PATH,
             Resource::DiskInfo::Source::BLOCK,
             Resource::DiskInfo::Source::MOUNT),
-        // We test the case where the source has identity (i.e., has
-        // an `id` set) and where not.
+        // We test the cases where the source has a vendor (i.e., has the
+        // `vendor` field set) and where not.
         ::testing::Bool(),
-        // We test the case where the source has profile (i.e., has
-        // an `profile` set) and where not.
+        // We test the cases where the source has an identity (i.e., has the
+        // `id` field set) and where not.
+        ::testing::Bool(),
+        // We test the cases where the source has a profile (i.e., has the
+        // `profile` field set) and where not.
         ::testing::Bool()));
 
 
@@ -2398,14 +2403,19 @@ TEST_P(DiskResourcesSourceTest, SourceIdentity)
 {
   auto parameters = GetParam();
 
-  Resource::DiskInfo::Source::Type type = std::tr1::get<0>(parameters);
-  bool hasIdentity = std::tr1::get<1>(parameters);
-  bool hasProfile = std::tr1::get<2>(parameters);
+  Resource::DiskInfo::Source::Type type = std::get<0>(parameters);
+  bool hasVendor = std::get<1>(parameters);
+  bool hasIdentity = std::get<2>(parameters);
+  bool hasProfile = std::get<3>(parameters);
 
-  // Create a disk, possibly with an id to signify identiy.
+  // Create a disk, possibly with an id to signify identity.
   Resource::DiskInfo::Source source;
   source.set_type(type);
 
+  if (hasVendor) {
+    source.set_vendor("vendor");
+  }
+
   if (hasIdentity) {
     source.set_id("id");
   }
diff --git a/src/tests/storage_local_resource_provider_tests.cpp 
b/src/tests/storage_local_resource_provider_tests.cpp
index 422a152..7887bd5 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -81,6 +81,9 @@ constexpr char URI_DISK_PROFILE_ADAPTOR_NAME[] =
 
 constexpr char TEST_SLRP_TYPE[] = "org.apache.mesos.rp.local.storage";
 constexpr char TEST_SLRP_NAME[] = "test";
+constexpr char TEST_CSI_PLUGIN_TYPE[] = "org.apache.mesos.csi.test";
+constexpr char TEST_CSI_PLUGIN_NAME[] = "local";
+constexpr char TEST_CSI_VENDOR[] = "org.apache.mesos.csi.test.local";
 
 
 class StorageLocalResourceProviderTest
@@ -196,13 +199,10 @@ public:
       const Option<string> volumes = None(),
       const Option<string> createParameters = None())
   {
-    const string testCsiPluginName = "test_csi_plugin";
-
     const string testCsiPluginPath =
       path::join(tests::flags.build_dir, "src", "test-csi-plugin");
 
-    const string testCsiPluginWorkDir =
-      path::join(sandbox.get(), testCsiPluginName);
+    const string testCsiPluginWorkDir = path::join(sandbox.get(), "storage");
     ASSERT_SOME(os::mkdir(testCsiPluginWorkDir));
 
     Try<string> resourceProviderConfig = strings::format(
@@ -218,7 +218,7 @@ public:
           ],
           "storage": {
             "plugin": {
-              "type": "org.apache.mesos.csi.test",
+              "type": "%s",
               "name": "%s",
               "containers": [
                 {
@@ -261,7 +261,8 @@ public:
         )~",
         TEST_SLRP_TYPE,
         TEST_SLRP_NAME,
-        testCsiPluginName,
+        TEST_CSI_PLUGIN_TYPE,
+        TEST_CSI_PLUGIN_NAME,
         testCsiPluginPath,
         testCsiPluginPath,
         stringify(capacity),
@@ -516,6 +517,8 @@ TEST_F(StorageLocalResourceProviderTest, DISABLED_SmallDisk)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       !r.disk().source().has_id() &&
       r.disk().source().has_profile();
   };
@@ -523,6 +526,8 @@ TEST_F(StorageLocalResourceProviderTest, DISABLED_SmallDisk)
   auto isPreExistingVolume = [](const Resource& r) {
     return r.has_disk() &&
       r.disk().has_source() &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       r.disk().source().has_id() &&
       !r.disk().source().has_profile();
   };
@@ -677,6 +682,8 @@ TEST_F(StorageLocalResourceProviderTest, ProfileAppeared)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       !r.disk().source().has_id() &&
       r.disk().source().has_profile() &&
       r.disk().source().profile() == profile;
@@ -812,6 +819,8 @@ TEST_F(StorageLocalResourceProviderTest, CreateDestroyDisk)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -855,6 +864,8 @@ TEST_F(StorageLocalResourceProviderTest, CreateDestroyDisk)
   }
 
   ASSERT_SOME(destroyed);
+  ASSERT_TRUE(destroyed->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, destroyed->disk().source().vendor());
   ASSERT_FALSE(destroyed->disk().source().has_id());
   ASSERT_FALSE(destroyed->disk().source().has_metadata());
   ASSERT_FALSE(destroyed->disk().source().has_mount());
@@ -992,6 +1003,8 @@ TEST_F(StorageLocalResourceProviderTest, 
CreateDestroyDiskRecovery)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -1062,6 +1075,8 @@ TEST_F(StorageLocalResourceProviderTest, 
CreateDestroyDiskRecovery)
   }
 
   ASSERT_SOME(destroyed);
+  ASSERT_TRUE(destroyed->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, destroyed->disk().source().vendor());
   ASSERT_FALSE(destroyed->disk().source().has_id());
   ASSERT_FALSE(destroyed->disk().source().has_metadata());
   ASSERT_FALSE(destroyed->disk().source().has_mount());
@@ -1504,6 +1519,8 @@ TEST_F(StorageLocalResourceProviderTest, 
AgentRegisteredWithNewId)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       !r.disk().source().has_id() &&
       r.disk().source().has_profile() &&
       r.disk().source().profile() == profile;
@@ -1526,6 +1543,8 @@ TEST_F(StorageLocalResourceProviderTest, 
AgentRegisteredWithNewId)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::MOUNT &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       r.disk().source().has_id() &&
       r.disk().source().has_profile() &&
       r.disk().source().profile() == profile;
@@ -1554,6 +1573,8 @@ TEST_F(StorageLocalResourceProviderTest, 
AgentRegisteredWithNewId)
     .begin();
 
   ASSERT_TRUE(created.has_provider_id());
+  ASSERT_TRUE(created.disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, created.disk().source().vendor());
   ASSERT_TRUE(created.disk().source().has_id());
   ASSERT_TRUE(created.disk().source().has_metadata());
   ASSERT_TRUE(created.disk().source().has_mount());
@@ -1604,6 +1625,8 @@ TEST_F(StorageLocalResourceProviderTest, 
AgentRegisteredWithNewId)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       r.disk().source().has_id() &&
       !r.disk().source().has_profile();
   };
@@ -1813,6 +1836,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ROOT_PublishResources)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -2030,6 +2055,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ROOT_PublishResourcesRecovery)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -2299,6 +2326,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ROOT_PublishResourcesReboot)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -2633,6 +2662,8 @@ TEST_F(
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -2807,6 +2838,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ImportPreprovisionedVolume)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       !r.disk().source().has_id() &&
       r.disk().source().has_profile() &&
       r.disk().source().profile() == profile;
@@ -2831,6 +2864,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ImportPreprovisionedVolume)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::RAW &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       r.disk().source().has_id() &&
       !r.disk().source().has_profile();
   };
@@ -2860,6 +2895,8 @@ TEST_F(StorageLocalResourceProviderTest, 
ImportPreprovisionedVolume)
     return r.has_disk() &&
       r.disk().has_source() &&
       r.disk().source().type() == Resource::DiskInfo::Source::MOUNT &&
+      r.disk().source().has_vendor() &&
+      r.disk().source().vendor() == TEST_CSI_VENDOR &&
       r.disk().source().has_id() &&
       r.disk().source().has_profile() &&
       r.disk().source().profile() == profile;
@@ -3466,6 +3503,8 @@ TEST_F(StorageLocalResourceProviderTest, 
OperationStateMetrics)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());
@@ -3742,6 +3781,8 @@ TEST_F(StorageLocalResourceProviderTest, 
CsiPluginRpcMetrics)
   }
 
   ASSERT_SOME(volume);
+  ASSERT_TRUE(volume->disk().source().has_vendor());
+  EXPECT_EQ(TEST_CSI_VENDOR, volume->disk().source().vendor());
   ASSERT_TRUE(volume->disk().source().has_id());
   ASSERT_TRUE(volume->disk().source().has_metadata());
   ASSERT_TRUE(volume->disk().source().has_mount());

Reply via email to