Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-2091: set grpid option #2423

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions cloud/blockstore/tests/csi_driver/e2e_tests_part2/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import subprocess

from pathlib import Path

import cloud.blockstore.tests.csi_driver.lib.csi_runner as csi


Expand Down Expand Up @@ -57,3 +59,71 @@ def test_readonly_volume(mount_path, access_type, vm_mode, gid):
raise
finally:
csi.cleanup_after_test(env, volume_name, access_type, [pod_id])


def test_mount_volume_group():
# Scenario
# 1. create volume and publish volume without mount volume group
# 2. create directory and file
# 3. unpublish volume
# 4. create new group with specified GID
# 5. publish volume with mount volume group GID
# 6. check that mounted dir and existing files have specified GID
# 7. create new directory and file
# 8. check that new directory and file have specified GID
env, run = csi.init()
try:
volume_name = "example-disk"
volume_size = 1024 ** 3
pod_name = "example-pod"
pod_id = "deadbeef1"
access_type = "mount"
env.csi.create_volume(name=volume_name, size=volume_size)
env.csi.stage_volume(volume_name, access_type)

gid = 1013
result = subprocess.run(
["groupadd", "-g", str(gid), "test_group_" + str(gid)],
capture_output=True,
)
assert result.returncode == 0

env.csi.publish_volume(
pod_id,
volume_name,
pod_name,
access_type
)

mount_path = Path("/var/lib/kubelet/pods") / pod_id / "volumes/kubernetes.io~csi" / volume_name / "mount"
test_dir1 = mount_path / "testdir1"
test_dir1.mkdir()
test_file1 = test_dir1 / "testfile1"
test_file1.touch()

env.csi.unpublish_volume(pod_id, volume_name, access_type)
env.csi.publish_volume(
pod_id,
volume_name,
pod_name,
access_type,
volume_mount_group=str(gid)
)

assert gid == mount_path.stat().st_gid
assert gid == test_dir1.stat().st_gid
assert gid == test_file1.stat().st_gid

test_file2 = mount_path / "testfile2"
test_file2.touch()
assert gid == test_file2.stat().st_gid

test_dir2 = mount_path / "testdir2"
test_dir2.mkdir()
assert gid == test_dir2.stat().st_gid

except subprocess.CalledProcessError as e:
csi.log_called_process_error(e)
raise
finally:
csi.cleanup_after_test(env, volume_name, access_type, [pod_id])
2 changes: 1 addition & 1 deletion cloud/blockstore/tools/csi_driver/internal/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (s *nodeService) nodeStageDiskAsFilesystem(
return fmt.Errorf("failed to create staging directory: %w", err)
}

mountOptions := []string{}
mountOptions := []string{"grpid"}
if mnt != nil {
for _, flag := range mnt.MountFlags {
mountOptions = append(mountOptions, flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func TestPublishUnpublishDiskForInfrakuber(t *testing.T) {

mockCallIsMountPoint := mounter.On("IsMountPoint", stagingTargetPath).Return(false, nil)

mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{}).Return(nil)
mounter.On("Mount", nbdDeviceFile, stagingTargetPath, "ext4", []string{"grpid"}).Return(nil)

_, err = nodeService.NodeStageVolume(ctx, &csi.NodeStageVolumeRequest{
VolumeId: diskId,
Expand Down
Loading