Skip to content

Commit a6bba6e

Browse files
authored
Merge pull request #2859 from IntersectMBO/imp_port_allocation
Improve ports allocation
2 parents 9e4a14b + bf35e21 commit a6bba6e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Tests execution can be configured using env variables.
9898
* `BOOTSTRAP_DIR` – path to a bootstrap dir for the given testnet (genesis files, config files, faucet data) (default: unset)
9999
* `KEEP_CLUSTERS_RUNNING` – don't stop cluster instances after testrun is finished
100100
(WARNING: this implies interactive behavior when running tests using the `./.github/regression.sh` script)
101+
* `PORTS_BASE` - base port number for ports range used by cluster instances (default: 23000)
101102
102103
When running tests using the `./.github/regression.sh` script, you can also use
103104

cardano_node_tests/utils/cluster_scripts.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,12 @@ def _preselect_addr(self, instance_num: int) -> str:
166166

167167
def get_instance_ports(self, instance_num: int) -> InstancePorts:
168168
"""Return ports mapping for given cluster instance."""
169-
ports_per_instance = 100
170-
ports_per_node = 5
169+
# Allocate 100 ports per each 18 pools
170+
ports_per_instance = ((self.num_pools - 1) // 18 + 1) * 100
171171
offset = instance_num * ports_per_instance
172-
base = 32000 + offset
172+
base = configuration.PORTS_BASE + offset
173173
last_port = base + ports_per_instance - 1
174+
ports_per_node = 5
174175

175176
def _get_node_ports(num: int) -> NodePorts:
176177
rec_base = base + (num * ports_per_node)

cardano_node_tests/utils/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def _check_cardano_node_socket_path() -> None:
3131
DBSYNC_DB = "dbsync"
3232
IS_XDIST = bool(os.environ.get("PYTEST_XDIST_TESTRUNUID"))
3333

34+
# Make sure the ports don't overlap with ephemeral port range. It's usually 32768 to 60999.
35+
# See `cat /proc/sys/net/ipv4/ip_local_port_range`.
36+
PORTS_BASE = int(os.environ.get("PORTS_BASE") or 23000)
37+
3438
# Used also in startup scripts as `if [ -n "$VAR" ]...`
3539
ENABLE_LEGACY = (os.environ.get("ENABLE_LEGACY") or "") != ""
3640
# Used also in startup scripts as `if [ -n "$VAR" ]...`

0 commit comments

Comments
 (0)