You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ch...@apache.org on 2018/11/29 18:32:02 UTC

[mesos] 03/09: Rewrote test `ReconcileDroppedOperation` for `CREATE_DISK`.

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

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

commit 37d6a222ab25c37cc0b5def45825583f65b11c00
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Wed Nov 14 21:03:19 2018 -0800

    Rewrote test `ReconcileDroppedOperation` for `CREATE_DISK`.
    
    Previously the `ReconcileDroppedOperation` test relies on converting
    preprovisioned volumes. To adapt the new semantics for `CREATE_DISK`,
    this test is rewritten to create two disks from a storage pool, with one
    operation dropped.
    
    Review: https://reviews.apache.org/r/69359
---
 .../storage_local_resource_provider_tests.cpp      | 74 +++++++++++-----------
 1 file changed, 37 insertions(+), 37 deletions(-)

diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index e5751a2..6058396 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -3720,15 +3720,20 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_CsiPluginRpcMetrics)
 
 
 // Master reconciles operations that are missing from a reregistering slave.
-// In this case, the `ApplyOperationMessage` is dropped, so the resource
-// provider should send OPERATION_DROPPED. Operations on agent default
-// resources are also tested here; for such operations, the agent generates the
-// dropped status.
+// In this case, one of the two `ApplyOperationMessage`s is dropped, so the
+// resource provider should send only one OPERATION_DROPPED.
+//
+// TODO(greggomann): Test operations on agent default resources: for such
+// operations, the agent generates the dropped status.
 TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
 {
   Clock::pause();
 
-  setupResourceProviderConfig(Bytes(0), "volume1:2GB;volume2:2GB");
+  const string profilesPath = path::join(sandbox.get(), "profiles.json");
+  ASSERT_SOME(os::write(profilesPath, createDiskProfileMapping("test")));
+  loadUriDiskProfileAdaptorModule(profilesPath);
+
+  setupResourceProviderConfig(Gigabytes(4));
 
   master::Flags masterFlags = CreateMasterFlags();
   Try<Owned<cluster::Master>> master = StartMaster(masterFlags);
@@ -3740,6 +3745,7 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
   slaveFlags.isolation = "filesystem/linux";
 
   slaveFlags.resource_provider_config_dir = resourceProviderConfigDir;
+  slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
 
   Future<SlaveRegisteredMessage> slaveRegisteredMessage =
     FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
@@ -3795,40 +3801,33 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
   EXPECT_CALL(sched, resourceOffers(&driver, _))
     .WillRepeatedly(DeclineOffers(declineFilters));
 
-  // We are only interested in pre-existing volumes, which have IDs but no
-  // profile. We use pre-existing volumes to make it easy to send multiple
-  // operations on multiple resources.
-  auto isPreExistingVolume = [](const Resource& r) {
+  auto isRaw = [](const Resource& r) {
     return r.has_disk() &&
       r.disk().has_source() &&
-      r.disk().source().has_id() &&
-      !r.disk().source().has_profile();
+      r.disk().source().has_profile() &&
+      r.disk().source().type() == Resource::DiskInfo::Source::RAW;
   };
 
   Future<vector<Offer>> offersBeforeOperations;
 
-  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
-      isPreExistingVolume)))
+  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(isRaw)))
     .WillOnce(FutureArg<1>(&offersBeforeOperations))
     .WillRepeatedly(DeclineOffers(declineFilters)); // Decline further offers.
 
   driver.start();
 
   AWAIT_READY(offersBeforeOperations);
-  ASSERT_FALSE(offersBeforeOperations->empty());
-
-  vector<Resource> sources;
+  ASSERT_EQ(1u, offersBeforeOperations->size());
 
-  foreach (
-      const Resource& resource,
-      offersBeforeOperations->at(0).resources()) {
-    if (isPreExistingVolume(resource) &&
-        resource.disk().source().type() == Resource::DiskInfo::Source::RAW) {
-      sources.push_back(resource);
-    }
-  }
+  Resources raw =
+    Resources(offersBeforeOperations->at(0).resources()).filter(isRaw);
 
-  ASSERT_EQ(2u, sources.size());
+  // Create two MOUNT disks of 2GB each.
+  ASSERT_SOME_EQ(Gigabytes(4), raw.disk());
+  Resource source1 = *raw.begin();
+  source1.mutable_scalar()->set_value(
+      static_cast<double>(Gigabytes(2).bytes()) / Bytes::MEGABYTES);
+  Resource source2 = *(raw - source1).begin();
 
   // Drop one of the operations on the way to the agent.
   Future<ApplyOperationMessage> applyOperationMessage =
@@ -3846,8 +3845,8 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
   // Attempt the creation of two volumes.
   driver.acceptOffers(
       {offersBeforeOperations->at(0).id()},
-      {CREATE_DISK(sources.at(0), Resource::DiskInfo::Source::MOUNT),
-       CREATE_DISK(sources.at(1), Resource::DiskInfo::Source::MOUNT)},
+      {CREATE_DISK(source1, Resource::DiskInfo::Source::MOUNT),
+       CREATE_DISK(source2, Resource::DiskInfo::Source::MOUNT)},
       acceptFilters);
 
   // Ensure that the operations are processed.
@@ -3894,8 +3893,15 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
 
   Future<vector<Offer>> offersAfterOperations;
 
-  EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
-      isPreExistingVolume)))
+  auto isMountDisk = [](const Resource& r) {
+    return r.has_disk() &&
+      r.disk().has_source() &&
+      r.disk().source().has_profile() &&
+      r.disk().source().type() == Resource::DiskInfo::Source::MOUNT;
+  };
+
+  EXPECT_CALL(
+      sched, resourceOffers(&driver, OffersHaveAnyResource(isMountDisk)))
     .WillOnce(FutureArg<1>(&offersAfterOperations));
 
   // Advance the clock to trigger a batch allocation.
@@ -3904,14 +3910,8 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_ReconcileDroppedOperation)
   AWAIT_READY(offersAfterOperations);
   ASSERT_FALSE(offersAfterOperations->empty());
 
-  vector<Resource> converted;
-
-  foreach (const Resource& resource, offersAfterOperations->at(0).resources()) {
-    if (isPreExistingVolume(resource) &&
-        resource.disk().source().type() == Resource::DiskInfo::Source::MOUNT) {
-      converted.push_back(resource);
-    }
-  }
+  Resources converted =
+    Resources(offersAfterOperations->at(0).resources()).filter(isMountDisk);
 
   ASSERT_EQ(1u, converted.size());