Skip to content

Commit

Permalink
CSI: fix misleading HTTP test
Browse files Browse the repository at this point in the history
The HTTP test to create CSI volumes depends on having a controller plugin to
talk to, but the test was using a node-only plugin, which allows it to
silently ignore the missing controller.
  • Loading branch information
tgross committed Mar 29, 2021
1 parent 74e37b6 commit 2f155b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
24 changes: 16 additions & 8 deletions command/agent/csi_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestHTTP_CSIEndpointUtils(t *testing.T) {
require.Equal(t, "bar", tops[0].Segments["foo"])
}

func TestHTTP_CSIEndpointVolume(t *testing.T) {
func TestHTTP_CSIEndpointRegisterVolume(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
server := s.Agent.Server()
Expand Down Expand Up @@ -95,28 +95,36 @@ func TestHTTP_CSIEndpointVolume(t *testing.T) {
resp = httptest.NewRecorder()
_, err = s.Server.CSIVolumeSpecificRequest(resp, req)
require.Equal(t, CodedError(400, "detach requires node ID"), err)
})
}

cArgs := structs.CSIVolumeCreateRequest{
func TestHTTP_CSIEndpointCreateVolume(t *testing.T) {
t.Parallel()
httpTest(t, nil, func(s *TestAgent) {
server := s.Agent.Server()
cleanup := state.CreateTestCSIPlugin(server.State(), "foo")
defer cleanup()

args := structs.CSIVolumeCreateRequest{
Volumes: []*structs.CSIVolume{{
ID: "baz",
PluginID: "foo",
AccessMode: structs.CSIVolumeAccessModeMultiNodeSingleWriter,
AttachmentMode: structs.CSIVolumeAttachmentModeFilesystem,
}},
}
body = encodeReq(cArgs)
req, err = http.NewRequest("PUT", "/v1/volumes/create", body)
body := encodeReq(args)
req, err := http.NewRequest("PUT", "/v1/volumes/create", body)
require.NoError(t, err)
resp = httptest.NewRecorder()
resp := httptest.NewRecorder()
_, err = s.Server.CSIVolumesRequest(resp, req)
require.NoError(t, err, "put error")
require.Error(t, err, "controller validate volume: No path to node")

req, err = http.NewRequest("DELETE", "/v1/volume/csi/baz", nil)
require.NoError(t, err)
resp = httptest.NewRecorder()
_, err = s.Server.CSIVolumeSpecificRequest(resp, req)
require.NoError(t, err, "delete error")

require.Error(t, err, "volume not found: baz")
})
}

Expand Down
2 changes: 2 additions & 0 deletions nomad/state/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func createTestCSIPlugin(s *StateStore, id string, requiresController bool) func
SupportsAttachDetach: true,
SupportsListVolumes: true,
SupportsListVolumesAttachedNodes: false,
SupportsCreateDeleteSnapshot: true,
SupportsListSnapshots: true,
},
},
}
Expand Down

0 comments on commit 2f155b1

Please sign in to comment.