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

e2e: add tests for RBD VolumeGroupSnapshots #4899

Merged
merged 2 commits into from
Nov 4, 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
21 changes: 21 additions & 0 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4856,6 +4856,27 @@ var _ = Describe("RBD", func() {
}
})

By("test volumeGroupSnapshot", func() {
supported, err := librbdSupportsVolumeGroupSnapshot(f)
if err != nil {
framework.Failf("failed to check for VolumeGroupSnapshot support: %v", err)
}
if !supported {
Skip("librbd does not support required VolumeGroupSnapshot function(s)")
}

scName := "csi-rbd-sc"
snapshotter, err := newRBDVolumeGroupSnapshot(f, f.UniqueName, scName, false, deployTimeout, 3)
if err != nil {
framework.Failf("failed to create RBDVolumeGroupSnapshot: %v", err)
}

err = snapshotter.TestVolumeGroupSnapshot()
if err != nil {
framework.Failf("failed to test volumeGroupSnapshot: %v", err)
}
})

// delete RBD provisioner secret
err := deleteCephUser(f, keyringRBDProvisionerUsername)
if err != nil {
Expand Down
22 changes: 22 additions & 0 deletions e2e/rbd_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,28 @@ func validateEncryptedFilesystem(f *framework.Framework, rbdImageSpec, pvName, a
return nil
}

// librbdSupportsVolumeGroupSnapshot checks for the rbd_group_snap_get_info in
// librbd.so.* in a ceph-csi container. If this function is available,
// VolumeGroupSnapshot support is available.
func librbdSupportsVolumeGroupSnapshot(f *framework.Framework) (bool, error) {
selector, err := getDaemonSetLabelSelector(f, cephCSINamespace, rbdDaemonsetName)
if err != nil {
return false, fmt.Errorf("failed to get labels: %w", err)
}
opt := metav1.ListOptions{
LabelSelector: selector,
}

// run a shell command (to expand the * in the filename), return 0 on stdout when successful
cmd := "sh -c 'grep -q rbd_group_snap_get_info /lib64/librbd.so.*; echo $?'"
stdout, _, err := execCommandInContainer(f, cmd, cephCSINamespace, "csi-rbdplugin", &opt)
if err != nil {
return false, fmt.Errorf("error checking for rbd_group_snap_get_info in /lib64/librbd.so.*: %w", err)
}

return strings.TrimSpace(stdout) == "0", nil
}

func listRBDImages(f *framework.Framework, pool string) ([]string, error) {
var imgInfos []string

Expand Down
62 changes: 62 additions & 0 deletions e2e/volumegroupsnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,65 @@ func (c *cephFSVolumeGroupSnapshot) ValidateResourcesForDelete() error {

return nil
}

type rbdVolumeGroupSnapshot struct {
*volumeGroupSnapshotterBase
}

var _ VolumeGroupSnapshotter = &rbdVolumeGroupSnapshot{}

func newRBDVolumeGroupSnapshot(f *framework.Framework, namespace,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function creates volumegroupsnapshot but the function name is not self-explanatory, so I think it will be good to have a comment here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe, but it follows the same naming as CephFS.

storageClass string,
blockPVC bool,
timeout, totalPVCCount int,
) (VolumeGroupSnapshotter, error) {
base, err := newVolumeGroupSnapshotBase(f, namespace, storageClass, blockPVC, timeout, totalPVCCount)
if err != nil {
return nil, fmt.Errorf("failed to create volumeGroupSnapshotterBase: %w", err)
}

return &rbdVolumeGroupSnapshot{
volumeGroupSnapshotterBase: base,
}, nil
}

func (rvgs *rbdVolumeGroupSnapshot) TestVolumeGroupSnapshot() error {
return rvgs.volumeGroupSnapshotterBase.testVolumeGroupSnapshot(rvgs)
}

func (rvgs *rbdVolumeGroupSnapshot) GetVolumeGroupSnapshotClass() (*groupsnapapi.VolumeGroupSnapshotClass, error) {
vgscPath := fmt.Sprintf("%s/%s", rbdExamplePath, "groupsnapshotclass.yaml")
vgsc := &groupsnapapi.VolumeGroupSnapshotClass{}
err := unmarshal(vgscPath, vgsc)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal VolumeGroupSnapshotClass: %w", err)
}

vgsc.Parameters["csi.storage.k8s.io/group-snapshotter-secret-namespace"] = cephCSINamespace
vgsc.Parameters["csi.storage.k8s.io/group-snapshotter-secret-name"] = rbdProvisionerSecretName
vgsc.Parameters["pool"] = defaultRBDPool

fsID, err := getClusterID(rvgs.framework)
if err != nil {
return nil, fmt.Errorf("failed to get clusterID: %w", err)
}
vgsc.Parameters["clusterID"] = fsID

return vgsc, nil
}

func (rvgs *rbdVolumeGroupSnapshot) ValidateResourcesForCreate(vgs *groupsnapapi.VolumeGroupSnapshot) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to have comment for function description, maybe describe the validation criteria.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are provided in the interface at e2e/volumegroupsnapshot_base.go.

sourcePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
clonePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
totalPVCCount := sourcePVCCount + clonePVCCount

validateOmapCount(rvgs.framework, totalPVCCount, rbdType, defaultRBDPool, volumesType)

return nil
}

func (rvgs *rbdVolumeGroupSnapshot) ValidateResourcesForDelete() error {
validateOmapCount(rvgs.framework, 0, rbdType, defaultRBDPool, volumesType)

return nil
}