nfs admin: fix handling of non-existing psuedo_paths for export info

Fixes: #815

When updates to the NFS mgr API were recently merged on Ceph main branch
the go-ceph test started failing. This occurred because go-ceph was
unintentionally relying on invalid JSON (an empty string) returned from
the API call for an invalid export pseudo path. On ceph main it now
returns an empty JSON object. This change treats both empty string
and empty JSON object as an error explicitly.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2023-01-30 14:57:37 -05:00 committed by mergify[bot]
parent d930ba7157
commit daf48e4aa2
1 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,8 @@
package nfs
import (
"errors"
"github.com/ceph/go-ceph/internal/commands"
)
@ -26,6 +28,10 @@ const (
Unspecifiedquash SquashMode = ""
)
var (
errNoExportInfo = errors.New("No export info found")
)
// SecType indicates the kind of security/authentication to be used by an export.
type SecType string
@ -115,6 +121,11 @@ func parseExportsList(res commands.Response) ([]ExportInfo, error) {
func parseExportInfo(res commands.Response) (ExportInfo, error) {
i := ExportInfo{}
// different versions of ceph may return nothing or empty json.
// detect these cases and return a specific error
if res.NoStatus().EmptyBody().Ok() {
return i, errNoExportInfo
}
if err := res.NoStatus().Unmarshal(&i).End(); err != nil {
return i, err
}