Debian Codegraph @

tests/functional/cylc-clean/06-nfs.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 # This test covers the interaction between "cylc clean" and "cylc cat-log -m t"
19 # on the NFS filesystem. The "cat-log" should not block the "clean".
20 #
21 # Tests: https://github.com/cylc/cylc-flow/pull/5359
22 #
23 # If you try to delete a file that is stored on NFS, which is open for reading
24 # by another process (e.g. `tail -f`), NFS will remove the file, but put a
25 # ".nfs" file in its place. This ".nfs" file will cause "rm" operations on
26 # the directory containing the NFS files to fail with one of two errors:
27 # * https://docs.python.org/3/library/errno.html#errno.EBUSY
28 # * https://docs.python.org/3/library/errno.html#errno.ENOTEMPTY
29 #
30 # To prevent "cylc cat-log -m t" which calls "tail -f" from blocking
31 # "cylc clean" commands, we retry the "rm" operation with a delay. This
32 # allows the "tail -f" to fail and release its file lock allowing the
33 # "rm" to pass on a subsequent attempt.
34
35 . "$(dirname "$0")/test_header"
36 set_test_number 2
37
38 # install a blank source workflow
39 init_workflow "${TEST_NAME_BASE}" <<< '# blank workflow'
40
41 # add a scheduler log file with something written to it
42 WORKFLOW_LOG_DIR="${WORKFLOW_RUN_DIR}/log/scheduler"
43 mkdir -p "$WORKFLOW_LOG_DIR"
44 LOG_STUFF='foo bar baz'
45 echo "${LOG_STUFF}" > "${WORKFLOW_LOG_DIR}/01-start-01.log"
46
47 # start cat-log running - this runs "tail -f"
48 cylc cat-log -m t "$WORKFLOW_NAME" > out 2>err & PID="$!"
49
50 # wait for tail to start
51 poll pgrep -P "$PID" tail
52
53 # try to clean the workflow
54 run_ok "${TEST_NAME_BASE}-clean" cylc clean -y "${WORKFLOW_NAME}"
55
56 # the tail command should have detected that the file isn't there any more
57 # and exited -> cat-log should have exited
58 poll_pid_done "$PID"
59
60 # ensure the log dir was removed correctly
61 # run_ok "${TEST_NAME_BASE}-dir-removed" [[ ! -d "${WORKFLOW_LOG_DIR}" ]]
62 TEST_NAME="${TEST_NAME_BASE}-log-dir-removed"
63 if [[ -d "${WORKFLOW_LOG_DIR}" ]]; then
64 fail "${TEST_NAME}"
65 else
66 ok "${TEST_NAME}"
67 fi
68
69 purge