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

Allow 'cylc reload' to reload global configuration #6509

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
22 changes: 21 additions & 1 deletion cylc/flow/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
RunMode,
StopMode,
)
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg


if TYPE_CHECKING:
Expand Down Expand Up @@ -329,7 +330,7 @@


@_command('reload_workflow')
async def reload_workflow(schd: 'Scheduler'):
async def reload_workflow(schd: 'Scheduler', reload_global: bool = False):
"""Reload workflow configuration."""
yield
# pause the workflow if not already
Expand Down Expand Up @@ -363,6 +364,25 @@
# give commands time to complete
sleep(1) # give any remove-init's time to complete

if reload_global:
# Reload global config if requested
LOG.info("Reloading the global configuration.")
try:
glbl_cfg(reload=True)
except (ParsecError, CylcConfigError) as exc:
if cylc.flow.flags.verbosity > 1:
# log full traceback in debug mode
LOG.exception(exc)

Check warning on line 375 in cylc/flow/commands.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/commands.py#L375

Added line #L375 was not covered by tests
LOG.critical(
f'Reload failed - {exc.__class__.__name__}: {exc}'
'\nThis is probably due to an issue with the new'
' configuration.'
'\nTo continue with the pre-reload config, un-pause the'
' workflow.'
'\nOtherwise, fix the configuration and attempt to reload'
' again.'
)

# reload the workflow definition
schd.reload_pending = 'loading the workflow definition'
schd.update_data_store() # update workflow status msg
Expand Down
4 changes: 4 additions & 0 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,10 @@ class Meta:
class Arguments:
workflows = graphene.List(WorkflowID, required=True)

reload_global = Boolean(
default_value=False,
description="Also reload global config")

result = GenericScalar()


Expand Down
11 changes: 10 additions & 1 deletion cylc/flow/scripts/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@

MUTATION = '''
mutation (
$wFlows: [WorkflowID]!
$wFlows: [WorkflowID]!,
$reloadGlobal: Boolean,
) {
reload (
workflows: $wFlows
reloadGlobal: $reloadGlobal
) {
result
}
Expand All @@ -87,6 +89,12 @@
multiworkflow=True,
argdoc=[WORKFLOW_ID_MULTI_ARG_DOC],
)

parser.add_option(

Check warning on line 93 in cylc/flow/scripts/reload.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/reload.py#L93

Added line #L93 was not covered by tests
"-g", "--global",
help="also reload global configuration.",
action="store_true", default=False, dest="reload_global")

return parser


Expand All @@ -97,6 +105,7 @@
'request_string': MUTATION,
'variables': {
'wFlows': [workflow_id],
'reloadGlobal': options.reload_global,
}
}

Expand Down
1 change: 0 additions & 1 deletion cylc/flow/task_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ def copy_to_reload_successor(
reload_successor.summary = self.summary
reload_successor.local_job_file_path = self.local_job_file_path
reload_successor.try_timers = self.try_timers
reload_successor.platform = self.platform
ScottWales marked this conversation as resolved.
Show resolved Hide resolved
reload_successor.job_vacated = self.job_vacated
reload_successor.poll_timer = self.poll_timer
reload_successor.timeout = self.timeout
Expand Down
70 changes: 70 additions & 0 deletions tests/integration/test_reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
TASK_STATUS_PREPARING,
TASK_STATUS_SUBMITTED,
)
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg


async def test_reload_waits_for_pending_tasks(
Expand Down Expand Up @@ -146,3 +147,72 @@ async def test_reload_failure(

# the config should be unchanged
assert schd.config.cfg['scheduling']['graph']['R1'] == 'one'


async def test_reload_global(
flow,
one_conf,
scheduler,
start,
log_filter,
tmp_path,
monkeypatch,
):

global_config_path = tmp_path / 'global.cylc'
monkeypatch.setenv("CYLC_CONF_PATH", str(global_config_path.parent))

# Original global config file
global_config_path.write_text("""
[platforms]
[[localhost]]
[[[meta]]]
x = 1
""")
assert glbl_cfg(reload=True).get(['platforms','localhost','meta','x']) == '1'

id_ = flow(one_conf)
schd = scheduler(id_)
async with start(schd):

# Modify the global config file
global_config_path.write_text("""
[platforms]
[[localhost]]
[[[meta]]]
x = 2
""")

# reload the workflow and global config
await commands.run_cmd(commands.reload_workflow(schd, reload_global=True))

# Global config should have been reloaded
assert log_filter(
contains=(
'Reloading the global configuration.'
)
)

# Task platforms reflect the new config
assert schd.pool.get_tasks()[0].platform['meta']['x'] == '2'

# Modify the global config file with an error
global_config_path.write_text("""
[ERROR]
[[localhost]]
[[[meta]]]
x = 3
""")

# reload the workflow and global config
await commands.run_cmd(commands.reload_workflow(schd, reload_global=True))

# Error is noted in the log
assert log_filter(
contains=(
'This is probably due to an issue with the new configuration.'
)
)

# Task platforms should be the last valid value
assert schd.pool.get_tasks()[0].platform['meta']['x'] == '2'
Loading