From d3ce313842c5837ab962b31d9dd98fdb9e1d2895 Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Tue, 7 Mar 2023 13:50:13 +0000 Subject: [PATCH] Stop searching platform groups after first match. --- cylc/flow/platforms.py | 4 ++++ tests/unit/test_platforms_get_platform.py | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cylc/flow/platforms.py b/cylc/flow/platforms.py index 35ffee6bdb5..b40360724d7 100644 --- a/cylc/flow/platforms.py +++ b/cylc/flow/platforms.py @@ -191,6 +191,9 @@ 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): @@ -198,6 +201,7 @@ def platform_from_name( platform_groups[platform_name_re], group_name=platform_name, bad_hosts=bad_hosts ) + break for platform_name_re in list(platforms): if ( diff --git a/tests/unit/test_platforms_get_platform.py b/tests/unit/test_platforms_get_platform.py index d26af0575b2..5e6a7ff1892 100644 --- a/tests/unit/test_platforms_get_platform.py +++ b/tests/unit/test_platforms_get_platform.py @@ -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