2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
package nomad
|
|
|
|
|
|
|
|
import (
|
2020-05-26 22:53:04 +00:00
|
|
|
"fmt"
|
2020-08-06 17:24:24 +00:00
|
|
|
"net/rpc"
|
2020-02-21 10:32:10 +00:00
|
|
|
"testing"
|
2020-08-06 17:24:24 +00:00
|
|
|
"time"
|
2020-02-21 10:32:10 +00:00
|
|
|
|
2020-04-10 20:47:21 +00:00
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
2023-05-01 21:18:34 +00:00
|
|
|
msgpackrpc "github.com/hashicorp/net-rpc-msgpackrpc"
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2020-02-21 10:32:10 +00:00
|
|
|
"github.com/hashicorp/nomad/client"
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
2020-04-10 20:47:21 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/uuid"
|
|
|
|
"github.com/hashicorp/nomad/nomad/mock"
|
2020-02-21 10:32:10 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
"github.com/hashicorp/nomad/testutil"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2021-03-19 14:52:43 +00:00
|
|
|
// MockClientCSI is a mock for the nomad.ClientCSI RPC server (see
|
|
|
|
// nomad/client_csi_endpoint.go). This can be used with a TestRPCOnlyClient to
|
|
|
|
// return specific plugin responses back to server RPCs for testing. Note that
|
|
|
|
// responses that have no bodies have no "Next*Response" field and will always
|
|
|
|
// return an empty response body.
|
|
|
|
type MockClientCSI struct {
|
2023-09-14 19:38:05 +00:00
|
|
|
NextValidateError error
|
|
|
|
NextAttachError error
|
|
|
|
NextAttachResponse *cstructs.ClientCSIControllerAttachVolumeResponse
|
|
|
|
NextDetachError error
|
|
|
|
NextCreateError error
|
|
|
|
NextCreateResponse *cstructs.ClientCSIControllerCreateVolumeResponse
|
|
|
|
NextDeleteError error
|
|
|
|
NextListExternalError error
|
|
|
|
NextListExternalResponse *cstructs.ClientCSIControllerListVolumesResponse
|
|
|
|
NextCreateSnapshotError error
|
|
|
|
NextCreateSnapshotResponse *cstructs.ClientCSIControllerCreateSnapshotResponse
|
|
|
|
NextDeleteSnapshotError error
|
|
|
|
NextListExternalSnapshotsError error
|
|
|
|
NextListExternalSnapshotsResponse *cstructs.ClientCSIControllerListSnapshotsResponse
|
|
|
|
NextControllerExpandVolumeError error
|
|
|
|
NextControllerExpandVolumeResponse *cstructs.ClientCSIControllerExpandVolumeResponse
|
|
|
|
NextNodeDetachError error
|
2023-09-18 19:29:29 +00:00
|
|
|
NextNodeExpandError error
|
|
|
|
LastNodeExpandRequest *cstructs.ClientCSINodeExpandVolumeRequest
|
2021-03-19 14:52:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newMockClientCSI() *MockClientCSI {
|
|
|
|
return &MockClientCSI{
|
2023-09-14 19:38:05 +00:00
|
|
|
NextAttachResponse: &cstructs.ClientCSIControllerAttachVolumeResponse{},
|
|
|
|
NextCreateResponse: &cstructs.ClientCSIControllerCreateVolumeResponse{},
|
|
|
|
NextListExternalResponse: &cstructs.ClientCSIControllerListVolumesResponse{},
|
|
|
|
NextCreateSnapshotResponse: &cstructs.ClientCSIControllerCreateSnapshotResponse{},
|
|
|
|
NextListExternalSnapshotsResponse: &cstructs.ClientCSIControllerListSnapshotsResponse{},
|
|
|
|
NextControllerExpandVolumeResponse: &cstructs.ClientCSIControllerExpandVolumeResponse{},
|
2021-03-19 14:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerValidateVolume(req *cstructs.ClientCSIControllerValidateVolumeRequest, resp *cstructs.ClientCSIControllerValidateVolumeResponse) error {
|
|
|
|
return c.NextValidateError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerAttachVolume(req *cstructs.ClientCSIControllerAttachVolumeRequest, resp *cstructs.ClientCSIControllerAttachVolumeResponse) error {
|
|
|
|
*resp = *c.NextAttachResponse
|
|
|
|
return c.NextAttachError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerDetachVolume(req *cstructs.ClientCSIControllerDetachVolumeRequest, resp *cstructs.ClientCSIControllerDetachVolumeResponse) error {
|
|
|
|
return c.NextDetachError
|
|
|
|
}
|
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
func (c *MockClientCSI) ControllerCreateVolume(req *cstructs.ClientCSIControllerCreateVolumeRequest, resp *cstructs.ClientCSIControllerCreateVolumeResponse) error {
|
|
|
|
*resp = *c.NextCreateResponse
|
|
|
|
return c.NextCreateError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerDeleteVolume(req *cstructs.ClientCSIControllerDeleteVolumeRequest, resp *cstructs.ClientCSIControllerDeleteVolumeResponse) error {
|
|
|
|
return c.NextDeleteError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerListVolumes(req *cstructs.ClientCSIControllerListVolumesRequest, resp *cstructs.ClientCSIControllerListVolumesResponse) error {
|
|
|
|
*resp = *c.NextListExternalResponse
|
|
|
|
return c.NextListExternalError
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
func (c *MockClientCSI) ControllerCreateSnapshot(req *cstructs.ClientCSIControllerCreateSnapshotRequest, resp *cstructs.ClientCSIControllerCreateSnapshotResponse) error {
|
|
|
|
*resp = *c.NextCreateSnapshotResponse
|
|
|
|
return c.NextCreateSnapshotError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerDeleteSnapshot(req *cstructs.ClientCSIControllerDeleteSnapshotRequest, resp *cstructs.ClientCSIControllerDeleteSnapshotResponse) error {
|
|
|
|
return c.NextDeleteSnapshotError
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *MockClientCSI) ControllerListSnapshots(req *cstructs.ClientCSIControllerListSnapshotsRequest, resp *cstructs.ClientCSIControllerListSnapshotsResponse) error {
|
|
|
|
*resp = *c.NextListExternalSnapshotsResponse
|
|
|
|
return c.NextListExternalSnapshotsError
|
|
|
|
}
|
|
|
|
|
2023-09-14 19:38:05 +00:00
|
|
|
func (c *MockClientCSI) ControllerExpandVolume(req *cstructs.ClientCSIControllerExpandVolumeRequest, resp *cstructs.ClientCSIControllerExpandVolumeResponse) error {
|
|
|
|
*resp = *c.NextControllerExpandVolumeResponse
|
|
|
|
return c.NextControllerExpandVolumeError
|
|
|
|
}
|
|
|
|
|
2021-03-19 14:52:43 +00:00
|
|
|
func (c *MockClientCSI) NodeDetachVolume(req *cstructs.ClientCSINodeDetachVolumeRequest, resp *cstructs.ClientCSINodeDetachVolumeResponse) error {
|
|
|
|
return c.NextNodeDetachError
|
|
|
|
}
|
|
|
|
|
2023-09-18 19:29:29 +00:00
|
|
|
func (c *MockClientCSI) NodeExpandVolume(req *cstructs.ClientCSINodeExpandVolumeRequest, resp *cstructs.ClientCSINodeExpandVolumeResponse) error {
|
|
|
|
c.LastNodeExpandRequest = req
|
|
|
|
return c.NextNodeExpandError
|
|
|
|
}
|
|
|
|
|
2020-02-21 10:32:10 +00:00
|
|
|
func TestClientCSIController_AttachVolume_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-02-21 10:32:10 +00:00
|
|
|
require := require.New(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
2020-02-21 10:32:10 +00:00
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerAttachVolumeRequest{
|
2020-08-06 17:24:24 +00:00
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
2020-02-21 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerAttachVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
2020-02-21 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_AttachVolume_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-02-21 10:32:10 +00:00
|
|
|
require := require.New(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
2020-02-21 10:32:10 +00:00
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerAttachVolumeRequest{
|
2020-08-06 17:24:24 +00:00
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
2020-02-21 10:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerAttachVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
2020-02-21 10:32:10 +00:00
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
|
|
|
func TestClientCSIController_DetachVolume_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-03-16 19:59:42 +00:00
|
|
|
require := require.New(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
req := &cstructs.ClientCSIControllerDetachVolumeRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDetachVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
func TestClientCSIController_DetachVolume_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
2020-03-16 19:59:42 +00:00
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerDetachVolumeRequest{
|
2020-08-06 17:24:24 +00:00
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
2020-03-16 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
2020-04-02 20:04:56 +00:00
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDetachVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
2020-03-16 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
func TestClientCSIController_ValidateVolume_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-03-16 19:59:42 +00:00
|
|
|
require := require.New(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
req := &cstructs.ClientCSIControllerValidateVolumeRequest{
|
|
|
|
VolumeID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerValidateVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
func TestClientCSIController_ValidateVolume_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-08-06 17:24:24 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
2020-03-16 19:59:42 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
req := &cstructs.ClientCSIControllerValidateVolumeRequest{
|
|
|
|
VolumeID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
2020-03-16 19:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
2020-08-06 17:24:24 +00:00
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerValidateVolume", req, &resp)
|
2021-03-19 14:52:43 +00:00
|
|
|
require.Error(err)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
2020-03-16 19:59:42 +00:00
|
|
|
}
|
2020-04-10 20:47:21 +00:00
|
|
|
|
2021-03-22 13:43:30 +00:00
|
|
|
func TestClientCSIController_CreateVolume_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerCreateVolume", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_CreateVolume_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerCreateVolumeRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerCreateVolume", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_DeleteVolume_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerDeleteVolumeRequest{
|
|
|
|
ExternalVolumeID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDeleteVolume", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_DeleteVolume_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerDeleteVolumeRequest{
|
|
|
|
ExternalVolumeID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDeleteVolume", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_ListVolumes_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerListVolumesRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerListVolumes", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_ListVolumes_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-03-22 13:43:30 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerListVolumesRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerListVolumes", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
2021-04-01 15:16:52 +00:00
|
|
|
func TestClientCSIController_CreateSnapshot_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerCreateSnapshotRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerCreateSnapshot", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_CreateSnapshot_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerCreateSnapshotRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerCreateSnapshot", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_DeleteSnapshot_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerDeleteSnapshotRequest{
|
|
|
|
ID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDeleteSnapshot", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_DeleteSnapshot_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerDeleteSnapshotRequest{
|
|
|
|
ID: "test",
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerDeleteSnapshot", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_ListSnapshots_Local(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupLocal(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerListSnapshotsRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerListSnapshots", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestClientCSIController_ListSnapshots_Forwarded(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2021-04-01 15:16:52 +00:00
|
|
|
require := require.New(t)
|
|
|
|
codec, cleanup := setupForward(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
req := &cstructs.ClientCSIControllerListSnapshotsRequest{
|
|
|
|
CSIControllerQuery: cstructs.CSIControllerQuery{PluginID: "minnie"},
|
|
|
|
}
|
|
|
|
|
|
|
|
var resp structs.GenericResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "ClientCSI.ControllerListSnapshots", req, &resp)
|
|
|
|
require.Error(err)
|
|
|
|
require.Contains(err.Error(), "no plugins registered for type")
|
|
|
|
}
|
|
|
|
|
2020-04-10 20:47:21 +00:00
|
|
|
func TestClientCSI_NodeForControllerPlugin(t *testing.T) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
2020-04-10 20:47:21 +00:00
|
|
|
srv, shutdown := TestServer(t, func(c *Config) {})
|
|
|
|
testutil.WaitForLeader(t, srv.RPC)
|
|
|
|
defer shutdown()
|
|
|
|
|
|
|
|
plugins := map[string]*structs.CSIInfo{
|
|
|
|
"minnie": {PluginID: "minnie",
|
|
|
|
Healthy: true,
|
|
|
|
ControllerInfo: &structs.CSIControllerInfo{},
|
|
|
|
NodeInfo: &structs.CSINodeInfo{},
|
|
|
|
RequiresControllerPlugin: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
state := srv.fsm.State()
|
|
|
|
|
|
|
|
node1 := mock.Node()
|
|
|
|
node1.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early versions
|
|
|
|
node1.CSIControllerPlugins = plugins
|
|
|
|
node2 := mock.Node()
|
|
|
|
node2.CSIControllerPlugins = plugins
|
|
|
|
node2.ID = uuid.Generate()
|
|
|
|
node3 := mock.Node()
|
|
|
|
node3.ID = uuid.Generate()
|
|
|
|
|
2020-10-19 13:30:15 +00:00
|
|
|
err := state.UpsertNode(structs.MsgTypeTestSetup, 1002, node1)
|
2020-04-10 20:47:21 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-19 13:30:15 +00:00
|
|
|
err = state.UpsertNode(structs.MsgTypeTestSetup, 1003, node2)
|
2020-04-10 20:47:21 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-19 13:30:15 +00:00
|
|
|
err = state.UpsertNode(structs.MsgTypeTestSetup, 1004, node3)
|
2020-04-10 20:47:21 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ws := memdb.NewWatchSet()
|
|
|
|
|
|
|
|
plugin, err := state.CSIPluginByID(ws, "minnie")
|
|
|
|
require.NoError(t, err)
|
2022-12-02 15:12:05 +00:00
|
|
|
|
2023-01-26 21:40:58 +00:00
|
|
|
clientCSI := NewClientCSIEndpoint(srv, nil)
|
2022-12-02 15:12:05 +00:00
|
|
|
nodeIDs, err := clientCSI.clientIDsForController(plugin.ID)
|
2020-08-06 17:24:24 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, 1, len(nodeIDs))
|
2020-04-10 20:47:21 +00:00
|
|
|
// only node1 has both the controller and a recent Nomad version
|
2020-08-06 17:24:24 +00:00
|
|
|
require.Equal(t, nodeIDs[0], node1.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets up a pair of servers, each with one client, and registers a plugin to the clients.
|
|
|
|
// returns a RPC client to the leader and a cleanup function.
|
|
|
|
func setupForward(t *testing.T) (rpc.ClientCodec, func()) {
|
|
|
|
|
2021-03-19 14:52:43 +00:00
|
|
|
s1, cleanupS1 := TestServer(t, func(c *Config) { c.BootstrapExpect = 2 })
|
|
|
|
s2, cleanupS2 := TestServer(t, func(c *Config) { c.BootstrapExpect = 2 })
|
|
|
|
TestJoin(t, s1, s2)
|
2020-08-06 17:24:24 +00:00
|
|
|
|
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
2021-03-19 14:52:43 +00:00
|
|
|
testutil.WaitForLeader(t, s2.RPC)
|
2020-08-06 17:24:24 +00:00
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
|
|
|
c1, cleanupC1 := client.TestClient(t, func(c *config.Config) {
|
|
|
|
c.Servers = []string{s1.config.RPCAddr.String()}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Wait for client initialization
|
|
|
|
select {
|
|
|
|
case <-c1.Ready():
|
|
|
|
case <-time.After(10 * time.Second):
|
|
|
|
cleanupC1()
|
2021-03-19 14:52:43 +00:00
|
|
|
cleanupS1()
|
|
|
|
cleanupS2()
|
2020-08-06 17:24:24 +00:00
|
|
|
t.Fatal("client timedout on initialize")
|
|
|
|
}
|
|
|
|
|
|
|
|
c2, cleanupC2 := client.TestClient(t, func(c *config.Config) {
|
|
|
|
c.Servers = []string{s2.config.RPCAddr.String()}
|
|
|
|
})
|
|
|
|
select {
|
|
|
|
case <-c2.Ready():
|
|
|
|
case <-time.After(10 * time.Second):
|
|
|
|
cleanupC1()
|
2021-03-19 14:52:43 +00:00
|
|
|
cleanupC2()
|
|
|
|
cleanupS1()
|
|
|
|
cleanupS2()
|
2020-08-06 17:24:24 +00:00
|
|
|
t.Fatal("client timedout on initialize")
|
|
|
|
}
|
|
|
|
|
|
|
|
s1.nodeConnsLock.Lock()
|
|
|
|
delete(s1.nodeConns, c2.NodeID())
|
|
|
|
s1.nodeConnsLock.Unlock()
|
|
|
|
|
|
|
|
s2.nodeConnsLock.Lock()
|
|
|
|
delete(s2.nodeConns, c1.NodeID())
|
|
|
|
s2.nodeConnsLock.Unlock()
|
|
|
|
|
|
|
|
waitForNodes(t, s2, 1, 2)
|
|
|
|
|
|
|
|
plugins := map[string]*structs.CSIInfo{
|
|
|
|
"minnie": {PluginID: "minnie",
|
|
|
|
Healthy: true,
|
|
|
|
ControllerInfo: &structs.CSIControllerInfo{},
|
|
|
|
NodeInfo: &structs.CSINodeInfo{},
|
|
|
|
RequiresControllerPlugin: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// update w/ plugin
|
|
|
|
node1 := c1.Node()
|
|
|
|
node1.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early versions
|
|
|
|
node1.CSIControllerPlugins = plugins
|
|
|
|
|
2020-10-19 13:30:15 +00:00
|
|
|
s1.fsm.state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
|
2020-08-06 17:24:24 +00:00
|
|
|
|
|
|
|
cleanup := func() {
|
|
|
|
cleanupC1()
|
|
|
|
cleanupC2()
|
2021-03-19 14:52:43 +00:00
|
|
|
cleanupS2()
|
|
|
|
cleanupS1()
|
2020-08-06 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return codec, cleanup
|
2020-04-10 20:47:21 +00:00
|
|
|
}
|
2020-05-26 22:53:04 +00:00
|
|
|
|
2020-08-06 17:24:24 +00:00
|
|
|
// sets up a single server with a client, and registers a plugin to the client.
|
|
|
|
func setupLocal(t *testing.T) (rpc.ClientCodec, func()) {
|
2021-03-19 14:52:43 +00:00
|
|
|
var err error
|
2020-08-06 17:24:24 +00:00
|
|
|
s1, cleanupS1 := TestServer(t, func(c *Config) { c.BootstrapExpect = 1 })
|
|
|
|
|
|
|
|
testutil.WaitForLeader(t, s1.RPC)
|
|
|
|
codec := rpcClient(t, s1)
|
|
|
|
|
2021-03-19 14:52:43 +00:00
|
|
|
mockCSI := newMockClientCSI()
|
|
|
|
mockCSI.NextValidateError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextAttachError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextDetachError = fmt.Errorf("no plugins registered for type")
|
2021-03-22 13:43:30 +00:00
|
|
|
mockCSI.NextCreateError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextDeleteError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextListExternalError = fmt.Errorf("no plugins registered for type")
|
2021-04-01 15:16:52 +00:00
|
|
|
mockCSI.NextCreateSnapshotError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextDeleteSnapshotError = fmt.Errorf("no plugins registered for type")
|
|
|
|
mockCSI.NextListExternalSnapshotsError = fmt.Errorf("no plugins registered for type")
|
2020-08-06 17:24:24 +00:00
|
|
|
|
2021-03-19 14:52:43 +00:00
|
|
|
c1, cleanupC1 := client.TestClientWithRPCs(t,
|
|
|
|
func(c *config.Config) {
|
|
|
|
c.Servers = []string{s1.config.RPCAddr.String()}
|
|
|
|
},
|
|
|
|
map[string]interface{}{"CSI": mockCSI},
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
cleanupC1()
|
2020-08-06 17:24:24 +00:00
|
|
|
cleanupS1()
|
2021-03-19 14:52:43 +00:00
|
|
|
require.NoError(t, err, "could not setup test client")
|
|
|
|
}
|
|
|
|
|
2022-08-18 23:32:04 +00:00
|
|
|
node1 := c1.UpdateConfig(func(c *config.Config) {
|
|
|
|
c.Node.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early versions
|
|
|
|
}).Node
|
2021-03-19 14:52:43 +00:00
|
|
|
|
|
|
|
req := &structs.NodeRegisterRequest{
|
|
|
|
Node: node1,
|
|
|
|
WriteRequest: structs.WriteRequest{Region: "global"},
|
|
|
|
}
|
|
|
|
var resp structs.NodeUpdateResponse
|
|
|
|
err = c1.RPC("Node.Register", req, &resp)
|
|
|
|
if err != nil {
|
2020-08-06 17:24:24 +00:00
|
|
|
cleanupC1()
|
2021-03-19 14:52:43 +00:00
|
|
|
cleanupS1()
|
|
|
|
require.NoError(t, err, "could not register client node")
|
2020-08-06 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
waitForNodes(t, s1, 1, 1)
|
|
|
|
|
|
|
|
plugins := map[string]*structs.CSIInfo{
|
|
|
|
"minnie": {PluginID: "minnie",
|
|
|
|
Healthy: true,
|
|
|
|
ControllerInfo: &structs.CSIControllerInfo{},
|
|
|
|
NodeInfo: &structs.CSINodeInfo{},
|
|
|
|
RequiresControllerPlugin: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// update w/ plugin
|
2022-08-18 23:32:04 +00:00
|
|
|
node1 = c1.UpdateConfig(func(c *config.Config) {
|
|
|
|
c.Node.CSIControllerPlugins = plugins
|
|
|
|
}).Node
|
2020-10-19 13:30:15 +00:00
|
|
|
s1.fsm.state.UpsertNode(structs.MsgTypeTestSetup, 1000, node1)
|
2020-08-06 17:24:24 +00:00
|
|
|
|
|
|
|
cleanup := func() {
|
|
|
|
cleanupC1()
|
2021-03-19 14:52:43 +00:00
|
|
|
cleanupS1()
|
2020-08-06 17:24:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return codec, cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
// waitForNodes waits until the server is connected to connectedNodes
|
|
|
|
// clients and totalNodes clients are in the state store
|
|
|
|
func waitForNodes(t *testing.T, s *Server, connectedNodes, totalNodes int) {
|
2020-05-26 22:53:04 +00:00
|
|
|
codec := rpcClient(t, s)
|
|
|
|
|
|
|
|
testutil.WaitForResult(func() (bool, error) {
|
|
|
|
connNodes := s.connectedNodes()
|
2020-08-06 17:24:24 +00:00
|
|
|
if len(connNodes) != connectedNodes {
|
|
|
|
return false, fmt.Errorf("expected %d connected nodes but found %d", connectedNodes, len(connNodes))
|
2020-05-26 22:53:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get := &structs.NodeListRequest{
|
|
|
|
QueryOptions: structs.QueryOptions{Region: "global"},
|
|
|
|
}
|
|
|
|
var resp structs.NodeListResponse
|
|
|
|
err := msgpackrpc.CallWithCodec(codec, "Node.List", get, &resp)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to list nodes: %v", err)
|
|
|
|
}
|
2020-08-06 17:24:24 +00:00
|
|
|
if len(resp.Nodes) != totalNodes {
|
|
|
|
return false, fmt.Errorf("expected %d total nodes but found %d", totalNodes, len(resp.Nodes))
|
2020-05-26 22:53:04 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}, func(err error) {
|
|
|
|
require.NoError(t, err)
|
|
|
|
})
|
|
|
|
}
|