| 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 for skip mode integration. |
| 17 |
""" |
| 18 |
|
| 19 |
from cylc.flow.cycling.integer import IntegerPoint |
| 20 |
from cylc.flow.id import TaskTokens |
| 21 |
from cylc.flow.scheduler import Scheduler |
| 22 |
from cylc.flow.task_outputs import TASK_OUTPUT_FAILED |
| 23 |
from cylc.flow.task_state import ( |
| 24 |
TASK_STATUS_FAILED, |
| 25 |
TASK_STATUS_SUCCEEDED, |
| 26 |
) |
| 27 |
|
| 28 |
|
| 29 |
async def test_settings_override_from_broadcast( |
| 30 |
flow, scheduler, start, complete, log_filter |
| 31 |
): |
| 32 |
"""Test that skip mode runs differently if settings are modified. |
| 33 |
""" |
| 34 |
cfg = { |
| 35 |
"scheduling": {"graph": {"R1": "foo:failed => bar"}}, |
| 36 |
"runtime": { |
| 37 |
"foo": { |
| 38 |
"events": { |
| 39 |
'handler events': 'failed', |
| 40 |
"handlers": 'echo "HELLO"' |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
id_ = flow(cfg) |
| 46 |
schd = scheduler(id_, run_mode='live') |
| 47 |
|
| 48 |
async with start(schd): |
| 49 |
schd.broadcast_mgr.put_broadcast( |
| 50 |
['1'], |
| 51 |
['foo'], |
| 52 |
[ |
| 53 |
{'run mode': 'skip'}, |
| 54 |
{'skip': {'outputs': 'failed'}}, |
| 55 |
{'skip': {'disable task event handlers': "False"}} |
| 56 |
] |
| 57 |
) |
| 58 |
|
| 59 |
foo, = schd.pool.get_tasks() |
| 60 |
|
| 61 |
schd.submit_task_jobs(schd.pool.get_tasks()) |
| 62 |
# Run mode has changed: |
| 63 |
assert foo.platform['name'] == 'skip' |
| 64 |
# Output failed emitted: |
| 65 |
assert foo.state.status == 'failed' |
| 66 |
# After processing events there is a handler in the subprocpool: |
| 67 |
schd.task_events_mgr.process_events(schd) |
| 68 |
assert 'echo "HELLO"' in schd.proc_pool.is_not_done()[0][0].cmd |
| 69 |
|
| 70 |
|
| 71 |
async def test_broadcast_changes_set_skip_outputs( |
| 72 |
flow, scheduler, start |
| 73 |
): |
| 74 |
"""When cylc set --out skip is used, task outputs are updated with |
| 75 |
broadcasts. |
| 76 |
|
| 77 |
Skip mode proposal point 4 |
| 78 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md |
| 79 |
|
| 80 |
| The cylc set --out option should accept the skip value which should |
| 81 |
| set the outputs defined in [runtime][<namespace>][skip]outputs. |
| 82 |
| The skip keyword should not be allowed in custom outputs. |
| 83 |
""" |
| 84 |
wid = flow({ |
| 85 |
'scheduling': {'graph': {'R1': 'foo:x?\nfoo:y?'}}, |
| 86 |
'runtime': {'foo': {'outputs': { |
| 87 |
'x': 'some message', 'y': 'another message'}}} |
| 88 |
}) |
| 89 |
schd = scheduler(wid, run_mode='live') |
| 90 |
async with start(schd): |
| 91 |
schd.broadcast_mgr.put_broadcast( |
| 92 |
['1'], |
| 93 |
['foo'], |
| 94 |
[{'skip': {'outputs': 'x'}}], |
| 95 |
) |
| 96 |
foo, = schd.pool.get_tasks() |
| 97 |
schd.pool.set_prereqs_and_outputs( |
| 98 |
{TaskTokens('1', 'foo')}, ['skip'], [], []) |
| 99 |
|
| 100 |
foo_outputs = foo.state.outputs.get_completed_outputs() |
| 101 |
|
| 102 |
assert foo_outputs == { |
| 103 |
'submitted': '(manually completed)', |
| 104 |
'started': '(manually completed)', |
| 105 |
'succeeded': '(manually completed)', |
| 106 |
'x': '(manually completed)'} |
| 107 |
|
| 108 |
|
| 109 |
async def test_skip_mode_outputs( |
| 110 |
flow, scheduler, reftest, |
| 111 |
): |
| 112 |
"""Skip mode can be configured by the `[runtime][<namespace>][skip]` |
| 113 |
section. |
| 114 |
|
| 115 |
Skip mode proposal point 2 |
| 116 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md |
| 117 |
""" |
| 118 |
graph = r""" |
| 119 |
# By default, all required outputs will be generated |
| 120 |
# plus succeeded if success is optional: |
| 121 |
foo? & foo:required_out => success_if_optional & required_outs |
| 122 |
|
| 123 |
# The outputs submitted and started are always produced |
| 124 |
# and do not need to be defined in [runtime][X][skip]outputs: |
| 125 |
foo:submitted => submitted_always |
| 126 |
foo:started => started_always |
| 127 |
|
| 128 |
# If outputs is specified and does not include either |
| 129 |
# succeeded or failed then succeeded will be produced. |
| 130 |
opt:optional_out? => optional_outs_produced |
| 131 |
|
| 132 |
should_fail:fail => did_fail |
| 133 |
""" |
| 134 |
wid = flow({ |
| 135 |
'scheduling': {'graph': {'R1': graph}}, |
| 136 |
'runtime': { |
| 137 |
'root': { |
| 138 |
'run mode': 'skip', |
| 139 |
'outputs': { |
| 140 |
'required_out': 'the plans have been on display...', |
| 141 |
'optional_out': 'its only four light years away...' |
| 142 |
} |
| 143 |
}, |
| 144 |
'opt': { |
| 145 |
'skip': { |
| 146 |
'outputs': 'optional_out' |
| 147 |
} |
| 148 |
}, |
| 149 |
'should_fail': { |
| 150 |
'skip': { |
| 151 |
'outputs': 'failed' |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
}) |
| 156 |
schd = scheduler(wid, run_mode='live', paused_start=False) |
| 157 |
assert await reftest(schd) == { |
| 158 |
('1/did_fail', ('1/should_fail',),), |
| 159 |
('1/foo', None,), |
| 160 |
('1/opt', None,), |
| 161 |
('1/optional_outs_produced', ('1/opt',),), |
| 162 |
('1/required_outs', ('1/foo', '1/foo',),), |
| 163 |
('1/should_fail', None,), |
| 164 |
('1/started_always', ('1/foo',),), |
| 165 |
('1/submitted_always', ('1/foo',),), |
| 166 |
('1/success_if_optional', ('1/foo', '1/foo',),), |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
async def test_doesnt_release_held_tasks( |
| 171 |
one_conf, flow, scheduler, start, log_filter, capture_live_submissions |
| 172 |
): |
| 173 |
"""Point 5 of the proposal |
| 174 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md |
| 175 |
|
| 176 |
| Tasks with run mode = skip will continue to abide by the is_held |
| 177 |
| flag as normal. |
| 178 |
|
| 179 |
""" |
| 180 |
one_conf['runtime'] = {'one': {'run mode': 'skip'}} |
| 181 |
schd = scheduler(flow(one_conf), run_mode='live', paused_start=False) |
| 182 |
async with start(schd): |
| 183 |
msg = 'held tasks shoudn\'t {}' |
| 184 |
|
| 185 |
# Set task to held and check submission in skip mode doesn't happen: |
| 186 |
schd.pool.hold_tasks({TaskTokens('1', 'one')}) |
| 187 |
schd.release_tasks_to_run() |
| 188 |
|
| 189 |
assert not log_filter(contains='=> running'), msg.format('run') |
| 190 |
assert not log_filter(contains='=> succeeded'), msg.format('succeed') |
| 191 |
|
| 192 |
# Release held task and assert that it now skips successfully: |
| 193 |
schd.pool.release_held_tasks({TaskTokens('1', 'one')}) |
| 194 |
schd.release_tasks_to_run() |
| 195 |
|
| 196 |
assert log_filter(contains='=> running'), msg.format('run') |
| 197 |
assert log_filter(contains='=> succeeded'), msg.format('succeed') |
| 198 |
|
| 199 |
|
| 200 |
async def test_prereqs_marked_satisfied_by_skip_mode( |
| 201 |
flow, scheduler, start, log_filter, complete |
| 202 |
): |
| 203 |
"""Point 8 from the skip mode proposal |
| 204 |
https://github.com/cylc/cylc-admin/blob/master/docs/proposal-skip-mode.md |
| 205 |
|
| 206 |
| When tasks are run in skip mode, the prerequisites which correspond |
| 207 |
| to the outputs they generate should be marked as "satisfied by skip mode" |
| 208 |
| rather than "satisfied naturally" for provenance reasons. |
| 209 |
""" |
| 210 |
schd = scheduler(flow({ |
| 211 |
'scheduling': {'graph': {'R1': 'foo => bar'}}, |
| 212 |
'runtime': {'foo': {'run mode': 'skip'}} |
| 213 |
}), run_mode='live') |
| 214 |
|
| 215 |
async with start(schd): |
| 216 |
foo = schd.pool.get_task(IntegerPoint(1), 'foo') |
| 217 |
schd.submit_task_jobs([foo]) |
| 218 |
bar = schd.pool.get_task(IntegerPoint(1), 'bar') |
| 219 |
satisfied_message, = bar.state.prerequisites[0]._satisfied.values() |
| 220 |
assert satisfied_message == 'satisfied by skip mode' |
| 221 |
|
| 222 |
|
| 223 |
async def test_outputs_can_be_changed( |
| 224 |
one_conf, flow, start, scheduler, validate |
| 225 |
): |
| 226 |
schd = scheduler(flow(one_conf), run_mode='live') |
| 227 |
async with start(schd): |
| 228 |
# Broadcast the task into skip mode, output failed and submit it: |
| 229 |
schd.broadcast_mgr.put_broadcast( |
| 230 |
["1"], |
| 231 |
["one"], |
| 232 |
[ |
| 233 |
{"run mode": "skip"}, |
| 234 |
{"skip": {"outputs": "failed"}}, |
| 235 |
], |
| 236 |
) |
| 237 |
schd.submit_task_jobs(schd.pool.get_tasks()) |
| 238 |
|
| 239 |
# Broadcast the task into skip mode, output succeeded and submit it: |
| 240 |
schd.broadcast_mgr.put_broadcast( |
| 241 |
['1'], ['one'], [{'skip': {'outputs': 'succeeded'}}] |
| 242 |
) |
| 243 |
schd.submit_task_jobs(schd.pool.get_tasks()) |
| 244 |
|
| 245 |
|
| 246 |
async def test_rerun_after_skip_mode_broadcast( |
| 247 |
flow, one_conf, scheduler, start |
| 248 |
): |
| 249 |
"""Test re-running a task after it has been set to skip. |
| 250 |
|
| 251 |
See https://github.com/cylc/cylc-flow/pull/6940 |
| 252 |
""" |
| 253 |
id_ = flow({ |
| 254 |
**one_conf, |
| 255 |
"runtime": { |
| 256 |
"one": { |
| 257 |
"execution time limit": "PT1M", |
| 258 |
}, |
| 259 |
}, |
| 260 |
}) |
| 261 |
schd: Scheduler = scheduler(id_, run_mode='live') |
| 262 |
async with start(schd): |
| 263 |
itask = schd.pool.get_tasks()[0] |
| 264 |
schd.submit_task_jobs([itask]) |
| 265 |
schd.task_events_mgr.process_message( |
| 266 |
itask, 'CRITICAL', TASK_OUTPUT_FAILED |
| 267 |
) |
| 268 |
assert itask.state(TASK_STATUS_FAILED) |
| 269 |
|
| 270 |
schd.broadcast_mgr.put_broadcast( |
| 271 |
['1'], ['root'], [{'run mode': 'skip'}] |
| 272 |
) |
| 273 |
schd.submit_task_jobs([itask]) |
| 274 |
assert itask.state(TASK_STATUS_SUCCEEDED) |