| 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 cleaning multiple run dirs |
| 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 18 |
| 25 |
|
| 26 |
RND_NAME="cylctb-x$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6)" |
| 27 |
WORKFLOW_NAME="${RND_NAME}/cylc-clean" |
| 28 |
WORKFLOW_RUN_DIR="${RUN_DIR}/${WORKFLOW_NAME}" |
| 29 |
|
| 30 |
create_workflow() { |
| 31 |
mkdir -p "${TEST_DIR}/${WORKFLOW_NAME}" # make source dir |
| 32 |
touch "${TEST_DIR}/${WORKFLOW_NAME}/flow.cylc" |
| 33 |
cylc install "${TEST_DIR}/${WORKFLOW_NAME}" --workflow-name="${WORKFLOW_NAME}" |
| 34 |
} |
| 35 |
|
| 36 |
# ----------------------------------------------------------------------------- |
| 37 |
|
| 38 |
for _ in 1 2; do |
| 39 |
create_workflow |
| 40 |
done |
| 41 |
|
| 42 |
TEST_NAME="tree-pre-clean-1" |
| 43 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii -L 1 "${HOME}/cylc-run/${WORKFLOW_NAME}" |
| 44 |
# Note: backticks need to be escaped in the heredoc |
| 45 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 46 |
${HOME}/cylc-run/${WORKFLOW_NAME} |
| 47 |
|-- _cylc-install |
| 48 |
|-- run1 |
| 49 |
|-- run2 |
| 50 |
\`-- runN -> run2 |
| 51 |
__TREE__ |
| 52 |
|
| 53 |
# Test trying to clean multiple run dirs without --yes fails: |
| 54 |
run_fail "${TEST_NAME_BASE}-no" cylc clean "$WORKFLOW_NAME" |
| 55 |
exists_ok "${WORKFLOW_RUN_DIR}/run1" |
| 56 |
exists_ok "${WORKFLOW_RUN_DIR}/run2" |
| 57 |
|
| 58 |
# Should work with --yes (removes top level dir too): |
| 59 |
run_ok "${TEST_NAME_BASE}-yes" cylc clean -y "$WORKFLOW_NAME" |
| 60 |
exists_fail "${RUN_DIR}/${RND_NAME}" |
| 61 |
|
| 62 |
# ----------------------------------------------------------------------------- |
| 63 |
# Should continue cleaning a list of workflows even if one fails. |
| 64 |
|
| 65 |
for _ in 1 2; do |
| 66 |
create_workflow |
| 67 |
done |
| 68 |
|
| 69 |
TEST_NAME="tree-pre-clean-2" |
| 70 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii -L 1 "${HOME}/cylc-run/${WORKFLOW_NAME}" |
| 71 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 72 |
${HOME}/cylc-run/${WORKFLOW_NAME} |
| 73 |
|-- _cylc-install |
| 74 |
|-- run1 |
| 75 |
|-- run2 |
| 76 |
\`-- runN -> run2 |
| 77 |
__TREE__ |
| 78 |
|
| 79 |
mkdir "${WORKFLOW_RUN_DIR}/run1/.service" |
| 80 |
echo 'x' > "${WORKFLOW_RUN_DIR}/run1/.service/db" # corrupted db! |
| 81 |
|
| 82 |
TEST_NAME="${TEST_NAME_BASE}-yes-no" |
| 83 |
run_fail "${TEST_NAME}" \ |
| 84 |
cylc clean -y "$WORKFLOW_NAME/run1" "$WORKFLOW_NAME/run2" |
| 85 |
|
| 86 |
grep_ok "file is not a database" "${TEST_NAME}.stderr" -e |
| 87 |
|
| 88 |
TEST_NAME="tree-post-clean-2" |
| 89 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii -L 1 "${HOME}/cylc-run/${WORKFLOW_NAME}" |
| 90 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 91 |
${HOME}/cylc-run/${WORKFLOW_NAME} |
| 92 |
|-- _cylc-install |
| 93 |
\`-- run1 |
| 94 |
__TREE__ |
| 95 |
|
| 96 |
purge "$WORKFLOW_NAME" |
| 97 |
|
| 98 |
# ----------------------------------------------------------------------------- |
| 99 |
# Should not clean top level dir if not empty. |
| 100 |
|
| 101 |
create_workflow |
| 102 |
|
| 103 |
touch "${WORKFLOW_RUN_DIR}/jellyfish.txt" |
| 104 |
|
| 105 |
TEST_NAME="tree-pre-clean-3" |
| 106 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii -L 1 "${HOME}/cylc-run/${WORKFLOW_NAME}" |
| 107 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 108 |
${HOME}/cylc-run/${WORKFLOW_NAME} |
| 109 |
|-- _cylc-install |
| 110 |
|-- jellyfish.txt |
| 111 |
|-- run1 |
| 112 |
\`-- runN -> run1 |
| 113 |
__TREE__ |
| 114 |
|
| 115 |
run_ok "${TEST_NAME}" cylc clean -y "$WORKFLOW_NAME" |
| 116 |
|
| 117 |
TEST_NAME="tree-post-clean-3" |
| 118 |
run_ok "${TEST_NAME}" tree --noreport --charset=ascii -L 1 "${HOME}/cylc-run/${WORKFLOW_NAME}" |
| 119 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 120 |
${HOME}/cylc-run/${WORKFLOW_NAME} |
| 121 |
|-- _cylc-install |
| 122 |
\`-- jellyfish.txt |
| 123 |
__TREE__ |
| 124 |
|
| 125 |
purge |