From d378e3a046f12d1a29484493eee7bc93fb79832f Mon Sep 17 00:00:00 2001 From: Tim Pillinger <26465611+wxtim@users.noreply.github.com> Date: Mon, 22 Apr 2024 14:45:26 +0100 Subject: [PATCH] ensure that sim mode won't fail if an invalid date is broadcast to it --- cylc/flow/run_modes/simulation.py | 37 +++++++++---------- .../integration/run_modes/test_simulation.py | 4 ++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cylc/flow/run_modes/simulation.py b/cylc/flow/run_modes/simulation.py index f2eb708aad3..3197857bec6 100644 --- a/cylc/flow/run_modes/simulation.py +++ b/cylc/flow/run_modes/simulation.py @@ -59,7 +59,9 @@ def submit_task_job( Returns: True - indicating that TaskJobManager need take no further action. """ - configure_sim_mode(rtconfig) + configure_sim_mode( + rtconfig, + itask.tdef.rtconfig['simulation']['fail cycle points']) itask.summary['started_time'] = now[0] task_job_mgr._set_retry_timers(itask, rtconfig) itask.mode_settings = ModeSettings( @@ -156,21 +158,12 @@ def __init__( if not rtconfig: rtconfig = itask.tdef.rtconfig if rtconfig and rtconfig != itask.tdef.rtconfig: - try: - rtconfig["simulation"][ - "fail cycle points" - ] = parse_fail_cycle_points( - rtconfig["simulation"]["fail cycle points"] - ) - except PointParsingError as exc: - # Broadcast Fail CP didn't parse - LOG.warning( - 'Broadcast fail cycle point was invalid:\n' - f' {exc.args[0]}' - ) - rtconfig['simulation'][ - 'fail cycle points' - ] = itask.tdef.rtconfig['simulation']['fail cycle points'] + rtconfig["simulation"][ + "fail cycle points" + ] = parse_fail_cycle_points( + rtconfig["simulation"]["fail cycle points"], + itask.tdef.rtconfig['simulation']['fail cycle points'] + ) # Calculate simulation info: self.simulated_run_length = ( @@ -183,7 +176,7 @@ def __init__( self.timeout = started_time + self.simulated_run_length -def configure_sim_mode(rtc): +def configure_sim_mode(rtc, fallback): """Adjust task defs for simulation and dummy mode. """ @@ -197,7 +190,8 @@ def configure_sim_mode(rtc): rtc["simulation"][ "fail cycle points" ] = parse_fail_cycle_points( - rtc["simulation"]["fail cycle points"] + rtc["simulation"]["fail cycle points"], + fallback ) @@ -240,7 +234,7 @@ def disable_platforms( def parse_fail_cycle_points( - f_pts_orig: List[str] + f_pts_orig: List[str], fallback ) -> 'Union[None, List[PointBase]]': """Parse `[simulation][fail cycle points]`. @@ -275,6 +269,7 @@ def parse_fail_cycle_points( LOG.warning( f'Invalid ISO 8601 date representation: {point_str}' ) + return fallback return f_pts @@ -303,7 +298,9 @@ def sim_time_check( if itask.mode_settings is None: rtconfig = task_events_manager.broadcast_mgr.get_updated_rtconfig( itask) - rtconfig = configure_sim_mode(rtconfig) + rtconfig = configure_sim_mode( + rtconfig, + itask.tdef.rtconfig['simulation']['fail cycle points']) itask.mode_settings = ModeSettings( itask, db_mgr, diff --git a/tests/integration/run_modes/test_simulation.py b/tests/integration/run_modes/test_simulation.py index 9ac2f651ddb..dd38a0eed59 100644 --- a/tests/integration/run_modes/test_simulation.py +++ b/tests/integration/run_modes/test_simulation.py @@ -423,6 +423,10 @@ async def test_settings_broadcast( 'Invalid ISO 8601 date representation: higadfuhasgiurguj' in log.messages[-1]) + # Check that the invalid broadcast hasn't + # changed the itask sim mode settings: + assert itask.mode_settings.sim_task_fails is True + schd.broadcast_mgr.put_broadcast( ['1066'], ['one'], [{ 'simulation': {'fail cycle points': '1'}