Skip to content

Commit c141eab

Browse files
mgr/smb: update port validation to use new smb constants
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 <[email protected]>
1 parent 1864170 commit c141eab

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/pybind/mgr/smb/tests/test_validation.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,17 @@ def test_check_access_name(value, ok, err_match):
144144
({'smb': 4455, 'sbmetrics': 9009}, 'invalid service names'),
145145
(
146146
{'smb': 4455, 'smbmetrics': 9999, 'ctdb': 9999},
147-
'must not be repeated',
147+
'must be unique',
148148
),
149+
# can't use 445 it's the default smb port!
150+
(
151+
{'smbmetrics': 445},
152+
'must be unique',
153+
),
154+
# its valid to swap stuff around (don't do this please)
155+
({'smbmetrics': 4379, 'ctdb': 9922}, None),
156+
# remote-control is a valid service name to modify
157+
({'remote-control': 65432}, None),
149158
],
150159
)
151160
def test_check_custom_ports(value, err_match):

src/pybind/mgr/smb/validation.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import posixpath
44
import re
55

6+
import ceph.smb.constants
7+
68
# Initially, this regex is pretty restrictive. But I (JJM) find that
79
# starting out more restricitive is better than not because it's generally
810
# easier to relax strict rules then discover someone relies on lax rules
@@ -114,14 +116,14 @@ def check_access_name(name: str) -> None:
114116
raise ValueError('login name may not exceed 128 characters')
115117

116118

117-
PORT_SERVICES = {"smb", "ctdb", "smbmetrics"}
118119
_MAX_PORT = (1 << 16) - 1
119120

120121

121122
def check_custom_ports(ports: Optional[Dict[str, int]]) -> None:
122123
if ports is None:
123124
return
124-
other = set(ports) - PORT_SERVICES
125+
_defaults = ceph.smb.constants.DEFAULT_PORTS
126+
other = set(ports) - set(_defaults)
125127
if other:
126128
raise ValueError(
127129
"invalid service names for custom ports:"
@@ -132,5 +134,12 @@ def check_custom_ports(ports: Optional[Dict[str, int]]) -> None:
132134
raise ValueError(
133135
f'invalid port number(s): {", ".join(sorted(invalid))}'
134136
)
135-
if len(ports) != len(set(ports.values())):
136-
raise ValueError('port numbers must not be repeated')
137+
# make sure ports are unique per service
138+
all_ports = _defaults | ports
139+
for port in all_ports.values():
140+
using_port = {s for s, p in all_ports.items() if p == port}
141+
if len(using_port) > 1:
142+
raise ValueError(
143+
'port numbers must be unique:'
144+
f' {port} used for {", ".join(sorted(using_port))}'
145+
)

0 commit comments

Comments
 (0)