2019-10-14 19:51:10 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCSIVolumeClaim(t *testing.T) {
|
2020-02-03 16:59:00 +00:00
|
|
|
vol := NewCSIVolume("", 0)
|
2020-01-08 22:27:43 +00:00
|
|
|
vol.AccessMode = CSIVolumeAccessModeMultiNodeSingleWriter
|
2020-03-03 15:59:58 +00:00
|
|
|
vol.Schedulable = true
|
2019-10-14 19:51:10 +00:00
|
|
|
|
2020-03-24 01:21:04 +00:00
|
|
|
alloc := &Allocation{ID: "a1", Namespace: "n", JobID: "j"}
|
2020-04-23 15:06:23 +00:00
|
|
|
claim := &CSIVolumeClaim{
|
|
|
|
AllocationID: alloc.ID,
|
|
|
|
NodeID: "foo",
|
|
|
|
Mode: CSIVolumeClaimRead,
|
|
|
|
}
|
2019-10-14 19:51:10 +00:00
|
|
|
|
2020-04-23 15:06:23 +00:00
|
|
|
require.NoError(t, vol.ClaimRead(claim, alloc))
|
2020-03-24 01:21:04 +00:00
|
|
|
require.True(t, vol.ReadSchedulable())
|
|
|
|
require.True(t, vol.WriteSchedulable())
|
2020-04-23 15:06:23 +00:00
|
|
|
require.NoError(t, vol.ClaimRead(claim, alloc))
|
2019-10-14 19:51:10 +00:00
|
|
|
|
2020-04-23 15:06:23 +00:00
|
|
|
claim.Mode = CSIVolumeClaimWrite
|
|
|
|
require.NoError(t, vol.ClaimWrite(claim, alloc))
|
2020-03-24 01:21:04 +00:00
|
|
|
require.True(t, vol.ReadSchedulable())
|
|
|
|
require.False(t, vol.WriteFreeClaims())
|
2019-10-14 19:51:10 +00:00
|
|
|
|
2020-04-23 15:06:23 +00:00
|
|
|
vol.ClaimRelease(claim)
|
2020-03-24 01:21:04 +00:00
|
|
|
require.True(t, vol.ReadSchedulable())
|
2020-04-30 21:11:31 +00:00
|
|
|
require.False(t, vol.WriteFreeClaims())
|
|
|
|
|
|
|
|
claim.State = CSIVolumeClaimStateReadyToFree
|
|
|
|
vol.ClaimRelease(claim)
|
|
|
|
require.True(t, vol.ReadSchedulable())
|
2020-03-24 01:21:04 +00:00
|
|
|
require.True(t, vol.WriteFreeClaims())
|
2019-10-14 19:51:10 +00:00
|
|
|
}
|
2020-03-26 13:43:59 +00:00
|
|
|
|
|
|
|
func TestCSIPluginCleanup(t *testing.T) {
|
|
|
|
plug := NewCSIPlugin("foo", 1000)
|
|
|
|
plug.AddPlugin("n0", &CSIInfo{
|
|
|
|
PluginID: "foo",
|
|
|
|
AllocID: "a0",
|
|
|
|
Healthy: true,
|
|
|
|
Provider: "foo-provider",
|
|
|
|
RequiresControllerPlugin: true,
|
|
|
|
RequiresTopologies: false,
|
|
|
|
ControllerInfo: &CSIControllerInfo{},
|
|
|
|
})
|
|
|
|
|
|
|
|
plug.AddPlugin("n0", &CSIInfo{
|
|
|
|
PluginID: "foo",
|
|
|
|
AllocID: "a0",
|
|
|
|
Healthy: true,
|
|
|
|
Provider: "foo-provider",
|
|
|
|
RequiresControllerPlugin: true,
|
|
|
|
RequiresTopologies: false,
|
|
|
|
NodeInfo: &CSINodeInfo{},
|
|
|
|
})
|
|
|
|
|
|
|
|
require.Equal(t, 1, plug.ControllersHealthy)
|
|
|
|
require.Equal(t, 1, plug.NodesHealthy)
|
|
|
|
|
|
|
|
plug.DeleteNode("n0")
|
|
|
|
require.Equal(t, 0, plug.ControllersHealthy)
|
|
|
|
require.Equal(t, 0, plug.NodesHealthy)
|
|
|
|
|
|
|
|
require.Equal(t, 0, len(plug.Controllers))
|
|
|
|
require.Equal(t, 0, len(plug.Nodes))
|
|
|
|
}
|