daemon-util_unittest.bash 2.85 KB
Newer Older
1 2 3
#!/bin/bash
#

4
# Copyright (C) 2010, 2011 Google Inc.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.

set -e

daemon_util=daemons/daemon-util

err() {
  echo "$@"
  echo 'Aborting'
  exit 1
}

31 32 33 34
if ! grep -q '^ENABLE_CONFD = ' lib/_autoconf.py; then
  err "Please update $0, confd enable feature is missing"
fi

35 36 37 38 39 40 41
if ! grep -q '^ENABLE_MOND = ' lib/_autoconf.py; then
  err "Please update $0, mond enable feature is missing"
fi

DAEMONS_LIST="noded masterd rapi"
STOPDAEMONS_LIST="rapi masterd noded"

42
if grep -q '^ENABLE_CONFD = True' lib/_autoconf.py; then
Thomas Thrainer's avatar
Thomas Thrainer committed
43 44
  DAEMONS_LIST="$DAEMONS_LIST confd luxid"
  STOPDAEMONS_LIST="luxid confd $STOPDAEMONS_LIST"
45 46
fi

47 48 49 50 51 52 53 54
if grep -q '^ENABLE_MOND = True' lib/_autoconf.py; then
  DAEMONS_LIST="$DAEMONS_LIST mond"
  STOPDAEMONS_LIST="mond $STOPDAEMONS_LIST"
fi

DAEMONS=$(echo $(for d in $DAEMONS_LIST; do echo "ganeti-$d"; done))
STOPDAEMONS=$(echo $(for d in $STOPDAEMONS_LIST; do echo "ganeti-$d"; done))

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
$daemon_util >/dev/null 2>&1 &&
  err "daemon-util succeeded without command"

$daemon_util this-is-an-unimplemented-command >/dev/null 2>&1 &&
  err "daemon-util accepted unimplemented command"

$daemon_util list_start_daemons >/dev/null 2>&1 &&
  err "daemon-util accepted command with underscores"

$daemon_util check-exitcode 0 ||
  err "check-exitcode 0 failed"

for i in 1 2 3 4 20 25 33; do
  $daemon_util check-exitcode $i >/dev/null 2>&1 && rc=0 || rc=$?
  test "$rc" == 1 || err "check-exitcode $i didn't return 1"
done

$daemon_util check-exitcode 11 >/dev/null 2>&1 ||
  err "check-exitcode 11 (not master) didn't return 0"

tmp=$(echo $($daemon_util list-start-daemons))
76
test "$tmp" == "$DAEMONS" ||
77 78 79
  err "list-start-daemons didn't return correct list of daemons"

tmp=$(echo $($daemon_util list-stop-daemons))
80
test "$tmp" == "$STOPDAEMONS" ||
81 82 83 84 85 86 87 88 89 90
  err "list-stop-daemons didn't return correct list of daemons"

$daemon_util is-daemon-name >/dev/null 2>&1 &&
  err "is-daemon-name didn't require daemon name"

for i in '' '.' '..' '-' 'not-a-daemon'; do
  $daemon_util is-daemon-name "$i" >/dev/null 2>&1 &&
    err "is-daemon-name thinks '$i' is a daemon name"
done

91
for i in $DAEMONS; do
92 93 94
  $daemon_util is-daemon-name $i >/dev/null 2>&1 ||
    err "is-daemon-name doesn't think '$i' is a daemon name"
done