| 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 |
# Test "cylc cat-log" on the workflow host. |
| 19 |
. "$(dirname "$0")/test_header" |
| 20 |
#------------------------------------------------------------------------------- |
| 21 |
set_test_number 43 |
| 22 |
install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" |
| 23 |
#------------------------------------------------------------------------------- |
| 24 |
TEST_NAME="${TEST_NAME_BASE}-validate" |
| 25 |
run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 26 |
#------------------------------------------------------------------------------- |
| 27 |
workflow_run_ok "${TEST_NAME_BASE}-run" \ |
| 28 |
cylc play --no-detach "${WORKFLOW_NAME}" --reference-test |
| 29 |
#------------------------------------------------------------------------------- |
| 30 |
TEST_NAME=${TEST_NAME_BASE}-workflow-log-log |
| 31 |
run_ok "${TEST_NAME}" cylc cat-log "${WORKFLOW_NAME}" |
| 32 |
contains_ok "${TEST_NAME}.stdout" "${WORKFLOW_RUN_DIR}/log/scheduler/log" |
| 33 |
#------------------------------------------------------------------------------- |
| 34 |
TEST_NAME=${TEST_NAME_BASE}-workflow-log-ok |
| 35 |
LOG_DIR="$(dirname "$(cylc cat-log -m p "${WORKFLOW_NAME}")")" |
| 36 |
echo "This is file 02-restart-02.log" > "${LOG_DIR}/02-restart-02.log" |
| 37 |
echo "This is file 03-restart-02.log" > "${LOG_DIR}/03-restart-02.log" |
| 38 |
# it should accept file paths relative to the scheduler log directory |
| 39 |
run_ok "${TEST_NAME}" cylc cat-log -f scheduler/03-restart-02.log "${WORKFLOW_NAME}" |
| 40 |
contains_ok "${TEST_NAME}.stdout" - << __END__ |
| 41 |
This is file 03-restart-02.log |
| 42 |
__END__ |
| 43 |
# it should pick the latest scheduler log file if no rotation number is provided |
| 44 |
run_ok "${TEST_NAME}" cylc cat-log --file s "${WORKFLOW_NAME}" |
| 45 |
contains_ok "${TEST_NAME}.stdout" - << __END__ |
| 46 |
This is file 03-restart-02.log |
| 47 |
__END__ |
| 48 |
# it should apply rotation number to scheduler log files |
| 49 |
run_ok "${TEST_NAME}" cylc cat-log -f s -r 1 "${WORKFLOW_NAME}" |
| 50 |
contains_ok "${TEST_NAME}.stdout" - << __END__ |
| 51 |
This is file 02-restart-02.log |
| 52 |
__END__ |
| 53 |
# it should list scheduler log files |
| 54 |
run_ok "${TEST_NAME}" cylc cat-log -m l "${WORKFLOW_NAME}" |
| 55 |
cmp_ok "${TEST_NAME}.stdout" - << __END__ |
| 56 |
config/01-start-01.cylc |
| 57 |
config/flow-processed.cylc |
| 58 |
install/01-install.log |
| 59 |
scheduler/01-start-01.log |
| 60 |
scheduler/02-restart-02.log |
| 61 |
scheduler/03-restart-02.log |
| 62 |
scheduler/reftest.log |
| 63 |
__END__ |
| 64 |
#------------------------------------------------------------------------------- |
| 65 |
TEST_NAME=${TEST_NAME_BASE}-task-out |
| 66 |
run_ok "${TEST_NAME}" cylc cat-log -f o "${WORKFLOW_NAME}//1/a-task" |
| 67 |
grep_ok '^the quick brown fox$' "${TEST_NAME}.stdout" |
| 68 |
#------------------------------------------------------------------------------- |
| 69 |
TEST_NAME=${TEST_NAME_BASE}-task-job |
| 70 |
run_ok "${TEST_NAME}" cylc cat-log -f j "${WORKFLOW_NAME}//1/a-task" |
| 71 |
contains_ok "${TEST_NAME}.stdout" - << __END__ |
| 72 |
# SCRIPT: |
| 73 |
# Write to task stdout log |
| 74 |
echo "the quick brown fox" |
| 75 |
# Write to task stderr log |
| 76 |
echo "jumped over the lazy dog" >&2 |
| 77 |
# Write to a custom log file |
| 78 |
echo "drugs, money & whitespace" > "\${CYLC_TASK_LOG_ROOT} custom.log" |
| 79 |
# Generate a warning message in the workflow log. |
| 80 |
cylc message -p WARNING 'marmite and squashed bananas' |
| 81 |
__END__ |
| 82 |
#------------------------------------------------------------------------------- |
| 83 |
TEST_NAME=${TEST_NAME_BASE}-task-err |
| 84 |
run_ok "${TEST_NAME}" cylc cat-log -f e "${WORKFLOW_NAME}//1/a-task" |
| 85 |
grep_ok "jumped over the lazy dog" "${TEST_NAME}.stdout" |
| 86 |
#------------------------------------------------------------------------------- |
| 87 |
TEST_NAME=${TEST_NAME_BASE}-task-status |
| 88 |
run_ok "${TEST_NAME}" cylc cat-log -f s "${WORKFLOW_NAME}//1/a-task" |
| 89 |
grep_ok "CYLC_JOB_RUNNER_NAME=background" "${TEST_NAME}.stdout" |
| 90 |
#------------------------------------------------------------------------------- |
| 91 |
TEST_NAME=${TEST_NAME_BASE}-task-activity |
| 92 |
run_ok "${TEST_NAME}" cylc cat-log -f a "${WORKFLOW_NAME}//1/a-task" |
| 93 |
grep_ok '\[jobs-submit ret_code\] 0' "${TEST_NAME}.stdout" |
| 94 |
#------------------------------------------------------------------------------- |
| 95 |
TEST_NAME=${TEST_NAME_BASE}-task-custom |
| 96 |
run_ok "${TEST_NAME}" cylc cat-log -f 'job custom.log' "${WORKFLOW_NAME}//1/a-task" |
| 97 |
grep_ok "drugs, money & whitespace" "${TEST_NAME}.stdout" |
| 98 |
#------------------------------------------------------------------------------- |
| 99 |
TEST_NAME=${TEST_NAME_BASE}-task-list-local-NN |
| 100 |
run_ok "${TEST_NAME}" cylc cat-log -f a -m l "${WORKFLOW_NAME}//1/a-task" |
| 101 |
contains_ok "${TEST_NAME}.stdout" <<__END__ |
| 102 |
job |
| 103 |
job-activity.log |
| 104 |
job custom.log |
| 105 |
job.err |
| 106 |
job.out |
| 107 |
job.status |
| 108 |
__END__ |
| 109 |
#------------------------------------------------------------------------------- |
| 110 |
TEST_NAME=${TEST_NAME_BASE}-task-list-local-01 |
| 111 |
run_ok "${TEST_NAME}" cylc cat-log -f a -m l -s 1 "${WORKFLOW_NAME}//1/a-task" |
| 112 |
contains_ok "${TEST_NAME}.stdout" <<__END__ |
| 113 |
job |
| 114 |
job-activity.log |
| 115 |
job custom.log |
| 116 |
job.err |
| 117 |
job.out |
| 118 |
job.status |
| 119 |
__END__ |
| 120 |
#------------------------------------------------------------------------------- |
| 121 |
TEST_NAME=${TEST_NAME_BASE}-task-list-local-02 |
| 122 |
run_fail cylc cat-log -f j -m l -s 2 "${WORKFLOW_NAME}//1/a-task" |
| 123 |
#------------------------------------------------------------------------------- |
| 124 |
TEST_NAME=${TEST_NAME_BASE}-task-log-dir-NN |
| 125 |
run_ok "${TEST_NAME}" cylc cat-log -f j -m d "${WORKFLOW_NAME}//1/a-task" |
| 126 |
grep_ok "${WORKFLOW_NAME}/log/job/1/a-task/NN$" "${TEST_NAME}.stdout" |
| 127 |
#------------------------------------------------------------------------------- |
| 128 |
TEST_NAME=${TEST_NAME_BASE}-task-log-dir-01 |
| 129 |
run_ok "${TEST_NAME}" cylc cat-log -f j -m d -s 1 "${WORKFLOW_NAME}//1/a-task" |
| 130 |
grep_ok "${WORKFLOW_NAME}/log/job/1/a-task/01$" "${TEST_NAME}.stdout" |
| 131 |
#------------------------------------------------------------------------------- |
| 132 |
TEST_NAME=${TEST_NAME_BASE}-task-job-path |
| 133 |
run_ok "${TEST_NAME}" cylc cat-log -f j -m p "${WORKFLOW_NAME}//1/a-task" |
| 134 |
grep_ok "${WORKFLOW_NAME}/log/job/1/a-task/NN/job$" "${TEST_NAME}.stdout" |
| 135 |
#------------------------------------------------------------------------------- |
| 136 |
# it shouldn't let you modify the file path to access other resources |
| 137 |
# use the dedicated options |
| 138 |
TEST_NAME=${TEST_NAME_BASE}-un-norm-path |
| 139 |
run_fail "${TEST_NAME}" cylc cat-log -f j/../02/j "${WORKFLOW_NAME}//1/a-task" |
| 140 |
grep_ok 'InputError' "${TEST_NAME}.stderr" |
| 141 |
#------------------------------------------------------------------------------- |
| 142 |
TEST_NAME=${TEST_NAME_BASE}-prepend-path |
| 143 |
run_ok "${TEST_NAME}-get-path" cylc cat-log -m p "${WORKFLOW_NAME}//1/a-task" |
| 144 |
run_ok "${TEST_NAME}" cylc cat-log --prepend-path "${WORKFLOW_NAME}//1/a-task" |
| 145 |
grep_ok "$(cat "#.*${TEST_NAME}-get-path.stdout")" "${TEST_NAME}.stdout" |
| 146 |
#------------------------------------------------------------------------------- |
| 147 |
TEST_NAME=${TEST_NAME_BASE}-submit-failed |
| 148 |
run_ok "${TEST_NAME}" cylc cat-log -m l "${WORKFLOW_NAME}//1/submit-failed" |
| 149 |
contains_ok "${TEST_NAME}.stdout" <<__END__ |
| 150 |
job.tmp |
| 151 |
job-activity.log |
| 152 |
__END__ |
| 153 |
#------------------------------------------------------------------------------- |
| 154 |
TEST_NAME=${TEST_NAME_BASE}-list-no-install-dir |
| 155 |
rm -r "${WORKFLOW_RUN_DIR}/log/install" |
| 156 |
run_ok "${TEST_NAME}-get-path" cylc cat-log -m l "${WORKFLOW_NAME}" |
| 157 |
#------------------------------------------------------------------------------- |
| 158 |
purge |
| 159 |
exit |