3 # Copyright (C) 2012 Google Inc.
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.
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.
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
20 # This is an offline testing script for most/all of the htools
21 # programs, checking basic command line functionality.
25 . $(dirname $0)/cli-tests-defs.sh
30 echo Using $T as temporary dir
32 echo Checking command line basic options
33 for prog in $ALL_ROLES; do
34 $prog --version >/dev/null
35 $prog --help >/dev/null
36 ! $prog --no-such-option 2>/dev/null
40 echo Checking missing backend failure
41 for prog in hspace hinfo hbal; do
46 echo Checking hail missing input file
50 echo Checking extra arguments
51 for prog in hspace hbal hinfo; do
52 ! $prog unexpected-argument 2>&1 | \
53 grep -q "Error: this program doesn't take any arguments"
57 echo Checking failure on multiple backends
58 (! hbal -t /dev/null -m localhost 2>&1 ) | \
59 grep -q "Error: Only one of the rapi, luxi, and data files options should be given."
62 echo Checking hspace machine-readable mode
63 hspace --simu p,4,8T,64g,16 --machine-readable \
64 --disk-template drbd -l 8 >$T/capacity
65 ( . $T/capacity && test "$HTS_OK" = "1" )
68 echo Checking hspace simulation to hinfo to hbal
69 # this cluster spec should be fine
70 hspace --simu p,4,8T,64g,16 -S $T/simu-onegroup \
71 --disk-template drbd -l 8 -v -v -v >/dev/null 2>&1
72 # results in .tiered and .standard
73 for suffix in standard tiered; do
74 BACKEND="-t$T/simu-onegroup.$suffix"
75 hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
76 hbal -v -v -p --print-instances $BACKEND >/dev/null 2>&1
77 # hbal should not be able to balance
78 hbal $BACKEND | grep -qE "(Nothing to do, exiting|No solution found)"
82 echo Checking hinfo and hbal on multi-nodegroup
83 hspace --simu p,4,8T,64g,16 --simu p,4,8T,64g,16 \
84 -S $T/simu-twogroups --disk-template drbd -l 8 >/dev/null 2>&1
85 # results in .tiered and .standard
86 for suffix in standard tiered; do
87 BACKEND="-t$T/simu-twogroups.$suffix"
88 hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
89 ! hbal $BACKEND >/dev/null 2>&1
90 # hbal should not be able to balance
91 ! hbal $BACKEND 2>&1 | grep -q "Found multiple node groups"
92 # but hbal should be able to balance one node group
93 hbal $BACKEND -G group-01 >/dev/null
94 # and it should not find an invalid group
95 ! hbal $BACKEND -G no-such-group >/dev/null 2>&1
99 echo Checking rebalancing
100 # we generate a cluster with two node groups, one with unallocable
101 # policy, then we change all nodes from this group to the allocable
102 # one, and we check for rebalancing
103 FROOT="$T/simu-rebal-orig"
104 hspace --simu u,4,8T,64g,16 --simu p,4,8T,64g,16 \
105 -S $FROOT --disk-template drbd -l 8 >/dev/null 2>&1
106 for suffix in standard tiered; do
107 RELOC="$T/simu-rebal-merged.$suffix"
108 # this relocates the nodes
109 sed -re 's/^(node-.*|fake-uuid-)-02(|.*)/\1-01\2/' \
110 < $FROOT.$suffix > $RELOC
112 hinfo -v -v -p --print-instances $BACKEND >/dev/null 2>&1
113 hbal -v -v -v -p --print-instances $BACKEND -G group-01 2>/dev/null | \
114 grep -qE -v "(Nothing to do, exiting|No solution found)"
115 hbal $BACKEND -G group-01 -C$T/rebal-cmds.$suffix \
116 -S $T/simu-rebal.$suffix >/dev/null 2>&1
117 grep -qE "gnt-instance (failover|migrate|replace-disks)" \
118 $T/rebal-cmds.$suffix
119 hbal $BACKEND -G group-01 -C \
120 -S $T/simu-rebal.$suffix 2>/dev/null | \
121 grep -qE "gnt-instance (failover|migrate|replace-disks)"
122 # state saved by hbal should be original
123 cmp $RELOC $T/simu-rebal.$suffix.original
124 # and we can't double rebalance
125 hbal -t $T/simu-rebal.$suffix.balanced \
127 grep -qE "(Nothing to do, exiting|No solution found)"
132 echo IAllocator checks
133 # test that on invalid files it can't parse the request
134 ! hail /dev/null 2>&1 | grep -q "Invalid JSON"
135 ! hail <(echo '[]') >/dev/null 2>&1
136 ! hail <(echo '{}') 2>&1 | grep -q "key 'request' not found"
137 ! hail <(echo '{"request": 0}') 2>&1 | grep -q "key 'request'"
138 ! hail $TESTDATA_DIR/hail-invalid-reloc.json >/dev/null 2>&1
140 # just test that it can read the file, print the cluster and generate
141 # pre and post allocation files
142 hail -v -v -v -p $TESTDATA_DIR/hail-alloc-drbd.json \
143 -S $T/hail-alloc >/dev/null 2>&1
144 ! cmp -s $T/hail-alloc.pre-ialloc $T/hail-alloc.post-ialloc
145 hail -v -v -v -p $TESTDATA_DIR/hail-reloc-drbd.json \
146 -S $T/hail-reloc >/dev/null 2>&1
147 ! cmp -s $T/hail-reloc.pre-ialloc $T/hail-reloc.post-ialloc
149 # and now start the real tests
150 hail $TESTDATA_DIR/hail-alloc-drbd.json | \
151 grep -q '"success":true,.*,"result":\["node2","node1"\]'
152 hail $TESTDATA_DIR/hail-reloc-drbd.json | \
153 grep -q '"success":true,.*,"result":\["node1"\]'
155 hail $TESTDATA_DIR/hail-node-evac.json | \
156 grep -Fq '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
158 hail $TESTDATA_DIR/hail-change-group.json | \
159 grep -Fq '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
161 for evac_mode in primary-only secondary-only all; do
162 sed -e 's/"evac_mode": "all"/"evac_mode": "'${evac_mode}'"/' \
163 < $TESTDATA_DIR/hail-node-evac.json \
164 > $T/hail-node-evac.json.$evac_mode
165 hail $T/hail-node-evac.json.$evac_mode | \
166 grep -q '"success":true,"info":"Request successful: 0 instances failed to move and 1 were moved successfully"'
169 # check that hail can use the simu and text backends
170 hail --simu p,8,8T,16g,16 $TESTDATA_DIR/hail-alloc-drbd.json | \
171 grep -q '"success":true,'
172 hail -t $T/simu-rebal-merged.standard $TESTDATA_DIR/hail-alloc-drbd.json | \
173 grep -q '"success":true,'
176 echo Checking file-based RAPI
178 URL="file://$TESTDATA_DIR/rapi"
179 hinfo -v -v -p --print-instances -m $URL >/dev/null 2>&1
180 hbal -v -v -p --print-instances -m $URL >/dev/null 2>&1
181 hscan -d $T/hscan/ -p -v -v $URL >/dev/null 2>&1
182 # check that we file parsing is correct, i.e. hscan saves correct text
183 # files, and is idempotent (rapi+text == rapi)
184 HS="$(ls $T/hscan/*.data|head -n1)"
185 hinfo -p --print-instances -m $URL > $T/hscan/direct.hinfo 2>&1
186 hinfo -p --print-instances -t $HS > $T/hscan/fromtext.hinfo 2>&1
187 cmp -s $T/hscan/direct.hinfo $T/hscan/fromtext.hinfo