2019-10-22 13:20:26 +00:00
|
|
|
// fake is a package that includes fake implementations of public interfaces
|
|
|
|
// from the CSI package for testing.
|
|
|
|
package fake
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2020-03-19 21:09:49 +00:00
|
|
|
"fmt"
|
2019-10-22 13:20:26 +00:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/plugins/base"
|
|
|
|
"github.com/hashicorp/nomad/plugins/csi"
|
|
|
|
"github.com/hashicorp/nomad/plugins/shared/hclspec"
|
2020-01-29 11:32:31 +00:00
|
|
|
"google.golang.org/grpc"
|
2019-10-22 13:20:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ csi.CSIPlugin = &Client{}
|
|
|
|
|
|
|
|
// Client is a mock implementation of the csi.CSIPlugin interface for use in testing
|
|
|
|
// external components
|
|
|
|
type Client struct {
|
|
|
|
Mu sync.RWMutex
|
|
|
|
|
|
|
|
NextPluginInfoResponse *base.PluginInfoResponse
|
|
|
|
NextPluginInfoErr error
|
|
|
|
PluginInfoCallCount int64
|
|
|
|
|
|
|
|
NextPluginProbeResponse bool
|
|
|
|
NextPluginProbeErr error
|
|
|
|
PluginProbeCallCount int64
|
|
|
|
|
2020-03-09 13:57:59 +00:00
|
|
|
NextPluginGetInfoNameResponse string
|
|
|
|
NextPluginGetInfoVersionResponse string
|
|
|
|
NextPluginGetInfoErr error
|
|
|
|
PluginGetInfoCallCount int64
|
2019-10-22 13:20:26 +00:00
|
|
|
|
|
|
|
NextPluginGetCapabilitiesResponse *csi.PluginCapabilitySet
|
|
|
|
NextPluginGetCapabilitiesErr error
|
|
|
|
PluginGetCapabilitiesCallCount int64
|
|
|
|
|
2019-12-18 10:57:55 +00:00
|
|
|
NextControllerGetCapabilitiesResponse *csi.ControllerCapabilitySet
|
|
|
|
NextControllerGetCapabilitiesErr error
|
|
|
|
ControllerGetCapabilitiesCallCount int64
|
|
|
|
|
2019-12-16 12:31:09 +00:00
|
|
|
NextControllerPublishVolumeResponse *csi.ControllerPublishVolumeResponse
|
|
|
|
NextControllerPublishVolumeErr error
|
|
|
|
ControllerPublishVolumeCallCount int64
|
|
|
|
|
2020-02-10 16:45:06 +00:00
|
|
|
NextControllerUnpublishVolumeResponse *csi.ControllerUnpublishVolumeResponse
|
|
|
|
NextControllerUnpublishVolumeErr error
|
|
|
|
ControllerUnpublishVolumeCallCount int64
|
|
|
|
|
2021-03-15 20:07:52 +00:00
|
|
|
NextControllerCreateVolumeResponse *csi.ControllerCreateVolumeResponse
|
|
|
|
NextControllerCreateVolumeErr error
|
|
|
|
ControllerCreateVolumeCallCount int64
|
|
|
|
|
|
|
|
NextControllerDeleteVolumeErr error
|
|
|
|
ControllerDeleteVolumeCallCount int64
|
|
|
|
|
|
|
|
NextControllerListVolumesResponse *csi.ControllerListVolumesResponse
|
|
|
|
NextControllerListVolumesErr error
|
|
|
|
ControllerListVolumesCallCount int64
|
|
|
|
|
2020-02-18 16:08:00 +00:00
|
|
|
NextControllerValidateVolumeErr error
|
|
|
|
ControllerValidateVolumeCallCount int64
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
NextControllerCreateSnapshotResponse *csi.ControllerCreateSnapshotResponse
|
|
|
|
NextControllerCreateSnapshotErr error
|
|
|
|
ControllerCreateSnapshotCallCount int64
|
|
|
|
|
|
|
|
NextControllerDeleteSnapshotErr error
|
|
|
|
ControllerDeleteSnapshotCallCount int64
|
|
|
|
|
|
|
|
NextControllerListSnapshotsResponse *csi.ControllerListSnapshotsResponse
|
|
|
|
NextControllerListSnapshotsErr error
|
|
|
|
ControllerListSnapshotsCallCount int64
|
|
|
|
|
2019-12-18 12:18:07 +00:00
|
|
|
NextNodeGetCapabilitiesResponse *csi.NodeCapabilitySet
|
|
|
|
NextNodeGetCapabilitiesErr error
|
|
|
|
NodeGetCapabilitiesCallCount int64
|
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
NextNodeGetInfoResponse *csi.NodeGetInfoResponse
|
|
|
|
NextNodeGetInfoErr error
|
|
|
|
NodeGetInfoCallCount int64
|
2020-01-23 11:28:57 +00:00
|
|
|
|
|
|
|
NextNodeStageVolumeErr error
|
|
|
|
NodeStageVolumeCallCount int64
|
2020-01-24 13:34:04 +00:00
|
|
|
|
|
|
|
NextNodeUnstageVolumeErr error
|
|
|
|
NodeUnstageVolumeCallCount int64
|
2020-01-24 16:20:23 +00:00
|
|
|
|
2020-03-23 17:55:26 +00:00
|
|
|
PrevVolumeCapability *csi.VolumeCapability
|
2020-01-24 16:20:23 +00:00
|
|
|
NextNodePublishVolumeErr error
|
|
|
|
NodePublishVolumeCallCount int64
|
2020-01-27 10:17:10 +00:00
|
|
|
|
|
|
|
NextNodeUnpublishVolumeErr error
|
|
|
|
NodeUnpublishVolumeCallCount int64
|
2019-10-22 13:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PluginInfo describes the type and version of a plugin.
|
|
|
|
func (c *Client) PluginInfo() (*base.PluginInfoResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.PluginInfoCallCount++
|
|
|
|
|
|
|
|
return c.NextPluginInfoResponse, c.NextPluginInfoErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigSchema returns the schema for parsing the plugins configuration.
|
|
|
|
func (c *Client) ConfigSchema() (*hclspec.Spec, error) {
|
|
|
|
return nil, errors.New("Unsupported")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig is used to set the configuration by passing a MessagePack
|
|
|
|
// encoding of it.
|
|
|
|
func (c *Client) SetConfig(a *base.Config) error {
|
|
|
|
return errors.New("Unsupported")
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginProbe is used to verify that the plugin is in a healthy state
|
|
|
|
func (c *Client) PluginProbe(ctx context.Context) (bool, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.PluginProbeCallCount++
|
|
|
|
|
|
|
|
return c.NextPluginProbeResponse, c.NextPluginProbeErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginGetInfo is used to return semantic data about the plugin.
|
|
|
|
// Response:
|
2022-08-16 14:06:30 +00:00
|
|
|
// - string: name, the name of the plugin in domain notation format.
|
2020-03-09 13:57:59 +00:00
|
|
|
func (c *Client) PluginGetInfo(ctx context.Context) (string, string, error) {
|
2019-10-22 13:20:26 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.PluginGetInfoCallCount++
|
|
|
|
|
2020-03-09 13:57:59 +00:00
|
|
|
return c.NextPluginGetInfoNameResponse, c.NextPluginGetInfoVersionResponse, c.NextPluginGetInfoErr
|
2019-10-22 13:20:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PluginGetCapabilities is used to return the available capabilities from the
|
|
|
|
// identity service. This currently only looks for the CONTROLLER_SERVICE and
|
|
|
|
// Accessible Topology Support
|
|
|
|
func (c *Client) PluginGetCapabilities(ctx context.Context) (*csi.PluginCapabilitySet, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.PluginGetCapabilitiesCallCount++
|
|
|
|
|
|
|
|
return c.NextPluginGetCapabilitiesResponse, c.NextPluginGetCapabilitiesErr
|
|
|
|
}
|
|
|
|
|
2019-12-18 10:57:55 +00:00
|
|
|
func (c *Client) ControllerGetCapabilities(ctx context.Context) (*csi.ControllerCapabilitySet, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.ControllerGetCapabilitiesCallCount++
|
|
|
|
|
|
|
|
return c.NextControllerGetCapabilitiesResponse, c.NextControllerGetCapabilitiesErr
|
|
|
|
}
|
|
|
|
|
2019-12-16 12:31:09 +00:00
|
|
|
// ControllerPublishVolume is used to attach a remote volume to a node
|
2020-03-30 20:26:03 +00:00
|
|
|
func (c *Client) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest, opts ...grpc.CallOption) (*csi.ControllerPublishVolumeResponse, error) {
|
2019-12-16 12:31:09 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.ControllerPublishVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextControllerPublishVolumeResponse, c.NextControllerPublishVolumeErr
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:45:06 +00:00
|
|
|
// ControllerUnpublishVolume is used to attach a remote volume to a node
|
2020-03-30 20:26:03 +00:00
|
|
|
func (c *Client) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest, opts ...grpc.CallOption) (*csi.ControllerUnpublishVolumeResponse, error) {
|
2020-02-10 16:45:06 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.ControllerUnpublishVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextControllerUnpublishVolumeResponse, c.NextControllerUnpublishVolumeErr
|
|
|
|
}
|
|
|
|
|
2020-05-15 12:16:01 +00:00
|
|
|
func (c *Client) ControllerValidateCapabilities(ctx context.Context, req *csi.ControllerValidateVolumeRequest, opts ...grpc.CallOption) error {
|
2020-02-18 16:08:00 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.ControllerValidateVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextControllerValidateVolumeErr
|
|
|
|
}
|
|
|
|
|
2021-03-15 20:07:52 +00:00
|
|
|
func (c *Client) ControllerCreateVolume(ctx context.Context, in *csi.ControllerCreateVolumeRequest, opts ...grpc.CallOption) (*csi.ControllerCreateVolumeResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerCreateVolumeCallCount++
|
|
|
|
return c.NextControllerCreateVolumeResponse, c.NextControllerCreateVolumeErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ControllerDeleteVolume(ctx context.Context, req *csi.ControllerDeleteVolumeRequest, opts ...grpc.CallOption) error {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerDeleteVolumeCallCount++
|
|
|
|
return c.NextControllerDeleteVolumeErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ControllerListVolumes(ctx context.Context, req *csi.ControllerListVolumesRequest, opts ...grpc.CallOption) (*csi.ControllerListVolumesResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerListVolumesCallCount++
|
|
|
|
return c.NextControllerListVolumesResponse, c.NextControllerListVolumesErr
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
func (c *Client) ControllerCreateSnapshot(ctx context.Context, req *csi.ControllerCreateSnapshotRequest, opts ...grpc.CallOption) (*csi.ControllerCreateSnapshotResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerCreateSnapshotCallCount++
|
|
|
|
return c.NextControllerCreateSnapshotResponse, c.NextControllerCreateSnapshotErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ControllerDeleteSnapshot(ctx context.Context, req *csi.ControllerDeleteSnapshotRequest, opts ...grpc.CallOption) error {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerDeleteSnapshotCallCount++
|
|
|
|
return c.NextControllerDeleteSnapshotErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ControllerListSnapshots(ctx context.Context, req *csi.ControllerListSnapshotsRequest, opts ...grpc.CallOption) (*csi.ControllerListSnapshotsResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
c.ControllerListSnapshotsCallCount++
|
|
|
|
return c.NextControllerListSnapshotsResponse, c.NextControllerListSnapshotsErr
|
|
|
|
}
|
|
|
|
|
2019-12-18 12:18:07 +00:00
|
|
|
func (c *Client) NodeGetCapabilities(ctx context.Context) (*csi.NodeCapabilitySet, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.NodeGetCapabilitiesCallCount++
|
|
|
|
|
|
|
|
return c.NextNodeGetCapabilitiesResponse, c.NextNodeGetCapabilitiesErr
|
|
|
|
}
|
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
// NodeGetInfo is used to return semantic data about the current node in
|
|
|
|
// respect to the SP.
|
|
|
|
func (c *Client) NodeGetInfo(ctx context.Context) (*csi.NodeGetInfoResponse, error) {
|
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.NodeGetInfoCallCount++
|
|
|
|
|
|
|
|
return c.NextNodeGetInfoResponse, c.NextNodeGetInfoErr
|
|
|
|
}
|
|
|
|
|
2020-01-23 11:28:57 +00:00
|
|
|
// NodeStageVolume is used when a plugin has the STAGE_UNSTAGE volume capability
|
|
|
|
// to prepare a volume for usage on a host. If err == nil, the response should
|
|
|
|
// be assumed to be successful.
|
2020-06-22 17:54:32 +00:00
|
|
|
func (c *Client) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest, opts ...grpc.CallOption) error {
|
2020-01-23 11:28:57 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.NodeStageVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextNodeStageVolumeErr
|
|
|
|
}
|
|
|
|
|
2020-01-24 13:34:04 +00:00
|
|
|
// NodeUnstageVolume is used when a plugin has the STAGE_UNSTAGE volume capability
|
|
|
|
// to undo the work performed by NodeStageVolume. If a volume has been staged,
|
|
|
|
// this RPC must be called before freeing the volume.
|
|
|
|
//
|
|
|
|
// If err == nil, the response should be assumed to be successful.
|
2020-01-31 11:11:17 +00:00
|
|
|
func (c *Client) NodeUnstageVolume(ctx context.Context, volumeID string, stagingTargetPath string, opts ...grpc.CallOption) error {
|
2020-01-24 13:34:04 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.NodeUnstageVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextNodeUnstageVolumeErr
|
|
|
|
}
|
|
|
|
|
2020-01-31 13:45:05 +00:00
|
|
|
func (c *Client) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest, opts ...grpc.CallOption) error {
|
2020-01-24 16:20:23 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
2020-03-23 17:55:26 +00:00
|
|
|
c.PrevVolumeCapability = req.VolumeCapability
|
2020-01-24 16:20:23 +00:00
|
|
|
c.NodePublishVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextNodePublishVolumeErr
|
|
|
|
}
|
|
|
|
|
2020-02-14 12:33:52 +00:00
|
|
|
func (c *Client) NodeUnpublishVolume(ctx context.Context, volumeID, targetPath string, opts ...grpc.CallOption) error {
|
2020-01-27 10:17:10 +00:00
|
|
|
c.Mu.Lock()
|
|
|
|
defer c.Mu.Unlock()
|
|
|
|
|
|
|
|
c.NodeUnpublishVolumeCallCount++
|
|
|
|
|
|
|
|
return c.NextNodeUnpublishVolumeErr
|
|
|
|
}
|
|
|
|
|
2021-08-30 09:08:12 +00:00
|
|
|
// Close the client and ensure any connections are cleaned up.
|
2019-10-22 13:20:26 +00:00
|
|
|
func (c *Client) Close() error {
|
2020-03-19 21:09:49 +00:00
|
|
|
|
|
|
|
c.NextPluginInfoResponse = nil
|
|
|
|
c.NextPluginInfoErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextPluginProbeResponse = false
|
|
|
|
c.NextPluginProbeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextPluginGetInfoNameResponse = ""
|
|
|
|
c.NextPluginGetInfoVersionResponse = ""
|
|
|
|
c.NextPluginGetInfoErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextPluginGetCapabilitiesResponse = nil
|
|
|
|
c.NextPluginGetCapabilitiesErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextControllerGetCapabilitiesResponse = nil
|
|
|
|
c.NextControllerGetCapabilitiesErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextControllerPublishVolumeResponse = nil
|
|
|
|
c.NextControllerPublishVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextControllerUnpublishVolumeResponse = nil
|
|
|
|
c.NextControllerUnpublishVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextControllerValidateVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodeGetCapabilitiesResponse = nil
|
|
|
|
c.NextNodeGetCapabilitiesErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodeGetInfoResponse = nil
|
|
|
|
c.NextNodeGetInfoErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodeStageVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodeUnstageVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodePublishVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
|
|
|
c.NextNodeUnpublishVolumeErr = fmt.Errorf("closed client")
|
|
|
|
|
2019-10-22 13:20:26 +00:00
|
|
|
return nil
|
|
|
|
}
|