Skip to content

Commit 3feb3e9

Browse files
committed
remove non-functional attempt to pick a port
1 parent c21c107 commit 3feb3e9

File tree

2 files changed

+3
-48
lines changed

2 files changed

+3
-48
lines changed

cylc/uiserver/ws.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from glob import glob
2626
import os
2727
from pathlib import Path
28-
import socket
2928
from typing import Annotated
3029

3130
LOG_ROOT_TMPL = "~/.cylc/%(ns)s-%(util)s-%(host)s-%(port)s"
@@ -162,39 +161,24 @@ def get_util_home(*args):
162161

163162

164163
def get_review_service_config(
165-
ports: tuple[Annotated[int, Ge(0)], Annotated[int, Ge(0)]] = (8000, 8999),
164+
port: Annotated[int, Ge(0)] = 8042,
166165
service_root: str = 'services/cylc'
167166
) -> dict:
168167
"""Get a configuration for Cylc Review as a service.
169168
170169
Args:
171-
ports: A range of ports to attempt to make the Cylc Review service
172-
available on.
170+
port: The port to make the Cylc Review service available on.
173171
service_root: Include web service name under root of URL.
174172
175173
Returns:
176174
Dictionary of settings for Cylc Review to be run as a hub service.
177175
"""
178-
port_found = False
179-
for port in range(ports[0], ports[1]):
180-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
181-
try:
182-
s.bind(('localhost', port))
183-
except Exception:
184-
pass
185-
else:
186-
port_found = True
187-
break
188-
189-
if not port_found:
190-
print('No suitable port found.')
191-
192176
return {
193177
"name": "cylc-review",
194178
"command": [
195179
"cylc", "review", "start",
196180
f"--port={port}",
197181
f"--service-root={service_root}",
198182
],
199-
"url": f"http://127.0.0.1:{port}/",
183+
"url": f"http://0.0.0.0:{port}/",
200184
}

tests/unit/test_ws.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,3 @@ def _mock_bind(input_):
3131
if port in list(range(8000, 8002)):
3232
raise Exception(f'Port is {port}')
3333
return True
34-
35-
36-
@contextmanager
37-
def _mock_socket(*args):
38-
"""Mock socket.socket context object
39-
"""
40-
yield SimpleNamespace(bind=_mock_bind)
41-
42-
43-
@pytest.mark.parametrize(
44-
'inputs, port',
45-
(
46-
(((8000, 8003), None), 8002),
47-
(((8000, 8003), 'gerbil/wheel'), 8002),
48-
)
49-
)
50-
def test_get_review_service_config(monkeypatch, inputs, port):
51-
monkeypatch.setattr('socket.socket', _mock_socket)
52-
result = get_review_service_config(*inputs)
53-
assert result['command'][3] == f'--port={port}'
54-
assert result['command'][4] == f'--service-root={inputs[1]}'
55-
assert result['url'] == f"http://127.0.0.1:{port}/"
56-
57-
58-
def test_get_review_service_config_no_port(monkeypatch):
59-
inputs = ((8000, 8001), None)
60-
monkeypatch.setattr('socket.socket', _mock_socket)
61-
with pytest.raises(Exception, match='bleugh'):
62-
get_review_service_config(*inputs)

0 commit comments

Comments
 (0)