| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
"""Test that using [runtime][TASK]run mode works in each mode. |
| 17 |
|
| 18 |
Point 3 of the Skip Mode proposal |
| 19 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md |
| 20 |
|
| 21 |
| The run mode should be controlled by a new task configuration |
| 22 |
| [runtime][<namespace>]run mode with the default being live. |
| 23 |
| As a runtime configuration, this can be defined in the workflow |
| 24 |
| for development / testing purposes or set by cylc broadcast. |
| 25 |
|
| 26 |
n.b: This is pretty much a functional test and |
| 27 |
probably ought to be labelled as such, but uses the |
| 28 |
integration test framework. |
| 29 |
""" |
| 30 |
|
| 31 |
import pytest |
| 32 |
|
| 33 |
from cylc.flow.cycling.iso8601 import ISO8601Point |
| 34 |
from cylc.flow.id import TaskTokens |
| 35 |
from cylc.flow.run_modes import WORKFLOW_RUN_MODES, RunMode |
| 36 |
from cylc.flow.scheduler import Scheduler, SchedulerStop |
| 37 |
from cylc.flow.task_state import TASK_STATUS_WAITING |
| 38 |
from cylc.flow.commands import ( |
| 39 |
run_cmd, |
| 40 |
force_trigger_tasks |
| 41 |
) |
| 42 |
|
| 43 |
|
| 44 |
@pytest.mark.parametrize('workflow_run_mode', sorted(WORKFLOW_RUN_MODES)) |
| 45 |
async def test_run_mode_override_from_config( |
| 46 |
capture_live_submissions, |
| 47 |
flow, |
| 48 |
scheduler, |
| 49 |
run, |
| 50 |
complete, |
| 51 |
workflow_run_mode, |
| 52 |
validate |
| 53 |
): |
| 54 |
"""Test that `[runtime][<namespace>]run mode` overrides workflow modes.""" |
| 55 |
id_ = flow({ |
| 56 |
'scheduling': { |
| 57 |
'graph': { |
| 58 |
'R1': 'live & skip', |
| 59 |
}, |
| 60 |
}, |
| 61 |
'runtime': { |
| 62 |
'live': {'run mode': 'live'}, |
| 63 |
'skip': {'run mode': 'skip'}, |
| 64 |
} |
| 65 |
}) |
| 66 |
run_mode = RunMode(workflow_run_mode) |
| 67 |
validate(id_) |
| 68 |
schd = scheduler(id_, run_mode=run_mode, paused_start=False) |
| 69 |
async with run(schd): |
| 70 |
await complete(schd) |
| 71 |
|
| 72 |
if workflow_run_mode == 'live': |
| 73 |
assert capture_live_submissions() == {'1/live'} |
| 74 |
elif workflow_run_mode == 'dummy': |
| 75 |
# Skip mode doesn't override dummy mode: |
| 76 |
assert capture_live_submissions() == {'1/live', '1/skip'} |
| 77 |
else: |
| 78 |
assert capture_live_submissions() == set() |
| 79 |
|
| 80 |
|
| 81 |
async def test_force_trigger_does_not_override_run_mode( |
| 82 |
flow, |
| 83 |
scheduler, |
| 84 |
start, |
| 85 |
): |
| 86 |
"""Force-triggering a task will not override the run mode. |
| 87 |
|
| 88 |
Taken from spec at |
| 89 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md#proposal |
| 90 |
""" |
| 91 |
wid = flow({ |
| 92 |
'scheduling': {'graph': {'R1': 'foo'}}, |
| 93 |
'runtime': {'foo': {'run mode': 'skip'}} |
| 94 |
}) |
| 95 |
schd = scheduler(wid, run_mode="live") |
| 96 |
async with start(schd): |
| 97 |
foo = schd.pool.get_tasks()[0] |
| 98 |
|
| 99 |
# Force trigger task: |
| 100 |
await run_cmd(force_trigger_tasks(schd, ['1/foo'], ['1'])) |
| 101 |
|
| 102 |
# ... but job submission will always change this to the correct mode: |
| 103 |
schd.submit_task_jobs([foo]) |
| 104 |
|
| 105 |
assert foo.run_mode.value == 'skip' |
| 106 |
|
| 107 |
|
| 108 |
async def test_run_mode_skip_abides_by_held(flow, scheduler, run): |
| 109 |
"""Tasks with run mode = skip will continue to abide by the |
| 110 |
is_held flag as normal. |
| 111 |
|
| 112 |
Taken from spec at |
| 113 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md#proposal |
| 114 |
""" |
| 115 |
wid = flow({ |
| 116 |
'scheduling': {'graph': {'R1': 'foo'}}, |
| 117 |
'runtime': {'foo': {'run mode': 'skip'}} |
| 118 |
}) |
| 119 |
schd: Scheduler = scheduler(wid, run_mode="live", paused_start=False) |
| 120 |
async with run(schd): |
| 121 |
foo = schd.pool.get_tasks()[0] |
| 122 |
assert not foo.state.is_held |
| 123 |
|
| 124 |
# Hold task, check that it's held: |
| 125 |
schd.pool.hold_tasks({TaskTokens('1', 'foo')}) |
| 126 |
await schd._main_loop() |
| 127 |
assert foo.state(TASK_STATUS_WAITING, is_held=True) |
| 128 |
|
| 129 |
schd.pool.release_held_tasks({TaskTokens('1', 'foo')}) |
| 130 |
assert not foo.state.is_held |
| 131 |
with pytest.raises(SchedulerStop): |
| 132 |
# Will shut down as foo has run |
| 133 |
await schd._main_loop() |
| 134 |
|
| 135 |
|
| 136 |
async def test_run_mode_override_from_broadcast( |
| 137 |
flow, scheduler, start, complete, log_filter, capture_live_submissions |
| 138 |
): |
| 139 |
"""Test that run_mode modifications only apply to one task. |
| 140 |
""" |
| 141 |
cfg = { |
| 142 |
"scheduler": {"cycle point format": "%Y"}, |
| 143 |
"scheduling": { |
| 144 |
"initial cycle point": "1000", |
| 145 |
"final cycle point": "1001", |
| 146 |
"graph": {"P1Y": "foo"}}, |
| 147 |
"runtime": { |
| 148 |
} |
| 149 |
} |
| 150 |
id_ = flow(cfg) |
| 151 |
schd = scheduler(id_, run_mode='live', paused_start=False) |
| 152 |
|
| 153 |
async with start(schd): |
| 154 |
schd.broadcast_mgr.put_broadcast( |
| 155 |
['1000'], ['foo'], [{'run mode': 'skip'}]) |
| 156 |
|
| 157 |
foo_1000 = schd.pool.get_task(ISO8601Point('1000'), 'foo') |
| 158 |
foo_1001 = schd.pool.get_task(ISO8601Point('1001'), 'foo') |
| 159 |
|
| 160 |
schd.submit_task_jobs([foo_1000, foo_1001]) |
| 161 |
assert foo_1000.run_mode.value == 'skip' |
| 162 |
assert capture_live_submissions() == {'1001/foo'} |