| 1 | #!/bin/bash |
|---|
| 2 | # vim: set fileencoding=utf-8 |
|---|
| 3 | # |
|---|
| 4 | # Copyright (C) 2010 Loic Dachary <loic@dachary.org> |
|---|
| 5 | # Copyright (C) 2009 Maxence Dunnewind <maxence@dunnewind.net> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software: you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 19 | |
|---|
| 20 | VERIFY_CACHE=${VERIFY_CACHE:-/tmp/gnt-verify} |
|---|
| 21 | TESTING=${TESTING:-false} |
|---|
| 22 | |
|---|
| 23 | if ! $TESTING |
|---|
| 24 | then |
|---|
| 25 | if [ $# -lt 1 ];then |
|---|
| 26 | echo "Use: $0 <node-name>" |
|---|
| 27 | exit 3 |
|---|
| 28 | fi |
|---|
| 29 | |
|---|
| 30 | NODE=$1 |
|---|
| 31 | |
|---|
| 32 | if ! gnt-node list -o name "$NODE" > /dev/null |
|---|
| 33 | then |
|---|
| 34 | echo "Node $NODE does not exist." |
|---|
| 35 | exit 1 |
|---|
| 36 | fi |
|---|
| 37 | |
|---|
| 38 | if [ ! -f $VERIFY_CACHE ] || find $VERIFY_CACHE -mmin +60 | grep $VERIFY_CACHE |
|---|
| 39 | then |
|---|
| 40 | gnt-cluster verify > $VERIFY_CACHE |
|---|
| 41 | fi |
|---|
| 42 | |
|---|
| 43 | ERR=$(grep "$NODE: not enough memory" < $VERIFY_CACHE) |
|---|
| 44 | if [ "$ERR" = "" ];then |
|---|
| 45 | echo "$NODE has enough memory to failover all instances" |
|---|
| 46 | exit 0 |
|---|
| 47 | else |
|---|
| 48 | echo $ERR |
|---|
| 49 | exit 2 |
|---|
| 50 | fi |
|---|
| 51 | else |
|---|
| 52 | set -xe |
|---|
| 53 | unset TESTING |
|---|
| 54 | test $(hostname --fqdn) = $(gnt-cluster getmaster) |
|---|
| 55 | # argument sanity check |
|---|
| 56 | $0 | grep Use: |
|---|
| 57 | if $0 |
|---|
| 58 | then |
|---|
| 59 | false |
|---|
| 60 | else |
|---|
| 61 | test $? = 3 |
|---|
| 62 | fi |
|---|
| 63 | # node existence sanity check |
|---|
| 64 | if $0 fakenode |
|---|
| 65 | then |
|---|
| 66 | false |
|---|
| 67 | else |
|---|
| 68 | test $? = 1 |
|---|
| 69 | fi |
|---|
| 70 | export VERIFY_CACHE=/tmp/test-check-ganeti |
|---|
| 71 | # simulate an error |
|---|
| 72 | echo ERROR: node $(hostname --fqdn): not enough memory on to accommodate failovers should peer node OTHERNODE fail > $VERIFY_CACHE |
|---|
| 73 | if $0 $(hostname --fqdn) |
|---|
| 74 | then |
|---|
| 75 | false |
|---|
| 76 | else |
|---|
| 77 | test $? = 2 |
|---|
| 78 | fi |
|---|
| 79 | # simulate success |
|---|
| 80 | > $VERIFY_CACHE |
|---|
| 81 | $0 $(hostname --fqdn) |
|---|
| 82 | # create cluster verify cache file |
|---|
| 83 | rm -f $VERIFY_CACHE |
|---|
| 84 | $0 $(hostname --fqdn) || true # not interested by the actual state of the cluster |
|---|
| 85 | test -f $VERIFY_CACHE |
|---|
| 86 | # refresh an old verify cache file |
|---|
| 87 | > $VERIFY_CACHE |
|---|
| 88 | touch -t 198001020304 $VERIFY_CACHE |
|---|
| 89 | $0 $(hostname --fqdn) || true # not interested by the actual state of the cluster |
|---|
| 90 | test -s $VERIFY_CACHE |
|---|
| 91 | echo DONE |
|---|
| 92 | fi |
|---|
| 93 | # Interpreted by emacs |
|---|
| 94 | # Local Variables: |
|---|
| 95 | # compile-command: "TESTING=true check_ganeti" |
|---|
| 96 | # End: |
|---|