Skip to content

Commit

Permalink
CSI: Include test case with and without staging support
Browse files Browse the repository at this point in the history
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
  • Loading branch information
olljanat committed Feb 7, 2023
1 parent 3188914 commit 849c087
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
10 changes: 7 additions & 3 deletions agent/csi/plugin/plugin.go
Expand Up @@ -301,10 +301,14 @@ func (np *nodePlugin) NodePublishVolume(ctx context.Context, req *api.VolumeAssi

// some volumes do not require staging. we can check this by checkign the
// staging variable, or we can just see if there is a staging path in the
// map.
// map. if plugin does not support staging we can just ignore this check.
stagingPath := ""
if vs, ok := np.volumeMap[req.ID]; ok {
stagingPath = vs.stagingPath
if np.staging {
if vs, ok := np.volumeMap[req.ID]; ok {
stagingPath = vs.stagingPath
} else {
return status.Error(codes.FailedPrecondition, "volume not staged")
}
}

c, err := np.Client(ctx)
Expand Down
25 changes: 24 additions & 1 deletion agent/csi/plugin/plugin_test.go
Expand Up @@ -79,10 +79,11 @@ func TestNodeUnstageVolume(t *testing.T) {
require.NoError(t, err)
}

func TestNodePublishVolume(t *testing.T) {
func TestNodePublishVolumeWithStaging(t *testing.T) {
plugin := "plugin-3"
node := "node-1"
nodePlugin := newVolumeClient(plugin, node)
nodePlugin.staging = true
s := &api.VolumeAssignment{
VolumeID: "vol3",
AccessMode: &api.VolumeAccessMode{
Expand All @@ -106,6 +107,28 @@ func TestNodePublishVolume(t *testing.T) {
require.NoError(t, err)
}

func TestNodePublishVolumeWithoutStaging(t *testing.T) {
plugin := "plugin-5"
node := "node-1"
nodePlugin := newVolumeClient(plugin, node)
nodePlugin.staging = false
s := &api.VolumeAssignment{
VolumeID: "vol3",
AccessMode: &api.VolumeAccessMode{
Scope: api.VolumeScopeMultiNode,
Sharing: api.VolumeSharingOneWriter,
AccessType: &api.VolumeAccessMode_Mount{
Mount: &api.VolumeAccessMode_MountVolume{},
},
},
Driver: &api.Driver{
Name: plugin,
},
}
err := nodePlugin.NodePublishVolume(context.Background(), s)
require.NoError(t, err)
}

func TestNodeUnpublishVolume(t *testing.T) {
plugin := "plugin-4"
node := "node-1"
Expand Down

0 comments on commit 849c087

Please sign in to comment.