github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/nomad/volumewatcher/interfaces_test.go (about) 1 package volumewatcher 2 3 import ( 4 "github.com/hashicorp/nomad/nomad/mock" 5 "github.com/hashicorp/nomad/nomad/state" 6 "github.com/hashicorp/nomad/nomad/structs" 7 ) 8 9 // Create a client node with plugin info 10 func testNode(plugin *structs.CSIPlugin, s *state.StateStore) *structs.Node { 11 node := mock.Node() 12 node.Attributes["nomad.version"] = "0.11.0" // client RPCs not supported on early version 13 node.CSINodePlugins = map[string]*structs.CSIInfo{ 14 plugin.ID: { 15 PluginID: plugin.ID, 16 Healthy: true, 17 RequiresControllerPlugin: plugin.ControllerRequired, 18 NodeInfo: &structs.CSINodeInfo{}, 19 }, 20 } 21 if plugin.ControllerRequired { 22 node.CSIControllerPlugins = map[string]*structs.CSIInfo{ 23 plugin.ID: { 24 PluginID: plugin.ID, 25 Healthy: true, 26 RequiresControllerPlugin: true, 27 ControllerInfo: &structs.CSIControllerInfo{ 28 SupportsReadOnlyAttach: true, 29 SupportsAttachDetach: true, 30 SupportsListVolumes: true, 31 SupportsListVolumesAttachedNodes: false, 32 }, 33 }, 34 } 35 } else { 36 node.CSIControllerPlugins = map[string]*structs.CSIInfo{} 37 } 38 s.UpsertNode(structs.MsgTypeTestSetup, 99, node) 39 return node 40 } 41 42 // Create a test volume with existing claim info 43 func testVolume(plugin *structs.CSIPlugin, alloc *structs.Allocation, nodeID string) *structs.CSIVolume { 44 vol := mock.CSIVolume(plugin) 45 vol.ControllerRequired = plugin.ControllerRequired 46 47 // these modes were set by the previous claim 48 vol.AccessMode = structs.CSIVolumeAccessModeMultiNodeReader 49 vol.AttachmentMode = structs.CSIVolumeAttachmentModeFilesystem 50 51 vol.ReadAllocs = map[string]*structs.Allocation{alloc.ID: alloc} 52 vol.ReadClaims = map[string]*structs.CSIVolumeClaim{ 53 alloc.ID: { 54 AllocationID: alloc.ID, 55 NodeID: nodeID, 56 AccessMode: structs.CSIVolumeAccessModeMultiNodeReader, 57 AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem, 58 Mode: structs.CSIVolumeClaimRead, 59 State: structs.CSIVolumeClaimStateTaken, 60 }, 61 } 62 return vol 63 } 64 65 type MockRPCServer struct { 66 state *state.StateStore 67 68 nextCSIUnpublishResponse *structs.CSIVolumeUnpublishResponse 69 nextCSIUnpublishError error 70 countCSIUnpublish int 71 } 72 73 func (srv *MockRPCServer) Unpublish(args *structs.CSIVolumeUnpublishRequest, reply *structs.CSIVolumeUnpublishResponse) error { 74 reply = srv.nextCSIUnpublishResponse 75 srv.countCSIUnpublish++ 76 return srv.nextCSIUnpublishError 77 } 78 79 func (srv *MockRPCServer) State() *state.StateStore { return srv.state } 80 81 type MockBatchingRPCServer struct { 82 MockRPCServer 83 } 84 85 type MockStatefulRPCServer struct { 86 MockRPCServer 87 }