Statistics
| Branch: | Tag: | Revision:

root / htools / offline-test.sh @ 8d616d4d

History | View | Annotate | Download (7.7 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2012 Google Inc.
4

    
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9

    
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14

    
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

    
20
# This is an offline testing script for most/all of the htools
21
# programs, checking basic command line functionality.
22

    
23
set -e
24
set -o pipefail
25

    
26
. $(dirname $0)/cli-tests-defs.sh
27

    
28
T=`mktemp -d`
29
trap 'rm -rf $T' EXIT
30
trap 'echo FAIL' ERR
31
echo Using $T as temporary dir
32

    
33
echo Checking command line basic options
34
for prog in $ALL_ROLES; do
35
  $prog --version >/dev/null
36
  $prog --help >/dev/null
37
  ! $prog --no-such-option 2>/dev/null
38
done
39
echo OK
40

    
41
echo Checking missing backend failure
42
for prog in hspace hinfo hbal; do
43
  ! $prog 2>/dev/null
44
done
45
echo OK
46

    
47
echo Checking hail missing input file
48
! hail 2>/dev/null
49
echo OK
50

    
51
echo Checking extra arguments
52
for prog in hspace hbal hinfo; do
53
  (! $prog unexpected-argument 2>&1 ) | \
54
    grep -q "Error: this program doesn't take any arguments"
55
done
56
echo OK
57

    
58
echo Checking failure on multiple backends
59
(! hbal -t /dev/null -m localhost 2>&1 ) | \
60
  grep -q "Error: Only one of the rapi, luxi, and data files options should be given."
61
echo OK
62

    
63
echo Checking hspace machine-readable mode
64
hspace --simu p,4,8T,64g,16 --machine-readable \
65
  --disk-template drbd -l 8 >$T/capacity
66
( . $T/capacity && test "$HTS_OK" = "1" )
67
echo OK
68

    
69
echo Checking hspace simulation to hinfo to hbal
70
# this cluster spec should be fine
71
hspace --simu p,4,8T,64g,16 -S $T/simu-onegroup \
72
  --disk-template drbd -l 8 -v -v -v >/dev/null 2>&1
73
# results in .tiered and .standard
74
for suffix in standard tiered; do
75
  BACKEND="-t$T/simu-onegroup.$suffix"
76
  hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
77
  hbal  -v -v -p --print-instances $BACKEND >/dev/null 2>&1
78
  # hbal should not be able to balance
79
  hbal $BACKEND | grep -qE "(Nothing to do, exiting|No solution found)"
80
done
81
echo OK
82

    
83
echo Checking hinfo and hbal on multi-nodegroup
84
hspace --simu p,4,8T,64g,16 --simu p,4,8T,64g,16 \
85
  -S $T/simu-twogroups --disk-template drbd -l 8 >/dev/null 2>&1
86
# results in .tiered and .standard
87
for suffix in standard tiered; do
88
  BACKEND="-t$T/simu-twogroups.$suffix"
89
  hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
90
  ! hbal $BACKEND >/dev/null 2>&1
91
  # hbal should not be able to balance
92
  ! hbal $BACKEND 2>&1 | grep -q "Found multiple node groups"
93
  # but hbal should be able to balance one node group
94
  hbal $BACKEND -G group-01 >/dev/null
95
  # and it should not find an invalid group
96
  ! hbal $BACKEND -G no-such-group >/dev/null 2>&1
97
done
98
echo OK
99

    
100
echo Checking rebalancing
101
# we generate a cluster with two node groups, one with unallocable
102
# policy, then we change all nodes from this group to the allocable
103
# one, and we check for rebalancing
104
FROOT="$T/simu-rebal-orig"
105
hspace --simu u,4,8T,64g,16 --simu p,4,8T,64g,16 \
106
  -S $FROOT --disk-template drbd -l 8 >/dev/null 2>&1
107
for suffix in standard tiered; do
108
  RELOC="$T/simu-rebal-merged.$suffix"
109
  # this relocates the nodes
110
  sed -re 's/^(node-.*|fake-uuid-)-02(|.*)/\1-01\2/' \
111
    < $FROOT.$suffix > $RELOC
112
  BACKEND="-t$RELOC"
113
  hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
114
  hbal -v -v -v -p --print-instances $BACKEND -G group-01 2>/dev/null | \
115
    grep -qE -v "(Nothing to do, exiting|No solution found)"
116
  hbal $BACKEND -G group-01 -C$T/rebal-cmds.$suffix \
117
    -S $T/simu-rebal.$suffix >/dev/null 2>&1
118
  grep -qE "gnt-instance (failover|migrate|replace-disks)" \
119
    $T/rebal-cmds.$suffix
120
  hbal $BACKEND -G group-01 -C \
121
    -S $T/simu-rebal.$suffix 2>/dev/null | \
122
    grep -qE "gnt-instance (failover|migrate|replace-disks)"
123
  # state saved by hbal should be original
124
  cmp $RELOC $T/simu-rebal.$suffix.original
125
  # and we can't double rebalance
126
  hbal -t $T/simu-rebal.$suffix.balanced \
127
    -G group-01 | \
128
    grep -qE "(Nothing to do, exiting|No solution found)"
129

    
130
done
131
echo OK
132

    
133
echo Checking utilisation-based code
134
BACKEND="-t $T/simu-onegroup.standard"
135
echo a > $T/dynu
136
(! hbal -U <(echo a) $BACKEND  2>&1 ) | grep -q "Cannot parse line"
137
(! hbal -U <(echo a b c d e f g h) $BACKEND 2>&1 ) | \
138
  grep -q "Cannot parse line"
139
(! hbal -U <(echo inst cpu mem dsk net) $BACKEND 2>&1 ) | \
140
  grep -Eq "cannot parse string '(cpu|mem|dsk|net)'"
141
# unknown instances are currently just ignored
142
hbal -U <(echo no-such-inst 2 2 2 2) $BACKEND >/dev/null 2>&1
143
# new-0 is the name of the first instance allocated by hspace
144
hbal -U <(echo new-0 2 2 2 2) $BACKEND >/dev/null 2>&1
145
echo OK
146

    
147
echo Checking selected/excluded instances
148
(! hbal $BACKEND --exclude-instances no-such-instance 2>&1 ) | \
149
  grep -q "Unknown instance"
150
(! hbal $BACKEND --select-instances no-such-instances 2>&1 ) | \
151
  grep -q "Unknown instance"
152
hbal $BACKEND --exclude-instances new-0 --select-instances new-1 >/dev/null
153
echo OK
154

    
155
echo IAllocator checks
156
# test that on invalid files it can't parse the request
157
(! hail /dev/null 2>&1 ) | grep -q "Invalid JSON"
158
! hail <(echo '[]') >/dev/null 2>&1
159
(! hail <(echo '{}') 2>&1 ) | grep -q "key 'request' not found"
160
(! hail <(echo '{"request": 0}') 2>&1 ) | grep -q "key 'request'"
161
! hail $TESTDATA_DIR/hail-invalid-reloc.json >/dev/null 2>&1
162

    
163
# just test that it can read the file, print the cluster and generate
164
# pre and post allocation files
165
hail -v -v -v -p $TESTDATA_DIR/hail-alloc-drbd.json \
166
  -S $T/hail-alloc >/dev/null 2>&1
167
! cmp -s $T/hail-alloc.pre-ialloc $T/hail-alloc.post-ialloc
168
hail -v -v -v -p $TESTDATA_DIR/hail-reloc-drbd.json \
169
  -S $T/hail-reloc >/dev/null 2>&1
170
! cmp -s $T/hail-reloc.pre-ialloc $T/hail-reloc.post-ialloc
171

    
172
# and now start the real tests
173
hail $TESTDATA_DIR/hail-alloc-drbd.json | \
174
  grep -q '"success":true,.*,"result":\["node2","node1"\]'
175
hail $TESTDATA_DIR/hail-reloc-drbd.json | \
176
  grep -q '"success":true,.*,"result":\["node1"\]'
177

    
178
hail $TESTDATA_DIR/hail-node-evac.json | \
179
  grep -Fq '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
180

    
181
hail $TESTDATA_DIR/hail-change-group.json | \
182
  grep -Fq '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
183

    
184
for evac_mode in primary-only secondary-only all; do
185
  sed -e 's/"evac_mode": "all"/"evac_mode": "'${evac_mode}'"/' \
186
    < $TESTDATA_DIR/hail-node-evac.json \
187
    > $T/hail-node-evac.json.$evac_mode
188
  hail $T/hail-node-evac.json.$evac_mode | \
189
    grep -q '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
190
done
191

    
192
# check that hail can use the simu and text backends
193
hail --simu p,8,8T,16g,16 $TESTDATA_DIR/hail-alloc-drbd.json | \
194
  grep -q '"success":true,'
195
hail -t $T/simu-rebal-merged.standard $TESTDATA_DIR/hail-alloc-drbd.json | \
196
  grep -q '"success":true,'
197
echo OK
198

    
199
echo Checking file-based RAPI
200
mkdir -p $T/hscan
201
URL="file://$TESTDATA_DIR/rapi"
202
hinfo -v -v -p --print-instances -m $URL >/dev/null 2>&1
203
hbal -v -v -p --print-instances -m $URL >/dev/null 2>&1
204
hscan -d $T/hscan/ -p -v -v $URL >/dev/null 2>&1
205
# check that we file parsing is correct, i.e. hscan saves correct text
206
# files, and is idempotent (rapi+text == rapi)
207
HS="$(ls $T/hscan/*.data|head -n1)"
208
hinfo -p --print-instances -m $URL > $T/hscan/direct.hinfo 2>&1
209
hinfo -p --print-instances -t $HS  > $T/hscan/fromtext.hinfo 2>&1
210
cmp -s $T/hscan/direct.hinfo $T/hscan/fromtext.hinfo
211
echo OK
212

    
213
echo All OK