Merge branch 'martins'
[martins/samba.git] / ctdb / tests / simple / 07_ctdb_process_exists.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Verify that 'ctdb process-exists' shows correct information.
7
8 The implementation is creative about how it gets PIDs for existing and
9 non-existing processes.
10
11 Prerequisites:
12
13 * An active CTDB cluster with at least 2 active nodes.
14
15 Steps:
16
17 1. Verify that the status on all of the ctdb nodes is 'OK'.
18 2. On one of the cluster nodes, get the PID of an existing process
19    (using ps wax).
20 3. Run 'ctdb process-exists <pid>' on the node and verify that the
21    correct output is shown.
22 4. Run 'ctdb process-exists <pid>' with a pid of a non-existent
23    process and verify that the correct output is shown.
24
25 Expected results:
26
27 * 'ctdb process-exists' shows the correct output.
28 EOF
29 }
30
31 . ctdb_test_functions.bash
32
33 ctdb_test_init "$@"
34
35 set -e
36
37 onnode 0 $CTDB_TEST_WRAPPER cluster_is_healthy
38
39 test_node=1
40
41 # Create a background process on $test_node that will last for 60 seconds.
42 # It should still be there when we check.
43 try_command_on_node $test_node 'sleep 60 >/dev/null 2>&1 & echo $!'
44 pid="$out"
45
46 echo "Checking for PID $pid on node $test_node"
47 # set -e is good, but avoid it here
48 status=0
49 onnode 0 "$CTDB process-exists ${test_node}:${pid}" || status=$?
50 echo "$out"
51
52 if [ $status -eq 0 ] ; then
53     echo "OK"
54 else
55     echo "BAD"
56     testfailures=1
57 fi
58
59 # Now just echo the PID of the shell from the onnode process on node
60 # 2.  This PID will disappear and PIDs shouldn't roll around fast
61 # enough to trick the test...  but there is a chance that will happen!
62 try_command_on_node $test_node 'echo $$'
63 pid="$out"
64
65 echo "Checking for PID $pid on node $test_node"
66 # set -e is good, but avoid it here
67 status=0
68 onnode 0 "$CTDB process-exists ${test_node}:${pid}" || status=$?
69 echo "$out"
70
71 if [ $status -ne 0 ] ; then
72     echo "OK"
73 else
74     echo "BAD"
75     testfailures=1
76 fi
77
78 ctdb_test_exit