Skip to content

Commit

Permalink
Fix platform selection bug.
Browse files Browse the repository at this point in the history
OrderedDictWithDefaults.__getiter__ will get the default, if it exists.
OrderedDictWithDefaults.get does not get the default and was causing
the platform selection to fail quietly and select localhost.
  • Loading branch information
wxtim committed Jul 8, 2022
1 parent 5e7ffad commit e0178f1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
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 @@ -34,6 +35,8 @@
PlatformLookupError,
GlobalConfigError
)
from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults


PLATFORMS = {
'desktop[0-9]{2}|laptop[0-9]{2}': {
Expand Down Expand Up @@ -599,3 +602,33 @@ 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.
"""
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'

0 comments on commit e0178f1

Please sign in to comment.