Skip to content

Commit

Permalink
prevent global config having forbidden platform names
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Oct 16, 2024
1 parent 047c76f commit bc8d067
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cylc/flow/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Range,
cylc_config_validate,
)
from cylc.flow.run_modes import JOBLESS_MODES


PLATFORM_REGEX_TEXT = '''
Expand Down Expand Up @@ -1887,6 +1888,13 @@ def default_for(
def upg(cfg, descr):
"""Upgrader."""
u = upgrader(cfg, descr)
for platform in JOBLESS_MODES:
u.forbid(
['platforms', platform],
GlobalConfigError,
f'Platform name "{platform}" is not permitted.',
is_section=True,
)
u.upgrade()


Expand Down
51 changes: 48 additions & 3 deletions cylc/flow/parsec/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def deprecate(
'silent': silent, 'is_section': is_section
})

def obsolete(self, vn, oldkeys, silent=False, is_section=False):
def obsolete(
self,
vn,
oldkeys,
silent: bool = False,
is_section: bool = False,
):
"""Remove an obsolete key from a config
Args:
vn (str):
Expand All @@ -89,18 +95,57 @@ def obsolete(self, vn, oldkeys, silent=False, is_section=False):
Path within config to be removed.
silent:
Set silent mode for this upgrade.
is_section (bool):
is_section:
Is a section heading.
hard_error:
Raise an error _NOW_.
"""
if vn not in self.upgrades:
self.upgrades[vn] = []
cvtr = converter(lambda x: x, "DELETED (OBSOLETE)") # identity
else:
cvtr = converter(lambda x: x, "DELETED (OBSOLETE)") # identity
self.upgrades[vn].append(
{
'old': oldkeys, 'new': None, 'cvt': cvtr, 'silent': silent,
'is_section': is_section
})

def forbid(
self,
oldkeys,
error: Exception,
message: str,
is_section: bool = False,
):
"""Disallow a subset of arguments.
Args:
vn (str):
Version at which this obsoletion occurs.
oldkeys (list):
Path within config to be removed.
silent:
Set silent mode for this upgrade.
is_section:
Is a section heading.
hard_error:
Raise an error _NOW_.
"""
if 'forbidden' not in self.upgrades:
self.upgrades['forbidden'] = []

def callback(_):
raise error(message)

self.upgrades['forbidden'].append(
{
'old': oldkeys,
'new': None,
'cvt': converter(callback, ''),
'silent': False,
'is_section': is_section,
}
)

def get_item(self, keys):
item = self.cfg
for key in keys:
Expand Down

0 comments on commit bc8d067

Please sign in to comment.