Skip to content

Commit

Permalink
Test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
udnay committed Feb 11, 2025
1 parent 6ec03d1 commit 95dcf13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/api/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ func (c *Cached) Prepare(ctx context.Context) error {
return err
}

// Once we've prepared the cache make it read-only for
// everyone except the user running the daemon
err = os.Chmod(c.GetCachePath(), 0755)
if err != nil {
return fmt.Errorf("failed to change permissions of cache path %s: %v", c.GetCachePath(), err)
}

c.currentVersion = version

logger.Info(ctx, c.GetCachePath())
Expand Down Expand Up @@ -222,7 +229,7 @@ func (s *Cached) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
// Unmount the overlay
err := execCommand("umount", targetPath)
if err != nil {
return nil, fmt.Errorf("failed to unmount overlay: %s", err)
return nil, fmt.Errorf("failed to unmount overlay at %s: %v", targetPath, err)
}

// Clean up upper and work directories from the overlay
Expand Down
15 changes: 15 additions & 0 deletions test/cached_csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func TestCachedCSIDriverMountsCache(t *testing.T) {
cacheFileInfo, err := os.Stat(path.Join(targetDir, fmt.Sprintf("objects/%v/pack/a/1", aHash)))
require.NoError(t, err)
require.Equal(t, formatFileMode(os.FileMode(0755)), formatFileMode(cacheFileInfo.Mode()&os.ModePerm))

_, err = cached.NodeUnpublishVolume(tc.Context(), &csi.NodeUnpublishVolumeRequest{
VolumeId: "foobar",
TargetPath: targetDir,
})
require.NoError(t, err)
}

func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) {
Expand All @@ -124,6 +130,8 @@ func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) {
require.NoError(t, err, "cached.Prepare must succeed")

targetDir := path.Join(tmpDir, "vol-target")
require.NoError(t, os.Chmod(targetDir, 0777))

stagingDir := path.Join(tmpDir, "vol-staging-target")
_, err = cached.NodePublishVolume(tc.Context(), &csi.NodePublishVolumeRequest{
VolumeId: "foobar",
Expand Down Expand Up @@ -157,6 +165,13 @@ func TestCachedCSIDriverMountsCacheAtSuffix(t *testing.T) {
cacheFileInfo, err = os.Stat(path.Join(targetDir, fmt.Sprintf("dl_cache/objects/%v/pack/a/1", aHash)))
require.NoError(t, err)
require.Equal(t, formatFileMode(os.FileMode(0755)), formatFileMode(cacheFileInfo.Mode()))
require.Equal(t, targetDir, path.Join(tmpDir, "vol-target"))

_, err = cached.NodeUnpublishVolume(tc.Context(), &csi.NodeUnpublishVolumeRequest{
VolumeId: "foobar",
TargetPath: targetDir,
})
require.NoError(t, err)
}

func TestCachedCSIDriverProbeFailsUntilPrepared(t *testing.T) {
Expand Down

0 comments on commit 95dcf13

Please sign in to comment.