]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: disable dictionary key sorting for cli output
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 25 Apr 2024 20:26:17 +0000 (16:26 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 1 May 2024 13:29:51 +0000 (09:29 -0400)
Use new adapter class options to disable key sorting for dicts when
converting to JSON or YAML. The smb module generally produces dicts
based on resource types that have a well defined key order and it's
nice to to "jumble it up."

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/cli.py

index fa39690fa2af53996067a66ea8b38cf4ecdd6e8e..7efd68699811809969aee24776a27a52ff7880c0 100644 (file)
@@ -1,6 +1,7 @@
 from typing import Any, Callable, Tuple
 
 import errno
+import functools
 
 import object_format
 from mgr_module import CLICommand
@@ -42,7 +43,16 @@ class SMBCommand:
     def __call__(self, func: Callable) -> Self:
         self._func = func
         cc = CLICommand(f'smb {self._name}', perm=self._perm)
-        rsp = object_format.Responder()
+        # the smb module assumes that it will always be used with python
+        # versions sufficiently new enough to always use ordered dicts
+        # (builtin).  We dont want the json/yaml sorted by keys losing our
+        # ordered k-v pairs.
+        _fmt = functools.partial(
+            object_format.ObjectFormatAdapter,
+            sort_json=False,
+            sort_yaml=False,
+        )
+        rsp = object_format.Responder(_fmt)
         self._command = cc(rsp(func))
         return self