Statistics
| Branch: | Tag: | Revision:

root / test / py / daemon-util_unittest.bash @ 595149d5

History | View | Annotate | Download (2.5 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 0f63f1f9 Iustin Pop
if ! grep -q '^ENABLE_CONFD = ' lib/_autoconf.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 0f63f1f9 Iustin Pop
if grep -q '^ENABLE_CONFD = True' lib/_autoconf.py; then
36 0f63f1f9 Iustin Pop
  DAEMONS="$(echo ganeti-{noded,masterd,rapi,confd})"
37 0f63f1f9 Iustin Pop
  STOPDAEMONS="$(echo ganeti-{confd,rapi,masterd,noded})"
38 0f63f1f9 Iustin Pop
else
39 0f63f1f9 Iustin Pop
  DAEMONS="$(echo ganeti-{noded,masterd,rapi})"
40 0f63f1f9 Iustin Pop
  STOPDAEMONS="$(echo ganeti-{rapi,masterd,noded})"
41 0f63f1f9 Iustin Pop
fi
42 0f63f1f9 Iustin Pop
43 571b34f8 Michael Hanselmann
$daemon_util >/dev/null 2>&1 &&
44 571b34f8 Michael Hanselmann
  err "daemon-util succeeded without command"
45 571b34f8 Michael Hanselmann
46 571b34f8 Michael Hanselmann
$daemon_util this-is-an-unimplemented-command >/dev/null 2>&1 &&
47 571b34f8 Michael Hanselmann
  err "daemon-util accepted unimplemented command"
48 571b34f8 Michael Hanselmann
49 571b34f8 Michael Hanselmann
$daemon_util list_start_daemons >/dev/null 2>&1 &&
50 571b34f8 Michael Hanselmann
  err "daemon-util accepted command with underscores"
51 571b34f8 Michael Hanselmann
52 571b34f8 Michael Hanselmann
$daemon_util check-exitcode 0 ||
53 571b34f8 Michael Hanselmann
  err "check-exitcode 0 failed"
54 571b34f8 Michael Hanselmann
55 571b34f8 Michael Hanselmann
for i in 1 2 3 4 20 25 33; do
56 571b34f8 Michael Hanselmann
  $daemon_util check-exitcode $i >/dev/null 2>&1 && rc=0 || rc=$?
57 571b34f8 Michael Hanselmann
  test "$rc" == 1 || err "check-exitcode $i didn't return 1"
58 571b34f8 Michael Hanselmann
done
59 571b34f8 Michael Hanselmann
60 571b34f8 Michael Hanselmann
$daemon_util check-exitcode 11 >/dev/null 2>&1 ||
61 571b34f8 Michael Hanselmann
  err "check-exitcode 11 (not master) didn't return 0"
62 571b34f8 Michael Hanselmann
63 571b34f8 Michael Hanselmann
tmp=$(echo $($daemon_util list-start-daemons))
64 0f63f1f9 Iustin Pop
test "$tmp" == "$DAEMONS" ||
65 571b34f8 Michael Hanselmann
  err "list-start-daemons didn't return correct list of daemons"
66 571b34f8 Michael Hanselmann
67 571b34f8 Michael Hanselmann
tmp=$(echo $($daemon_util list-stop-daemons))
68 0f63f1f9 Iustin Pop
test "$tmp" == "$STOPDAEMONS" ||
69 571b34f8 Michael Hanselmann
  err "list-stop-daemons didn't return correct list of daemons"
70 571b34f8 Michael Hanselmann
71 571b34f8 Michael Hanselmann
$daemon_util is-daemon-name >/dev/null 2>&1 &&
72 571b34f8 Michael Hanselmann
  err "is-daemon-name didn't require daemon name"
73 571b34f8 Michael Hanselmann
74 571b34f8 Michael Hanselmann
for i in '' '.' '..' '-' 'not-a-daemon'; do
75 571b34f8 Michael Hanselmann
  $daemon_util is-daemon-name "$i" >/dev/null 2>&1 &&
76 571b34f8 Michael Hanselmann
    err "is-daemon-name thinks '$i' is a daemon name"
77 571b34f8 Michael Hanselmann
done
78 571b34f8 Michael Hanselmann
79 0f63f1f9 Iustin Pop
for i in $DAEMONS; do
80 571b34f8 Michael Hanselmann
  $daemon_util is-daemon-name $i >/dev/null 2>&1 ||
81 571b34f8 Michael Hanselmann
    err "is-daemon-name doesn't think '$i' is a daemon name"
82 571b34f8 Michael Hanselmann
done