Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix platform selection bug. #4975

Merged
merged 3 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ default job runner directives for platforms.

### Fixes

[#4975](https://github.com/cylc/cylc-flow/pull/4975) - Fix selection of
platforms from `[job]` and `[remote]` configs.

[#4970](https://github.com/cylc/cylc-flow/pull/4970) - Fix handling of suicide
triggers in back-compat mode.

Expand Down
5 changes: 3 additions & 2 deletions cylc/flow/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def get_platform(
# Need to calculate platform
task_job_section: Dict[Any, Any] = {}
task_remote_section: Dict[Any, Any] = {}
task_job_section = task_conf.get("job", {})
task_remote_section = task_conf.get("remote", {})
task_job_section = task_conf['job'] if 'job' in task_conf else {}
task_remote_section = (
task_conf['remote'] if 'remote' in task_conf else {})
return platform_from_name(
platform_from_job_info(
glbl_cfg(cached=False).get(['platforms']),
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/test_platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults
from cylc.flow.platforms import (
get_all_platforms_for_install_target,
get_platform,
get_platform_deprecated_settings,
get_random_platform_for_install_target, is_platform_definition_subshell,
platform_from_name, platform_from_job_info,
Expand All @@ -35,6 +36,7 @@
GlobalConfigError
)


PLATFORMS = {
'desktop[0-9]{2}|laptop[0-9]{2}': {
'job runner': 'background'
Expand Down Expand Up @@ -599,3 +601,34 @@ def test_is_platform_definition_subshell(
assert err_msg in str(exc.value)
else:
assert is_platform_definition_subshell(plat_val) is expected


def test_get_platform_from_OrderedDictWithDefaults(mock_glbl_cfg):
"""Get platform works with OrderedDictWithDefaults.

Most tests use dictionaries to check platforms functionality.
This one was added to catch an issue where the behaviour of
dict.get != OrderedDictWithDefaults.get.
wxtim marked this conversation as resolved.
Show resolved Hide resolved
See - https://github.com/cylc/cylc-flow/issues/4979
"""
mock_glbl_cfg(
'cylc.flow.platforms.glbl_cfg',
'''
[platforms]
[[skarloey]]
hosts = foo, bar
job runner = slurm
'''
)
task_conf = OrderedDictWithDefaults()
task_conf.defaults_ = dict([
('job', dict([
('batch system', 'slurm')
])),
('remote', dict([
('host', 'foo')
]))
])
result = get_platform(task_conf)['name']
assert result == 'skarloey'