Skip to content

Commit

Permalink
csi: fix mocked modes in volumewatcher test
Browse files Browse the repository at this point in the history
The volumewatcher test incorrectly represents the change in attachment
and access modes introduced in Nomad 1.1.0 to support volume
creation. This leads to a test that happens to pass but only
accidentally.

Update the test to correctly represent the volume modes set by the
existing claims on the test volumes.
  • Loading branch information
tgross committed Feb 22, 2022
1 parent 950ccaf commit 31db51a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,8 +2156,8 @@ func CSIVolume(plugin *structs.CSIPlugin) *structs.CSIVolume {
ExternalID: "vol-01",
Namespace: "default",
Topologies: []*structs.CSITopology{},
AccessMode: structs.CSIVolumeAccessModeSingleNodeWriter,
AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem,
AccessMode: structs.CSIVolumeAccessModeUnknown,
AttachmentMode: structs.CSIVolumeAttachmentModeUnknown,
MountOptions: &structs.CSIMountOptions{},
Secrets: structs.CSISecrets{},
Parameters: map[string]string{},
Expand Down
16 changes: 11 additions & 5 deletions nomad/volumewatcher/interfaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ func testNode(plugin *structs.CSIPlugin, s *state.StateStore) *structs.Node {
return node
}

// Create a test volume with claim info
// Create a test volume with existing claim info
func testVolume(plugin *structs.CSIPlugin, alloc *structs.Allocation, nodeID string) *structs.CSIVolume {
vol := mock.CSIVolume(plugin)
vol.ControllerRequired = plugin.ControllerRequired

// these modes were set by the previous claim
vol.AccessMode = structs.CSIVolumeAccessModeMultiNodeReader
vol.AttachmentMode = structs.CSIVolumeAttachmentModeFilesystem

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,
AllocationID: alloc.ID,
NodeID: nodeID,
AccessMode: structs.CSIVolumeAccessModeMultiNodeReader,
AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem,
Mode: structs.CSIVolumeClaimRead,
State: structs.CSIVolumeClaimStateTaken,
},
}
return vol
Expand Down
2 changes: 2 additions & 0 deletions nomad/volumewatcher/volumes_watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ func TestVolumeWatch_StartStop(t *testing.T) {
AllocationID: alloc1.ID,
NodeID: node.ID,
Mode: structs.CSIVolumeClaimRead,
AccessMode: structs.CSIVolumeAccessModeMultiNodeReader,
}

index++
err = srv.State().CSIVolumeClaim(index, vol.Namespace, vol.ID, claim)
require.NoError(err)
Expand Down

0 comments on commit 31db51a

Please sign in to comment.