From ac071c6fb976f8e059ca196df9dad092e5eecf71 Mon Sep 17 00:00:00 2001 From: Scott Wales Date: Fri, 27 Oct 2023 14:22:43 +1100 Subject: [PATCH] Set forward variables by platform --- cylc/flow/cfgspec/globalcfg.py | 16 ++++++++-------- cylc/flow/remote.py | 5 +---- tests/unit/cfgspec/test_globalcfg.py | 10 ++++++++++ tests/unit/test_remote.py | 12 ++---------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/cylc/flow/cfgspec/globalcfg.py b/cylc/flow/cfgspec/globalcfg.py index d42415d2a9c..e07db4c140b 100644 --- a/cylc/flow/cfgspec/globalcfg.py +++ b/cylc/flow/cfgspec/globalcfg.py @@ -784,14 +784,6 @@ def default_for( {REPLACES}``[suite servers][run host select]rank``. ''') - Conf('ssh forward environment variables', VDR.V_STRING_LIST, '', - desc=''' - A list containing the names of the environment variables to - forward with SSH connections to the workflow host from - the host running 'cylc play' - - .. versionadded:: 8.3.0 - ''') with Conf('host self-identification', desc=f''' How Cylc determines and shares the identity of the workflow host. @@ -1640,6 +1632,14 @@ def default_for( .. versionadded:: 8.0.0 ''') + Conf('ssh forward environment variables', VDR.V_STRING_LIST, '', + desc=''' + A list containing the names of the environment variables to + forward with SSH connections to the workflow host from + the host running 'cylc play' + + .. versionadded:: 8.3.0 + ''') with Conf('selection', desc=''' How to select a host from the list of platform hosts. diff --git a/cylc/flow/remote.py b/cylc/flow/remote.py index 5d9ed7c3937..8a72d56b6d6 100644 --- a/cylc/flow/remote.py +++ b/cylc/flow/remote.py @@ -35,7 +35,6 @@ from cylc.flow.option_parsers import verbosity_to_opts from cylc.flow.platforms import get_platform, get_host_from_platform from cylc.flow.util import format_cmd -from cylc.flow.cfgspec.glbl_cfg import glbl_cfg def get_proc_ancestors(): @@ -300,9 +299,7 @@ def construct_ssh_cmd( 'CYLC_COVERAGE', 'CLIENT_COMMS_METH', 'CYLC_ENV_NAME', - *(glbl_cfg().get(['scheduler']) - ['run hosts'] - ['ssh forward environment variables']), + *platform['ssh forward environment variables'], ]: if envvar in os.environ: command.append( diff --git a/tests/unit/cfgspec/test_globalcfg.py b/tests/unit/cfgspec/test_globalcfg.py index 2becda1caad..6db8d76dcf8 100644 --- a/tests/unit/cfgspec/test_globalcfg.py +++ b/tests/unit/cfgspec/test_globalcfg.py @@ -148,3 +148,13 @@ def test_source_dir_validation( assert "must be an absolute path" in str(excinfo.value) else: glblcfg.load() + +def test_platform_ssh_forward_variables(mock_global_config): + + glblcfg: GlobalConfig = mock_global_config(''' + [platforms] + [[foo]] + ssh forward environment variables = "FOO", "BAR" + ''') + + assert glblcfg.get(['platforms','foo','ssh forward environment variables']) == ["FOO", "BAR"] diff --git a/tests/unit/test_remote.py b/tests/unit/test_remote.py index c3c0c1ca9ff..8d24fc0bb3a 100644 --- a/tests/unit/test_remote.py +++ b/tests/unit/test_remote.py @@ -90,25 +90,17 @@ def test_construct_rsync_over_ssh_cmd(): ] -def test_construct_ssh_cmd_forward_env(mock_glbl_cfg): +def test_construct_ssh_cmd_forward_env(): """ Test for 'ssh forward environment variables' """ import os - mock_glbl_cfg( - 'cylc.flow.remote.glbl_cfg', - ''' - [scheduler] - [[run hosts]] - ssh forward environment variables = FOO, BAR - ''' - ) - host = 'example.com' config = { 'ssh command': 'ssh', 'use login shell': None, 'cylc path': None, + 'ssh forward environment variables': ['FOO', 'BAZ'], } # Variable isn't set, no change to command