]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add validation function for smb cluster custom ports
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 11 Jun 2025 18:57:34 +0000 (14:57 -0400)
committerAdam King <adking@redhat.com>
Wed, 9 Jul 2025 15:52:24 +0000 (11:52 -0400)
Add a function that will be used to validate the smb cluster's
custom port values (when provided).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 81a5081b7b22aea2371f3c3f9e5003ba3643e947)

src/pybind/mgr/smb/validation.py

index f9607cddcdf56c30a204c5f768030020fd154f22..8d83e24b4f97dc61f62975ad1b46bbab79b3f2f7 100644 (file)
@@ -112,3 +112,25 @@ def check_access_name(name: str) -> None:
         )
     if len(name) > 128:
         raise ValueError('login name may not exceed 128 characters')
+
+
+PORT_SERVICES = {"smb", "ctdb", "smbmetrics"}
+_MAX_PORT = (1 << 16) - 1
+
+
+def check_custom_ports(ports: Optional[Dict[str, int]]) -> None:
+    if ports is None:
+        return
+    other = set(ports) - PORT_SERVICES
+    if other:
+        raise ValueError(
+            "invalid service names for custom ports:"
+            f' {", ".join(sorted(other))}'
+        )
+    invalid = {str(p) for p in ports.values() if not 0 < p <= _MAX_PORT}
+    if invalid:
+        raise ValueError(
+            f'invalid port number(s): {", ".join(sorted(invalid))}'
+        )
+    if len(ports) != len(set(ports.values())):
+        raise ValueError('port numbers must not be repeated')