2019-12-16 13:19:59 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/dynamicplugins"
|
|
|
|
"github.com/hashicorp/nomad/client/structs"
|
2020-01-09 16:14:07 +00:00
|
|
|
nstructs "github.com/hashicorp/nomad/nomad/structs"
|
2019-12-16 13:19:59 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/csi"
|
|
|
|
"github.com/hashicorp/nomad/plugins/csi/fake"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
var fakePlugin = &dynamicplugins.PluginInfo{
|
|
|
|
Name: "test-plugin",
|
|
|
|
Type: "csi-controller",
|
|
|
|
ConnectionInfo: &dynamicplugins.PluginConnectionInfo{},
|
|
|
|
}
|
|
|
|
|
2020-04-02 20:04:56 +00:00
|
|
|
var fakeNodePlugin = &dynamicplugins.PluginInfo{
|
|
|
|
Name: "test-plugin",
|
|
|
|
Type: "csi-node",
|
|
|
|
ConnectionInfo: &dynamicplugins.PluginConnectionInfo{},
|
|
|
|
}
|
|
|
|
|
2020-02-21 09:48:19 +00:00
|
|
|
func TestCSIController_AttachVolume(t *testing.T) {
|
2019-12-16 13:19:59 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
2019-12-17 11:37:33 +00:00
|
|
|
Request *structs.ClientCSIControllerAttachVolumeRequest
|
2019-12-16 13:19:59 +00:00
|
|
|
ExpectedErr error
|
2019-12-17 11:37:33 +00:00
|
|
|
ExpectedResponse *structs.ClientCSIControllerAttachVolumeResponse
|
2019-12-16 13:19:59 +00:00
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates volumeid is not empty",
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: VolumeID is required"),
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates nodeid is not empty",
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: ClientCSINodeID is required"),
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
{
|
|
|
|
Name: "validates AccessMode",
|
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
2020-02-21 10:55:41 +00:00
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
2020-02-21 10:32:10 +00:00
|
|
|
AccessMode: nstructs.CSIVolumeAccessMode("foo"),
|
2019-12-17 11:37:33 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: unknown volume access mode: foo"),
|
2019-12-17 11:37:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates attachmentmode is not empty",
|
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeMultiNodeReader,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentMode("bar"),
|
2019-12-17 11:37:33 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: unknown volume attachment mode: bar"),
|
2019-12-17 11:37:33 +00:00
|
|
|
},
|
2019-12-16 13:19:59 +00:00
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerPublishVolumeErr = errors.New("hello")
|
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerAttachVolume: hello"),
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handles nil PublishContext",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerPublishVolumeResponse = &csi.ControllerPublishVolumeResponse{}
|
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
ExpectedResponse: &structs.ClientCSIControllerAttachVolumeResponse{},
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handles non-nil PublishContext",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerPublishVolumeResponse = &csi.ControllerPublishVolumeResponse{
|
|
|
|
PublishContext: map[string]string{"foo": "bar"},
|
|
|
|
}
|
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
Request: &structs.ClientCSIControllerAttachVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
2019-12-16 13:19:59 +00:00
|
|
|
},
|
2019-12-17 11:37:33 +00:00
|
|
|
ExpectedResponse: &structs.ClientCSIControllerAttachVolumeResponse{
|
2019-12-16 13:19:59 +00:00
|
|
|
PublishContext: map[string]string{"foo": "bar"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
2019-12-17 11:37:33 +00:00
|
|
|
var resp structs.ClientCSIControllerAttachVolumeResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err = client.ClientRPC("CSI.ControllerAttachVolume", tc.Request, &resp)
|
2019-12-16 13:19:59 +00:00
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-02-18 16:08:38 +00:00
|
|
|
|
2020-02-21 09:48:19 +00:00
|
|
|
func TestCSIController_ValidateVolume(t *testing.T) {
|
2020-02-18 16:08:38 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerValidateVolumeRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerValidateVolumeResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "validates volumeid is not empty",
|
|
|
|
Request: &structs.ClientCSIControllerValidateVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerValidateVolume: VolumeID is required"),
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerValidateVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
2020-02-18 16:08:38 +00:00
|
|
|
VolumeID: "foo",
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerValidateVolume: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates attachmentmode",
|
|
|
|
Request: &structs.ClientCSIControllerValidateVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
2021-06-03 19:47:55 +00:00
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
VolumeCapabilities: []*nstructs.CSIVolumeCapability{{
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentMode("bar"),
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeMultiNodeReader,
|
|
|
|
}},
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerValidateVolume: unknown volume attachment mode: bar"),
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates AccessMode",
|
|
|
|
Request: &structs.ClientCSIControllerValidateVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
2021-06-03 19:47:55 +00:00
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
VolumeCapabilities: []*nstructs.CSIVolumeCapability{{
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessMode("foo"),
|
|
|
|
}},
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerValidateVolume: unknown volume access mode: foo"),
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerValidateVolumeErr = errors.New("hello")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerValidateVolumeRequest{
|
2020-02-21 10:32:10 +00:00
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
2020-02-18 16:08:38 +00:00
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerValidateVolume: hello"),
|
2020-02-18 16:08:38 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerValidateVolumeResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err = client.ClientRPC("CSI.ControllerValidateVolume", tc.Request, &resp)
|
2020-02-18 16:08:38 +00:00
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
|
|
|
func TestCSIController_DetachVolume(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerDetachVolumeRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerDetachVolumeResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerDetachVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerDetachVolume: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
2020-03-16 19:59:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates volumeid is not empty",
|
|
|
|
Request: &structs.ClientCSIControllerDetachVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerDetachVolume: VolumeID is required"),
|
2020-03-16 19:59:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates nodeid is not empty",
|
|
|
|
Request: &structs.ClientCSIControllerDetachVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerDetachVolume: ClientCSINodeID is required"),
|
2020-03-16 19:59:42 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerUnpublishVolumeErr = errors.New("hello")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerDetachVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
ClientCSINodeID: "abcde",
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.ControllerDetachVolume: hello"),
|
2020-03-16 19:59:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerDetachVolumeResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err = client.ClientRPC("CSI.ControllerDetachVolume", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
func TestCSIController_CreateVolume(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerCreateVolumeRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerCreateVolumeResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateVolume: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates AccessMode",
|
|
|
|
Request: &structs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
Name: "1234-4321-1234-4321",
|
|
|
|
VolumeCapabilities: []*nstructs.CSIVolumeCapability{
|
|
|
|
{
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessMode("foo"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateVolume: unknown volume access mode: foo"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates attachmentmode is not empty",
|
|
|
|
Request: &structs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
Name: "1234-4321-1234-4321",
|
|
|
|
VolumeCapabilities: []*nstructs.CSIVolumeCapability{
|
|
|
|
{
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeMultiNodeReader,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentMode("bar"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateVolume: unknown volume attachment mode: bar"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerCreateVolumeErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
Name: "1234-4321-1234-4321",
|
|
|
|
VolumeCapabilities: []*nstructs.CSIVolumeCapability{
|
|
|
|
{
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeSingleNodeWriter,
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateVolume: internal plugin error"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerCreateVolumeResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerCreateVolume", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCSIController_DeleteVolume(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerDeleteVolumeRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerDeleteVolumeResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerDeleteVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerDeleteVolume: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerDeleteVolumeErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerDeleteVolumeRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
ExternalVolumeID: "1234-4321-1234-4321",
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerDeleteVolume: internal plugin error"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerDeleteVolumeResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerDeleteVolume", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCSIController_ListVolumes(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerListVolumesRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerListVolumesResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerListVolumesRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerListVolumes: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerListVolumesErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerListVolumesRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerListVolumes: internal plugin error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns volumes",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerListVolumesResponse = &csi.ControllerListVolumesResponse{
|
|
|
|
Entries: []*csi.ListVolumesResponse_Entry{
|
|
|
|
{
|
|
|
|
Volume: &csi.Volume{
|
|
|
|
CapacityBytes: 1000000,
|
|
|
|
ExternalVolumeID: "vol-1",
|
|
|
|
VolumeContext: map[string]string{"foo": "bar"},
|
|
|
|
ContentSource: &csi.VolumeContentSource{
|
|
|
|
SnapshotID: "snap-1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Status: &csi.ListVolumesResponse_VolumeStatus{
|
|
|
|
PublishedNodeIds: []string{"i-1234", "i-5678"},
|
|
|
|
VolumeCondition: &csi.VolumeCondition{
|
|
|
|
Message: "ok",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NextToken: "2",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerListVolumesRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
StartingToken: "1",
|
|
|
|
MaxEntries: 100,
|
|
|
|
},
|
|
|
|
ExpectedResponse: &structs.ClientCSIControllerListVolumesResponse{
|
|
|
|
Entries: []*nstructs.CSIVolumeExternalStub{
|
|
|
|
{
|
|
|
|
ExternalID: "vol-1",
|
|
|
|
CapacityBytes: 1000000,
|
|
|
|
VolumeContext: map[string]string{"foo": "bar"},
|
|
|
|
SnapshotID: "snap-1",
|
|
|
|
PublishedExternalNodeIDs: []string{"i-1234", "i-5678"},
|
|
|
|
Status: "ok",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NextToken: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerListVolumesResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerListVolumes", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-04-01 15:16:52 +00:00
|
|
|
func TestCSIController_CreateSnapshot(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerCreateSnapshotRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerCreateSnapshotResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerCreateSnapshotRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateSnapshot: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerCreateSnapshotErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerCreateSnapshotRequest{
|
|
|
|
ExternalSourceVolumeID: "vol-1",
|
|
|
|
Name: "1234-4321-1234-4321",
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerCreateSnapshot: internal plugin error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns snapshot on success",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerCreateSnapshotResponse = &csi.ControllerCreateSnapshotResponse{
|
|
|
|
Snapshot: &csi.Snapshot{
|
|
|
|
ID: "snap-12345",
|
|
|
|
SourceVolumeID: "vol-1",
|
|
|
|
SizeBytes: 10000000,
|
|
|
|
IsReady: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerCreateSnapshotRequest{
|
|
|
|
ExternalSourceVolumeID: "vol-1",
|
|
|
|
Name: "1234-4321-1234-4321",
|
|
|
|
Secrets: nstructs.CSISecrets{"password": "xyzzy"},
|
|
|
|
Parameters: map[string]string{"foo": "bar"},
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedResponse: &structs.ClientCSIControllerCreateSnapshotResponse{
|
|
|
|
ID: "snap-12345",
|
|
|
|
ExternalSourceVolumeID: "vol-1",
|
|
|
|
SizeBytes: 10000000,
|
|
|
|
IsReady: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerCreateSnapshotResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerCreateSnapshot", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCSIController_DeleteSnapshot(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerDeleteSnapshotRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerDeleteSnapshotResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerDeleteSnapshotRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerDeleteSnapshot: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerDeleteSnapshotErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerDeleteSnapshotRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
ID: "1234-4321-1234-4321",
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerDeleteSnapshot: internal plugin error"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerDeleteSnapshotResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerDeleteSnapshot", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCSIController_ListSnapshots(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSIControllerListSnapshotsRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSIControllerListSnapshotsResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSIControllerListSnapshotsRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerListSnapshots: CSI client error (retryable): plugin some-garbage for type csi-controller not found"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerListSnapshotsErr = errors.New("internal plugin error")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerListSnapshotsRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ExpectedErr: errors.New("CSI.ControllerListSnapshots: internal plugin error"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns volumes",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextControllerListSnapshotsResponse = &csi.ControllerListSnapshotsResponse{
|
|
|
|
Entries: []*csi.ListSnapshotsResponse_Entry{
|
|
|
|
{
|
|
|
|
Snapshot: &csi.Snapshot{
|
|
|
|
ID: "snap-1",
|
|
|
|
SourceVolumeID: "vol-1",
|
|
|
|
SizeBytes: 1000000,
|
|
|
|
IsReady: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NextToken: "2",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSIControllerListSnapshotsRequest{
|
|
|
|
CSIControllerQuery: structs.CSIControllerQuery{
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
StartingToken: "1",
|
|
|
|
MaxEntries: 100,
|
|
|
|
},
|
|
|
|
ExpectedResponse: &structs.ClientCSIControllerListSnapshotsResponse{
|
|
|
|
Entries: []*nstructs.CSISnapshot{
|
|
|
|
{
|
|
|
|
ID: "snap-1",
|
|
|
|
ExternalSourceVolumeID: "vol-1",
|
|
|
|
SizeBytes: 1000000,
|
|
|
|
IsReady: true,
|
|
|
|
PluginID: fakePlugin.Name,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NextToken: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(
|
|
|
|
dynamicplugins.PluginTypeCSIController, dispenserFunc)
|
|
|
|
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSIControllerListSnapshotsResponse
|
|
|
|
err = client.ClientRPC("CSI.ControllerListSnapshots", tc.Request, &resp)
|
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-03-22 13:43:30 +00:00
|
|
|
|
2020-04-02 20:04:56 +00:00
|
|
|
func TestCSINode_DetachVolume(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cases := []struct {
|
|
|
|
Name string
|
|
|
|
ClientSetupFunc func(*fake.Client)
|
|
|
|
Request *structs.ClientCSINodeDetachVolumeRequest
|
|
|
|
ExpectedErr error
|
|
|
|
ExpectedResponse *structs.ClientCSINodeDetachVolumeResponse
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "returns plugin not found errors",
|
|
|
|
Request: &structs.ClientCSINodeDetachVolumeRequest{
|
|
|
|
PluginID: "some-garbage",
|
|
|
|
VolumeID: "-",
|
|
|
|
AllocID: "-",
|
|
|
|
NodeID: "-",
|
|
|
|
AttachmentMode: nstructs.CSIVolumeAttachmentModeFilesystem,
|
|
|
|
AccessMode: nstructs.CSIVolumeAccessModeMultiNodeReader,
|
|
|
|
ReadOnly: true,
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.NodeDetachVolume: plugin some-garbage for type csi-node not found"),
|
2020-04-02 20:04:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates volumeid is not empty",
|
|
|
|
Request: &structs.ClientCSINodeDetachVolumeRequest{
|
|
|
|
PluginID: fakeNodePlugin.Name,
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.NodeDetachVolume: VolumeID is required"),
|
2020-04-02 20:04:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validates nodeid is not empty",
|
|
|
|
Request: &structs.ClientCSINodeDetachVolumeRequest{
|
|
|
|
PluginID: fakeNodePlugin.Name,
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
},
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.NodeDetachVolume: AllocID is required"),
|
2020-04-02 20:04:56 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "returns transitive errors",
|
|
|
|
ClientSetupFunc: func(fc *fake.Client) {
|
|
|
|
fc.NextNodeUnpublishVolumeErr = errors.New("wont-see-this")
|
|
|
|
},
|
|
|
|
Request: &structs.ClientCSINodeDetachVolumeRequest{
|
|
|
|
PluginID: fakeNodePlugin.Name,
|
|
|
|
VolumeID: "1234-4321-1234-4321",
|
|
|
|
AllocID: "4321-1234-4321-1234",
|
|
|
|
},
|
|
|
|
// we don't have a csimanager in this context
|
2021-03-22 13:43:30 +00:00
|
|
|
ExpectedErr: errors.New("CSI.NodeDetachVolume: plugin test-plugin for type csi-node not found"),
|
2020-04-02 20:04:56 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
require := require.New(t)
|
|
|
|
client, cleanup := TestClient(t, nil)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
fakeClient := &fake.Client{}
|
|
|
|
if tc.ClientSetupFunc != nil {
|
|
|
|
tc.ClientSetupFunc(fakeClient)
|
|
|
|
}
|
|
|
|
|
|
|
|
dispenserFunc := func(*dynamicplugins.PluginInfo) (interface{}, error) {
|
|
|
|
return fakeClient, nil
|
|
|
|
}
|
|
|
|
client.dynamicRegistry.StubDispenserForType(dynamicplugins.PluginTypeCSINode, dispenserFunc)
|
|
|
|
err := client.dynamicRegistry.RegisterPlugin(fakeNodePlugin)
|
|
|
|
require.Nil(err)
|
|
|
|
|
|
|
|
var resp structs.ClientCSINodeDetachVolumeResponse
|
|
|
|
err = client.ClientRPC("CSI.NodeDetachVolume", tc.Request, &resp)
|
2020-03-16 19:59:42 +00:00
|
|
|
require.Equal(tc.ExpectedErr, err)
|
|
|
|
if tc.ExpectedResponse != nil {
|
|
|
|
require.Equal(tc.ExpectedResponse, &resp)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|