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 2019/05/02 22:46:57 UTC
[mesos] branch master updated (6bc1c80 -> 18bc6c9)
This is an automated email from the ASF dual-hosted git repository.
chhsiao pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git.
from 6bc1c80 Fixed the flaky ExamplesTest.DynamicReservationFramework.
new 5eff8b2 Made the `RetryRpcWithExponentialBackoff` SLRP test work with CSI v1.
new 75d718f Added a SLRP unit test for persistent block volume creation.
new 18bc6c9 Added SLRP unit tests for destroying unpublished persistent volumes.
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/examples/test_csi_plugin.cpp | 53 +-
src/tests/mock_csi_plugin.cpp | 54 +-
.../storage_local_resource_provider_tests.cpp | 1383 ++++++++++++++++----
3 files changed, 1195 insertions(+), 295 deletions(-)
[mesos] 03/03: Added SLRP unit tests for destroying unpublished
persistent volumes.
Posted by ch...@apache.org.
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 18bc6c95a67e2ac2dd4d5557608d75b7fb01d383
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Mon Feb 11 20:52:26 2019 -0800
Added SLRP unit tests for destroying unpublished persistent volumes.
This patch adds 3 unit tests: `DestroyUnpublishedPersistentVolume`,
`DestroyUnpublishedPersistentVolumeWithRecovery`, and
`DestroyUnpublishedPersistentVolumeWithReboot` to test that the SLRP is
resilient to misbehaved CSI plugins that fail to publish volumes.
Review: https://reviews.apache.org/r/69955
---
.../storage_local_resource_provider_tests.cpp | 667 +++++++++++++++++++++
1 file changed, 667 insertions(+)
diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index efc03c2..a2d2705 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -416,6 +416,46 @@ public:
UNREACHABLE();
}
+ // Set up an expected `NodePublishVolume` CSI call for a given mock CSI
+ // plugin. When the call is made to the mock plugin, `result` will be
+ // responded. When the response is received by the volume manager, the
+ // returned future will be satisfied.
+ Future<Nothing> futureNodePublishVolumeCall(
+ MockCSIPlugin* plugin, const Try<Nothing, StatusError>& result)
+ {
+ if (GetParam() == csi::v0::API_VERSION) {
+ EXPECT_CALL(*plugin, NodePublishVolume(
+ _, _, A<csi::v0::NodePublishVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v0::NodePublishVolumeRequest* request,
+ csi::v0::NodePublishVolumeResponse* response) {
+ return result.isError() ? result.error().status : grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v0::VolumeManagerProcess::__call<
+ csi::v0::NodePublishVolumeResponse>);
+ } else if (GetParam() == csi::v1::API_VERSION) {
+ EXPECT_CALL(*plugin, NodePublishVolume(
+ _, _, A<csi::v1::NodePublishVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v1::NodePublishVolumeRequest* request,
+ csi::v1::NodePublishVolumeResponse* response) {
+ return result.isError() ? result.error().status : grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v1::VolumeManagerProcess::__call<
+ csi::v1::NodePublishVolumeResponse>);
+ }
+
+ // This extra closure is necessary in order to use `FAIL` as it requires a
+ // void return type.
+ [&] { FAIL() << "Unsupported CSI API version " << GetParam(); }();
+
+ UNREACHABLE();
+ }
+
// Create a JSON string representing a disk profile mapping containing the
// given profile-parameter pairs.
static string createDiskProfileMapping(
@@ -3130,6 +3170,633 @@ TEST_P(StorageLocalResourceProviderTest, CreatePersistentBlockVolume)
}
+// This test verifies that if a persistent volumes is never published by the
+// storage local resource provider, the volume can be destroyed.
+//
+// To accomplish this:
+// 1. Create a MOUNT disk from a RAW disk resource.
+// 2. Create a persistent volume on the MOUNT disk then launches a task to
+// write a file into it.
+// 3. Return `UNIMPLEMENTED` for the `NodePublishVolume` call. The task will
+// fail to launch.
+// 4. Destroy the persistent volume and the MOUNT disk.
+TEST_P(StorageLocalResourceProviderTest, DestroyUnpublishedPersistentVolume)
+{
+ const string profilesPath = path::join(sandbox.get(), "profiles.json");
+
+ ASSERT_SOME(
+ os::write(profilesPath, createDiskProfileMapping({{"test", None()}})));
+
+ loadUriDiskProfileAdaptorModule(profilesPath);
+
+ const string mockCsiEndpoint =
+ "unix://" + path::join(sandbox.get(), "mock_csi.sock");
+
+ MockCSIPlugin plugin;
+ ASSERT_SOME(plugin.startup(mockCsiEndpoint));
+
+ setupResourceProviderConfig(Bytes(0), None(), None(), mockCsiEndpoint);
+
+ Try<Owned<cluster::Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Owned<MasterDetector> detector = master.get()->createDetector();
+
+ slave::Flags slaveFlags = CreateSlaveFlags();
+ slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ // Register a framework to exercise operations.
+ FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
+ framework.set_roles(0, "storage");
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, framework, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ // We use the following filter to filter offers that do not have wanted
+ // resources for 365 days (the maximum).
+ Filters declineFilters;
+ declineFilters.set_refuse_seconds(Days(365).secs());
+
+ // Decline unwanted offers. The master can send such offers before the
+ // resource provider receives profile updates.
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ Offer offer = offers->at(0);
+
+ // Create a MOUNT disk.
+ Resource raw = *Resources(offer.resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .begin();
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isMountDisk<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {CREATE_DISK(raw, Resource::DiskInfo::Source::MOUNT)});
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ Resource created = *Resources(offer.resources())
+ .filter(std::bind(isMountDisk<Resource>, lambda::_1, "test"))
+ .begin();
+
+ // Create a persistent MOUNT volume then launch a task to write a file.
+ Resource persistentVolume = created;
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_id(id::UUID::random().toString());
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_principal(framework.principal());
+ persistentVolume.mutable_disk()->mutable_volume()
+ ->set_container_path("volume");
+ persistentVolume.mutable_disk()->mutable_volume()->set_mode(Volume::RW);
+
+ Future<Nothing> taskFailed;
+ EXPECT_CALL(sched, statusUpdate(&driver, TaskStatusStateEq(TASK_FAILED)))
+ .WillOnce(FutureSatisfy(&taskFailed));
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(persistentVolume)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ // Fail resource publishing.
+ Future<Nothing> nodePublishVolumeCall = futureNodePublishVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNIMPLEMENTED, "")));
+
+ driver.acceptOffers(
+ {offer.id()},
+ {CREATE(persistentVolume),
+ LAUNCH({createTask(
+ offer.slave_id(),
+ persistentVolume,
+ createCommandInfo("touch " + path::join("volume", "file")))})});
+
+ AWAIT_READY(nodePublishVolumeCall);
+
+ AWAIT_READY(taskFailed);
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ // Destroy the persistent volume and the MOUNT disk.
+ //
+ // NOTE: The order of the two `FUTURE_PROTOBUF`s is reversed because
+ // Google Mock will search the expectations in reverse order.
+ Future<UpdateOperationStatusMessage> destroyDiskOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+ Future<UpdateOperationStatusMessage> destroyOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveResource(raw)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {DESTROY(persistentVolume), DESTROY_DISK(created)});
+
+ AWAIT_READY(destroyOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyOperationStatus->status().state());
+
+ AWAIT_READY(destroyDiskOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyDiskOperationStatus->status().state());
+
+ AWAIT_EXPECT_READY(offers)
+ << "Failed to wait for an offer containing resource '" << raw << "'";
+}
+
+
+// This test verifies that if a persistent volumes is never published by the
+// storage local resource provider, the volume can be destroyed after recovery.
+//
+// To accomplish this:
+// 1. Create a MOUNT disk from a RAW disk resource.
+// 2. Create a persistent volume on the MOUNT disk then launches a task to
+// write a file into it.
+// 3. Return `UNIMPLEMENTED` for the `NodePublishVolume` call. The task will
+// fail to launch.
+// 4. Restart the agent.
+// 5. Destroy the persistent volume and the MOUNT disk.
+TEST_P(
+ StorageLocalResourceProviderTest,
+ DestroyUnpublishedPersistentVolumeWithRecovery)
+{
+ const string profilesPath = path::join(sandbox.get(), "profiles.json");
+
+ ASSERT_SOME(
+ os::write(profilesPath, createDiskProfileMapping({{"test", None()}})));
+
+ loadUriDiskProfileAdaptorModule(profilesPath);
+
+ const string mockCsiEndpoint =
+ "unix://" + path::join(sandbox.get(), "mock_csi.sock");
+
+ MockCSIPlugin plugin;
+ ASSERT_SOME(plugin.startup(mockCsiEndpoint));
+
+ setupResourceProviderConfig(Bytes(0), None(), None(), mockCsiEndpoint);
+
+ Try<Owned<cluster::Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Owned<MasterDetector> detector = master.get()->createDetector();
+
+ slave::Flags slaveFlags = CreateSlaveFlags();
+ slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ // Register a framework to exercise operations.
+ FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
+ framework.set_roles(0, "storage");
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, framework, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ // We use the following filter to filter offers that do not have wanted
+ // resources for 365 days (the maximum).
+ Filters declineFilters;
+ declineFilters.set_refuse_seconds(Days(365).secs());
+
+ // Decline unwanted offers. The master can send such offers before the
+ // resource provider receives profile updates.
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ Offer offer = offers->at(0);
+
+ // Create a MOUNT disk.
+ Resource raw = *Resources(offer.resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .begin();
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isMountDisk<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {CREATE_DISK(raw, Resource::DiskInfo::Source::MOUNT)});
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ Resource created = *Resources(offer.resources())
+ .filter(std::bind(isMountDisk<Resource>, lambda::_1, "test"))
+ .begin();
+
+ // Create a persistent MOUNT volume then launch a task to write a file.
+ Resource persistentVolume = created;
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_id(id::UUID::random().toString());
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_principal(framework.principal());
+ persistentVolume.mutable_disk()->mutable_volume()
+ ->set_container_path("volume");
+ persistentVolume.mutable_disk()->mutable_volume()->set_mode(Volume::RW);
+
+ Future<Nothing> taskFailed;
+ EXPECT_CALL(sched, statusUpdate(&driver, TaskStatusStateEq(TASK_FAILED)))
+ .WillOnce(FutureSatisfy(&taskFailed));
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(persistentVolume)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ // Fail resource publishing.
+ Future<Nothing> nodePublishVolumeCall = futureNodePublishVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNIMPLEMENTED, "")));
+
+ driver.acceptOffers(
+ {offer.id()},
+ {CREATE(persistentVolume),
+ LAUNCH({createTask(
+ offer.slave_id(),
+ persistentVolume,
+ createCommandInfo("touch " + path::join("volume", "file")))})});
+
+ AWAIT_READY(nodePublishVolumeCall);
+
+ AWAIT_READY(taskFailed);
+
+ AWAIT_READY(offers);
+
+ // Restart the agent.
+ EXPECT_CALL(sched, offerRescinded(_, _));
+
+ slave.get()->terminate();
+
+ // NOTE: The mock CSI plugin always returns 4GB for `GetCapacity` calls, hence
+ // the resource provider would report an extra storage pool, and when it shows
+ // up, we know that the resource provider has finished reconciling storage
+ // pools and thus operations won't be dropped.
+ //
+ // To achieve this, we drop `SlaveRegisteredMessage`s other than the first one
+ // to avoid unexpected `UpdateSlaveMessage`s. Then, we also drop the first two
+ // `UpdateSlaveMessage`s (one sent after agent reregistration and one after
+ // resource provider reregistration) and wait for the third one, which should
+ // contain the extra storage pool. We let it fall through to trigger an offer
+ // allocation for the persistent volume.
+ //
+ // Since the extra storage pool is never used, we reject the offers if only
+ // the storage pool is presented.
+ //
+ // TODO(chhsiao): Remove this workaround once MESOS-9553 is done.
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ // NOTE: The order of these expectations is reversed because Google Mock will
+ // search the expectations in reverse order.
+ Future<UpdateSlaveMessage> updateSlaveMessage =
+ FUTURE_PROTOBUF(UpdateSlaveMessage(), _, _);
+
+ DROP_PROTOBUF(UpdateSlaveMessage(), _, _);
+ DROP_PROTOBUF(UpdateSlaveMessage(), _, _);
+ DROP_PROTOBUFS(SlaveReregisteredMessage(), _, _);
+ FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(persistentVolume)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(updateSlaveMessage);
+ ASSERT_EQ(1, updateSlaveMessage->resource_providers().providers_size());
+ ASSERT_FALSE(Resources(
+ updateSlaveMessage->resource_providers().providers(0).total_resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .empty());
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ // Destroy the persistent volume and the MOUNT disk.
+ //
+ // NOTE: The order of the two `FUTURE_PROTOBUF`s is reversed because
+ // Google Mock will search the expectations in reverse order.
+ Future<UpdateOperationStatusMessage> destroyDiskOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+ Future<UpdateOperationStatusMessage> destroyOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveResource(raw)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {DESTROY(persistentVolume), DESTROY_DISK(created)});
+
+ AWAIT_READY(destroyOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyOperationStatus->status().state());
+
+ AWAIT_READY(destroyDiskOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyDiskOperationStatus->status().state());
+
+ AWAIT_EXPECT_READY(offers)
+ << "Failed to wait for an offer containing resource '" << raw << "'";
+}
+
+
+// This test verifies that if a persistent volumes is never published by the
+// storage local resource provider, the volume can be destroyed after agent
+// reboot.
+//
+// To accomplish this:
+// 1. Create a MOUNT disk from a RAW disk resource.
+// 2. Create a persistent volume on the MOUNT disk then launches a task to
+// write a file into it.
+// 3. Return `UNIMPLEMENTED` for the `NodePublishVolume` call. The task will
+// fail to launch.
+// 4. Simulate an agent reboot.
+// 5. Destroy the persistent volume and the MOUNT disk.
+TEST_P(
+ StorageLocalResourceProviderTest,
+ DestroyUnpublishedPersistentVolumeWithReboot)
+{
+ const string profilesPath = path::join(sandbox.get(), "profiles.json");
+
+ ASSERT_SOME(
+ os::write(profilesPath, createDiskProfileMapping({{"test", None()}})));
+
+ loadUriDiskProfileAdaptorModule(profilesPath);
+
+ const string mockCsiEndpoint =
+ "unix://" + path::join(sandbox.get(), "mock_csi.sock");
+
+ MockCSIPlugin plugin;
+ ASSERT_SOME(plugin.startup(mockCsiEndpoint));
+
+ setupResourceProviderConfig(Bytes(0), None(), None(), mockCsiEndpoint);
+
+ Try<Owned<cluster::Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Owned<MasterDetector> detector = master.get()->createDetector();
+
+ slave::Flags slaveFlags = CreateSlaveFlags();
+ slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ // Register a framework to exercise operations.
+ FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
+ framework.set_roles(0, "storage");
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, framework, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ // We use the following filter to filter offers that do not have wanted
+ // resources for 365 days (the maximum).
+ Filters declineFilters;
+ declineFilters.set_refuse_seconds(Days(365).secs());
+
+ // Decline unwanted offers. The master can send such offers before the
+ // resource provider receives profile updates.
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ Offer offer = offers->at(0);
+
+ // Create a MOUNT disk.
+ Resource raw = *Resources(offer.resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .begin();
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isMountDisk<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {CREATE_DISK(raw, Resource::DiskInfo::Source::MOUNT)});
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ Resource created = *Resources(offer.resources())
+ .filter(std::bind(isMountDisk<Resource>, lambda::_1, "test"))
+ .begin();
+
+ // Create a persistent MOUNT volume then launch a task to write a file.
+ Resource persistentVolume = created;
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_id(id::UUID::random().toString());
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_principal(framework.principal());
+ persistentVolume.mutable_disk()->mutable_volume()
+ ->set_container_path("volume");
+ persistentVolume.mutable_disk()->mutable_volume()->set_mode(Volume::RW);
+
+ Future<Nothing> taskFailed;
+ EXPECT_CALL(sched, statusUpdate(&driver, TaskStatusStateEq(TASK_FAILED)))
+ .WillOnce(FutureSatisfy(&taskFailed));
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(persistentVolume)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ // Fail resource publishing.
+ Future<Nothing> nodePublishVolumeCall = futureNodePublishVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNIMPLEMENTED, "")));
+
+ driver.acceptOffers(
+ {offer.id()},
+ {CREATE(persistentVolume),
+ LAUNCH({createTask(
+ offer.slave_id(),
+ persistentVolume,
+ createCommandInfo("touch " + path::join("volume", "file")))})});
+
+ AWAIT_READY(nodePublishVolumeCall);
+
+ AWAIT_READY(taskFailed);
+
+ AWAIT_READY(offers);
+
+ // Shutdown the agent and unmount all CSI volumes to simulate a reboot.
+ EXPECT_CALL(sched, offerRescinded(_, _));
+
+ slave->reset();
+
+ const string csiRootDir = slave::paths::getCsiRootDir(slaveFlags.work_dir);
+ ASSERT_SOME(fs::unmountAll(csiRootDir));
+
+ // Inject the boot IDs to simulate a reboot.
+ ASSERT_SOME(os::write(
+ slave::paths::getBootIdPath(
+ slave::paths::getMetaRootDir(slaveFlags.work_dir)),
+ "rebooted! ;)"));
+
+ Try<list<string>> volumePaths =
+ csi::paths::getVolumePaths(csiRootDir, "*", "*");
+ ASSERT_SOME(volumePaths);
+ ASSERT_FALSE(volumePaths->empty());
+
+ foreach (const string& path, volumePaths.get()) {
+ Try<csi::paths::VolumePath> volumePath =
+ csi::paths::parseVolumePath(csiRootDir, path);
+ ASSERT_SOME(volumePath);
+
+ const string volumeStatePath = csi::paths::getVolumeStatePath(
+ csiRootDir, volumePath->type, volumePath->name, volumePath->volumeId);
+
+ Result<csi::state::VolumeState> volumeState =
+ slave::state::read<csi::state::VolumeState>(volumeStatePath);
+
+ ASSERT_SOME(volumeState);
+
+ if (volumeState->state() == csi::state::VolumeState::PUBLISHED) {
+ volumeState->set_boot_id("rebooted! ;)");
+ ASSERT_SOME(slave::state::checkpoint(volumeStatePath, volumeState.get()));
+ }
+ }
+
+ // NOTE: The mock CSI plugin always returns 4GB for `GetCapacity` calls, hence
+ // the resource provider would report an extra storage pool, and when it shows
+ // up, we know that the resource provider has finished reconciling storage
+ // pools and thus operations won't be dropped.
+ //
+ // To achieve this, we drop `SlaveRegisteredMessage`s other than the first one
+ // to avoid unexpected `UpdateSlaveMessage`s. Then, we also drop the first two
+ // `UpdateSlaveMessage`s (one sent after agent reregistration and one after
+ // resource provider reregistration) and wait for the third one, which should
+ // contain the extra storage pool. We let it fall through to trigger an offer
+ // allocation for the persistent volume.
+ //
+ // Since the extra storage pool is never used, we reject the offers if only
+ // the storage pool is presented.
+ //
+ // TODO(chhsiao): Remove this workaround once MESOS-9553 is done.
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ // NOTE: The order of these expectations is reversed because Google Mock will
+ // search the expectations in reverse order.
+ Future<UpdateSlaveMessage> updateSlaveMessage =
+ FUTURE_PROTOBUF(UpdateSlaveMessage(), _, _);
+
+ DROP_PROTOBUF(UpdateSlaveMessage(), _, _);
+ DROP_PROTOBUF(UpdateSlaveMessage(), _, _);
+ DROP_PROTOBUFS(SlaveReregisteredMessage(), _, _);
+ FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _);
+
+ // Restart the agent.
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(persistentVolume)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(updateSlaveMessage);
+ ASSERT_EQ(1, updateSlaveMessage->resource_providers().providers_size());
+ ASSERT_FALSE(Resources(
+ updateSlaveMessage->resource_providers().providers(0).total_resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .empty());
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ // Destroy the persistent volume and the MOUNT disk.
+ //
+ // NOTE: The order of the two `FUTURE_PROTOBUF`s is reversed because
+ // Google Mock will search the expectations in reverse order.
+ Future<UpdateOperationStatusMessage> destroyDiskOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+ Future<UpdateOperationStatusMessage> destroyOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(raw)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers(
+ {offer.id()}, {DESTROY(persistentVolume), DESTROY_DISK(created)});
+
+ AWAIT_READY(destroyOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyOperationStatus->status().state());
+
+ AWAIT_READY(destroyDiskOperationStatus);
+ EXPECT_EQ(OPERATION_FINISHED, destroyDiskOperationStatus->status().state());
+
+ AWAIT_EXPECT_READY(offers)
+ << "Failed to wait for an offer containing resource '" << raw << "'";
+}
+
+
// This test verifies that if the storage local resource provider fails to clean
// up a persistent volume, the volume will not be destroyed.
//
[mesos] 02/03: Added a SLRP unit test for persistent block volume
creation.
Posted by ch...@apache.org.
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 75d718f3141d073593c4608bbe8d8027e1e1123a
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Wed Feb 6 12:29:37 2019 -0800
Added a SLRP unit test for persistent block volume creation.
Test `CreateDestroyPersistentBlockVolume` verifies that SLRP would fail
a `CREATE` operation on a BLOCK disk resource, and a followup `DESTROY`
will be dropped (instead of failing the SLRP).
Review: https://reviews.apache.org/r/69954
---
src/tests/mock_csi_plugin.cpp | 30 +++-
.../storage_local_resource_provider_tests.cpp | 162 +++++++++++++++++++++
2 files changed, 190 insertions(+), 2 deletions(-)
diff --git a/src/tests/mock_csi_plugin.cpp b/src/tests/mock_csi_plugin.cpp
index dacdc15..82dae64 100644
--- a/src/tests/mock_csi_plugin.cpp
+++ b/src/tests/mock_csi_plugin.cpp
@@ -16,6 +16,8 @@
#include "tests/mock_csi_plugin.hpp"
+#include <algorithm>
+
#include <stout/bytes.hpp>
using std::string;
@@ -61,8 +63,20 @@ MockCSIPlugin::MockCSIPlugin()
EXPECT_CALL(*this, Probe(_, _, A<csi::v0::ProbeResponse*>()))
.WillRepeatedly(Return(Status::OK));
+ // Return a success by default for testing with the test CSI plugin in
+ // forwarding mode.
EXPECT_CALL(*this, CreateVolume(_, _, A<csi::v0::CreateVolumeResponse*>()))
- .WillRepeatedly(Return(Status::OK));
+ .WillRepeatedly(Invoke([](
+ ServerContext* context,
+ const csi::v0::CreateVolumeRequest* request,
+ csi::v0::CreateVolumeResponse* response) {
+ response->mutable_volume()->set_capacity_bytes(std::max(
+ request->capacity_range().required_bytes(),
+ request->capacity_range().limit_bytes()));
+ response->mutable_volume()->set_id(request->name());
+
+ return Status::OK;
+ }));
EXPECT_CALL(*this, DeleteVolume(_, _, A<csi::v0::DeleteVolumeResponse*>()))
.WillRepeatedly(Return(Status::OK));
@@ -169,8 +183,20 @@ MockCSIPlugin::MockCSIPlugin()
EXPECT_CALL(*this, Probe(_, _, A<csi::v1::ProbeResponse*>()))
.WillRepeatedly(Return(Status::OK));
+ // Return a success by default for testing with the test CSI plugin in
+ // forwarding mode.
EXPECT_CALL(*this, CreateVolume(_, _, A<csi::v1::CreateVolumeResponse*>()))
- .WillRepeatedly(Return(Status::OK));
+ .WillRepeatedly(Invoke([](
+ ServerContext* context,
+ const csi::v1::CreateVolumeRequest* request,
+ csi::v1::CreateVolumeResponse* response) {
+ response->mutable_volume()->set_capacity_bytes(std::max(
+ request->capacity_range().required_bytes(),
+ request->capacity_range().limit_bytes()));
+ response->mutable_volume()->set_volume_id(request->name());
+
+ return Status::OK;
+ }));
EXPECT_CALL(*this, DeleteVolume(_, _, A<csi::v1::DeleteVolumeResponse*>()))
.WillRepeatedly(Return(Status::OK));
diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index 09e7ca0..efc03c2 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -501,6 +501,23 @@ static bool isMountDisk(const Resource& r, const string& profile)
}
+// Tests whether a resource is a BLOCK disk of a given profile but not a
+// persistent volume. A BLOCK disk has both profile and source ID set.
+template <typename Resource>
+static bool isBlockDisk(const Resource& r, const string& profile)
+{
+ return r.has_disk() &&
+ r.disk().has_source() &&
+ r.disk().source().type() == Resource::DiskInfo::Source::BLOCK &&
+ 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 &&
+ !r.disk().has_persistence();
+}
+
+
// Tests whether a resource is a preprovisioned volume. A preprovisioned volume
// is a RAW disk resource with a source ID but no profile.
template <typename Resource>
@@ -2968,6 +2985,151 @@ TEST_P(
}
+// This test verifies that the storage local resource provider would fail to
+// create a persistent volume on a BLOCK disk resource.
+//
+// TODO(chhsiao): Update this test once persistent BLOCK volumes are supported.
+TEST_P(StorageLocalResourceProviderTest, CreatePersistentBlockVolume)
+{
+ const string profilesPath = path::join(sandbox.get(), "profiles.json");
+ Try<string> blockDiskProfileMapping = strings::format(
+ R"~(
+ {
+ "profile_matrix": {
+ "test": {
+ "csi_plugin_type_selector": {
+ "plugin_type": "%s"
+ },
+ "volume_capabilities": {
+ "block": {},
+ "access_mode": {
+ "mode": "SINGLE_NODE_WRITER"
+ }
+ }
+ }
+ }
+ }
+ )~",
+ TEST_CSI_PLUGIN_TYPE);
+
+ ASSERT_SOME(blockDiskProfileMapping);
+ ASSERT_SOME(os::write(profilesPath, blockDiskProfileMapping.get()));
+
+ loadUriDiskProfileAdaptorModule(profilesPath);
+
+ const string mockCsiEndpoint =
+ "unix://" + path::join(sandbox.get(), "mock_csi.sock");
+
+ // We use a mock CSI plugin here because the test CSI plugin does not support
+ // block volumes yet.
+ MockCSIPlugin plugin;
+ ASSERT_SOME(plugin.startup(mockCsiEndpoint));
+
+ setupResourceProviderConfig(Bytes(0), None(), None(), mockCsiEndpoint);
+
+ Try<Owned<cluster::Master>> master = StartMaster();
+ ASSERT_SOME(master);
+
+ Owned<MasterDetector> detector = master.get()->createDetector();
+
+ slave::Flags slaveFlags = CreateSlaveFlags();
+ slaveFlags.disk_profile_adaptor = URI_DISK_PROFILE_ADAPTOR_NAME;
+
+ Future<SlaveRegisteredMessage> slaveRegisteredMessage =
+ FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
+
+ Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags);
+ ASSERT_SOME(slave);
+
+ AWAIT_READY(slaveRegisteredMessage);
+
+ // Register a framework to exercise operations.
+ FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
+ framework.set_roles(0, "storage");
+
+ MockScheduler sched;
+ MesosSchedulerDriver driver(
+ &sched, framework, master.get()->pid, DEFAULT_CREDENTIAL);
+
+ EXPECT_CALL(sched, registered(&driver, _, _));
+
+ // We use the following filter to filter offers that do not have wanted
+ // resources for 365 days (the maximum).
+ Filters declineFilters;
+ declineFilters.set_refuse_seconds(Days(365).secs());
+
+ // Decline unwanted offers. The master can send such offers before the
+ // resource provider receives profile updates.
+ EXPECT_CALL(sched, resourceOffers(&driver, _))
+ .WillRepeatedly(DeclineOffers(declineFilters));
+
+ Future<vector<Offer>> offers;
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isStoragePool<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.start();
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ Offer offer = offers->at(0);
+
+ // Create a BLOCK disk.
+ Resource raw = *Resources(offer.resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .begin();
+
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isBlockDisk<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
+
+ // We use the following filter so that the resources will not be filtered for
+ // 5 seconds (the default).
+ Filters acceptFilters;
+ acceptFilters.set_refuse_seconds(0);
+
+ driver.acceptOffers(
+ {offer.id()},
+ {CREATE_DISK(raw, Resource::DiskInfo::Source::BLOCK)},
+ acceptFilters);
+
+ AWAIT_READY(offers);
+ ASSERT_EQ(1u, offers->size());
+
+ offer = offers->at(0);
+
+ Resource created = *Resources(offer.resources())
+ .filter(std::bind(isBlockDisk<Resource>, lambda::_1, "test"))
+ .begin();
+
+ // Create a persistent BLOCK volume, which would fail.
+ Resource persistentVolume = created;
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_id(id::UUID::random().toString());
+ persistentVolume.mutable_disk()->mutable_persistence()
+ ->set_principal(framework.principal());
+ persistentVolume.mutable_disk()->mutable_volume()
+ ->set_container_path("volume");
+ persistentVolume.mutable_disk()->mutable_volume()->set_mode(Volume::RW);
+
+ Future<UpdateOperationStatusMessage> createOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
+
+ EXPECT_CALL(
+ sched, resourceOffers(&driver, OffersHaveResource(created)))
+ .WillOnce(FutureArg<1>(&offers));
+
+ driver.acceptOffers({offer.id()}, {CREATE(persistentVolume)}, acceptFilters);
+
+ AWAIT_READY(createOperationStatus);
+ EXPECT_EQ(OPERATION_FAILED, createOperationStatus->status().state());
+
+ AWAIT_EXPECT_READY(offers)
+ << "Failed to wait for an offer containing resource '" << created << "'";
+}
+
+
// This test verifies that if the storage local resource provider fails to clean
// up a persistent volume, the volume will not be destroyed.
//
[mesos] 01/03: Made the `RetryRpcWithExponentialBackoff` SLRP test
work with CSI v1.
Posted by ch...@apache.org.
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 5eff8b208e23b0ce9d064a7acea92a984f9b7c64
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Mon Apr 8 21:22:36 2019 -0700
Made the `RetryRpcWithExponentialBackoff` SLRP test work with CSI v1.
This patch enables the unit test to test against CSI v1 through the
following changes:
* The forwarding mode of the test CSI plugin now respects the
`--api_version` option. When specified, only requests of the proper
CSI version will be forwarded.
* The expectations of `CreateVolume` and `DeleteVolume` calls in the
unit tests are parameterized against the CSI version string.
* The mock CSI plugin now provides a default implementation for the
`GetCapacity` call so the unit test can be simplified.
Review: https://reviews.apache.org/r/70431
---
src/examples/test_csi_plugin.cpp | 53 ++-
src/tests/mock_csi_plugin.cpp | 24 +-
.../storage_local_resource_provider_tests.cpp | 396 +++++++++++----------
3 files changed, 259 insertions(+), 214 deletions(-)
diff --git a/src/examples/test_csi_plugin.cpp b/src/examples/test_csi_plugin.cpp
index b54d666..03f782e 100644
--- a/src/examples/test_csi_plugin.cpp
+++ b/src/examples/test_csi_plugin.cpp
@@ -1716,8 +1716,12 @@ Try<Nothing, StatusError> TestCSIPlugin::nodeUnpublishVolume(
class CSIProxy
{
public:
- CSIProxy(const string& _endpoint, const string& forward)
- : endpoint(_endpoint),
+ CSIProxy(
+ const Option<string>& _apiVersion,
+ const string& _endpoint,
+ const string& forward)
+ : apiVersion(_apiVersion),
+ endpoint(_endpoint),
stub(grpc::CreateChannel(forward, grpc::InsecureChannelCredentials())),
service(new AsyncGenericService()) {}
@@ -1747,6 +1751,7 @@ private:
void serve(ServerCompletionQueue* completionQueue);
+ const Option<string> apiVersion;
const string endpoint;
GenericStub stub;
@@ -1779,13 +1784,13 @@ void CSIProxy::run()
// The lifecycle of a forwarded CSI call is shown as follows. The transitions
// happen after the completions of the API calls.
//
-// Server-side
-// +-------------+ +-------------+ WriteAndFinish +---+
-// | INITIALIZED | | FINISHING +----------------> X |
-// +------+------+ +------^------+ +---+
-// Server-side | | Client-side
-// RequestCall | Server-side | Finish (unary call)
-// +------v------+ Read +------+------+
+// Unsupported Server-side
+// +-------------+ API version +-------------+ WriteAndFinish +---+
+// | INITIALIZED | +---------> FINISHING +----------------> X |
+// +------+------+ | +------^------+ +---+
+// Server-side | +------+ | Client-side
+// RequestCall | | Server-side | Finish (unary call)
+// +------v---+--+ Read +------+------+
// | REQUESTED +-------------> FORWARDING |
// +-------------+ +-------------+
//
@@ -1816,7 +1821,7 @@ void CSIProxy::serve(ServerCompletionQueue* completionQueue)
if (!ok) {
// Server-side `RequestCall`: the server has been shutdown so continue
// to drain the queue.
- continue;
+ break;
}
call->state = Call::State::REQUESTED;
@@ -1841,13 +1846,29 @@ void CSIProxy::serve(ServerCompletionQueue* completionQueue)
case Call::State::REQUESTED: {
if (!ok) {
// Server-side `Read`: the client has done a `WritesDone` already, so
- // clean up the call and move on to the next one.
+ // clean up the call and move to the next iteration immediately.
delete call;
continue;
}
- LOG(INFO) << "Forwarding " << call->serverContext.method() << " call";
+ // The expected method names are of the following form:
+ // /csi.<api_version>.<service_name>/<rpc_name>
+ // See: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests // NOLINT
+ if (apiVersion.isSome() &&
+ !strings::startsWith(
+ call->serverContext.method(),
+ "/csi." + apiVersion.get() + ".")) {
+ // The proxy does not support the API version of the call so respond
+ // with `UNIMPLEMENTED`.
+ call->state = Call::State::FINISHING;
+ call->status = Status(grpc::UNIMPLEMENTED, "");
+ call->serverReaderWriter.WriteAndFinish(
+ call->response, WriteOptions(), call->status, call);
+
+ break;
+ }
+ LOG(INFO) << "Forwarding " << call->serverContext.method() << " call";
call->state = Call::State::FORWARDING;
call->clientContext.set_wait_for_ready(true);
@@ -1895,10 +1916,10 @@ void CSIProxy::serve(ServerCompletionQueue* completionQueue)
<< call->serverContext.method() << " call";
}
- // The call is completed so clean it up.
+ // The call is completed so clean it up and move to the next iteration
+ // immediately.
delete call;
-
- break;
+ continue;
}
}
}
@@ -2000,7 +2021,7 @@ int main(int argc, char** argv)
}
if (flags.forward.isSome()) {
- CSIProxy proxy(flags.endpoint, flags.forward.get());
+ CSIProxy proxy(flags.api_version, flags.endpoint, flags.forward.get());
proxy.run();
} else {
diff --git a/src/tests/mock_csi_plugin.cpp b/src/tests/mock_csi_plugin.cpp
index cbcb59f..dacdc15 100644
--- a/src/tests/mock_csi_plugin.cpp
+++ b/src/tests/mock_csi_plugin.cpp
@@ -16,6 +16,8 @@
#include "tests/mock_csi_plugin.hpp"
+#include <stout/bytes.hpp>
+
using std::string;
using std::unique_ptr;
@@ -80,8 +82,17 @@ MockCSIPlugin::MockCSIPlugin()
EXPECT_CALL(*this, ListVolumes(_, _, A<csi::v0::ListVolumesResponse*>()))
.WillRepeatedly(Return(Status::OK));
+ // Return an arbitrary available capacity by default for testing with the test
+ // CSI plugin in forwarding mode.
EXPECT_CALL(*this, GetCapacity(_, _, A<csi::v0::GetCapacityResponse*>()))
- .WillRepeatedly(Return(Status::OK));
+ .WillRepeatedly(Invoke([](
+ ServerContext* context,
+ const csi::v0::GetCapacityRequest* request,
+ csi::v0::GetCapacityResponse* response) {
+ response->set_available_capacity(Gigabytes(4).bytes());
+
+ return Status::OK;
+ }));
// Enable all controller RPC capabilities by default for testing with the test
// CSI plugin in forwarding mode.
@@ -179,8 +190,17 @@ MockCSIPlugin::MockCSIPlugin()
EXPECT_CALL(*this, ListVolumes(_, _, A<csi::v1::ListVolumesResponse*>()))
.WillRepeatedly(Return(Status::OK));
+ // Return an arbitrary available capacity by default for testing with the test
+ // CSI plugin in forwarding mode.
EXPECT_CALL(*this, GetCapacity(_, _, A<csi::v1::GetCapacityResponse*>()))
- .WillRepeatedly(Return(Status::OK));
+ .WillRepeatedly(Invoke([](
+ ServerContext* context,
+ const csi::v1::GetCapacityRequest* request,
+ csi::v1::GetCapacityResponse* response) {
+ response->set_available_capacity(Gigabytes(4).bytes());
+
+ return Status::OK;
+ }));
// Enable all controller RPC capabilities by default for testing with the test
// CSI plugin in forwarding mode.
diff --git a/src/tests/storage_local_resource_provider_tests.cpp b/src/tests/storage_local_resource_provider_tests.cpp
index 8bf4d23..09e7ca0 100644
--- a/src/tests/storage_local_resource_provider_tests.cpp
+++ b/src/tests/storage_local_resource_provider_tests.cpp
@@ -38,7 +38,9 @@
#include <stout/foreach.hpp>
#include <stout/hashmap.hpp>
+#include <stout/stringify.hpp>
#include <stout/strings.hpp>
+#include <stout/unreachable.hpp>
#include <stout/uri.hpp>
#include <stout/os/realpath.hpp>
@@ -46,6 +48,8 @@
#include "csi/paths.hpp"
#include "csi/state.hpp"
#include "csi/v0_volume_manager_process.hpp"
+#include "csi/v1_volume_manager_process.hpp"
+#include "csi/volume_manager.hpp"
#include "linux/fs.hpp"
@@ -114,7 +118,8 @@ constexpr char TEST_CSI_VENDOR[] = "org.apache.mesos.csi.test.local";
class StorageLocalResourceProviderTest
- : public ContainerizerTest<slave::MesosContainerizer>
+ : public ContainerizerTest<slave::MesosContainerizer>,
+ public testing::WithParamInterface<string>
{
public:
void SetUp() override
@@ -261,6 +266,7 @@ public:
"value": "%s",
"arguments": [
"%s",
+ "--api_version=%s",
"--work_dir=%s",
"--available_capacity=%s",
"%s",
@@ -296,6 +302,7 @@ public:
TEST_CSI_PLUGIN_NAME,
testCsiPluginPath,
testCsiPluginPath,
+ GetParam(),
testCsiPluginWorkDir.get(),
stringify(capacity),
createParameters.isSome()
@@ -310,6 +317,105 @@ public:
resourceProviderConfig.get()));
}
+ // Set up an expected `CreateVolume` CSI call for a given mock CSI plugin.
+ // When the call is made to the mock plugin, `result` will be responded. When
+ // the response is received by the volume manager, the returned future will be
+ // satisfied.
+ Future<Nothing> futureCreateVolumeCall(
+ MockCSIPlugin* plugin, const Try<csi::VolumeInfo, StatusError>& result)
+ {
+ if (GetParam() == csi::v0::API_VERSION) {
+ EXPECT_CALL(*plugin, CreateVolume(
+ _, _, A<csi::v0::CreateVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v0::CreateVolumeRequest* request,
+ csi::v0::CreateVolumeResponse* response) {
+ if (result.isError()) {
+ return result.error().status;
+ }
+
+ response->mutable_volume()->set_id(result->id);
+ response->mutable_volume()
+ ->set_capacity_bytes(result->capacity.bytes());
+ *response->mutable_volume()->mutable_attributes() = result->context;
+
+ return grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v0::VolumeManagerProcess::__call<
+ csi::v0::CreateVolumeResponse>);
+ } else if (GetParam() == csi::v1::API_VERSION) {
+ EXPECT_CALL(*plugin, CreateVolume(
+ _, _, A<csi::v1::CreateVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v1::CreateVolumeRequest* request,
+ csi::v1::CreateVolumeResponse* response) {
+ if (result.isError()) {
+ return result.error().status;
+ }
+
+ response->mutable_volume()->set_volume_id(result->id);
+ response->mutable_volume()
+ ->set_capacity_bytes(result->capacity.bytes());
+ *response->mutable_volume()
+ ->mutable_volume_context() = result->context;
+
+ return grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v1::VolumeManagerProcess::__call<
+ csi::v1::CreateVolumeResponse>);
+ }
+
+ // This extra closure is necessary in order to use `FAIL` as it requires a
+ // void return type.
+ [&] { FAIL() << "Unsupported CSI API version " << GetParam(); }();
+
+ UNREACHABLE();
+ }
+
+ // Set up an expected `DeleteVolume` CSI call for a given mock CSI plugin.
+ // When the call is made to the mock plugin, `result` will be responded. When
+ // the response is received by the volume manager, the returned future will be
+ // satisfied.
+ Future<Nothing> futureDeleteVolumeCall(
+ MockCSIPlugin* plugin, const Try<Nothing, StatusError>& result)
+ {
+ if (GetParam() == csi::v0::API_VERSION) {
+ EXPECT_CALL(*plugin, DeleteVolume(
+ _, _, A<csi::v0::DeleteVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v0::DeleteVolumeRequest* request,
+ csi::v0::DeleteVolumeResponse* response) {
+ return result.isError() ? result.error().status : grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v0::VolumeManagerProcess::__call<
+ csi::v0::DeleteVolumeResponse>);
+ } else if (GetParam() == csi::v1::API_VERSION) {
+ EXPECT_CALL(*plugin, DeleteVolume(
+ _, _, A<csi::v1::DeleteVolumeResponse*>()))
+ .WillOnce(Invoke([result](
+ grpc::ServerContext* context,
+ const csi::v1::DeleteVolumeRequest* request,
+ csi::v1::DeleteVolumeResponse* response) {
+ return result.isError() ? result.error().status : grpc::Status::OK;
+ }));
+
+ return FUTURE_DISPATCH(_, &csi::v1::VolumeManagerProcess::__call<
+ csi::v1::DeleteVolumeResponse>);
+ }
+
+ // This extra closure is necessary in order to use `FAIL` as it requires a
+ // void return type.
+ [&] { FAIL() << "Unsupported CSI API version " << GetParam(); }();
+
+ UNREACHABLE();
+ }
+
// Create a JSON string representing a disk profile mapping containing the
// given profile-parameter pairs.
static string createDiskProfileMapping(
@@ -410,9 +516,16 @@ static bool isPreprovisionedVolume(const Resource& r)
}
+INSTANTIATE_TEST_CASE_P(
+ CSIVersion,
+ StorageLocalResourceProviderTest,
+ testing::Values(csi::v0::API_VERSION, csi::v1::API_VERSION),
+ [](const testing::TestParamInfo<string>& info) { return info.param; });
+
+
// This test verifies that a storage local resource provider can report
// no resource and recover from this state.
-TEST_F(StorageLocalResourceProviderTest, NoResource)
+TEST_P(StorageLocalResourceProviderTest, NoResource)
{
Clock::pause();
@@ -493,7 +606,7 @@ TEST_F(StorageLocalResourceProviderTest, NoResource)
// This test verifies that any zero-sized volume reported by a CSI
// plugin will be ignored by the storage local resource provider.
-TEST_F(StorageLocalResourceProviderTest, DISABLED_ZeroSizedDisk)
+TEST_P(StorageLocalResourceProviderTest, DISABLED_ZeroSizedDisk)
{
Clock::pause();
@@ -545,7 +658,7 @@ TEST_F(StorageLocalResourceProviderTest, DISABLED_ZeroSizedDisk)
// This test verifies that the storage local resource provider can
// handle disks less than 1MB correctly.
-TEST_F(StorageLocalResourceProviderTest, DISABLED_SmallDisk)
+TEST_P(StorageLocalResourceProviderTest, DISABLED_SmallDisk)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -629,7 +742,7 @@ TEST_F(StorageLocalResourceProviderTest, DISABLED_SmallDisk)
// This test verifies that a framework can receive offers having new storage
// pools from the storage local resource provider after a profile appears.
-TEST_F(StorageLocalResourceProviderTest, ProfileAppeared)
+TEST_P(StorageLocalResourceProviderTest, ProfileAppeared)
{
Clock::pause();
@@ -749,7 +862,7 @@ TEST_F(StorageLocalResourceProviderTest, ProfileAppeared)
// This test verifies that the storage local resource provider can create then
// destroy a MOUNT disk from a storage pool with other pipelined operations.
-TEST_F(StorageLocalResourceProviderTest, CreateDestroyDisk)
+TEST_P(StorageLocalResourceProviderTest, CreateDestroyDisk)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -888,7 +1001,7 @@ TEST_F(StorageLocalResourceProviderTest, CreateDestroyDisk)
// This test verifies that the storage local resource provider can destroy a
// MOUNT disk created from a storage pool with other pipelined operations after
// recovery.
-TEST_F(StorageLocalResourceProviderTest, CreateDestroyDiskWithRecovery)
+TEST_P(StorageLocalResourceProviderTest, CreateDestroyDiskWithRecovery)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -1091,7 +1204,7 @@ TEST_F(StorageLocalResourceProviderTest, CreateDestroyDiskWithRecovery)
// RAW disk would show up as of profile 'test2'.
// 4. Destroy the MOUNT disk of profile 'test1'. All 4GB RAW disk would show
// up as of profile 'test2'.
-TEST_F(StorageLocalResourceProviderTest, ProfileDisappeared)
+TEST_P(StorageLocalResourceProviderTest, ProfileDisappeared)
{
Clock::pause();
@@ -1365,7 +1478,7 @@ TEST_F(StorageLocalResourceProviderTest, ProfileDisappeared)
// This test verifies that the storage local resource provider can
// recover if the plugin is killed during an agent failover..
-TEST_F(StorageLocalResourceProviderTest, AgentFailoverPluginKilled)
+TEST_P(StorageLocalResourceProviderTest, AgentFailoverPluginKilled)
{
setupResourceProviderConfig(Bytes(0), "volume0:4GB");
@@ -1473,7 +1586,7 @@ TEST_F(StorageLocalResourceProviderTest, AgentFailoverPluginKilled)
// provider ID would change as well, and any created volume becomes a
// preprovisioned volume. A framework should be able to either create a MOUNT
// disk from a preprovisioned volume and use it, or destroy it directly.
-TEST_F(StorageLocalResourceProviderTest, ROOT_AgentRegisteredWithNewId)
+TEST_P(StorageLocalResourceProviderTest, ROOT_AgentRegisteredWithNewId)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -1824,7 +1937,7 @@ TEST_F(StorageLocalResourceProviderTest, ROOT_AgentRegisteredWithNewId)
// 3. Destroy the persistent volume but keep the MOUNT disk. The file should
// be deleted.
// 4. Destroy the MOUNT disk.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest, ROOT_CreateDestroyPersistentMountVolume)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -2018,7 +2131,7 @@ TEST_F(
// 6. Destroy the persistent volume but keep the MOUNT disk. The file should
// be deleted.
// 7. Destroy the MOUNT disk.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
ROOT_CreateDestroyPersistentMountVolumeWithRecovery)
{
@@ -2296,7 +2409,7 @@ TEST_F(
// 6. Destroy the persistent volume but keep the MOUNT disk. The file should
// be deleted.
// 7. Destroy the MOUNT disk.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
ROOT_CreateDestroyPersistentMountVolumeWithReboot)
{
@@ -2608,7 +2721,7 @@ TEST_F(
// This test verifies that the storage local resource provider can
// restart its CSI plugin after it is killed and continue to work
// properly.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
ROOT_PublishUnpublishResourcesPluginKilled)
{
@@ -2866,7 +2979,7 @@ TEST_F(
// would fail with EBUSY.
// 4. Destroys the persistent volume and the MOUNT disk. `DESTROY` would fail
// and `DESTROY_DISK` would be dropped.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest, ROOT_DestroyPersistentMountVolumeFailed)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -3031,7 +3144,7 @@ TEST_F(
// is known to the disk profile adaptor, and can return the space back to the
// storage pool through either destroying the MOUNT disk, or destroying a RAW
// disk directly.
-TEST_F(StorageLocalResourceProviderTest, CreateDestroyPreprovisionedVolume)
+TEST_P(StorageLocalResourceProviderTest, CreateDestroyPreprovisionedVolume)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -3235,7 +3348,7 @@ TEST_F(StorageLocalResourceProviderTest, CreateDestroyPreprovisionedVolume)
// master, so that it isn't acknowledged by the master.
// 3. Advances the clock and verifies that the agent resends the operation
// status update.
-TEST_F(StorageLocalResourceProviderTest, RetryOperationStatusUpdate)
+TEST_P(StorageLocalResourceProviderTest, RetryOperationStatusUpdate)
{
Clock::pause();
@@ -3384,7 +3497,7 @@ TEST_F(StorageLocalResourceProviderTest, RetryOperationStatusUpdate)
// master, so that it isn't acknowledged by the master.
// 3. Restarts the agent.
// 4. Verifies that the agent resends the operation status update.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
RetryOperationStatusUpdateAfterRecovery)
{
@@ -3555,7 +3668,7 @@ TEST_F(
// This test verifies that storage local resource provider properly
// reports the metric related to CSI plugin container terminations.
-TEST_F(StorageLocalResourceProviderTest, ContainerTerminationMetric)
+TEST_P(StorageLocalResourceProviderTest, ContainerTerminationMetric)
{
// Since we want to observe a fixed number of `UpdateSlaveMessage`s,
// register the agent with paused clock to ensure it does not
@@ -3663,7 +3776,7 @@ TEST_F(StorageLocalResourceProviderTest, ContainerTerminationMetric)
// This test verifies that operation status updates contain the
// agent ID and resource provider ID of originating providers.
-TEST_F(StorageLocalResourceProviderTest, OperationUpdate)
+TEST_P(StorageLocalResourceProviderTest, OperationUpdate)
{
Clock::pause();
@@ -3826,7 +3939,7 @@ TEST_F(StorageLocalResourceProviderTest, OperationUpdate)
// operations since we have no control over the completion of an operation. Once
// we support out-of-band CSI plugins through domain sockets, we could test this
// metric against a mock CSI plugin.
-TEST_F(StorageLocalResourceProviderTest, OperationStateMetrics)
+TEST_P(StorageLocalResourceProviderTest, OperationStateMetrics)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -4052,7 +4165,7 @@ TEST_F(StorageLocalResourceProviderTest, OperationStateMetrics)
// `cancelled` metrics for RPCs since we have no control over the completion of
// an operation. Once we support out-of-band CSI plugins through domain sockets,
// we could test these metrics against a mock CSI plugin.
-TEST_F(StorageLocalResourceProviderTest, CsiPluginRpcMetrics)
+TEST_P(StorageLocalResourceProviderTest, CsiPluginRpcMetrics)
{
const string profilesPath = path::join(sandbox.get(), "profiles.json");
@@ -4218,7 +4331,7 @@ TEST_F(StorageLocalResourceProviderTest, CsiPluginRpcMetrics)
//
// TODO(greggomann): Test operations on agent default resources: for such
// operations, the agent generates the dropped status.
-TEST_F(StorageLocalResourceProviderTest, ReconcileDroppedOperation)
+TEST_P(StorageLocalResourceProviderTest, ReconcileDroppedOperation)
{
Clock::pause();
@@ -4404,7 +4517,7 @@ TEST_F(StorageLocalResourceProviderTest, ReconcileDroppedOperation)
// This test verifies that if an operation ID is specified, operation status
// updates are resent to the scheduler until acknowledged.
-TEST_F(StorageLocalResourceProviderTest, RetryOperationStatusUpdateToScheduler)
+TEST_P(StorageLocalResourceProviderTest, RetryOperationStatusUpdateToScheduler)
{
Clock::pause();
@@ -4591,7 +4704,7 @@ TEST_F(StorageLocalResourceProviderTest, RetryOperationStatusUpdateToScheduler)
// This test ensures that the master responds with the latest state
// for operations that are terminal at the master, but have not been
// acknowledged by the framework.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
ReconcileUnacknowledgedTerminalOperation)
{
@@ -4778,7 +4891,7 @@ TEST_F(
// clock is advanced exponentially to trigger retries.
// 6. Returns `UNIMPLEMENTED` for the next `DeleteVolume` call to verify that
// there is no retry on a non-retryable error.
-TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
+TEST_P(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
{
Clock::pause();
@@ -4798,71 +4911,6 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
MockCSIPlugin plugin;
ASSERT_SOME(plugin.startup(mockCsiEndpoint));
- // TODO(chhsiao): Since this test expects CSI v0 protobufs, we disable CSI v1
- // for now. Remove this once the expectations are parameterized.
- EXPECT_CALL(plugin, Probe(_, _, A<csi::v1::ProbeResponse*>()))
- .WillRepeatedly(Return(grpc::Status(grpc::UNIMPLEMENTED, "")));
-
- EXPECT_CALL(plugin, GetCapacity(_, _, A<csi::v0::GetCapacityResponse*>()))
- .WillRepeatedly(Invoke([](
- grpc::ServerContext* context,
- const csi::v0::GetCapacityRequest* request,
- csi::v0::GetCapacityResponse* response) {
- response->set_available_capacity(Gigabytes(4).bytes());
-
- return grpc::Status::OK;
- }));
-
- Queue<csi::v0::CreateVolumeRequest> createVolumeRequests;
- Queue<Try<csi::v0::CreateVolumeResponse, StatusError>> createVolumeResults;
- EXPECT_CALL(plugin, CreateVolume(_, _, A<csi::v0::CreateVolumeResponse*>()))
- .WillRepeatedly(Invoke([&](
- grpc::ServerContext* context,
- const csi::v0::CreateVolumeRequest* request,
- csi::v0::CreateVolumeResponse* response) -> grpc::Status {
- Future<Try<csi::v0::CreateVolumeResponse, StatusError>> result =
- createVolumeResults.get();
-
- EXPECT_TRUE(result.isPending());
- createVolumeRequests.put(*request);
-
- // This extra closure is necessary in order to use `AWAIT_ASSERT_*`, as
- // these macros require a void return type.
- [&] { AWAIT_ASSERT_READY(result); }();
-
- if (result->isError()) {
- return result->error().status;
- }
-
- *response = result->get();
- return grpc::Status::OK;
- }));
-
- Queue<csi::v0::DeleteVolumeRequest> deleteVolumeRequests;
- Queue<Try<csi::v0::DeleteVolumeResponse, StatusError>> deleteVolumeResults;
- EXPECT_CALL(plugin, DeleteVolume(_, _, A<csi::v0::DeleteVolumeResponse*>()))
- .WillRepeatedly(Invoke([&](
- grpc::ServerContext* context,
- const csi::v0::DeleteVolumeRequest* request,
- csi::v0::DeleteVolumeResponse* response) -> grpc::Status {
- Future<Try<csi::v0::DeleteVolumeResponse, StatusError>> result =
- deleteVolumeResults.get();
-
- EXPECT_TRUE(result.isPending());
- deleteVolumeRequests.put(*request);
-
- // This extra closure is necessary in order to use `AWAIT_ASSERT_*`, as
- // these macros require a void return type.
- [&] { AWAIT_ASSERT_READY(result); }();
-
- if (result->isError()) {
- return result->error().status;
- }
-
- *response = result->get();
- return grpc::Status::OK;
- }));
-
setupResourceProviderConfig(Bytes(0), None(), None(), mockCsiEndpoint);
master::Flags masterFlags = CreateMasterFlags();
@@ -4935,9 +4983,7 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
AWAIT_READY(offers);
ASSERT_EQ(1u, offers->size());
- Resource raw = *Resources(offers->at(0).resources())
- .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
- .begin();
+ Offer offer = offers->at(0);
// We expect that the following RPC calls are made during startup: `Probe`,
// `GetPluginInfo` (2), `GetPluginCapabilities, `ControllerGetCapabilities`,
@@ -4952,80 +4998,58 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
EXPECT_TRUE(metricEquals(metricName("csi_plugin/rpcs_failed"), 0));
// Create a MOUNT disk.
- Future<UpdateOperationStatusMessage> updateOperationStatus =
- FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
-
- driver.acceptOffers(
- {offers->at(0).id()},
- {CREATE_DISK(raw, Resource::DiskInfo::Source::MOUNT)});
-
- AWAIT_READY(createVolumeRequests.get())
- << "Failed to wait for CreateVolumeRequest #1";
+ Resource raw = *Resources(offer.resources())
+ .filter(std::bind(isStoragePool<Resource>, lambda::_1, "test"))
+ .begin();
- // Settle the clock to verify that there is no more outstanding request.
- Clock::settle();
- ASSERT_EQ(0u, createVolumeRequests.size());
+ EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
+ std::bind(isMountDisk<Resource>, lambda::_1, "test"))))
+ .WillOnce(FutureArg<1>(&offers));
- Future<Nothing> createVolumeCall = FUTURE_DISPATCH(
- _, &csi::v0::VolumeManagerProcess::__call<csi::v0::CreateVolumeResponse>);
+ Future<UpdateOperationStatusMessage> updateOperationStatus =
+ FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
// Return `DEADLINE_EXCEEDED` for the first `CreateVolume` call.
- createVolumeResults.put(
- StatusError(grpc::Status(grpc::DEADLINE_EXCEEDED, "")));
+ Future<Nothing> createVolumeCall = futureCreateVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::DEADLINE_EXCEEDED, "")));
- AWAIT_READY(createVolumeCall);
+ driver.acceptOffers(
+ {offer.id()}, {CREATE_DISK(raw, Resource::DiskInfo::Source::MOUNT)});
- Duration createVolumeBackoff = csi::v0::DEFAULT_CSI_RETRY_BACKOFF_FACTOR;
+ AWAIT_READY(createVolumeCall) << "Failed to wait for CreateVolume call #1";
- // Settle the clock to ensure that the retry timer has been set, then advance
- // the clock by the maximum backoff to trigger a retry.
- Clock::settle();
- Clock::advance(createVolumeBackoff);
+ Duration createVolumeBackoff = csi::v0::DEFAULT_CSI_RETRY_BACKOFF_FACTOR;
- // Return `UNAVAILABLE` for subsequent `CreateVolume` calls.
for (size_t i = 1; i < numRetryableErrors; i++) {
- AWAIT_READY(createVolumeRequests.get())
- << "Failed to wait for CreateVolumeRequest #" << (i + 1);
+ // Return `UNAVAILABLE` for subsequent `CreateVolume` calls.
+ createVolumeCall = futureCreateVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNAVAILABLE, "")));
- // Settle the clock to verify that there is no more outstanding request.
+ // Settle the clock to ensure that the retry timer has been set, then
+ // advance the clock by the maximum backoff to trigger a retry.
Clock::settle();
- ASSERT_EQ(0u, createVolumeRequests.size());
-
- createVolumeCall = FUTURE_DISPATCH(
- _,
- &csi::v0::VolumeManagerProcess::__call<csi::v0::CreateVolumeResponse>);
-
- createVolumeResults.put(StatusError(grpc::Status(grpc::UNAVAILABLE, "")));
+ Clock::advance(createVolumeBackoff);
- AWAIT_READY(createVolumeCall);
+ AWAIT_READY(createVolumeCall)
+ << "Failed to wait for CreateVolume call #" << (i + 1);
createVolumeBackoff = std::min(
createVolumeBackoff * 2, csi::v0::DEFAULT_CSI_RETRY_INTERVAL_MAX);
-
- // Settle the clock to ensure that the retry timer has been set, then
- // advance the clock by the maximum backoff to trigger a retry.
- Clock::settle();
- Clock::advance(createVolumeBackoff);
}
- AWAIT_READY(createVolumeRequests.get())
- << "Failed to wait for CreateVolumeRequest #" << (numRetryableErrors + 1);
+ // Return a successful response for the last `CreateVolume` call.
+ createVolumeCall = futureCreateVolumeCall(
+ &plugin,
+ csi::VolumeInfo{Megabytes(raw.scalar().value()).bytes(),
+ id::UUID::random().toString()});
- // Settle the clock to verify that there is no more outstanding request.
+ // Settle the clock to ensure that the retry timer has been set, then
+ // advance the clock by the maximum backoff to trigger a retry.
Clock::settle();
- ASSERT_EQ(0u, createVolumeRequests.size());
-
- EXPECT_CALL(sched, resourceOffers(&driver, OffersHaveAnyResource(
- std::bind(isMountDisk<Resource>, lambda::_1, "test"))))
- .WillOnce(FutureArg<1>(&offers));
-
- // Return a successful response for the last `CreateVolume` call.
- csi::v0::CreateVolumeResponse createVolumeResponse;
- createVolumeResponse.mutable_volume()->set_id(id::UUID::random().toString());
- createVolumeResponse.mutable_volume()->set_capacity_bytes(
- Megabytes(raw.scalar().value()).bytes());
+ Clock::advance(createVolumeBackoff);
- createVolumeResults.put(std::move(createVolumeResponse));
+ AWAIT_READY(createVolumeCall)
+ << "Failed to wait for CreateVolume call #" << (numRetryableErrors + 1);
AWAIT_READY(updateOperationStatus);
EXPECT_EQ(OPERATION_FINISHED, updateOperationStatus->status().state());
@@ -5036,73 +5060,53 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
AWAIT_READY(offers);
ASSERT_EQ(1u, offers->size());
- Resource created = *Resources(offers->at(0).resources())
+ offer = offers->at(0);
+
+ // Destroy the MOUNT disk.
+ Resource created = *Resources(offer.resources())
.filter(std::bind(isMountDisk<Resource>, lambda::_1, "test"))
.begin();
- // Destroy the MOUNT disk.
updateOperationStatus = FUTURE_PROTOBUF(UpdateOperationStatusMessage(), _, _);
- driver.acceptOffers({offers->at(0).id()}, {DESTROY_DISK(created)});
-
- AWAIT_READY(deleteVolumeRequests.get())
- << "Failed to wait for DeleteVolumeRequest #1";
-
- // Settle the clock to verify that there is no more outstanding request.
- Clock::settle();
- ASSERT_EQ(0u, deleteVolumeRequests.size());
-
- Future<Nothing> deleteVolumeCall = FUTURE_DISPATCH(
- _, &csi::v0::VolumeManagerProcess::__call<csi::v0::DeleteVolumeResponse>);
-
// Return `DEADLINE_EXCEEDED` for the first `DeleteVolume` call.
- deleteVolumeResults.put(
- StatusError(grpc::Status(grpc::DEADLINE_EXCEEDED, "")));
+ Future<Nothing> deleteVolumeCall = futureDeleteVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::DEADLINE_EXCEEDED, "")));
- AWAIT_READY(deleteVolumeCall);
+ driver.acceptOffers({offers->at(0).id()}, {DESTROY_DISK(created)});
- Duration deleteVolumeBackoff = csi::v0::DEFAULT_CSI_RETRY_BACKOFF_FACTOR;
+ AWAIT_READY(deleteVolumeCall) << "Failed to wait for DeleteVolume call #1";
- // Settle the clock to ensure that the retry timer has been set, then advance
- // the clock by the maximum backoff to trigger a retry.
- Clock::settle();
- Clock::advance(deleteVolumeBackoff);
+ Duration deleteVolumeBackoff = csi::v0::DEFAULT_CSI_RETRY_BACKOFF_FACTOR;
- // Return `UNAVAILABLE` for subsequent `DeleteVolume` calls.
for (size_t i = 1; i < numRetryableErrors; i++) {
- AWAIT_READY(deleteVolumeRequests.get())
- << "Failed to wait for DeleteVolumeRequest #" << (i + 1);
+ // Return `UNAVAILABLE` for subsequent `DeleteVolume` calls.
+ deleteVolumeCall = futureDeleteVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNAVAILABLE, "")));
- // Settle the clock to verify that there is no more outstanding request.
+ // Settle the clock to ensure that the retry timer has been set, then
+ // advance the clock by the maximum backoff to trigger a retry.
Clock::settle();
- ASSERT_EQ(0u, deleteVolumeRequests.size());
-
- deleteVolumeCall = FUTURE_DISPATCH(
- _,
- &csi::v0::VolumeManagerProcess::__call<csi::v0::DeleteVolumeResponse>);
-
- deleteVolumeResults.put(StatusError(grpc::Status(grpc::UNAVAILABLE, "")));
+ Clock::advance(deleteVolumeBackoff);
- AWAIT_READY(deleteVolumeCall);
+ AWAIT_READY(deleteVolumeCall)
+ << "Failed to wait for DeleteVolume call #" << (i + 1);
deleteVolumeBackoff = std::min(
deleteVolumeBackoff * 2, csi::v0::DEFAULT_CSI_RETRY_INTERVAL_MAX);
-
- // Settle the clock to ensure that the retry timer has been set, then
- // advance the clock by the maximum backoff to trigger a retry.
- Clock::settle();
- Clock::advance(deleteVolumeBackoff);
}
- AWAIT_READY(deleteVolumeRequests.get())
- << "Failed to wait for DeleteVolumeRequest #" << (numRetryableErrors + 1);
+ // Return a non-retryable error for the last `DeleteVolume` call.
+ deleteVolumeCall = futureDeleteVolumeCall(
+ &plugin, StatusError(grpc::Status(grpc::UNIMPLEMENTED, "")));
- // Settle the clock to verify that there is no more outstanding request.
+ // Settle the clock to ensure that the retry timer has been set, then
+ // advance the clock by the maximum backoff to trigger a retry.
Clock::settle();
- ASSERT_EQ(0u, deleteVolumeRequests.size());
+ Clock::advance(deleteVolumeBackoff);
- // Return a non-retryable error for the last `DeleteVolume` call.
- deleteVolumeResults.put(StatusError(grpc::Status(grpc::UNIMPLEMENTED, "")));
+ AWAIT_READY(deleteVolumeCall)
+ << "Failed to wait for DeleteVolume call #" << (numRetryableErrors + 1);
AWAIT_READY(updateOperationStatus);
EXPECT_EQ(OPERATION_FAILED, updateOperationStatus->status().state());
@@ -5126,7 +5130,7 @@ TEST_F(StorageLocalResourceProviderTest, RetryRpcWithExponentialBackoff)
// (i.e. the master cannot assume the success of the operation) operation
// status updates that originate from frameworks which have been torn down.
// Non-speculative operations include CREATE_DISK.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
FrameworkTeardownBeforeTerminalOperationStatusUpdate)
{
@@ -5297,7 +5301,7 @@ TEST_F(
// the master fails over, but the operation's originating framework
// never reregisters. Alternatively, and uncommonly, pending operations
// on an agent migrated from one master to another will produce orphans.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
TerminalOrphanOperationAfterMasterFailover)
{
@@ -5485,7 +5489,7 @@ TEST_F(
// This test verifies that operators can reserve/unreserve and
// create/destroy persistent volumes with resource provider resources.
-TEST_F(
+TEST_P(
StorageLocalResourceProviderTest,
OperatorOperationsWithResourceProviderResources)
{