root / test / py / daemon-util_unittest.bash @ 6b06efa7
History | View | Annotate | Download (2.9 kB)
1 | 571b34f8 | Michael Hanselmann | #!/bin/bash |
---|---|---|---|
2 | 571b34f8 | Michael Hanselmann | # |
3 | 571b34f8 | Michael Hanselmann | |
4 | 0f63f1f9 | Iustin Pop | # Copyright (C) 2010, 2011 Google Inc. |
5 | 571b34f8 | Michael Hanselmann | # |
6 | 571b34f8 | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify |
7 | 571b34f8 | Michael Hanselmann | # it under the terms of the GNU General Public License as published by |
8 | 571b34f8 | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or |
9 | 571b34f8 | Michael Hanselmann | # (at your option) any later version. |
10 | 571b34f8 | Michael Hanselmann | # |
11 | 571b34f8 | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but |
12 | 571b34f8 | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 571b34f8 | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | 571b34f8 | Michael Hanselmann | # General Public License for more details. |
15 | 571b34f8 | Michael Hanselmann | # |
16 | 571b34f8 | Michael Hanselmann | # You should have received a copy of the GNU General Public License |
17 | 571b34f8 | Michael Hanselmann | # along with this program; if not, write to the Free Software |
18 | 571b34f8 | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
19 | 571b34f8 | Michael Hanselmann | # 02110-1301, USA. |
20 | 571b34f8 | Michael Hanselmann | |
21 | 571b34f8 | Michael Hanselmann | set -e |
22 | 571b34f8 | Michael Hanselmann | |
23 | 571b34f8 | Michael Hanselmann | daemon_util=daemons/daemon-util |
24 | 571b34f8 | Michael Hanselmann | |
25 | 571b34f8 | Michael Hanselmann | err() { |
26 | 571b34f8 | Michael Hanselmann | echo "$@" |
27 | 571b34f8 | Michael Hanselmann | echo 'Aborting' |
28 | 571b34f8 | Michael Hanselmann | exit 1 |
29 | 571b34f8 | Michael Hanselmann | } |
30 | 571b34f8 | Michael Hanselmann | |
31 | b8669a69 | Jose A. Lopes | if ! grep -q '^ENABLE_CONFD = ' lib/_constants.py; then |
32 | 0f63f1f9 | Iustin Pop | err "Please update $0, confd enable feature is missing" |
33 | 0f63f1f9 | Iustin Pop | fi |
34 | 0f63f1f9 | Iustin Pop | |
35 | b8669a69 | Jose A. Lopes | if ! grep -q '^ENABLE_MOND = ' lib/_constants.py; then |
36 | 13cc7b84 | Michele Tartara | err "Please update $0, mond enable feature is missing" |
37 | 13cc7b84 | Michele Tartara | fi |
38 | 13cc7b84 | Michele Tartara | |
39 | 6b06efa7 | Petr Pudlak | DAEMONS_LIST="noded masterd rapi luxid" |
40 | 6b06efa7 | Petr Pudlak | STOPDAEMONS_LIST="luxid rapi masterd noded" |
41 | 13cc7b84 | Michele Tartara | |
42 | b8669a69 | Jose A. Lopes | if grep -q '^ENABLE_CONFD = True' lib/_constants.py; then |
43 | 6b06efa7 | Petr Pudlak | DAEMONS_LIST="$DAEMONS_LIST confd" |
44 | 6b06efa7 | Petr Pudlak | STOPDAEMONS_LIST="confd $STOPDAEMONS_LIST" |
45 | 0f63f1f9 | Iustin Pop | fi |
46 | 0f63f1f9 | Iustin Pop | |
47 | b8669a69 | Jose A. Lopes | if grep -q '^ENABLE_MOND = True' lib/_constants.py; then |
48 | 13cc7b84 | Michele Tartara | DAEMONS_LIST="$DAEMONS_LIST mond" |
49 | 13cc7b84 | Michele Tartara | STOPDAEMONS_LIST="mond $STOPDAEMONS_LIST" |
50 | 13cc7b84 | Michele Tartara | fi |
51 | 13cc7b84 | Michele Tartara | |
52 | 13cc7b84 | Michele Tartara | DAEMONS=$(echo $(for d in $DAEMONS_LIST; do echo "ganeti-$d"; done)) |
53 | 13cc7b84 | Michele Tartara | STOPDAEMONS=$(echo $(for d in $STOPDAEMONS_LIST; do echo "ganeti-$d"; done)) |
54 | 13cc7b84 | Michele Tartara | |
55 | 571b34f8 | Michael Hanselmann | $daemon_util >/dev/null 2>&1 && |
56 | 571b34f8 | Michael Hanselmann | err "daemon-util succeeded without command" |
57 | 571b34f8 | Michael Hanselmann | |
58 | 571b34f8 | Michael Hanselmann | $daemon_util this-is-an-unimplemented-command >/dev/null 2>&1 && |
59 | 571b34f8 | Michael Hanselmann | err "daemon-util accepted unimplemented command" |
60 | 571b34f8 | Michael Hanselmann | |
61 | 571b34f8 | Michael Hanselmann | $daemon_util list_start_daemons >/dev/null 2>&1 && |
62 | 571b34f8 | Michael Hanselmann | err "daemon-util accepted command with underscores" |
63 | 571b34f8 | Michael Hanselmann | |
64 | 571b34f8 | Michael Hanselmann | $daemon_util check-exitcode 0 || |
65 | 571b34f8 | Michael Hanselmann | err "check-exitcode 0 failed" |
66 | 571b34f8 | Michael Hanselmann | |
67 | 571b34f8 | Michael Hanselmann | for i in 1 2 3 4 20 25 33; do |
68 | 571b34f8 | Michael Hanselmann | $daemon_util check-exitcode $i >/dev/null 2>&1 && rc=0 || rc=$? |
69 | 571b34f8 | Michael Hanselmann | test "$rc" == 1 || err "check-exitcode $i didn't return 1" |
70 | 571b34f8 | Michael Hanselmann | done |
71 | 571b34f8 | Michael Hanselmann | |
72 | 571b34f8 | Michael Hanselmann | $daemon_util check-exitcode 11 >/dev/null 2>&1 || |
73 | 571b34f8 | Michael Hanselmann | err "check-exitcode 11 (not master) didn't return 0" |
74 | 571b34f8 | Michael Hanselmann | |
75 | 571b34f8 | Michael Hanselmann | tmp=$(echo $($daemon_util list-start-daemons)) |
76 | 0f63f1f9 | Iustin Pop | test "$tmp" == "$DAEMONS" || |
77 | 571b34f8 | Michael Hanselmann | err "list-start-daemons didn't return correct list of daemons" |
78 | 571b34f8 | Michael Hanselmann | |
79 | 571b34f8 | Michael Hanselmann | tmp=$(echo $($daemon_util list-stop-daemons)) |
80 | 0f63f1f9 | Iustin Pop | test "$tmp" == "$STOPDAEMONS" || |
81 | 571b34f8 | Michael Hanselmann | err "list-stop-daemons didn't return correct list of daemons" |
82 | 571b34f8 | Michael Hanselmann | |
83 | 571b34f8 | Michael Hanselmann | $daemon_util is-daemon-name >/dev/null 2>&1 && |
84 | 571b34f8 | Michael Hanselmann | err "is-daemon-name didn't require daemon name" |
85 | 571b34f8 | Michael Hanselmann | |
86 | 571b34f8 | Michael Hanselmann | for i in '' '.' '..' '-' 'not-a-daemon'; do |
87 | 571b34f8 | Michael Hanselmann | $daemon_util is-daemon-name "$i" >/dev/null 2>&1 && |
88 | 571b34f8 | Michael Hanselmann | err "is-daemon-name thinks '$i' is a daemon name" |
89 | 571b34f8 | Michael Hanselmann | done |
90 | 571b34f8 | Michael Hanselmann | |
91 | 0f63f1f9 | Iustin Pop | for i in $DAEMONS; do |
92 | 571b34f8 | Michael Hanselmann | $daemon_util is-daemon-name $i >/dev/null 2>&1 || |
93 | 571b34f8 | Michael Hanselmann | err "is-daemon-name doesn't think '$i' is a daemon name" |
94 | 571b34f8 | Michael Hanselmann | done |