| 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 the cylc clean command |
| 19 |
|
| 20 |
. "$(dirname "$0")/test_header" |
| 21 |
if ! command -v 'tree' >'/dev/null'; then |
| 22 |
skip_all '"tree" command not available' |
| 23 |
fi |
| 24 |
set_test_number 12 |
| 25 |
|
| 26 |
# Generate random name for symlink dirs to avoid any clashes with other tests |
| 27 |
SYM_NAME="$(mktemp -u)" |
| 28 |
SYM_NAME="${SYM_NAME##*tmp.}" |
| 29 |
|
| 30 |
create_test_global_config "" " |
| 31 |
[install] |
| 32 |
[[symlink dirs]] |
| 33 |
[[[localhost]]] |
| 34 |
run = ${TEST_DIR}/${SYM_NAME}/run |
| 35 |
log = ${TEST_DIR}/${SYM_NAME}/log |
| 36 |
log/job = ${TEST_DIR}/${SYM_NAME}/job |
| 37 |
share = ${TEST_DIR}/${SYM_NAME}/share |
| 38 |
share/cycle = ${TEST_DIR}/${SYM_NAME}/cycle |
| 39 |
work = ${TEST_DIR}/${SYM_NAME}/work |
| 40 |
" |
| 41 |
install_workflow "${TEST_NAME_BASE}" basic-workflow |
| 42 |
|
| 43 |
run_ok "${TEST_NAME_BASE}-val" cylc validate "$WORKFLOW_NAME" |
| 44 |
|
| 45 |
# Create a fake sibling workflow dir in the ${SYM_NAME}/log dir: |
| 46 |
mkdir "${TEST_DIR}/${SYM_NAME}/log/cylc-run/${CYLC_TEST_REG_BASE}/leave-me-alone" |
| 47 |
|
| 48 |
FUNCTIONAL_DIR="${TEST_SOURCE_DIR_BASE%/*}" |
| 49 |
# ----------------------------------------------------------------------------- |
| 50 |
TEST_NAME="run-dir-readlink-pre-clean" |
| 51 |
readlink "$WORKFLOW_RUN_DIR" > "${TEST_NAME}.stdout" |
| 52 |
|
| 53 |
cmp_ok "${TEST_NAME}.stdout" <<< "${TEST_DIR}/${SYM_NAME}/run/cylc-run/${WORKFLOW_NAME}" |
| 54 |
|
| 55 |
|
| 56 |
INSTALL_LOG_FILE=$(ls "${TEST_DIR}/${SYM_NAME}/log/cylc-run/${WORKFLOW_NAME}/log/install") |
| 57 |
TEST_NAME="test-dir-tree-pre-clean" |
| 58 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}" |
| 59 |
# Note: backticks need to be escaped in the heredoc |
| 60 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 61 |
${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${CYLC_TEST_REG_BASE} |
| 62 |
\`-- ${FUNCTIONAL_DIR} |
| 63 |
\`-- cylc-clean |
| 64 |
\`-- ${TEST_NAME_BASE} |
| 65 |
\`-- share |
| 66 |
\`-- cycle |
| 67 |
${TEST_DIR}/${SYM_NAME}/job/cylc-run/${CYLC_TEST_REG_BASE} |
| 68 |
\`-- ${FUNCTIONAL_DIR} |
| 69 |
\`-- cylc-clean |
| 70 |
\`-- ${TEST_NAME_BASE} |
| 71 |
\`-- log |
| 72 |
\`-- job |
| 73 |
${TEST_DIR}/${SYM_NAME}/log/cylc-run/${CYLC_TEST_REG_BASE} |
| 74 |
|-- ${FUNCTIONAL_DIR} |
| 75 |
| \`-- cylc-clean |
| 76 |
| \`-- ${TEST_NAME_BASE} |
| 77 |
| \`-- log |
| 78 |
| |-- install |
| 79 |
| | \`-- ${INSTALL_LOG_FILE} |
| 80 |
| \`-- job -> ${TEST_DIR}/${SYM_NAME}/job/cylc-run/${WORKFLOW_NAME}/log/job |
| 81 |
\`-- leave-me-alone |
| 82 |
${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE} |
| 83 |
\`-- ${FUNCTIONAL_DIR} |
| 84 |
\`-- cylc-clean |
| 85 |
\`-- ${TEST_NAME_BASE} |
| 86 |
|-- _cylc-install |
| 87 |
| \`-- source -> ${TEST_DIR}/${WORKFLOW_NAME} |
| 88 |
|-- flow.cylc |
| 89 |
|-- log -> ${TEST_DIR}/${SYM_NAME}/log/cylc-run/${WORKFLOW_NAME}/log |
| 90 |
|-- share -> ${TEST_DIR}/${SYM_NAME}/share/cylc-run/${WORKFLOW_NAME}/share |
| 91 |
\`-- work -> ${TEST_DIR}/${SYM_NAME}/work/cylc-run/${WORKFLOW_NAME}/work |
| 92 |
${TEST_DIR}/${SYM_NAME}/share/cylc-run/${CYLC_TEST_REG_BASE} |
| 93 |
\`-- ${FUNCTIONAL_DIR} |
| 94 |
\`-- cylc-clean |
| 95 |
\`-- ${TEST_NAME_BASE} |
| 96 |
\`-- share |
| 97 |
\`-- cycle -> ${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${WORKFLOW_NAME}/share/cycle |
| 98 |
${TEST_DIR}/${SYM_NAME}/work/cylc-run/${CYLC_TEST_REG_BASE} |
| 99 |
\`-- ${FUNCTIONAL_DIR} |
| 100 |
\`-- cylc-clean |
| 101 |
\`-- ${TEST_NAME_BASE} |
| 102 |
\`-- work |
| 103 |
__TREE__ |
| 104 |
# ----------------------------------------------------------------------------- |
| 105 |
TEST_NAME="clean" |
| 106 |
run_ok "$TEST_NAME" cylc clean "$WORKFLOW_NAME" |
| 107 |
dump_std "$TEST_NAME" |
| 108 |
# ----------------------------------------------------------------------------- |
| 109 |
TEST_NAME="run-dir-not-exist-post-clean" |
| 110 |
exists_fail "$WORKFLOW_RUN_DIR" |
| 111 |
|
| 112 |
TEST_NAME="test-dir-tree-post-clean" |
| 113 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii "${TEST_DIR}/${SYM_NAME}/"*"/cylc-run/${CYLC_TEST_REG_BASE}" |
| 114 |
|
| 115 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 116 |
${TEST_DIR}/${SYM_NAME}/log/cylc-run/${CYLC_TEST_REG_BASE} |
| 117 |
\`-- leave-me-alone |
| 118 |
__TREE__ |
| 119 |
# ----------------------------------------------------------------------------- |
| 120 |
TEST_NAME="clean-non-exist" |
| 121 |
run_ok "$TEST_NAME" cylc clean "$WORKFLOW_NAME" |
| 122 |
dump_std "$TEST_NAME" |
| 123 |
cmp_ok "${TEST_NAME}.stdout" << __EOF__ |
| 124 |
INFO - No directory to clean at ${WORKFLOW_RUN_DIR} |
| 125 |
__EOF__ |
| 126 |
# ----------------------------------------------------------------------------- |
| 127 |
TEST_NAME="clean-non-exist-pattern" |
| 128 |
run_ok "$TEST_NAME" cylc clean "nope*" |
| 129 |
dump_std "$TEST_NAME" |
| 130 |
cmp_ok "${TEST_NAME}.stderr" << __EOF__ |
| 131 |
WARNING - No stopped workflows matching nope* |
| 132 |
__EOF__ |
| 133 |
# ----------------------------------------------------------------------------- |
| 134 |
purge |