github.com/uchennaokeke444/nomad@v0.11.8/nomad/structs/csi_test.go (about) 1 package structs 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func TestCSIVolumeClaim(t *testing.T) { 10 vol := NewCSIVolume("", 0) 11 vol.AccessMode = CSIVolumeAccessModeMultiNodeSingleWriter 12 vol.Schedulable = true 13 14 alloc := &Allocation{ID: "a1", Namespace: "n", JobID: "j"} 15 claim := &CSIVolumeClaim{ 16 AllocationID: alloc.ID, 17 NodeID: "foo", 18 Mode: CSIVolumeClaimRead, 19 } 20 21 require.NoError(t, vol.ClaimRead(claim, alloc)) 22 require.True(t, vol.ReadSchedulable()) 23 require.True(t, vol.WriteSchedulable()) 24 require.NoError(t, vol.ClaimRead(claim, alloc)) 25 26 claim.Mode = CSIVolumeClaimWrite 27 require.NoError(t, vol.ClaimWrite(claim, alloc)) 28 require.True(t, vol.ReadSchedulable()) 29 require.False(t, vol.WriteFreeClaims()) 30 31 vol.ClaimRelease(claim) 32 require.True(t, vol.ReadSchedulable()) 33 require.False(t, vol.WriteFreeClaims()) 34 35 claim.State = CSIVolumeClaimStateReadyToFree 36 vol.ClaimRelease(claim) 37 require.True(t, vol.ReadSchedulable()) 38 require.True(t, vol.WriteFreeClaims()) 39 } 40 41 func TestCSIPluginCleanup(t *testing.T) { 42 plug := NewCSIPlugin("foo", 1000) 43 plug.AddPlugin("n0", &CSIInfo{ 44 PluginID: "foo", 45 AllocID: "a0", 46 Healthy: true, 47 Provider: "foo-provider", 48 RequiresControllerPlugin: true, 49 RequiresTopologies: false, 50 ControllerInfo: &CSIControllerInfo{}, 51 }) 52 53 plug.AddPlugin("n0", &CSIInfo{ 54 PluginID: "foo", 55 AllocID: "a0", 56 Healthy: true, 57 Provider: "foo-provider", 58 RequiresControllerPlugin: true, 59 RequiresTopologies: false, 60 NodeInfo: &CSINodeInfo{}, 61 }) 62 63 require.Equal(t, 1, plug.ControllersHealthy) 64 require.Equal(t, 1, plug.NodesHealthy) 65 66 plug.DeleteNode("n0") 67 require.Equal(t, 0, plug.ControllersHealthy) 68 require.Equal(t, 0, plug.NodesHealthy) 69 70 require.Equal(t, 0, len(plug.Controllers)) 71 require.Equal(t, 0, len(plug.Nodes)) 72 }