From daf48e4aa2238422c8b2c6d21f60e1590119158c Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 30 Jan 2023 14:57:37 -0500 Subject: [PATCH] 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 --- common/admin/nfs/export.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/admin/nfs/export.go b/common/admin/nfs/export.go index 6b981b7..9b29761 100644 --- a/common/admin/nfs/export.go +++ b/common/admin/nfs/export.go @@ -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 }