Skip to content

Commit dad9a37

Browse files
committed
remove non-functional attempt to pick a port
fix sort order fixed small bug in broadcast states qurey fix test Remove lint from tests Update tests/functional/cylc-review/05-cycles-job-fails/suite.rc Co-authored-by: Oliver Sanders <oliver.sanders@metoffice.gov.uk> Update tests/functional/cylc-review/12-cycle-counts.t Co-authored-by: Oliver Sanders <oliver.sanders@metoffice.gov.uk> Modify comment set local platform use python subproc for testing Turn off cylc review by default with Cylc hub, and turn on how to document it.
1 parent c99a715 commit dad9a37

File tree

12 files changed

+56
-121
lines changed

12 files changed

+56
-121
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,25 @@ jobs:
5353
bash
5454
coreutils
5555
56-
- name: install cylc-flow
57-
uses: cylc/release-actions/install-cylc-components@v1
58-
with:
59-
cylc_flow: true
60-
cylc_flow_opts: ''
61-
editable_installations: true
56+
# - name: install cylc-flow
57+
# uses: cylc/release-actions/install-cylc-components@v1
58+
# with:
59+
# cylc_flow: true
60+
# cylc_flow_opts: ''
61+
# editable_installations: true
62+
63+
- name: bodge
64+
run: |
65+
# This is a bodge to make this branch work before companion branches merged:
66+
pip install -e git+https://github.com/wxtim/cylc@feat.cylc-review#egg=cylc-flow --no-deps
6267
6368
- name: install cylc-uiserver
6469
run: |
6570
pip install -e .[all]
6671
6772
- name: Style test
6873
if: startsWith(matrix.os, 'ubuntu')
69-
run: flake8 cylc/uiserver/* tests/unit/* tests/integration/*
74+
run: flake8 cylc/uiserver/* tests/integration/*
7075

7176
- name: Type checking
7277
if: startsWith(matrix.os, 'ubuntu')
@@ -88,13 +93,13 @@ jobs:
8893
8994
cat >> "$CONF_PATH/global.cylc" <<__HERE__
9095
[platforms]
91-
[[_local_background_indep_tcp]]
96+
[[_local_background_shared_tcp]]
9297
hosts = localhost
9398
install target = localhost
9499
ssh command = ssh -oBatchMode=yes -oConnectTimeout=8 -oStrictHostKeyChecking=no
95100
__HERE__
96101
97-
# Check that Cylc Review is ready to run
102+
# Check that Cylc Review is installed!
98103
# (We're only interested if it emits an error):
99104
cylc review --help > /dev/null || exit 1
100105
@@ -115,10 +120,6 @@ jobs:
115120
116121
- name: Coverage report
117122
run: |
118-
echo pwd:
119-
pwd
120-
echo ls:
121-
ls
122123
coverage combine --append src/cylc-flow
123124
coverage xml --ignore-errors
124125
coverage report

cylc/uiserver/app.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@
5151
``c.CylcUIServer.site_authorization`` should be defined in
5252
``/etc/cylc/uiserver/jupyter_config.py``, or, alternatively, via
5353
the environment variable ``CYLC_SITE_CONF_PATH``.
54+
55+
Cylc Review Service
56+
^^^^^^^^^^^^^^^^^^^
57+
58+
Cylc hub can be configured to automatically serve the Cylc Review static
59+
log-file viewer. To enable Cylc Review, add the following to your
60+
`jupyterhub_config.py`:
61+
62+
.. code-block:: python
63+
64+
c.JupyterHub.services = [get_review_service_config()]
65+
5466
"""
5567

5668
from concurrent.futures import ProcessPoolExecutor

cylc/uiserver/jupyter_config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,6 @@
107107
c.ServerApp.authorizer_class = CylcAuthorizer
108108

109109

110-
# Setup Cylc Review
111-
c.JupyterHub.services = [get_review_service_config()]
110+
# Setup Cylc Review - uncomment to start Cylc review with Cylc Hub
111+
# n.b. if installed with pip optional dependence [review] must be specified.
112+
# c.JupyterHub.services = [get_review_service_config()]

cylc/uiserver/review.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ def suites(
527527
elif order == "name_desc":
528528
data["entries"].sort(key=lambda entry: entry["name"], reverse=True)
529529
elif order == "time_asc":
530-
data["entries"].sort(key=self._sort_summary_entries, reverse=True)
530+
data["entries"].sort(key=self._sort_summary_entries, reverse=False)
531531
else: # order == "time_desc"
532-
data["entries"].sort(key=self._sort_summary_entries)
532+
data["entries"].sort(key=self._sort_summary_entries, reverse=True)
533533
data["of_n_entries"] = len(data["entries"])
534534
if per_page:
535535
data["n_pages"] = data["of_n_entries"] // per_page

cylc/uiserver/review_dao.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def get_suite_broadcast_states(self, user_name, suite_name):
166166
"""Return broadcast states of a suite.
167167
[[point, name, key, value], ...]
168168
"""
169-
stmt = self.pre_select_broadcast_states(
170-
self._db_init(user_name, suite_name), order="ASC")[0]
169+
stmt = CylcWorkflowDAO.pre_select_broadcast_states(
170+
self=self._db_init(user_name, suite_name), order="ASC")[0]
171171
broadcast_states = []
172172
for row in self._db_exec(user_name, suite_name, stmt):
173173
point, namespace, key, value = row

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/functional/cylc-review/05-cycles-job-fails/suite.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
script = false
1515
[[rehab]]
1616
script = """
17-
cylc set "${CYLC_WORKFLOW_NAME}//${CYLC_TASK_CYCLE_POINT}/loser"
17+
cylc set "${CYLC_WORKFLOW_ID}//${CYLC_TASK_CYCLE_POINT}/loser"
1818
sleep 1
1919
"""

tests/functional/cylc-review/08-suites-page.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ cylc_ws_json_greps "${TEST_NAME}.stdout" "${TEST_NAME}.stdout" \
5757
"[('page',), 1]" \
5858
"[('per_page',), 100]" \
5959
"[('of_n_entries',), 2]" \
60-
"[('entries', 0, 'name'), '${PREFIX_GROUP1}a']" \
61-
"[('entries', 1, 'name'), '${PREFIX_GROUP1}b']"
60+
"[('entries', 0, 'name'), '${PREFIX_GROUP1}b']" \
61+
"[('entries', 1, 'name'), '${PREFIX_GROUP1}a']"
6262
#-------------------------------------------------------------------------------
6363
# Data transfer output check for [abc], sort by time_asc
6464
TEST_NAME="${TEST_NAME_BASE}-200-curl-suites-time-asc"
@@ -69,8 +69,8 @@ cylc_ws_json_greps "${TEST_NAME}.stdout" "${TEST_NAME}.stdout" \
6969
"[('page',), 1]" \
7070
"[('per_page',), 100]" \
7171
"[('of_n_entries',), 2]" \
72-
"[('entries', 0, 'name'), '${PREFIX_GROUP1}b']" \
73-
"[('entries', 1, 'name'), '${PREFIX_GROUP1}a']"
72+
"[('entries', 0, 'name'), '${PREFIX_GROUP1}a']" \
73+
"[('entries', 1, 'name'), '${PREFIX_GROUP1}b']"
7474
#-------------------------------------------------------------------------------
7575
# Data transfer output check for [abc], sort by name_asc
7676
TEST_NAME="${TEST_NAME_BASE}-200-curl-suites-name-asc"
@@ -105,7 +105,7 @@ cylc_ws_json_greps "${TEST_NAME}.stdout" "${TEST_NAME}.stdout" \
105105
"[('page',), 1]" \
106106
"[('per_page',), 1]" \
107107
"[('of_n_entries',), 3]" \
108-
"[('entries', 0, 'name'), '${PREFIX_GROUP2}1']"
108+
"[('entries', 0, 'name'), '${PREFIX_GROUP2}3']"
109109
#-------------------------------------------------------------------------------
110110
# Data transfer output check for [1-10], page 2
111111
TEST_NAME="${TEST_NAME_BASE}-200-curl-suites-2-page-2"
@@ -127,7 +127,7 @@ cylc_ws_json_greps "${TEST_NAME}.stdout" "${TEST_NAME}.stdout" \
127127
"[('page',), 3]" \
128128
"[('per_page',), 1]" \
129129
"[('of_n_entries',), 3]" \
130-
"[('entries', 0, 'name'), '${PREFIX_GROUP2}3']"
130+
"[('entries', 0, 'name'), '${PREFIX_GROUP2}1']"
131131
#-------------------------------------------------------------------------------
132132
# Tidy up - note suites trivial so stop early on by themselves
133133
rm -fr "${HOME}/cylc-run/${TOP_LEVEL_TEST_DIR}"

tests/functional/cylc-review/12-cycle-counts.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ init_workflow "${TEST_NAME_BASE}" <<'__SUITE_RC__'
3434
T06 = bar[-PT6H] => baz
3535
[runtime]
3636
[[foo]]
37-
script = cylc stop $CYLC_WORKFLOW_NAME bar.20100101T0000Z; sleep 5
37+
script = cylc stop "${CYLC_WORKFLOW_ID}//20100101T0000Z/bar"; sleep 5
3838
[[bar, baz]]
3939
script = true
4040
__SUITE_RC__

tests/integration/test_cylc_review.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
from contextlib import suppress
1818
import json
19+
from multiprocessing import Process
1920
import pytest
2021
import socket
21-
import subprocess
2222
import requests
2323
from time import sleep
2424

2525
from cylc.flow import __version__ as CYLC_VERSION
2626

27+
from cylc.uiserver.review import CylcReviewService
28+
from cylc.uiserver.ws import _ws_init
29+
2730

2831
@pytest.fixture(scope='module')
2932
def run_cylc_review(request):
@@ -35,18 +38,12 @@ def run_cylc_review(request):
3538
Yields:
3639
Server process, request to home page as json
3740
"""
38-
39-
proc = subprocess.Popen(
40-
[
41-
'cylc',
42-
'review',
43-
'start',
44-
'--port', port,
45-
f'--service-root={service_root}',
46-
],
47-
stdout=subprocess.PIPE,
48-
stderr=subprocess.STDOUT,
49-
)
41+
proc = Process(target=_ws_init, kwargs={
42+
'service_cls': CylcReviewService,
43+
'port': port,
44+
'service_root': service_root
45+
})
46+
proc.start()
5047

5148
# Ensure that home-page is accessible:
5249
timeout_counter = 0
@@ -80,6 +77,7 @@ def test_basic_path(run_cylc_review):
8077
'host': socket.gethostname(),
8178
'cylc_version': CYLC_VERSION,
8279
'script': '/foo/cylc-review',
80+
'jupythub_base': None,
8381
}
8482
data = json.loads(run_cylc_review[1].text)
8583
assert data == expect

0 commit comments

Comments
 (0)