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/01/29 21:14:38 UTC

[mesos] 06/08: Improved the default actions of the mock CSI plugin.

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 39c4a7791cf938ccbacff4858d9e00d3e6866798
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
AuthorDate: Tue Jan 22 14:08:35 2019 -0800

    Improved the default actions of the mock CSI plugin.
    
    This patch removes the macros used to generate the default actions for
    the mock CSI plugin, and makes it returns all possible capabilities by
    default so it can be used to test SLRP w/ a proxy-mode test CSI plugin.
    
    Review: https://reviews.apache.org/r/69814
---
 src/tests/mock_csi_plugin.cpp |  92 +++++++++++++++++++++++++++++++++--
 src/tests/mock_csi_plugin.hpp | 110 ++++++++++++++++++++++++++++++++----------
 2 files changed, 171 insertions(+), 31 deletions(-)

diff --git a/src/tests/mock_csi_plugin.cpp b/src/tests/mock_csi_plugin.cpp
index 17c6335..1024570 100644
--- a/src/tests/mock_csi_plugin.cpp
+++ b/src/tests/mock_csi_plugin.cpp
@@ -33,19 +33,101 @@ using mesos::csi::v0::Node;
 using process::grpc::client::Connection;
 
 using testing::_;
+using testing::Invoke;
 using testing::Return;
 
 namespace mesos {
 namespace internal {
 namespace tests {
 
-#define DECLARE_MOCK_CSI_METHOD_IMPL(name) \
-  EXPECT_CALL(*this, name(_, _, _))        \
-    .WillRepeatedly(Return(Status::OK));
-
 MockCSIPlugin::MockCSIPlugin()
 {
-  CSI_METHOD_FOREACH(DECLARE_MOCK_CSI_METHOD_IMPL)
+  EXPECT_CALL(*this, GetPluginInfo(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  // Enable all plugin capabilities by default for testing with the test CSI
+  // plugin in forwarding mode.
+  EXPECT_CALL(*this, GetPluginCapabilities(_, _, _))
+    .WillRepeatedly(Invoke([](
+        ServerContext* context,
+        const csi::v0::GetPluginCapabilitiesRequest* request,
+        csi::v0::GetPluginCapabilitiesResponse* response) {
+      response->add_capabilities()->mutable_service()->set_type(
+          csi::v0::PluginCapability::Service::CONTROLLER_SERVICE);
+
+      return Status::OK;
+    }));
+
+  EXPECT_CALL(*this, Probe(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, CreateVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, DeleteVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, ControllerPublishVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, ControllerUnpublishVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, ValidateVolumeCapabilities(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, ListVolumes(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, GetCapacity(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  // Enable all controller capabilities by default for testing with the test CSI
+  // plugin in forwarding mode.
+  EXPECT_CALL(*this, ControllerGetCapabilities(_, _, _))
+    .WillRepeatedly(Invoke([](
+        ServerContext* context,
+        const csi::v0::ControllerGetCapabilitiesRequest* request,
+        csi::v0::ControllerGetCapabilitiesResponse* response) {
+      response->add_capabilities()->mutable_rpc()->set_type(
+          csi::v0::ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME);
+      response->add_capabilities()->mutable_rpc()->set_type(
+          csi::v0::ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME);
+      response->add_capabilities()->mutable_rpc()->set_type(
+          csi::v0::ControllerServiceCapability::RPC::GET_CAPACITY);
+      response->add_capabilities()->mutable_rpc()->set_type(
+          csi::v0::ControllerServiceCapability::RPC::LIST_VOLUMES);
+
+      return Status::OK;
+    }));
+
+  EXPECT_CALL(*this, NodeStageVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, NodeUnstageVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, NodePublishVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, NodeUnpublishVolume(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  EXPECT_CALL(*this, NodeGetId(_, _, _))
+    .WillRepeatedly(Return(Status::OK));
+
+  // Enable all node capabilities by default for testing with the test CSI
+  // plugin in forwarding mode.
+  EXPECT_CALL(*this, NodeGetCapabilities(_, _, _))
+    .WillRepeatedly(Invoke([](
+        ServerContext* context,
+        const csi::v0::NodeGetCapabilitiesRequest* request,
+        csi::v0::NodeGetCapabilitiesResponse* response) {
+      response->add_capabilities()->mutable_rpc()->set_type(
+          csi::v0::NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME);
+
+      return Status::OK;
+    }));
 }
 
 
diff --git a/src/tests/mock_csi_plugin.hpp b/src/tests/mock_csi_plugin.hpp
index 4642326..6897fbc 100644
--- a/src/tests/mock_csi_plugin.hpp
+++ b/src/tests/mock_csi_plugin.hpp
@@ -37,31 +37,6 @@ namespace mesos {
 namespace internal {
 namespace tests {
 
-#define CSI_METHOD_FOREACH(macro)            \
-  macro(GetPluginInfo)                       \
-  macro(GetPluginCapabilities)               \
-  macro(Probe)                               \
-  macro(CreateVolume)                        \
-  macro(DeleteVolume)                        \
-  macro(ControllerPublishVolume)             \
-  macro(ControllerUnpublishVolume)           \
-  macro(ValidateVolumeCapabilities)          \
-  macro(ListVolumes)                         \
-  macro(GetCapacity)                         \
-  macro(ControllerGetCapabilities)           \
-  macro(NodeStageVolume)                     \
-  macro(NodeUnstageVolume)                   \
-  macro(NodePublishVolume)                   \
-  macro(NodeUnpublishVolume)                 \
-  macro(NodeGetId)                           \
-  macro(NodeGetCapabilities)
-
-#define DECLARE_MOCK_CSI_METHOD(name)        \
-  MOCK_METHOD3(name, grpc::Status(           \
-      grpc::ServerContext* context,          \
-      const csi::v0::name##Request* request, \
-      csi::v0::name##Response* response));
-
 // Definition of a mock CSI plugin to be used in tests with gmock.
 class MockCSIPlugin : public csi::v0::Identity::Service,
                       public csi::v0::Controller::Service,
@@ -70,7 +45,90 @@ class MockCSIPlugin : public csi::v0::Identity::Service,
 public:
   MockCSIPlugin();
 
-  CSI_METHOD_FOREACH(DECLARE_MOCK_CSI_METHOD)
+  MOCK_METHOD3(GetPluginInfo, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::GetPluginInfoRequest*,
+      csi::v0::GetPluginInfoResponse*));
+
+  MOCK_METHOD3(GetPluginCapabilities, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::GetPluginCapabilitiesRequest*,
+      csi::v0::GetPluginCapabilitiesResponse*));
+
+  MOCK_METHOD3(Probe, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ProbeRequest*,
+      csi::v0::ProbeResponse*));
+
+  MOCK_METHOD3(CreateVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::CreateVolumeRequest*,
+      csi::v0::CreateVolumeResponse*));
+
+  MOCK_METHOD3(DeleteVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::DeleteVolumeRequest*,
+      csi::v0::DeleteVolumeResponse*));
+
+  MOCK_METHOD3(ControllerPublishVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ControllerPublishVolumeRequest*,
+      csi::v0::ControllerPublishVolumeResponse*));
+
+  MOCK_METHOD3(ControllerUnpublishVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ControllerUnpublishVolumeRequest*,
+      csi::v0::ControllerUnpublishVolumeResponse*));
+
+  MOCK_METHOD3(ValidateVolumeCapabilities, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ValidateVolumeCapabilitiesRequest*,
+      csi::v0::ValidateVolumeCapabilitiesResponse*));
+
+  MOCK_METHOD3(ListVolumes, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ListVolumesRequest*,
+      csi::v0::ListVolumesResponse*));
+
+  MOCK_METHOD3(GetCapacity, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::GetCapacityRequest*,
+      csi::v0::GetCapacityResponse*));
+
+  MOCK_METHOD3(ControllerGetCapabilities, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::ControllerGetCapabilitiesRequest*,
+      csi::v0::ControllerGetCapabilitiesResponse*));
+
+  MOCK_METHOD3(NodeStageVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodeStageVolumeRequest*,
+      csi::v0::NodeStageVolumeResponse*));
+
+  MOCK_METHOD3(NodeUnstageVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodeUnstageVolumeRequest*,
+      csi::v0::NodeUnstageVolumeResponse*));
+
+  MOCK_METHOD3(NodePublishVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodePublishVolumeRequest*,
+      csi::v0::NodePublishVolumeResponse*));
+
+  MOCK_METHOD3(NodeUnpublishVolume, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodeUnpublishVolumeRequest*,
+      csi::v0::NodeUnpublishVolumeResponse*));
+
+  MOCK_METHOD3(NodeGetId, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodeGetIdRequest*,
+      csi::v0::NodeGetIdResponse*));
+
+  MOCK_METHOD3(NodeGetCapabilities, grpc::Status(
+      grpc::ServerContext*,
+      const csi::v0::NodeGetCapabilitiesRequest*,
+      csi::v0::NodeGetCapabilitiesResponse*));
 
   Try<process::grpc::client::Connection> startup(
       const Option<std::string>& address = None());