From 8bc6ef4fa5e2fddb3774ba2e1f226794abf2715b Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Thu, 9 Mar 2023 16:55:55 +0530 Subject: [PATCH] cephfs/admin: Add tests for Subvolume{Group} pinning API Signed-off-by: Anoop C S --- cephfs/admin/pin_test.go | 59 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 cephfs/admin/pin_test.go diff --git a/cephfs/admin/pin_test.go b/cephfs/admin/pin_test.go new file mode 100644 index 0000000..265ab63 --- /dev/null +++ b/cephfs/admin/pin_test.go @@ -0,0 +1,59 @@ +//go:build !nautilus && ceph_preview +// +build !nautilus,ceph_preview + +package admin + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestPinSubVolume(t *testing.T) { + fsa := getFSAdmin(t) + volume := "cephfs" + + subvolname := "cephfs_subvol" + err := fsa.CreateSubVolume(volume, NoGroup, subvolname, nil) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolume(volume, NoGroup, subvolname) + assert.NoError(t, err) + }() + + var ec errorCode + _, err = fsa.PinSubVolume(volume, subvolname, "distributed", "2") + assert.True(t, errors.As(err, &ec)) + assert.Equal(t, -22, ec.ErrorCode()) + + _, err = fsa.PinSubVolume(volume, subvolname, "distributed", "1") + assert.NoError(t, err) +} + +func TestPinSubVolumeGroup(t *testing.T) { + fsa := getFSAdmin(t) + volume := "cephfs" + + subvolumegroup := "cephfs_subvol_group" + err := fsa.CreateSubVolumeGroup(volume, subvolumegroup, nil) + assert.NoError(t, err) + defer func() { + err := fsa.RemoveSubVolumeGroup(volume, subvolumegroup) + assert.NoError(t, err) + }() + + // mds_export_ephemeral_random_max has a default value of 0.01. EINVAL + // is returned for an attempt to set a value beyond this config. + var ec errorCode + _, err = fsa.PinSubVolumeGroup(volume, subvolumegroup, "random", "0.5") + assert.True(t, errors.As(err, &ec)) + assert.Equal(t, -22, ec.ErrorCode()) + + _, err = fsa.PinSubVolumeGroup(volume, subvolumegroup, "random", "0.01") + assert.NoError(t, err) +} + +type errorCode interface { + ErrorCode() int +}