]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/tox: run pytest in parallel 69603/head
authorSun Yuechi <sunyuechi@iscas.ac.cn>
Thu, 18 Jun 2026 19:06:06 +0000 (03:06 +0800)
committerSun Yuechi <sunyuechi@iscas.ac.cn>
Fri, 19 Jun 2026 15:08:37 +0000 (23:08 +0800)
The py3 and coverage tox environments run the full mgr pytest suite
serially, which makes run-tox-mgr the longest test in CI. Add
pytest-xdist and pass `-n auto` to both so the suite is distributed
across the available CPUs.

pytest-xdist is constrained to <2 to stay compatible with the pinned
pytest-cov. Running in parallel also surfaced a hard-coded port in
cephadm's test_node_proxy, which now allocates an ephemeral port per
process.

Signed-off-by: Sun Yuechi <sunyuechi@iscas.ac.cn>
src/pybind/mgr/cephadm/tests/test_node_proxy.py
src/pybind/mgr/requirements.txt
src/pybind/mgr/tox.ini

index dd5f99f508c27566fdd2ace91dd500186a1ef574..75fe7d6fab916bd28c3386089cae9d5b47b10772 100644 (file)
@@ -1,5 +1,6 @@
 import cherrypy
 import json
+import socket
 from _pytest.monkeypatch import MonkeyPatch
 from urllib.error import URLError
 from cherrypy.test import helper
@@ -9,7 +10,16 @@ from cephadm.inventory import AgentCache, NodeProxyCache, Inventory
 from cephadm.ssl_cert_utils import SSLCerts
 from . import node_proxy_data
 
-PORT = 58585
+
+def _free_port() -> int:
+    # Pick an ephemeral port so the test server does not clash with other
+    # pytest-xdist workers running this module in parallel.
+    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
+        s.bind(('127.0.0.1', 0))
+        return s.getsockname()[1]
+
+
+PORT = _free_port()
 fake_cert = """-----BEGIN CERTIFICATE-----\nMIICxjCCAa4CEQDIZSujNBlKaLJzmvntjukjMA0GCSqGSIb3DQEBDQUAMCExDTAL\nBgNVBAoMBENlcGgxEDAOBgNVBAMMB2NlcGhhZG0wHhcNMjIwNzEzMTE0NzA3WhcN\nMzIwNzEwMTE0NzA3WjAhMQ0wCwYDVQQKDARDZXBoMRAwDgYDVQQDDAdjZXBoYWRt\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyyMe4DMA+MeYK7BHZMHB\nq7zjliEOcNgxomjU8qbf5USF7Mqrf6+/87XWqj4pCyAW8x0WXEr6A56a+cmBVmt+\nqtWDzl020aoId6lL5EgLLn6/kMDCCJLq++Lg9cEofMSvcZh+lY2f+1p+C+00xent\nrLXvXGOilAZWaQfojT2BpRnNWWIFbpFwlcKrlg2G0cFjV5c1m6a0wpsQ9JHOieq0\nSvwCixajwq3CwAYuuiU1wjI4oJO4Io1+g8yB3nH2Mo/25SApCxMXuXh4kHLQr/T4\n4hqisvG4uJYgKMcSIrWj5o25mclByGi1UI/kZkCUES94i7Z/3ihx4Bad0AMs/9tw\nFwIDAQABMA0GCSqGSIb3DQEBDQUAA4IBAQAf+pwz7Gd7mDwU2LY0TQXsK6/8KGzh\nHuX+ErOb8h5cOAbvCnHjyJFWf6gCITG98k9nxU9NToG0WYuNm/max1y/54f0dtxZ\npUo6KSNl3w6iYCfGOeUIj8isi06xMmeTgMNzv8DYhDt+P2igN6LenqWTVztogkiV\nxQ5ZJFFLEw4sN0CXnrZX3t5ruakxLXLTLKeE0I91YJvjClSBGkVJq26wOKQNHMhx\npWxeydQ5EgPZY+Aviz5Dnxe8aB7oSSovpXByzxURSabOuCK21awW5WJCGNpmqhWK\nZzACBDEstccj57c4OGV0eayHJRsluVr2e9NHRINZA3qdB37e6gsI1xHo\n-----END CERTIFICATE-----\n"""
 
 
index 044674f9be569b7f76d8480cba4a9280a3bb3f71..96712691c763080a33c19a1b843406c36dfd8348 100644 (file)
@@ -3,3 +3,4 @@ asyncssh==2.9
 kubernetes
 urllib3==1.26.15
 pytest==7.4.4
+pytest-xdist <2
index 647b9e45a933520035dc955c7643eae24cddec09..1443659719bba65e811547cb2ded9e6e2c833c30 100644 (file)
@@ -61,7 +61,7 @@ deps =
     -rrequirements.txt
     -rrook/requirements.txt
 commands =
-    pytest --doctest-modules {posargs:}
+    pytest -n auto --doctest-modules {posargs:}
 
 [testenv:nooptional]
 setenv =
@@ -87,7 +87,7 @@ deps =
 #   COVERAGE_REPORT=html tox -e coverage -- <module>
 #   <your-browser> htmlcov/index.html
 commands =
-    pytest --cov={posargs:.} --cov-report={env:COVERAGE_REPORT:term} {posargs:.}
+    pytest -n auto --cov={posargs:.} --cov-report={env:COVERAGE_REPORT:term} {posargs:.}
 
 
 [testenv:{,py37-,py38-,py39-,py310-}mypy]