Skip to content

Commit

Permalink
Stop searching platform groups after first match.
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Mar 7, 2023
1 parent 62fdc6e commit d3ce313
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
4 changes: 4 additions & 0 deletions cylc/flow/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,17 @@ def platform_from_name(
platform_name = 'localhost'

platform_group = None
# The list is reversed to allow user-set platform groups (which are loaded
# later than site set platforms) to be matched first and override site
# defined platforms.
for platform_name_re in reversed(list(platform_groups)):
# Platform is member of a group.
if re.fullmatch(platform_name_re, platform_name):
platform_name = get_platform_from_group(
platform_groups[platform_name_re], group_name=platform_name,
bad_hosts=bad_hosts
)
break

for platform_name_re in list(platforms):
if (
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/test_platforms_get_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,25 @@ def test_get_platform_using_platform_name_from_job_info(


def test_get_platform_groups_basic(mock_glbl_cfg):
# get platform from group works.
"""get platform from group works.
Additionally, ensure that we stop after selecting the first
appropriate platform.
"""
mock_glbl_cfg(
'cylc.flow.platforms.glbl_cfg',
'''
[platforms]
[[aleph]]
hosts = aleph
[[bet]]
hosts = bet
[[aleph, bet, alpha, beta]]
[platform groups]
[[hebrew_letters]]
platforms = alpha, beta
[[[selection]]]
method = definition order
[[aleph]]
platforms = alpha
[[.*_letters]]
platforms = aleph, bet
[[[selection]]]
method = definition order
Expand Down

0 comments on commit d3ce313

Please sign in to comment.