]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/smb: update port validation to use new smb constants
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 13 Aug 2025 16:58:06 +0000 (12:58 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Sat, 16 Aug 2025 20:43:05 +0000 (16:43 -0400)
Make behavior consistent across the smb mgr module and the service spec
class by using the same set of constants.
Fix an issue supporting the customization of the `remote-control`
sidecar's port.

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

index bdf40a67448ee8e245dac2be3b7e68452b699998..3c30b6b02f69adbefcabbc4c51d54963fbbdf538 100644 (file)
@@ -144,8 +144,17 @@ def test_check_access_name(value, ok, err_match):
         ({'smb': 4455, 'sbmetrics': 9009}, 'invalid service names'),
         (
             {'smb': 4455, 'smbmetrics': 9999, 'ctdb': 9999},
-            'must not be repeated',
+            'must be unique',
         ),
+        # can't use 445 it's the default smb port!
+        (
+            {'smbmetrics': 445},
+            'must be unique',
+        ),
+        # its valid to swap stuff around (don't do this please)
+        ({'smbmetrics': 4379, 'ctdb': 9922}, None),
+        # remote-control is a valid service name to modify
+        ({'remote-control': 65432}, None),
     ],
 )
 def test_check_custom_ports(value, err_match):
index 8d83e24b4f97dc61f62975ad1b46bbab79b3f2f7..41d76b77d3f30c00e7cf2a3243c0cd196506bce1 100644 (file)
@@ -3,6 +3,8 @@ from typing import Dict, Optional
 import posixpath
 import re
 
+import ceph.smb.constants
+
 # Initially, this regex is pretty restrictive.  But I (JJM) find that
 # starting out more restricitive is better than not because it's generally
 # easier to relax strict rules then discover someone relies on lax rules
@@ -114,14 +116,14 @@ def check_access_name(name: str) -> None:
         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
+    _defaults = ceph.smb.constants.DEFAULT_PORTS
+    other = set(ports) - set(_defaults)
     if other:
         raise ValueError(
             "invalid service names for custom ports:"
@@ -132,5 +134,12 @@ def check_custom_ports(ports: Optional[Dict[str, int]]) -> None:
         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')
+    # make sure ports are unique per service
+    all_ports = _defaults | ports
+    for port in all_ports.values():
+        using_port = {s for s, p in all_ports.items() if p == port}
+        if len(using_port) > 1:
+            raise ValueError(
+                'port numbers must be unique:'
+                f' {port} used for {", ".join(sorted(using_port))}'
+            )