Statistics
| Branch: | Tag: | Revision:

root / test / py / daemon-util_unittest.bash @ 13cc7b84

History | View | Annotate | Download (2.8 kB)

1
#!/bin/bash
2
#
3

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

    
21
set -e
22

    
23
daemon_util=daemons/daemon-util
24

    
25
err() {
26
  echo "$@"
27
  echo 'Aborting'
28
  exit 1
29
}
30

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

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

    
39
DAEMONS_LIST="noded masterd rapi"
40
STOPDAEMONS_LIST="rapi masterd noded"
41

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

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

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

    
55
$daemon_util >/dev/null 2>&1 &&
56
  err "daemon-util succeeded without command"
57

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

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

    
64
$daemon_util check-exitcode 0 ||
65
  err "check-exitcode 0 failed"
66

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

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

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

    
79
tmp=$(echo $($daemon_util list-stop-daemons))
80
test "$tmp" == "$STOPDAEMONS" ||
81
  err "list-stop-daemons didn't return correct list of daemons"
82

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

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

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