Statistics
| Branch: | Tag: | Revision:

root / test / daemon-util_unittest.bash @ 415feb2e

History | View | Annotate | Download (2.5 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_CONFD = True' lib/_autoconf.py; then
36
  DAEMONS="$(echo ganeti-{noded,masterd,rapi,confd})"
37
  STOPDAEMONS="$(echo ganeti-{confd,rapi,masterd,noded})"
38
else
39
  DAEMONS="$(echo ganeti-{noded,masterd,rapi})"
40
  STOPDAEMONS="$(echo ganeti-{rapi,masterd,noded})"
41
fi
42

    
43
$daemon_util >/dev/null 2>&1 &&
44
  err "daemon-util succeeded without command"
45

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

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

    
52
$daemon_util check-exitcode 0 ||
53
  err "check-exitcode 0 failed"
54

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

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

    
63
tmp=$(echo $($daemon_util list-start-daemons))
64
test "$tmp" == "$DAEMONS" ||
65
  err "list-start-daemons didn't return correct list of daemons"
66

    
67
tmp=$(echo $($daemon_util list-stop-daemons))
68
test "$tmp" == "$STOPDAEMONS" ||
69
  err "list-stop-daemons didn't return correct list of daemons"
70

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

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

    
79
for i in $DAEMONS; do
80
  $daemon_util is-daemon-name $i >/dev/null 2>&1 ||
81
    err "is-daemon-name doesn't think '$i' is a daemon name"
82
done