From 742e542ef9e5f198adc2495c5225dc1ae096a6b2 Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 17 Apr 2024 13:34:45 -0400 Subject: [PATCH] mgr/pybind/object_format: fix json-pretty being marked invalid without this patch you'd get ``` [ceph: root@vm-00 /]# ceph nfs cluster info --format json-pretty Error EINVAL: Unknown format name: json-pretty ``` this seems to be because valid formats are checked using the class ``` class Format(str, enum.Enum): plain = "plain" json = "json" json_pretty = "json-pretty" yaml = "yaml" xml_pretty = "xml-pretty" xml = "xml" ``` and then ``` set(str(v) for v in Format.__members__) ``` but that resolves to ``` {'yaml', 'json_pretty', 'plain', 'xml', 'json', 'xml_pretty'} ``` and so json-pretty is marked as invalid. Note that it's also impossible to pass json_pretty as the format as core ceph blocks it with invalid choice: 'json_pretty' (choose from 'json', 'json-pretty', 'xml', 'xml-pretty', 'plain', 'yaml') Fixes: https://tracker.ceph.com/issues/65554 Signed-off-by: Adam King (cherry picked from commit cd988a01a0edf13882527f5526f1793d4dece437) --- src/pybind/mgr/object_format.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pybind/mgr/object_format.py b/src/pybind/mgr/object_format.py index 4a2b6fa8b69..85b19711044 100644 --- a/src/pybind/mgr/object_format.py +++ b/src/pybind/mgr/object_format.py @@ -533,9 +533,9 @@ class Responder: formatter = self._formatter(obj) if format_req is None: format_req = self.default_format - if format_req not in formatter.valid_formats(): - raise UnknownFormat(format_req) req = str(format_req).replace("-", "_") + if req not in formatter.valid_formats(): + raise UnknownFormat(format_req) ffunc = getattr(formatter, f"format_{req}", None) if ffunc is None: raise UnsupportedFormat(format_req) -- 2.39.5