Debian Codegraph @

tests/f/restart/34-auto-restart-basic.t

raw
1 #!/usr/bin/env bash
2 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
3 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #-------------------------------------------------------------------------------
18 export REQUIRE_PLATFORM='loc:remote fs:shared runner:background'
19 . "$(dirname "$0")/test_header"
20 #-------------------------------------------------------------------------------
21 set_test_number 10
22 if ${CYLC_TEST_DEBUG:-false}; then ERR=2; else ERR=1; fi
23 #-------------------------------------------------------------------------------
24 # run through the shutdown - restart procedure
25 BASE_GLOBAL_CONFIG="
26 [scheduler]
27 [[main loop]]
28 plugins = health check, auto restart
29 [[[auto restart]]]
30 interval = PT2S
31 [[events]]
32 abort on inactivity timeout = True
33 abort on stall timeout = True
34 inactivity timeout = PT1M
35 stall timeout = PT1M
36 [scheduler]
37 [[run hosts]]
38 available = localhost, ${CYLC_TEST_HOST}"
39
40 TEST_NAME="${TEST_NAME_BASE}"
41 init_workflow "${TEST_NAME}" - <<'__FLOW_CONFIG__'
42 [task parameters]
43 foo = 1..25
44 [scheduling]
45 [[graph]]
46 R1 = "task<foo> => task<foo+1>"
47 [runtime]
48 [[task<foo>]]
49 [[task_26]]
50 __FLOW_CONFIG__
51
52 # run workflow on localhost normally
53 create_test_global_config '' "${BASE_GLOBAL_CONFIG}"
54 run_ok "${TEST_NAME}-workflow-start" cylc play "${WORKFLOW_NAME}" --host=localhost -s 'FOO="foo"' -v
55 cylc workflow-state "${WORKFLOW_NAME}//1/task_foo01:succeeded" --interval=1 --max-polls=20 >& $ERR
56
57 # condemn localhost
58 create_test_global_config '' "
59 ${BASE_GLOBAL_CONFIG}
60 [scheduler]
61 [[run hosts]]
62 condemned = $(hostname)
63 "
64 # test shutdown procedure - scan the first log file
65 FILE=$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)
66 log_scan "${TEST_NAME}-shutdown-log-scan" "${FILE}" 20 1 \
67 'The Cylc workflow host will soon become un-available' \
68 'Workflow shutting down - REQUEST(NOW-NOW)' \
69 "Attempting to restart on \"${CYLC_TEST_HOST}\"" \
70 "Workflow now running on \"${CYLC_TEST_HOST}\""
71 LATEST_TASK=$(cylc workflow-state --old-format "${WORKFLOW_NAME}//*/*:succeeded" \
72 | cut -d ',' -f 1 | sort | tail -n 1 | sed 's/task_foo//')
73
74 # test restart procedure - scan the second log file created on restart
75 poll_workflow_restart
76 FILE=$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)
77 log_scan "${TEST_NAME}-restart-log-scan" "${FILE}" 20 1 \
78 "Scheduler: url=tcp://$(get_fqdn "${CYLC_TEST_HOST}")"
79 run_ok "${TEST_NAME}-restart-success" \
80 cylc workflow-state "${WORKFLOW_NAME}//1/$(printf 'task_foo%02d' $(( LATEST_TASK + 3 ))):succeeded" \
81 --interval=1 --max-polls=60
82
83 # check the command the workflow has been restarted with
84 run_ok "${TEST_NAME}-contact" cylc get-contact "${WORKFLOW_NAME}"
85 grep_ok "cylc play ${WORKFLOW_NAME} -v --host=${CYLC_TEST_HOST} --host=localhost" \
86 "${TEST_NAME}-contact.stdout"
87
88 # stop workflow
89 cylc stop "${WORKFLOW_NAME}" --kill --max-polls=10 --interval=2 2>'/dev/null'
90
91 # Check correct number of logs
92 ls "${WORKFLOW_RUN_DIR}/log/scheduler/" > ls_logs.out
93 cmp_ok ls_logs.out << __EOF__
94 01-start-01.log
95 02-restart-02.log
96 log
97 __EOF__
98
99 purge