open-nomad/nomad/volumewatcher/interfaces_test.go
Tim Gross 314458ebdb
csi: update volumewatcher to use unpublish RPC (#8579)
This changeset updates `nomad/volumewatcher` to take advantage of the
`CSIVolume.Unpublish` RPC. This lets us eliminate a bunch of code and
associated tests. The raft batching code can be safely dropped, as the
characteristic times of the CSI RPCs are on the order of seconds or even
minutes, so batching up raft RPCs added complexity without any real world
performance wins.

Includes refactor w/ test cleanup and dead code elimination in volumewatcher
2020-08-06 14:31:18 -04:00

82 lines
2.3 KiB
Go

package volumewatcher
import (
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/state"
"github.com/hashicorp/nomad/nomad/structs"
)
// Create a client node with plugin info
func testNode(plugin *structs.CSIPlugin, s *state.StateStore) *structs.Node {
node := mock.Node()
node.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early version
node.CSINodePlugins = map[string]*structs.CSIInfo{
plugin.ID: {
PluginID: plugin.ID,
Healthy: true,
RequiresControllerPlugin: plugin.ControllerRequired,
NodeInfo: &structs.CSINodeInfo{},
},
}
if plugin.ControllerRequired {
node.CSIControllerPlugins = map[string]*structs.CSIInfo{
plugin.ID: {
PluginID: plugin.ID,
Healthy: true,
RequiresControllerPlugin: true,
ControllerInfo: &structs.CSIControllerInfo{
SupportsReadOnlyAttach: true,
SupportsAttachDetach: true,
SupportsListVolumes: true,
SupportsListVolumesAttachedNodes: false,
},
},
}
} else {
node.CSIControllerPlugins = map[string]*structs.CSIInfo{}
}
s.UpsertNode(99, node)
return node
}
// Create a test volume with claim info
func testVolume(plugin *structs.CSIPlugin, alloc *structs.Allocation, nodeID string) *structs.CSIVolume {
vol := mock.CSIVolume(plugin)
vol.ControllerRequired = plugin.ControllerRequired
vol.ReadAllocs = map[string]*structs.Allocation{alloc.ID: alloc}
vol.ReadClaims = map[string]*structs.CSIVolumeClaim{
alloc.ID: {
AllocationID: alloc.ID,
NodeID: nodeID,
Mode: structs.CSIVolumeClaimRead,
State: structs.CSIVolumeClaimStateTaken,
},
}
return vol
}
type MockRPCServer struct {
state *state.StateStore
nextCSIUnpublishResponse *structs.CSIVolumeUnpublishResponse
nextCSIUnpublishError error
countCSIUnpublish int
}
func (srv *MockRPCServer) Unpublish(args *structs.CSIVolumeUnpublishRequest, reply *structs.CSIVolumeUnpublishResponse) error {
reply = srv.nextCSIUnpublishResponse
srv.countCSIUnpublish++
return srv.nextCSIUnpublishError
}
func (srv *MockRPCServer) State() *state.StateStore { return srv.state }
type MockBatchingRPCServer struct {
MockRPCServer
}
type MockStatefulRPCServer struct {
MockRPCServer
}