| 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 that cylc clean succesfully removes the workflow on remote host |
| 19 |
|
| 20 |
export REQUIRE_PLATFORM='loc:remote fs:indep' |
| 21 |
. "$(dirname "$0")/test_header" |
| 22 |
|
| 23 |
SSH_CMD="$(cylc config -d -i "[platforms][${CYLC_TEST_PLATFORM}]ssh command") ${CYLC_TEST_HOST}" |
| 24 |
|
| 25 |
if ! $SSH_CMD command -v 'tree' > '/dev/null'; then |
| 26 |
skip_all "'tree' command not available on remote host ${CYLC_TEST_HOST}" |
| 27 |
fi |
| 28 |
set_test_number 10 |
| 29 |
|
| 30 |
# Generate random name for symlink dirs to avoid any clashes with other tests |
| 31 |
SYM_NAME="$(mktemp -u)" |
| 32 |
SYM_NAME="${SYM_NAME##*tmp.}" |
| 33 |
|
| 34 |
create_test_global_config "" " |
| 35 |
[install] |
| 36 |
[[symlink dirs]] |
| 37 |
[[[${CYLC_TEST_INSTALL_TARGET}]]] |
| 38 |
run = ${TEST_DIR}/${SYM_NAME}/run |
| 39 |
log = ${TEST_DIR}/${SYM_NAME}/other |
| 40 |
log/job = ${TEST_DIR}/${SYM_NAME}/job |
| 41 |
share = ${TEST_DIR}/${SYM_NAME}/other |
| 42 |
share/cycle = ${TEST_DIR}/${SYM_NAME}/cycle |
| 43 |
work = ${TEST_DIR}/${SYM_NAME}/other |
| 44 |
" |
| 45 |
init_workflow "${TEST_NAME_BASE}" << __FLOW__ |
| 46 |
[scheduler] |
| 47 |
allow implicit tasks = True |
| 48 |
[scheduling] |
| 49 |
[[graph]] |
| 50 |
R1 = santa |
| 51 |
[runtime] |
| 52 |
[[root]] |
| 53 |
platform = ${CYLC_TEST_PLATFORM} |
| 54 |
script = touch flow.cylc # testing that remote clean does not scan for workflows |
| 55 |
__FLOW__ |
| 56 |
|
| 57 |
FUNCTIONAL_DIR="${TEST_SOURCE_DIR_BASE%/*}" |
| 58 |
|
| 59 |
run_ok "${TEST_NAME_BASE}-validate" cylc validate "$WORKFLOW_NAME" |
| 60 |
|
| 61 |
workflow_run_ok "${TEST_NAME_BASE}-run" cylc play "$WORKFLOW_NAME" --no-detach |
| 62 |
|
| 63 |
# Create a fake sibling workflow dir: |
| 64 |
$SSH_CMD mkdir "${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${CYLC_TEST_REG_BASE}/leave-me-alone" |
| 65 |
|
| 66 |
# ----------------------------------------------------------------------------- |
| 67 |
|
| 68 |
TEST_NAME="run-dir-readlink-pre-clean.remote" |
| 69 |
$SSH_CMD readlink "\$HOME/cylc-run/${WORKFLOW_NAME}" > "${TEST_NAME}.stdout" |
| 70 |
cmp_ok "${TEST_NAME}.stdout" <<< "${TEST_DIR}/${SYM_NAME}/run/cylc-run/${WORKFLOW_NAME}" |
| 71 |
|
| 72 |
TEST_NAME="test-dir-tree-pre-clean.remote" |
| 73 |
# shellcheck disable=SC2086 |
| 74 |
run_ok "${TEST_NAME}" $SSH_CMD tree -L 8 --noreport --charset=ascii \ |
| 75 |
"${TEST_DIR}/${SYM_NAME}/"'*'"/cylc-run/${CYLC_TEST_REG_BASE}" |
| 76 |
# Note: backticks need to be escaped in the heredoc |
| 77 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 78 |
${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${CYLC_TEST_REG_BASE} |
| 79 |
|-- ${FUNCTIONAL_DIR} |
| 80 |
| \`-- cylc-clean |
| 81 |
| \`-- ${TEST_NAME_BASE} |
| 82 |
| \`-- share |
| 83 |
| \`-- cycle |
| 84 |
| \`-- 1 |
| 85 |
\`-- leave-me-alone |
| 86 |
${TEST_DIR}/${SYM_NAME}/job/cylc-run/${CYLC_TEST_REG_BASE} |
| 87 |
\`-- ${FUNCTIONAL_DIR} |
| 88 |
\`-- cylc-clean |
| 89 |
\`-- ${TEST_NAME_BASE} |
| 90 |
\`-- log |
| 91 |
\`-- job |
| 92 |
\`-- 1 |
| 93 |
\`-- santa |
| 94 |
|-- 01 |
| 95 |
\`-- NN -> 01 |
| 96 |
${TEST_DIR}/${SYM_NAME}/other/cylc-run/${CYLC_TEST_REG_BASE} |
| 97 |
\`-- ${FUNCTIONAL_DIR} |
| 98 |
\`-- cylc-clean |
| 99 |
\`-- ${TEST_NAME_BASE} |
| 100 |
|-- log |
| 101 |
| \`-- job -> ${TEST_DIR}/${SYM_NAME}/job/cylc-run/${WORKFLOW_NAME}/log/job |
| 102 |
|-- share |
| 103 |
| \`-- cycle -> ${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${WORKFLOW_NAME}/share/cycle |
| 104 |
\`-- work |
| 105 |
\`-- 1 |
| 106 |
\`-- santa |
| 107 |
\`-- flow.cylc |
| 108 |
${TEST_DIR}/${SYM_NAME}/run/cylc-run/${CYLC_TEST_REG_BASE} |
| 109 |
\`-- ${FUNCTIONAL_DIR} |
| 110 |
\`-- cylc-clean |
| 111 |
\`-- ${TEST_NAME_BASE} |
| 112 |
|-- log -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/log |
| 113 |
|-- share -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/share |
| 114 |
\`-- work -> ${TEST_DIR}/${SYM_NAME}/other/cylc-run/${WORKFLOW_NAME}/work |
| 115 |
__TREE__ |
| 116 |
|
| 117 |
# ----------------------------------------------------------------------------- |
| 118 |
|
| 119 |
TEST_NAME="cylc-clean-ok" |
| 120 |
run_ok "$TEST_NAME" cylc clean "$WORKFLOW_NAME" --timeout PT2M |
| 121 |
# (timeout opt is covered by unit tests but no harm double-checking here) |
| 122 |
dump_std "$TEST_NAME" |
| 123 |
|
| 124 |
TEST_NAME="run-dir-not-exist-post-clean.local" |
| 125 |
# (Could use the function `exists_ok` here instead, but this keeps it consistent with the remote test below) |
| 126 |
if [[ ! -e "$WORKFLOW_RUN_DIR" ]]; then |
| 127 |
ok "$TEST_NAME" |
| 128 |
else |
| 129 |
fail "$TEST_NAME" |
| 130 |
fi |
| 131 |
|
| 132 |
TEST_NAME="run-dir-not-exist-post-clean.remote" |
| 133 |
if $SSH_CMD [[ ! -a "\$HOME/cylc-run/${WORKFLOW_NAME}" ]]; then |
| 134 |
ok "$TEST_NAME" |
| 135 |
else |
| 136 |
fail "$TEST_NAME" |
| 137 |
fi |
| 138 |
|
| 139 |
TEST_NAME="test-dir-tree-post-clean.remote" |
| 140 |
# shellcheck disable=SC2086 |
| 141 |
run_ok "${TEST_NAME}" $SSH_CMD tree --noreport --charset=ascii \ |
| 142 |
"${TEST_DIR}/${SYM_NAME}/"'*'"/cylc-run/${CYLC_TEST_REG_BASE}" |
| 143 |
# Note: backticks need to be escaped in the heredoc |
| 144 |
cmp_ok "${TEST_NAME}.stdout" << __TREE__ |
| 145 |
${TEST_DIR}/${SYM_NAME}/cycle/cylc-run/${CYLC_TEST_REG_BASE} |
| 146 |
\`-- leave-me-alone |
| 147 |
__TREE__ |
| 148 |
|
| 149 |
purge |