Skip to content

Commit

Permalink
add check for shared volumes in getVolumeStats (#2419)
Browse files Browse the repository at this point in the history
* add check for shared volumes in getVolumeStats

Adds check for shared v4 volumes that have a different attach path than the assumed CSI volume path.

JIRA: PWX-35351

Signed-off-by: dahuang <[email protected]>
  • Loading branch information
dahuang-purestorage authored Feb 21, 2024
1 parent ac3b370 commit 1ec45ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion csi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ func (s *OsdCsiServer) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetV
}

var attachPathMatch bool
sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id)
for _, attachPath := range vol.AttachPath {
if attachPath == path {
if attachPath == path || attachPath == sharedPath {
attachPathMatch = true
}
}
Expand Down
15 changes: 14 additions & 1 deletion csi/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,9 @@ func TestNodeGetVolumeStats(t *testing.T) {
used := int64(1 * 1024 * 1024)
available := size - used
id := "myvol123"
sharedPath := fmt.Sprintf("%s/%s", api.SharedVolExportPrefix, id) // "/var/lib/osd/pxns/myvol123"
vol := &api.Volume{
AttachPath: []string{"/test"},
AttachPath: []string{"/test", sharedPath},
Id: id,
Locator: &api.VolumeLocator{
Name: id,
Expand Down Expand Up @@ -1104,6 +1105,18 @@ func TestNodeGetVolumeStats(t *testing.T) {
assert.Equal(t, false, resp.VolumeCondition.Abnormal)
assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message)

// Get VolumeStats - shared volume
resp, err = c.NodeGetVolumeStats(
context.Background(),
&csi.NodeGetVolumeStatsRequest{VolumeId: id, VolumePath: sharedPath})
assert.NoError(t, err)
assert.Equal(t, 1, len(resp.Usage))
assert.Equal(t, size, resp.Usage[0].Total)
assert.Equal(t, used, resp.Usage[0].Used)
assert.Equal(t, available, resp.Usage[0].Available)
assert.Equal(t, false, resp.VolumeCondition.Abnormal)
assert.Equal(t, "Volume status is up", resp.VolumeCondition.Message)

// Get VolumeStats - down
vol.Status = api.VolumeStatus_VOLUME_STATUS_DOWN
resp, err = c.NodeGetVolumeStats(
Expand Down

0 comments on commit 1ec45ab

Please sign in to comment.