]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add a simple validation function for log level dict
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 25 Feb 2026 00:22:10 +0000 (19:22 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Fri, 27 Feb 2026 15:40:09 +0000 (10:40 -0500)
Add a simple validation function for log level dict. Values in this
dict are expected to vary and will support some amount of "guessing"
so we don't do much with the values.

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

index 02fab2a642a1d859d8a9f415428176185d978e1f..18166205375c20f08700f95f12c29d0c36ebcbff 100644 (file)
@@ -141,3 +141,27 @@ def check_custom_ports(ports: Optional[Dict[str, int]]) -> None:
                 'port numbers must be unique:'
                 f' {port} used for {", ".join(sorted(using_port))}'
             )
+
+
+def check_debug_level(debug_level: Optional[dict[str, str]]) -> None:
+    """Check the types of the debug_level parameter.
+    NOTE: this is intentionally fairly loose with regards to values in order
+    to retain state and lazily translate values as needed.
+    """
+    if debug_level is None:
+        return
+    if not isinstance(debug_level, dict):
+        raise ValueError(f'invalid debug_level type: {type(debug_level)}')
+    _keys = {'samba', 'ctdb'}
+    for key, value in debug_level.items():
+        if not isinstance(key, str):
+            raise ValueError(f'invalid type in debug_level: {type(key)}')
+        if not isinstance(value, str):
+            raise ValueError(f'invalid type in debug_level: {type(value)}')
+        if key not in _keys:
+            raise ValueError(f'invalid key in debug_level: {key!r}')
+        if not (
+            value.isdigit()
+            or value.upper() in ceph.smb.constants.DEBUG_LEVEL_TERMS
+        ):
+            raise ValueError(f'invalid value in debug_level: {value!r}')