cephfs admin: move volume status to octopus specific files

The volume status command does not appear to be able to return JSON
on nautilus. Disable it on anything other than octopus for now.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-08-05 15:22:19 -04:00 committed by John Mulligan
parent c1ff3a6b18
commit d327bf4f3e
4 changed files with 86 additions and 74 deletions

View File

@ -9,35 +9,3 @@ func (fsa *FSAdmin) ListVolumes() ([]string, error) {
r, s, err := fsa.rawMgrCommand(listVolumesCmd)
return parseListNames(r, s, err)
}
// VolumePool reports on the pool status for a CephFS volume.
type VolumePool struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Available uint64 `json:"avail"`
Used uint64 `json:"used"`
}
// VolumeStatus reports various properties of a CephFS volume.
// TODO: Fill in.
type VolumeStatus struct {
MDSVersion string `json:"mds_version"`
Pools []VolumePool `json:"pools"`
}
func parseVolumeStatus(res []byte, status string, err error) (*VolumeStatus, error) {
var vs VolumeStatus
err = unmarshalResponseJSON(res, status, err, &vs)
return &vs, err
}
// VolumeStatus returns a VolumeStatus object for the given volume name.
func (fsa *FSAdmin) VolumeStatus(name string) (*VolumeStatus, error) {
r, s, err := fsa.marshalMgrCommand(map[string]string{
"fs": name,
"prefix": "fs status",
"format": "json",
})
return parseVolumeStatus(r, s, err)
}

View File

@ -0,0 +1,35 @@
// +build octopus
package admin
// VolumePool reports on the pool status for a CephFS volume.
type VolumePool struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Available uint64 `json:"avail"`
Used uint64 `json:"used"`
}
// VolumeStatus reports various properties of a CephFS volume.
// TODO: Fill in.
type VolumeStatus struct {
MDSVersion string `json:"mds_version"`
Pools []VolumePool `json:"pools"`
}
func parseVolumeStatus(res []byte, status string, err error) (*VolumeStatus, error) {
var vs VolumeStatus
err = unmarshalResponseJSON(res, status, err, &vs)
return &vs, err
}
// VolumeStatus returns a VolumeStatus object for the given volume name.
func (fsa *FSAdmin) VolumeStatus(name string) (*VolumeStatus, error) {
r, s, err := fsa.marshalMgrCommand(map[string]string{
"fs": name,
"prefix": "fs status",
"format": "json",
})
return parseVolumeStatus(r, s, err)
}

View File

@ -0,0 +1,51 @@
// +build octopus
package admin
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVolumeStatus(t *testing.T) {
fsa := getFSAdmin(t)
vs, err := fsa.VolumeStatus("cephfs")
assert.NoError(t, err)
assert.Contains(t, vs.MDSVersion, "version")
}
var sampleVolumeStatus1 = []byte(`
{
"clients": [{"clients": 1, "fs": "cephfs"}],
"mds_version": "ceph version 15.2.4 (7447c15c6ff58d7fce91843b705a268a1917325c) octopus (stable)",
"mdsmap": [{"dns": 76, "inos": 19, "name": "Z", "rank": 0, "rate": 0.0, "state": "active"}],
"pools": [{"avail": 1017799872, "id": 2, "name": "cephfs_metadata", "type": "metadata", "used": 2204126}, {"avail": 1017799872, "id": 1, "name": "cephfs_data", "type": "data", "used": 0}]
}
`)
func TestParseVolumeStatus(t *testing.T) {
t.Run("error", func(t *testing.T) {
_, err := parseVolumeStatus(nil, "", errors.New("bonk"))
assert.Error(t, err)
assert.Equal(t, "bonk", err.Error())
})
t.Run("statusSet", func(t *testing.T) {
_, err := parseVolumeStatus(nil, "unexpected!", nil)
assert.Error(t, err)
})
t.Run("badJSON", func(t *testing.T) {
_, err := parseVolumeStatus([]byte("_XxXxX"), "", nil)
assert.Error(t, err)
})
t.Run("ok", func(t *testing.T) {
s, err := parseVolumeStatus(sampleVolumeStatus1, "", nil)
assert.NoError(t, err)
if assert.NotNil(t, s) {
assert.Contains(t, s.MDSVersion, "ceph version 15.2.4")
assert.Contains(t, s.MDSVersion, "octopus")
}
})
}

View File

@ -3,7 +3,6 @@
package admin
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
@ -17,44 +16,3 @@ func TestListVolumes(t *testing.T) {
assert.Len(t, vl, 1)
assert.Equal(t, "cephfs", vl[0])
}
func TestVolumeStatus(t *testing.T) {
fsa := getFSAdmin(t)
vs, err := fsa.VolumeStatus("cephfs")
assert.NoError(t, err)
assert.Contains(t, vs.MDSVersion, "version")
}
var sampleVolumeStatus1 = []byte(`
{
"clients": [{"clients": 1, "fs": "cephfs"}],
"mds_version": "ceph version 15.2.4 (7447c15c6ff58d7fce91843b705a268a1917325c) octopus (stable)",
"mdsmap": [{"dns": 76, "inos": 19, "name": "Z", "rank": 0, "rate": 0.0, "state": "active"}],
"pools": [{"avail": 1017799872, "id": 2, "name": "cephfs_metadata", "type": "metadata", "used": 2204126}, {"avail": 1017799872, "id": 1, "name": "cephfs_data", "type": "data", "used": 0}]
}
`)
func TestParseVolumeStatus(t *testing.T) {
t.Run("error", func(t *testing.T) {
_, err := parseVolumeStatus(nil, "", errors.New("bonk"))
assert.Error(t, err)
assert.Equal(t, "bonk", err.Error())
})
t.Run("statusSet", func(t *testing.T) {
_, err := parseVolumeStatus(nil, "unexpected!", nil)
assert.Error(t, err)
})
t.Run("badJSON", func(t *testing.T) {
_, err := parseVolumeStatus([]byte("_XxXxX"), "", nil)
assert.Error(t, err)
})
t.Run("ok", func(t *testing.T) {
s, err := parseVolumeStatus(sampleVolumeStatus1, "", nil)
assert.NoError(t, err)
if assert.NotNil(t, s) {
assert.Contains(t, s.MDSVersion, "ceph version 15.2.4")
assert.Contains(t, s.MDSVersion, "octopus")
}
})
}