Debian Codegraph @

tests/functional/restart/42-auto-restart-ping-pong.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 # play a game of Cylc workflow ping pong bouncing a workflow back and forth between
19 # two servers by condemning them in turn in order to see if anything breaks
20 export REQUIRE_PLATFORM='loc:remote fs:shared runner:background'
21 . "$(dirname "$0")/test_header"
22 export CLOWNS="${CYLC_TEST_HOST}"
23 export JOKERS="${HOSTNAME}"
24
25 BASE_GLOBAL_CONFIG='
26 [scheduler]
27 [[main loop]]
28 plugins = health check, auto restart
29 [[[auto restart]]]
30 interval = PT5S
31 [[events]]
32 abort on inactivity timeout = True
33 abort on stall timeout = True
34 inactivity timeout = PT2M
35 stall timeout = PT2M
36 '
37
38 init_workflow "${TEST_NAME_BASE}" <<< '
39 [scheduling]
40 initial cycle point = 2000
41 final cycle point = 9999 # test cylc/cylc-flow/issues/2799
42 [[graph]]
43 P1Y = foo[-P1Y] => foo
44 [runtime]
45 [[foo]]
46 script = sleep 5
47 '
48 cd "${WORKFLOW_RUN_DIR}" || exit 1
49 stuck_in_the_middle() {
50 # swap the condemned host forcing the workflow to jump ship
51 local temp="${JOKERS}"
52 JOKERS="${CLOWNS}"; CLOWNS="${temp}"
53 create_test_global_config '' "
54 ${BASE_GLOBAL_CONFIG}
55 [scheduler]
56 [[run hosts]]
57 available = ${JOKERS}, ${CLOWNS}
58 condemned = ${CLOWNS}
59 "
60 }
61
62 kill_workflow() {
63 cylc stop --now --now --max-polls=10 --interval=2 "${WORKFLOW_NAME}" 2>'/dev/null'
64 purge
65 }
66
67 log_scan2() {
68 NO_TESTS="$(( NO_TESTS - $# + 4 ))"
69 if ! log_scan "$@"; then
70 skip $NO_TESTS # skip remaining tests
71 kill_workflow
72 exit 1
73 fi
74 }
75
76 EARS=5 # number of times to bounce the workflow between hosts
77 NO_TESTS="$(( EARS * 5 + 1 ))"
78 set_test_number "${NO_TESTS}"
79
80 run_ok "${TEST_NAME_BASE}-validate" cylc validate "${WORKFLOW_NAME}"
81
82 # run the workflow
83 stuck_in_the_middle
84 cylc play "${WORKFLOW_NAME}" --host="${JOKERS}" --abort-if-any-task-fails
85 poll_workflow_running
86 sleep 1
87
88 # get the log file
89 FILE=$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)
90 #-------------------------------------------------------------------------------
91 for ear in $(seq 1 "${EARS}"); do
92 stuck_in_the_middle # swap the condemned host
93
94 # test the shutdown procedure
95 log_scan2 "${TEST_NAME_BASE}-${ear}-stop" "${FILE}" 40 1 \
96 'The Cylc workflow host will soon become un-available' \
97 'Workflow shutting down - REQUEST(NOW-NOW)' \
98 "Attempting to restart on \"${JOKERS}\""\
99 "Workflow now running on \"${JOKERS}\""
100
101 poll_workflow_restart
102
103 # test the restart procedure
104 FILE=$(cylc cat-log "${WORKFLOW_NAME}" -m p |xargs readlink -f)
105 log_scan2 "${TEST_NAME_BASE}-${ear}-restart" "${FILE}" 20 1 \
106 "Scheduler: url=tcp://$(get_fqdn "${JOKERS}")"
107 sleep 2
108 done
109
110 kill_workflow
111
112 exit