]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/pybind/object_format: fix json-pretty being marked invalid
authorAdam King <adking@redhat.com>
Wed, 17 Apr 2024 17:34:45 +0000 (13:34 -0400)
committerAdam King <adking@redhat.com>
Tue, 27 Aug 2024 14:10:17 +0000 (10:10 -0400)
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 <adking@redhat.com>
(cherry picked from commit cd988a01a0edf13882527f5526f1793d4dece437)

src/pybind/mgr/object_format.py

index 4a2b6fa8b69b1e6e66e737240cdf2de6c8808eb5..85b19711044c6ab5047dd733bb754f09bef96470 100644 (file)
@@ -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)