github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 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 vol.ReadAllocs = map[string]*structs.Allocation{alloc.ID: alloc} 48 vol.ReadClaims = map[string]*structs.CSIVolumeClaim{ 49 alloc.ID: { 50 AllocationID: alloc.ID, 51 NodeID: nodeID, 52 Mode: structs.CSIVolumeClaimRead, 53 State: structs.CSIVolumeClaimStateTaken, 54 }, 55 } 56 return vol 57 } 58 59 type MockRPCServer struct { 60 state *state.StateStore 61 62 nextCSIUnpublishResponse *structs.CSIVolumeUnpublishResponse 63 nextCSIUnpublishError error 64 countCSIUnpublish int 65 } 66 67 func (srv *MockRPCServer) Unpublish(args *structs.CSIVolumeUnpublishRequest, reply *structs.CSIVolumeUnpublishResponse) error { 68 reply = srv.nextCSIUnpublishResponse 69 srv.countCSIUnpublish++ 70 return srv.nextCSIUnpublishError 71 } 72 73 func (srv *MockRPCServer) State() *state.StateStore { return srv.state } 74 75 type MockBatchingRPCServer struct { 76 MockRPCServer 77 } 78 79 type MockStatefulRPCServer struct { 80 MockRPCServer 81 }