cephfs admin: add a SubVolumeGroupPath function

The SubVolumeGroupPath function maps the subvolumegroup to a path from
the root of the cephfs, and works like `ceph fs subvolumegroup getpath
...`.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-09-01 09:11:02 -04:00 committed by John Mulligan
parent b66dcaf565
commit fbb4f957eb
2 changed files with 38 additions and 0 deletions

View File

@ -77,3 +77,18 @@ func (fsa *FSAdmin) RemoveSubVolumeGroup(volume, name string) error {
})
return checkEmptyResponseExpected(r, s, err)
}
// SubVolumeGroupPath returns the path to the subvolume from the root of the
// file system.
//
// Similar To:
// ceph fs subvolumegroup getpath <volume> <group_name>
func (fsa *FSAdmin) SubVolumeGroupPath(volume, name string) (string, error) {
m := map[string]string{
"prefix": "fs subvolumegroup getpath",
"vol_name": volume,
"group_name": name,
// ceph doesn't respond in json for this cmd (even if you ask)
}
return extractPathResponse(fsa.marshalMgrCommand(m))
}

View File

@ -87,3 +87,26 @@ func TestRemoveSubVolumeGroup(t *testing.T) {
nowCount := len(lsvg)
assert.Equal(t, beforeCount, nowCount)
}
func TestSubVolumeGroupPath(t *testing.T) {
fsa := getFSAdmin(t)
volume := "cephfs"
group := "grewp"
err := fsa.CreateSubVolumeGroup(volume, group, nil)
assert.NoError(t, err)
defer func() {
err := fsa.RemoveSubVolumeGroup(volume, group)
assert.NoError(t, err)
}()
path, err := fsa.SubVolumeGroupPath(volume, group)
assert.NoError(t, err)
assert.Contains(t, path, "/volumes/"+group)
assert.NotContains(t, path, "\n")
// invalid group name
path, err = fsa.SubVolumeGroupPath(volume, "oops")
assert.Error(t, err)
assert.Equal(t, "", path)
}