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

Prevent platforms and groups sharing names #4445

Merged
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
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ omit=
parallel = True
plugins=
source=
./bin
./cylc
timid = False

Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Fix ``cylc stop --kill`` which was not actually killing task jobs.
[#4338](https://github.com/cylc/cylc-flow/pull/4338) - Cylc install -C option
now works with relative paths.

[#4445](https://github.com/cylc/cylc-flow/pull/4445) - Cylc will prevent you
using the same name for a platform and a platform group. Which one it should
pick is ambiguous, and is a setup error.

-------------------------------------------------------------------------------
## __cylc-8.0b2 (<span actions:bind='release-date'>Released 2021-07-28</span>)__

Expand Down
20 changes: 20 additions & 0 deletions cylc/flow/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from cylc.flow import LOG
from cylc.flow import __version__ as CYLC_VERSION
from cylc.flow.exceptions import GlobalConfigError
from cylc.flow.hostuserutil import get_user_home
from cylc.flow.network.client_factory import CommsMeth
from cylc.flow.parsec.config import (
Expand Down Expand Up @@ -1141,6 +1142,7 @@ def load(self):
raise

self._set_default_editors()
self._no_platform_group_name_overlap()

def _set_default_editors(self):
# default to $[G]EDITOR unless an editor is defined in the config
Expand All @@ -1150,3 +1152,21 @@ def _set_default_editors(self):
cfg['editors']['terminal'] = os.environ.get('EDITOR') or 'vi'
if not cfg['editors']['gui']:
cfg['editors']['gui'] = os.environ.get('GEDITOR') or 'gvim -fg'

def _no_platform_group_name_overlap(self):
if (
'platforms' in self.sparse and
'platform groups' in self.sparse
):
names_in_platforms_and_groups = set(
self.sparse['platforms'].keys()).intersection(
set(self.sparse['platform groups'].keys()))

if names_in_platforms_and_groups:
msg = (
'Platforms and platform groups must not share names. '
'The following are in both sets:'
)
for name in names_in_platforms_and_groups:
msg += f'\n * {name}'
raise GlobalConfigError(msg)
4 changes: 4 additions & 0 deletions cylc/flow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class WorkflowConfigError(CylcConfigError):
"""Exception for configuration errors in a Cylc workflow configuration."""


class GlobalConfigError(CylcConfigError):
"""Exception for configuration errors in a Cylc global configuration."""


class GraphParseError(WorkflowConfigError):
"""Exception for errors in Cylc workflow graphing."""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------
# Test that Platforms and Platform Groups return an error listing items
# defined in both.
# Not having additional tests for cases with no overlap or platforms only
# becuase other tests will fail.
# Not testing for platform groups only because the really should never happen.

. "$(dirname "$0")/test_header"
#-------------------------------------------------------------------------------
set_test_number 4

create_test_global_config '' '''
[platforms]
[[Thomas]]
[[Percy]]
[[Edward]]
[[Skarloey]]
[platform groups]
[[Thomas]]
[[Percy]]
[[Gordon]]
[[Rhenas]]
'''

run_fail "${TEST_NAME_BASE}" cylc config
grep_ok "GlobalConfigError" "${TEST_NAME_BASE}.stderr"
grep_ok "\* Thomas" "${TEST_NAME_BASE}.stderr"
grep_ok "\* Percy" "${TEST_NAME_BASE}.stderr"



exit