From: John Mulligan Date: Thu, 25 Apr 2024 20:26:17 +0000 (-0400) Subject: mgr/smb: disable dictionary key sorting for cli output X-Git-Tag: v20.0.0~1971^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a98538318efc3b7229ebb0f26f923b8a5bd528a4;p=ceph.git mgr/smb: disable dictionary key sorting for cli output 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 --- diff --git a/src/pybind/mgr/smb/cli.py b/src/pybind/mgr/smb/cli.py index fa39690fa2a..7efd6869981 100644 --- a/src/pybind/mgr/smb/cli.py +++ b/src/pybind/mgr/smb/cli.py @@ -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